xp_comm_proj/nstats/node_stats.c
/*-node_sum---------------------------------------------------------------------
 *  Description: Returns a vector representing the sums of node values
 *   Parameters: field    the field of nodes
 *               i        component index for analysis
 * Return Value: the vector or null (failure)
 */
node_sum
Description: Returns a vector representing the sums of node values
Parameters: field    the field of nodes
i        component index for analysis
Return Value: the vector or null (failure)
node_sum Description : Returns a vector representing the sums of node values Parameters : field the field of nodes i component index for analysis Return Value : the vector or null ( failure )
double *
node_sum(FIELD *field, int i)
{
  double *sum;
  sum = (double *)calloc(field->veclen[i], sizeof(double));
  if (sum)
    {
      switch (field->data_type[i])
	{
	  int k, j, i2c;
	  unsigned char *charPtr;
	  short *shortPtr;
	  int *intPtr;
	  float *floatPtr;
	  double *dblPtr;
	case DTYPE_CHAR:
	case DTYPE_BYTE:
	  charPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  i2c = *charPtr++;
		  sum[k] += i2c;
		}
	    }
	  break;
	case DTYPE_SHORT:
          shortPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  sum[k] += *shortPtr++;
		}
	    }
	  break;  
	case DTYPE_INT:
          intPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  sum[k] += *intPtr++;
		}
	    }
	  break;  
	case DTYPE_FLOAT:
          floatPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
		for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  sum[k] += *floatPtr++;
		}
	    }
	  break;  
	case DTYPE_DOUBLE:
 	  dblPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  sum[k] += *dblPtr++;
		}
	    }
	  break;  
	default:
	  free(sum);
	  return NULL;
	  break;
	}
    }
  return sum;
}
double * node_sum ( FIELD * field , int i ) { double * sum ; sum = ( double * ) calloc ( field -> veclen [ i ] , sizeof ( double ) ) ; if ( sum ) { switch ( field -> data_type [ i ] ) { int k , j , i2c ; unsigned char * charPtr ; short * shortPtr ; int * intPtr ; float * floatPtr ; double * dblPtr ; case DTYPE_CHAR : case DTYPE_BYTE : charPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { i2c = * charPtr ++ ; sum [ k ] += i2c ; } } break ; case DTYPE_SHORT : shortPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { sum [ k ] += * shortPtr ++ ; } } break ; case DTYPE_INT : intPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { sum [ k ] += * intPtr ++ ; } } break ; case DTYPE_FLOAT : floatPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { sum [ k ] += * floatPtr ++ ; } } break ; case DTYPE_DOUBLE : dblPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { sum [ k ] += * dblPtr ++ ; } } break ; default : free ( sum ) ; return NULL ; break ; } } return sum ; }
node_sum
  Description: Returns a vector representing the sums of node values
   Parameters: field    the field of nodes
               i        component index for analysis
 Return Value: the vector or null (failure)
node_sum Description : Returns a vector representing the sums of node values Parameters : field the field of nodes i component index for analysis Return Value : the vector or null ( failure )