xp_comm_proj/nstats/node_stats.c
/*-node_stats-------------------------------------------------------------------
 *  Description: Returns a string of node statistics of a FIELD
 *   Parameters: field                the field
 * Return value: the string/NULL success/failure
 */
node_stats
Description: Returns a string of node statistics of a FIELD
Parameters: field                the field
Return value: the string/NULL success/failure
node_stats Description : Returns a string of node statistics of a FIELD Parameters : field the field Return value : the string / NULL success / failure
char *
node_stats(FIELD *field)
{
  char *stats, tmpStr[128];
  stats = malloc(sizeof(char) * NSTATSLEN);
  if (stats)
    {
      if (field)
	{
	  int i, j;
	  sprintf(stats, "Dimensions: ");
	  for (i = 0;
	       i < field->ndim - 1;
	       i++)
	    {
	      sprintf(tmpStr, "%d x ", field->dims[i]);
	      strcat(stats, tmpStr);
	    }
	  sprintf(tmpStr, "%d\n", field->dims[i]);
	  strcat(stats, tmpStr);
	  sprintf(tmpStr, "No. Nodes: %d\n", field->ndata);
	  strcat(stats, tmpStr);
	  for (i = 0;
	       i < field->ncomp;
	       i++)
	    {
	      double *sum;
	      unsigned int *nonzero;
	      sprintf(tmpStr,
		      "Component #%d\n  Vector Length %d\n",
		      i, field->veclen[i], field->data_type[i] );
	      strcat(stats, tmpStr);
	      switch (field->data_type[i])
		{
		case DTYPE_CHAR:
		  sprintf(tmpStr, "  Data Type: Character\n");
		  break;
		case DTYPE_BYTE:
		  sprintf(tmpStr, "  Data Type: Byte\n");
		  break;  
		case DTYPE_SHORT:
		  sprintf(tmpStr, "  Data Type: Short Integer\n");
		  break;  
		case DTYPE_INT:
		  sprintf(tmpStr, "  Data Type: Integer\n");
		  break;  
		case DTYPE_FLOAT:
		  sprintf(tmpStr, "  Data Type: Single-Precision Float\n");
		  break;  
		case DTYPE_DOUBLE:
		  sprintf(tmpStr, "  Data Type: Double-Precision Float\n");
		  break;  
		default:
		  sprintf(tmpStr, "  Data Type: Other\n");
		}
	      strcat(stats, tmpStr);
	      nonzero = nonzero_node_count(field, i);
	      if (nonzero)
		{
		  strcat(stats, "  No. non-zero nodes: ");
		  sprintf(tmpStr, "(%u", nonzero[0]);
		  strcat(stats, tmpStr);
		  for (j = 1;
		       j < field->veclen[i];
		       j++)
		    {
		      sprintf(tmpStr, ", %u", nonzero[j]);
		      strcat(stats, tmpStr);
		    }
		  strcat(stats, ")\n");
		}
	      free(nonzero);
	      sum = node_sum(field, i);
	      if (sum)
		{
		  strcat(stats, "  Node value sum: ");
		  sprintf(tmpStr, "(%f", sum[0]);
		  strcat(stats, tmpStr);
		  for (j = 1;
		       j < field->veclen[i];
		       j++)
		    {
		      sprintf(tmpStr, ", %f", sum[j]);
		      strcat(stats, tmpStr);
		    }
		  strcat(stats, ")\n");
		}
	      free(sum);
	    }
	}
    }
  else
    {
      set_avs_err("Cannot allocate memory for string.");
    }
  return stats;
}
char * node_stats ( FIELD * field ) { char * stats , tmpStr [ 128 ] ; stats = malloc ( sizeof ( char ) * NSTATSLEN ) ; if ( stats ) { if ( field ) { int i , j ; sprintf ( stats , " " ) ; for ( i = 0 ; i < field -> ndim - 1 ; i ++ ) { sprintf ( tmpStr , " " , field -> dims [ i ] ) ; strcat ( stats , tmpStr ) ; } sprintf ( tmpStr , " \n " , field -> dims [ i ] ) ; strcat ( stats , tmpStr ) ; sprintf ( tmpStr , " \n " , field -> ndata ) ; strcat ( stats , tmpStr ) ; for ( i = 0 ; i < field -> ncomp ; i ++ ) { double * sum ; unsigned int * nonzero ; sprintf ( tmpStr , " \n \n " , i , field -> veclen [ i ] , field -> data_type [ i ] ) ; strcat ( stats , tmpStr ) ; switch ( field -> data_type [ i ] ) { case DTYPE_CHAR : sprintf ( tmpStr , " \n " ) ; break ; case DTYPE_BYTE : sprintf ( tmpStr , " \n " ) ; break ; case DTYPE_SHORT : sprintf ( tmpStr , " \n " ) ; break ; case DTYPE_INT : sprintf ( tmpStr , " \n " ) ; break ; case DTYPE_FLOAT : sprintf ( tmpStr , " \n " ) ; break ; case DTYPE_DOUBLE : sprintf ( tmpStr , " \n " ) ; break ; default : sprintf ( tmpStr , " \n " ) ; } strcat ( stats , tmpStr ) ; nonzero = nonzero_node_count ( field , i ) ; if ( nonzero ) { strcat ( stats , " " ) ; sprintf ( tmpStr , " " , nonzero [ 0 ] ) ; strcat ( stats , tmpStr ) ; for ( j = 1 ; j < field -> veclen [ i ] ; j ++ ) { sprintf ( tmpStr , " " , nonzero [ j ] ) ; strcat ( stats , tmpStr ) ; } strcat ( stats , " \n " ) ; } free ( nonzero ) ; sum = node_sum ( field , i ) ; if ( sum ) { strcat ( stats , " " ) ; sprintf ( tmpStr , " " , sum [ 0 ] ) ; strcat ( stats , tmpStr ) ; for ( j = 1 ; j < field -> veclen [ i ] ; j ++ ) { sprintf ( tmpStr , " " , sum [ j ] ) ; strcat ( stats , tmpStr ) ; } strcat ( stats , " \n " ) ; } free ( sum ) ; } } } else { set_avs_err ( " " ) ; } return stats ; }
node_stats
  Description: Returns a string of node statistics of a FIELD
   Parameters: field                the field
 Return value: the string/NULL success/failure
node_stats Description : Returns a string of node statistics of a FIELD Parameters : field the field Return value : the string / NULL success / failure
/* Allocate space for the string */ /* Count nonzero node values */ /* Sum node values */