xp_comm_proj/nstats/node_stats.c
/*-nonzero_node_count-----------------------------------------------------------
 *  Description: Returns a vector representing the numbers of non-zero nodes
 *   Parameters: field    the field of nodes
 *               i        component index for analysis
 * Return Value: the vector or null (failure)
 */
nonzero_node_count
Description: Returns a vector representing the numbers of non-zero nodes
Parameters: field    the field of nodes
i        component index for analysis
Return Value: the vector or null (failure)
nonzero_node_count Description : Returns a vector representing the numbers of non - zero nodes Parameters : field the field of nodes i component index for analysis Return Value : the vector or null ( failure )
unsigned int *
nonzero_node_count(FIELD *field, int i)
{
  unsigned int *nz;
  nz = (unsigned int *)calloc(field->veclen[i], sizeof(unsigned int));
  if (nz)
    {
      switch (field->data_type[i])
	{
	  int k, j;
	  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++)
		{
		  if (*charPtr++)
		    {
		      nz[k]++;
		    }
		}
	    }
	  break;  
	case DTYPE_SHORT:
	  shortPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  if (*shortPtr++)
		    {
		      nz[k]++;
		    }
		}
	    }
	  break;  
	case DTYPE_INT:
	  intPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  if (*intPtr++)
		    {
		      nz[k]++;
		    }
		}
	    }
	  break;  
	case DTYPE_FLOAT:
	  floatPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  if (*floatPtr++)
		    {
		      nz[k]++;
		    }
		}
	    }
	  break;  
	case DTYPE_DOUBLE:
	  dblPtr = field->data[i];
	  for (j = 0;
	       j < field->ndata;
	       j++)
	    {
	      for (k = 0;
		   k < field->veclen[i];
		   k++)
		{
		  if (*dblPtr++)
		    {
		      nz[k]++;
		    }
		}
	    }
	  break;  
	default:
	  free(nz);
	  return NULL;
	  break;
	}
    }
  return nz;
}
unsigned int * nonzero_node_count ( FIELD * field , int i ) { unsigned int * nz ; nz = ( unsigned int * ) calloc ( field -> veclen [ i ] , sizeof ( unsigned int ) ) ; if ( nz ) { switch ( field -> data_type [ i ] ) { int k , j ; 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 ++ ) { if ( * charPtr ++ ) { nz [ k ] ++ ; } } } break ; case DTYPE_SHORT : shortPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { if ( * shortPtr ++ ) { nz [ k ] ++ ; } } } break ; case DTYPE_INT : intPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { if ( * intPtr ++ ) { nz [ k ] ++ ; } } } break ; case DTYPE_FLOAT : floatPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { if ( * floatPtr ++ ) { nz [ k ] ++ ; } } } break ; case DTYPE_DOUBLE : dblPtr = field -> data [ i ] ; for ( j = 0 ; j < field -> ndata ; j ++ ) { for ( k = 0 ; k < field -> veclen [ i ] ; k ++ ) { if ( * dblPtr ++ ) { nz [ k ] ++ ; } } } break ; default : free ( nz ) ; return NULL ; break ; } } return nz ; }
nonzero_node_count
  Description: Returns a vector representing the numbers of non-zero nodes
   Parameters: field    the field of nodes
               i        component index for analysis
 Return Value: the vector or null (failure)
nonzero_node_count Description : Returns a vector representing the numbers of non - zero nodes Parameters : field the field of nodes i component index for analysis Return Value : the vector or null ( failure )