コード例 #1
0
int put_truth_table(int exoid, int num_blk, int num_var, int varid, int *table, const char *label)
{
  long start[2], count[2]; 
  int  iresult = 0;
  nclong *lptr;
  char errmsg[MAX_ERR_LENGTH];
  
  /* this contortion is necessary because netCDF is expecting nclongs; fortunately
     it's necessary only when ints and nclongs aren't the same size */

  start[0] = 0;
  start[1] = 0;
  
  count[0] = num_blk;
  count[1] = num_var;
    
  if (sizeof(int) == sizeof(nclong)) {
    iresult = ncvarput (exoid, varid, start, count, table);
  } else {
    lptr = itol (table, (int)(num_blk*num_var));
    iresult = ncvarput (exoid, varid, start, count, lptr);
    lptr = static_cast<nclong*>(safe_free(lptr));
  }
    
  if (iresult == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
	    "Error: failed to store %s variable truth table in file id %d",
	    label, exoid);
    ex_err("ex_put_all_var_param",errmsg,exerrval);
   }
  return iresult;
}
コード例 #2
0
ファイル: v2i.c プロジェクト: stcorp/harp
int
ncvarputs(
    int		ncid,
    int		varid,
    const long*	start,
    const long*	count,
    const long*	stride,
    const void*	value
)
{
	if(stride == NULL)
		return ncvarput(ncid, varid, start, count, value);
	/* else */
	{
	NDIMS_DECL
	A_DECL(stp, size_t, ndims, start);
	A_DECL(cntp, size_t, ndims, count);
	A_DECL(strdp, ptrdiff_t, ndims, stride);
	A_INIT(stp, size_t, ndims, start);
	A_INIT(cntp, size_t, ndims, count);
	A_INIT(strdp, ptrdiff_t, ndims, stride);
	{
	const int status = nc_put_vars(ncid, varid, stp, cntp, strdp, value);
	A_FREE(strdp);
	A_FREE(cntp);
	A_FREE(stp);
	if(status != NC_NOERR)
	{
		nc_advise("ncvarputs", status, "ncid %d", ncid);
		return -1;
	}
	}
	return 0;
	}
}
コード例 #3
0
ファイル: minc_compat.c プロジェクト: BIC-MNI/minc
MNCAPI int
MI2varput(int fd, int varid, const long *start_ptr,
          const long *count_ptr, const void *val_ptr)
{
    if (MI2_ISH5OBJ(fd)) {
        return (hdf_varput(fd, varid, start_ptr, count_ptr, val_ptr));
    }
    else {
        return (ncvarput(fd, varid, start_ptr, count_ptr, val_ptr));
    }
}
コード例 #4
0
ファイル: upet2mnc.c プロジェクト: Angel-Fernandez/minc-tools
static void
copy_frame(struct conversion_info *ci_ptr)
{
    long start[5];
    long count[5];
    size_t nitems;

    message(MSG_INFO, "Inserting frame #%d\n", ci_ptr->frame_index);

    /* Actually read the data from the image file.
     */
    nitems = fread(ci_ptr->frame_buffer, ci_ptr->frame_nbytes, 1, 
                   ci_ptr->img_fp);

    if (nitems != 1) {
        message(MSG_FATAL, "Read failed with error %d, return %d\n",
                errno, nitems);
        exit(-1);
    }

    /* Setup the starts and counts for the data block.
     */
    start[DIM_T] = ci_ptr->frame_index - ci_ptr->frame_zero;
    start[DIM_X] = 0;
    start[DIM_Y] = 0;
    start[DIM_Z] = 0;
    start[DIM_W] = 0;
    
    count[DIM_T] = 1;
    count[DIM_X] = ci_ptr->dim_lengths[DIM_X];
    count[DIM_Y] = ci_ptr->dim_lengths[DIM_Y];
    count[DIM_Z] = ci_ptr->dim_lengths[DIM_Z];
    count[DIM_W] = ci_ptr->dim_lengths[DIM_W];

    /* Perform swapping if necessary.
     */
    if (ci_ptr->swap_size != 0) {
      swap_data(ci_ptr->swap_size, ci_ptr->frame_nvoxels, 
                ci_ptr->frame_buffer);
    }

    /* Scale the raw data into the final range.
     */
    scale_data(ci_ptr->minc_type, ci_ptr->frame_nvoxels, ci_ptr->frame_buffer,
               COMBINED_SCALE_FACTOR(ci_ptr));

    /* For now we perform no conversions on the data as it is stored.
     * This may be worth modifying in the future, to allow storage of
     * non-floating-point formats from a typical microPET file.
     */
    ncvarput(ci_ptr->mnc_fd, ncvarid(ci_ptr->mnc_fd, MIimage), start, count, 
             ci_ptr->frame_buffer);
}
コード例 #5
0
ファイル: bloodtonc.c プロジェクト: BIC-MNI/emma
/* ----------------------------- MNI Header -----------------------------------
@NAME       : mivarsetdouble
@INPUT      : file_CDF   -> A handle for the open netCDF file.
              name       -> The name of the variable to place the data in.
              num_values -> The number of values to write.
              values     -> The values to write.
@OUTPUT     : none
@RETURNS    : int        -> The return value of ncvarput.  MI_ERROR if an
                            error occurs.
@DESCRIPTION: Writes doubles to a one dimensional netCDF variable, starting
              at location 0, and continuing for num_values.
@METHOD     : none
@GLOBALS    : none
@CALLS      : netCDF library
@CREATED    : June 4, 1993 by MW
@MODIFIED   :
---------------------------------------------------------------------------- */
int mivarsetdouble (int file_CDF, char *name, long num_values, double values[])
{
    int varid;
    long start[1], length[1];

    varid = ncvarid (file_CDF, name);
    if (varid == MI_ERROR)
    {
        return (MI_ERROR);
    }

    start[0] = 0;
    length[0] = num_values;

    return (ncvarput (file_CDF, varid, start, length, values));
}
コード例 #6
0
ファイル: expnvv.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_put_nodal_varid_var(int   exoid,
                           int   time_step,
                           int   nodal_var_index,
                           int   num_nodes, 
                           int   varid,
                           const void *nodal_var_vals)
{
  long start[3], count[3];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  if (ex_large_model(exoid) == 0) {
    start[0] = --time_step;
    start[1] = --nodal_var_index;
    start[2] = 0;

    count[0] = 1;
    count[1] = 1;
    count[2] = num_nodes;
  } else {
    start[0] = --time_step;
    start[1] = 0;

    count[0] = 1;
    count[1] = num_nodes;
  }

  if (ncvarput (exoid, varid, start, count,
                ex_conv_array(exoid,WRITE_CONVERT,nodal_var_vals,num_nodes)) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to store nodal variables in file id %d",
              exoid);
      ex_err("ex_put_nodal_varid_var",errmsg,exerrval);
      return (EX_FATAL);
    }

  return (EX_NOERR);
}
コード例 #7
0
ファイル: expnmap.c プロジェクト: hs9906/paraview
int ex_put_num_map ( int exoid,
                     int map_type,
                     int map_id,
                     const int *map )
{
   int dimid, varid, iresult;
   long start[1]; 
   nclong ldum, *lptr;
   long num_maps, num_entries, count[1];
   int cur_num_maps;
   char *cdum;
   char errmsg[MAX_ERR_LENGTH];
   const char* tname;
   const char* dnumentries;
   const char* dnummaps;
   const char* vmapids;
   const char* vmap = 0;
   struct list_item** map_ctr_list;

   exerrval = 0; /* clear error code */

   cdum = 0;

   switch ( map_type ) {
   case EX_NODE_MAP:
     tname = "node";
     dnumentries = DIM_NUM_NODES;
     dnummaps = DIM_NUM_NM;
     vmapids = VAR_NM_PROP(1);
     map_ctr_list = &nm_ctr_list;
     break;
   case EX_EDGE_MAP:
     tname = "edge";
     dnumentries = DIM_NUM_EDGE;
     dnummaps = DIM_NUM_EDM;
     vmapids = VAR_EDM_PROP(1);
     map_ctr_list = &edm_ctr_list;
     break;
   case EX_FACE_MAP:
     tname = "face";
     dnumentries = DIM_NUM_FACE;
     dnummaps = DIM_NUM_FAM;
     vmapids = VAR_FAM_PROP(1);
     map_ctr_list = &fam_ctr_list;
     break;
   case EX_ELEM_MAP:
     tname = "element";
     dnumentries = DIM_NUM_ELEM;
     dnummaps = DIM_NUM_EM;
     vmapids = VAR_EM_PROP(1);
     map_ctr_list = &em_ctr_list;
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf( errmsg,
       "Error: Bad map type (%d) specified for file id %d",
       map_type, exoid );
     ex_err( "ex_put_num_map", errmsg, exerrval );
     return (EX_FATAL);
   }

/* Make sure the file contains entries */
   if ((dimid = (ncdimid (exoid, dnumentries))) == -1 )
   {
     return (EX_NOERR);
   }

/* first check if any maps are specified */

   if ((dimid = (ncdimid (exoid, dnummaps))) == -1 )
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: no %s maps specified in file id %d",
             tname,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Check for duplicate map id entry */
   ex_id_lkup(exoid,vmapids,map_id); 
   if (exerrval != EX_LOOKUPFAIL)   /* found the map id */
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: %s map %d already defined in file id %d",
             tname,map_id,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return(EX_FATAL);
   }

/* Get number of maps initialized for this file */
   if ((ncdiminq (exoid,dimid,cdum,&num_maps)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of %s maps in file id %d",
             tname,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Keep track of the total number of maps defined using a counter stored
   in a linked list keyed by exoid.
   NOTE: ex_get_file_item  is used to find the number of maps
         for a specific file and returns that value.
*/
   cur_num_maps = ex_get_file_item(exoid, map_ctr_list );
   if (cur_num_maps >= num_maps)
   {
     exerrval = EX_FATAL;
     sprintf(errmsg,
          "Error: exceeded number of %s maps (%ld) specified in file id %d",
             tname,num_maps,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/*   NOTE: ex_inc_file_item  is used to find the number of maps
         for a specific file and returns that value incremented. */

   cur_num_maps = ex_inc_file_item(exoid, map_ctr_list );

/* write out information to previously defined variable */

   /* first get id of variable */

   if ((varid = ncvarid (exoid, vmapids)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate %s map ids in file id %d",
             tname,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   /* then, write out map id */

   start[0] = cur_num_maps;

   ldum = (nclong)map_id;
   if (ncvarput1 (exoid, varid, start, &ldum) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store %s map id %d in file id %d",
             tname,map_id,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/* determine number of entries */

   if ((dimid = (ncdimid (exoid, dnumentries))) == -1 )
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: couldn't determine number of %s entries in file id %d",
             tname,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (ncdiminq (exoid, dimid, (char *) 0, &num_entries) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of %s entries in file id %d",
             tname,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   switch ( map_type ) {
   case EX_NODE_MAP:
     vmap = VAR_NODE_MAP(cur_num_maps+1);
     break;
   case EX_EDGE_MAP:
     vmap = VAR_EDGE_MAP(cur_num_maps+1);
     break;
   case EX_FACE_MAP:
     vmap = VAR_FACE_MAP(cur_num_maps+1);
     break;
   case EX_ELEM_MAP:
     vmap = VAR_ELEM_MAP(cur_num_maps+1);
     break;
   }

/* locate variable array in which to store the map */
   if ((varid = ncvarid(exoid,vmap)) == -1)
     {
#if 0
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to locate %s map %d in file id %d",
               vmap,map_id,exoid);
       ex_err("ex_put_num_map",errmsg,exerrval);
       return (EX_FATAL);
#endif
       int dims[2];
       ncerr = 0;

       if ( ncredef( exoid ) == -1 ) {
         exerrval = ncerr;
         sprintf(errmsg, "Error: failed to place file id %d into define mode", exoid);
         ex_err("ex_put_num_map",errmsg,exerrval);
         return (EX_FATAL);
       }

       dims[0] = dimid;
       if ( (varid = ncvardef( exoid, vmap, NC_LONG, 1, dims )) == -1 ) {
         exerrval = ncerr;
         sprintf(errmsg, "Error: failed to define map %s in file id %d", vmap, exoid);
         ex_err("ex_put_num_map",errmsg,exerrval);
       }

       if ( ncendef( exoid ) == -1 ) { /* exit define mode */
         sprintf( errmsg, "Error: failed to complete definition for file id %d", exoid );
         ex_err( "ex_put_num_map", errmsg, exerrval );
         varid = -1; /* force early exit */
       }

       if ( varid == -1 ) /* we couldn't define variable and have prepared error message. */
         return (EX_FATAL);
     }

/* write out the map  */

/* this contortion is necessary because netCDF is expecting nclongs; fortunately
   it's necessary only when ints and nclongs aren't the same size */

   start[0] = 0;
   count[0] = num_entries;

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarput (exoid, varid, start, count, map);
   } else {
      lptr = itol (map, (int)num_entries);
      iresult = ncvarput (exoid, varid, start, count, lptr);
      free(lptr);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store %s map in file id %d",
             tname,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);
}
コード例 #8
0
ファイル: wr_dpi.c プロジェクト: goma/brkfix
static void
put_variable(const int netcdf_unit,
	     const nc_type netcdf_type,
	     const int num_dimensions,
	     const int dimension_val_1,
	     const int dimension_val_2,
	     const int variable_identifier,
	     const void *variable_address)
{
  int err;
  char err_msg[MAX_CHAR_ERR_MSG];

  /*
   * If a variable was really defined properly and doesn't have a valid
   * identifier, then don't even try to put it.
   */

  if ( variable_identifier < 0 )
    {
      return;
    }

#ifdef NETCDF_3		/* pure netCDF 3 calls... */
  switch ( netcdf_type )
    {
    case NC_INT:
      err = nc_put_var_int(netcdf_unit, variable_identifier, variable_address);
      if ( err != NC_NOERR )
	{
	  sprintf(err_msg, "nc_put_var_int() varid=%d", 
		       variable_identifier);
	  EH(-1, err_msg);
	}
      break;
      
    case NC_CHAR:
      err = nc_put_var_text(netcdf_unit, variable_identifier, 
			    variable_address);
      if ( err != NC_NOERR )
	{
	  sprintf(err_msg, "nc_put_var_text() varid=%d", 
		       variable_identifier);
	  EH(-1, err_msg);
	}
      break;

    case NC_DOUBLE:
      err = nc_put_var_double(netcdf_unit, variable_identifier, 
			      variable_address);
      if ( err != NC_NOERR )
	{
	  sprintf(err_msg, "nc_put_var_double() varid=%d", 
		       variable_identifier);
	  EH(-1, err_msg);
	}
	break;

    default:
      EH(-1, "Specified netCDF data type unrecognized or unimplemented.");
      break;
    }
#endif

#ifdef NETCDF_2		/* backward compatibility mode to netcdf2 */
  
  if ( num_dimensions < 0 || num_dimensions > 2 )
    {
      sprintf(err_msg, "Bad or too large dimension value %d", 
		   num_dimensions);
      EH(-1, err_msg);
    }

  for ( i=0; i<num_dimensions; i++)
    {
      count[i] = 1;
      start[i] = 0;
    }

  if ( num_dimensions > 0 )
    {
      if ( dimension_val_1 < 1 )
	{
	  /*
	   * This is a case where you didn't really want to put any
	   * variables here, right? I mean, really, a dimension of zero?
	   */
	  return;
	  /*
	  sprintf(err_msg, 
	  "Data type %s (%d dimensional) has dimension values = %d %d",
		       string_type(netcdf_type), num_dimensions, 
		       dimension_val_1, dimension_val_2);
	  EH(-1, err_msg);
	  */
	}
      count[0] = dimension_val_1;
    }

  if ( num_dimensions > 1 ) 
    {
      if ( dimension_val_2 < 1 )
	{
	  /*
	   * Another case of where you were not serious. Here a 2D array
	   * has the second dimension of zero, so it is pretty darn flat.
	   * So flat, in fact, that we're going to call it done and leave
	   * right away.
	   */
	  return;
	  /*
	  sprintf(err_msg, 
	  "Data type %s (%d dimensional) has dimension values = %d %d",
		       string_type(netcdf_type), num_dimensions, 
		       dimension_val_1, dimension_val_2);
	  EH(-1, err_msg);
	  */
	}
      count[1] = dimension_val_2;
    }

  /*
   * If we've made it here, then presumably the dimensions have some meat
   * to them.
   */

  err = ncvarput(netcdf_unit, variable_identifier, start, count, 
		 variable_address);
  EH(err, "ncvarput");
#endif

  return;
}
コード例 #9
0
ファイル: expcor.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_put_coord (int   exoid,
                  const void *x_coor,
                  const void *y_coor,
                  const void *z_coor)
{
  int coordid;
  int coordidx, coordidy, coordidz;

  int numnoddim, ndimdim, i;
  long num_nod, num_dim, start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* inquire id's of previously defined dimensions  */

  if ((numnoddim = ncdimid (exoid, DIM_NUM_NODES)) == -1)
    {
      /* If not found, then this file is storing 0 nodes.
         Return immediately */
      return (EX_NOERR);
    }

  if (ncdiminq (exoid, numnoddim, NULL, &num_nod) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: inquire failed to return number of nodes in file id %d",
              exoid);
      ex_err("ex_put_coord",errmsg,exerrval);
      return (EX_FATAL);
    }

  if ((ndimdim = ncdimid (exoid, DIM_NUM_DIM)) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to locate number of dimensions in file id %d",
              exoid);
      ex_err("ex_put_coord",errmsg,exerrval);
      return (EX_FATAL);
    }

  if (ncdiminq (exoid, ndimdim, NULL, &num_dim) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to get number of dimensions in file id %d",
              exoid);
      ex_err("ex_put_coord",errmsg,exerrval);
      return (EX_FATAL);
    }

  /* write out the coordinates  */
  if (ex_large_model(exoid) == 0) {
    if ((coordid = ncvarid (exoid, VAR_COORD)) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to locate nodal coordinates in file id %d", exoid);
      ex_err("ex_put_coord",errmsg,exerrval);
      return (EX_FATAL);
    } 

    for (i=0; i<num_dim; i++)
      {
        start[0] = i;
        start[1] = 0;

        count[0] = 1;
        count[1] = num_nod;

        if (i == 0 && x_coor != NULL)
          {
            if (ncvarput (exoid, coordid, start, count,
                          ex_conv_array(exoid,WRITE_CONVERT,x_coor,(int)num_nod)) == -1)
              {
                exerrval = ncerr;
                sprintf(errmsg,
                        "Error: failed to put X coord array in file id %d", exoid);
                ex_err("ex_put_coord",errmsg,exerrval);
                return (EX_FATAL);
              }
          }

        else if (i == 1 && y_coor != NULL)
          {
            if (ncvarput (exoid, coordid, start, count,
                          ex_conv_array(exoid,WRITE_CONVERT,y_coor,(int)num_nod)) == -1)
              {
                exerrval = ncerr;
                sprintf(errmsg,
                        "Error: failed to put Y coord array in file id %d", exoid);
                ex_err("ex_put_coord",errmsg,exerrval);
                return (EX_FATAL);
              }
          }

        else if (i == 2 && z_coor != NULL)
          {
            if (ncvarput (exoid, coordid, start, count,
                          ex_conv_array(exoid,WRITE_CONVERT,z_coor,(int)num_nod)) == -1)
              {
                exerrval = ncerr;
                sprintf(errmsg,
                        "Error: failed to put Z coord array in file id %d", exoid);
                ex_err("ex_put_coord",errmsg,exerrval);
                return (EX_FATAL);
              }
          }
      }
  } else {
    if ((coordidx = ncvarid (exoid, VAR_COORD_X)) == -1)
      {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to locate x nodal coordinates in file id %d", exoid);
        ex_err("ex_put_coord",errmsg,exerrval);
        return (EX_FATAL);
      }

    if (num_dim > 1) {
      if ((coordidy = ncvarid (exoid, VAR_COORD_Y)) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
                  "Error: failed to locate y nodal coordinates in file id %d", exoid);
          ex_err("ex_put_coord",errmsg,exerrval);
          return (EX_FATAL);
        }
    } else {
      coordidy = 0;
    }
    if (num_dim > 2) {
      if ((coordidz = ncvarid (exoid, VAR_COORD_Z)) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
                  "Error: failed to locate z nodal coordinates in file id %d", exoid);
          ex_err("ex_put_coord",errmsg,exerrval);
          return (EX_FATAL);
        }
    } else {
      coordidz = 0;
    }
    /* write out the coordinates  */
    for (i=0; i<num_dim; i++)
      {
        const void *coor;
        char *which;
        int status;
       
        if (i == 0) {
          coor = x_coor;
          which = "X";
          coordid = coordidx;
        } else if (i == 1) {
          coor = y_coor;
          which = "Y";
          coordid = coordidy;
        } else if (i == 2) {
          coor = z_coor;
          which = "Z";
          coordid = coordidz;
        }

        if (coor != NULL) {
        if (nc_flt_code(exoid) == NC_FLOAT) {
          status = nc_put_var_float(exoid, coordid, 
                                    ex_conv_array(exoid,WRITE_CONVERT,
                                                  coor,(int)num_nod));
        } else {
          status = nc_put_var_double(exoid, coordid, 
                                     ex_conv_array(exoid,WRITE_CONVERT,
                                                   coor,(int)num_nod));
        }

        if (status == -1)
          {
            exerrval = ncerr;
            sprintf(errmsg,
                    "Error: failed to put %s coord array in file id %d", which, exoid);
            ex_err("ex_put_coord",errmsg,exerrval);
            return (EX_FATAL);
          }
        }
      }
  }
  return (EX_NOERR);
}
コード例 #10
0
int ex_put_var_name (int   exoid,
                     const char *var_type,
                     int   var_num,
                     const char *var_name)
{
   int varid; 
   long  start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

/* inquire previously defined dimensions  */

   if ((ncdimid (exoid, DIM_STR)) < 0)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get string length in file id %d",exoid);
     ex_err("ex_put_var_name",errmsg,exerrval);
     return (EX_FATAL);
   }

/* inquire previously defined variables  */

   if (*var_type == 'g' || *var_type == 'G')
   {
     if ((varid = ncvarid (exoid, VAR_NAME_GLO_VAR)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Warning: no global variables names stored in file id %d", exoid);
       ex_err("ex_put_var_name",errmsg,exerrval);
       return (EX_WARN);
     }
   }

   else if (*var_type == 'n' || *var_type == 'N')
   {
     if ((varid = ncvarid (exoid, VAR_NAME_NOD_VAR)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Warning: no nodal variable names stored in file id %d",
               exoid);
       ex_err("ex_put_var_name",errmsg,exerrval);
       return (EX_WARN);
     }

   }

   else if (*var_type == 'e' || *var_type == 'E')
   {

     if ((varid = ncvarid (exoid, VAR_NAME_ELE_VAR)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Warning: no element variable names stored in file id %d",
               exoid);
       ex_err("ex_put_var_name",errmsg,exerrval);
       return (EX_WARN);
     }
   }

   else if (*var_type == 'm' || *var_type == 'M')
   {

     if ((varid = ncvarid (exoid, VAR_NAME_NSET_VAR)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Warning: no nodeset variable names stored in file id %d",
               exoid);
       ex_err("ex_put_var_name",errmsg,exerrval);
       return (EX_WARN);
     }
   }

   else if (*var_type == 's' || *var_type == 'S')
   {

     if ((varid = ncvarid (exoid, VAR_NAME_SSET_VAR)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Warning: no sideset variable names stored in file id %d",
               exoid);
       ex_err("ex_put_var_name",errmsg,exerrval);
       return (EX_WARN);
     }
   }

   else       /* invalid variable type */
   {
     exerrval = EX_BADPARAM;
      sprintf(errmsg,
             "Error: Invalid variable type %c specified in file id %d",
              *var_type, exoid);
      ex_err("ex_put_var_name",errmsg,exerrval);
     return (EX_WARN);
   }

/* write EXODUS variable name */

   start[0] = var_num-1;
   start[1] = 0;

   count[0] = 1;
   count[1] = strlen(var_name) + 1;

   if (ncvarput (exoid, varid, start, count, (void*)var_name) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store %c variable name %d in file id %d",
             *var_type, var_num, exoid);
     ex_err("ex_put_var_name",errmsg,exerrval);
     return (EX_FATAL);
   }

   return(EX_NOERR);
}
コード例 #11
0
int ex_put_names (int   exoid,
		  int   obj_type,
		  char *names[])
{
   int i, varid; 
   long num_entity;
   long  start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];
   const char *routine = "ex_put_names";
   
   exerrval = 0; /* clear error code */

   if (obj_type == EX_ELEM_BLOCK) {
     ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element block", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_EL_BLK)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate element block names in file id %d",
	       exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
   }
   else if (obj_type == EX_NODE_SET) {
     ex_get_dimension(exoid, DIM_NUM_NS, "nodeset", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_NS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate nodeset names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
   }
   else if (obj_type == EX_SIDE_SET) {
     ex_get_dimension(exoid, DIM_NUM_SS, "sideset", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_SS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate sideset names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   else if (obj_type == EX_NODE_MAP) {
     ex_get_dimension(exoid, DIM_NUM_NM, "node map", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_NM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate node map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   else if (obj_type == EX_ELEM_MAP) {
     ex_get_dimension(exoid, DIM_NUM_EM, "element map", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_EM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate element map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   else {/* invalid type */
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
	     "Error: Invalid type specified in file id %d", exoid);
     ex_err(routine,errmsg,exerrval);
     return(EX_FATAL);
   }
   

   /* write EXODUS entitynames */

   for (i=0; i<num_entity; i++)
   {
     if (names[i] != '\0') {
       start[0] = i;
       start[1] = 0;
       
       count[0] = 1;
       count[1] = strlen(names[i]) + 1;
       
       if (ncvarput (exoid, varid, start, count, (void*) names[i]) == -1) {
	 exerrval = ncerr;
	 sprintf(errmsg,
		 "Error: failed to store entity names in file id %d", exoid);
	 ex_err(routine,errmsg,exerrval);
	 return (EX_FATAL);
       }
     }
   }
   return(EX_NOERR);
}
コード例 #12
0
ファイル: exppa.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_put_prop_array (int   exoid,
                       int   obj_type,
                       const char *prop_name,
                       const int  *values)
{
   int num_props, i, propid, dimid, dims[1], iresult;
   int found = FALSE;
   long start[1], count[1], num_obj; 
   nclong *lptr;
   char name[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_STR_LENGTH+1];
   char obj_stype[MAX_VAR_NAME_LENGTH+1];
   char dim_name[MAX_VAR_NAME_LENGTH+1];

   char errmsg[MAX_ERR_LENGTH];

   exerrval  = 0; /* clear error code */

/* check if property has already been created */

   num_props = ex_get_num_props(exoid, obj_type);

   switch (obj_type)
   {
     case EX_ELEM_BLOCK:
       strcpy (obj_stype, VAR_ID_EL_BLK);
       strcpy (dim_name, DIM_NUM_EL_BLK);
       break;
     case EX_NODE_SET:
       strcpy (obj_stype, VAR_NS_IDS);
       strcpy (dim_name, DIM_NUM_NS);
       break;
     case EX_SIDE_SET:
       strcpy (obj_stype, VAR_SS_IDS);
       strcpy (dim_name, DIM_NUM_SS);
       break;
     case EX_ELEM_MAP:
       strcpy (obj_stype, VAR_EM_PROP(1));
       strcpy (dim_name, DIM_NUM_EM);
       break;
     case EX_NODE_MAP:
       strcpy (obj_stype, VAR_NM_PROP(1));
       strcpy (dim_name, DIM_NUM_NM);
       break;
     default:
       exerrval = EX_BADPARAM;
       sprintf(errmsg, "Error: object type %d not supported; file id %d",
               obj_type, exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
   }
/*   inquire id of previously defined dimension (number of objects) */

     if ((dimid = ncdimid (exoid, dim_name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to locate number of %s objects in file id %d",
               obj_stype, exoid);
       ex_err("ex_put_prop_array",errmsg, exerrval);
       return (EX_FATAL);
     }

/*   get number of objects */

     if (ncdiminq (exoid, dimid, dim_name, &num_obj) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get number of %s objects in file id %d",
               obj_stype, exoid);
       ex_err("ex_put_prop_array",errmsg, exerrval);
       return (EX_FATAL);
     }



   for (i=1; i<=num_props; i++)
   {
     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(i));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(i));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(i));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(i));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(i));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_put_prop_array",errmsg,exerrval);
         return(EX_FATAL);
     }

     if ((propid = ncvarid (exoid, name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to get property array id in file id %d",
               exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   compare stored attribute name with passed property name   */

     memset(tmpstr, 0, MAX_STR_LENGTH+1);
     if ((ncattget (exoid, propid, ATT_PROP_NAME, tmpstr)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (strcmp(tmpstr, prop_name) == 0) 
     {
       found = TRUE;
       break;
     }
   }

/* if property array has not been created, create it */

   if (!found)
   {
/* put netcdf file into define mode  */

     if (ncredef (exoid) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

/*   create a variable with a name xx_prop#, where # is the new number   */
/*   of properties                                                       */

     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(num_props+1));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(num_props+1));
         break;
       case EX_SIDE_SET:
         strcpy (name, VAR_SS_PROP(num_props+1));
         break;
       case EX_ELEM_MAP:
         strcpy (name, VAR_EM_PROP(num_props+1));
         break;
       case EX_NODE_MAP:
         strcpy (name, VAR_NM_PROP(num_props+1));
         break;
       default:
         exerrval = EX_BADPARAM;
         sprintf(errmsg, "Error: object type %d not supported; file id %d",
           obj_type, exoid);
         ex_err("ex_put_prop_array",errmsg,exerrval);
         goto error_ret;        /* Exit define mode and return */
     }

     dims[0] = dimid;
     ncsetfill(exoid, NC_FILL); /* fill with zeros per routine spec */

     if ((propid = ncvardef (exoid, name, NC_LONG, 1, dims)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
          "Error: failed to create property array variable in file id %d",
               exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       goto error_ret;  /* Exit define mode and return */
     }
     ncsetfill(exoid, NC_NOFILL); /* default: nofill */


/*   store property name as attribute of property array variable */

     if ((ncattput (exoid, propid, ATT_PROP_NAME, NC_CHAR,
                    strlen(prop_name)+1, prop_name)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to store property name %s in file id %d",
               prop_name,exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       goto error_ret;  /* Exit define mode and return */
     }

/* leave define mode  */

     if (ncendef (exoid) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to leave define mode in file id %d",
          exoid);
       ex_err("ex_put_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

   }

/* put num_obj values in property array */

/* this contortion is necessary because netCDF is expecting nclongs; fortunately
   it's necessary only when ints and nclongs aren't the same size  */

   start[0] = 0;
   count[0] = num_obj;

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarput (exoid, propid, start, count, values);
   } else {
      lptr = itol (values, (int)num_obj);
      iresult = ncvarput (exoid, propid, start, count, lptr);
      free(lptr);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store property values in file id %d",
             exoid);
     ex_err("ex_put_prop_array",errmsg,exerrval);
     return (EX_FATAL);
   }


   return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  ncsetfill(exoid, NC_NOFILL); /* default: nofill */
  if (ncendef (exoid) == -1)     /* exit define mode */
  {
    sprintf(errmsg,
           "Error: failed to complete definition for file id %d",
            exoid);
    ex_err("ex_put_prop_array",errmsg,exerrval);
  }
  return (EX_FATAL);
}
コード例 #13
0
int ex_put_elem_attr (int   exoid,
                      int   elem_blk_id,
                      const void *attrib)
{
   int numelbdim, numattrdim, attrid, elem_blk_id_ndx;
   long num_elem_this_blk, num_attr, start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

  /* Determine index of elem_blk_id in VAR_ID_EL_BLK array */
  elem_blk_id_ndx = ex_id_lkup(exoid,VAR_ID_EL_BLK,elem_blk_id);
  if (exerrval != 0) 
  {
    if (exerrval == EX_NULLENTITY)
    {
      sprintf(errmsg,
              "Warning: no attributes allowed for NULL block %d in file id %d",
              elem_blk_id,exoid);
      ex_err("ex_put_elem_attr",errmsg,EX_MSG);
      return (EX_WARN);              /* no attributes for this element block */
    }
    else
    {
      sprintf(errmsg,
             "Error: no element block id %d in %s array in file id %d",
              elem_blk_id, VAR_ID_EL_BLK, exoid);
      ex_err("ex_put_elem_attr",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

/* inquire id's of previously defined dimensions  */

  if ((numelbdim = ncdimid (exoid, DIM_NUM_EL_IN_BLK(elem_blk_id_ndx))) == -1)
  {
    if (ncerr == NC_EBADDIM)
    {
      exerrval = ncerr;
      sprintf(errmsg,
         "Error: no element block with id %d in file id %d",
             elem_blk_id, exoid);
      ex_err("ex_put_elem_attr",errmsg,exerrval);
      return (EX_FATAL);
    }
    else
    {
      exerrval = ncerr;
      sprintf(errmsg,
        "Error: failed to locate number of elements for block %d in file id %d",
             elem_blk_id, exoid);
      ex_err("ex_put_elem_attr",errmsg,exerrval);
      return (EX_FATAL);
    }
  }


  if (ncdiminq (exoid, numelbdim, (char *) 0, &num_elem_this_blk) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to get number of elements for block %d in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_put_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }


  if ((numattrdim = ncdimid(exoid, DIM_NUM_ATT_IN_BLK(elem_blk_id_ndx))) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: number of attributes not defined for block %d in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_put_elem_attr",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }

  if (ncdiminq (exoid, numattrdim, (char *) 0, &num_attr) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
         "Error: failed to get number of attributes for block %d in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_put_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((attrid = ncvarid (exoid, VAR_ATTRIB(elem_blk_id_ndx))) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
        "Error: failed to locate attribute variable for block %d in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_put_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }


/* write out the attributes  */

  start[0] = 0;
  start[1] = 0;

  count[0] = num_elem_this_blk;
  count[1] = num_attr;

  if (ncvarput (exoid, attrid, start, count,
                ex_conv_array(exoid,WRITE_CONVERT,attrib,
                (int)num_attr*num_elem_this_blk)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
            "Error: failed to put attributes for block %d in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_put_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }


  return(EX_NOERR);

}
コード例 #14
0
ファイル: expcss.c プロジェクト: unidevop/sjtu-project-pipe
int ex_put_concat_side_sets (int   exoid,
                             const int  *side_set_ids,
                             const int  *num_elem_per_set,
                             const int  *num_dist_per_set,
                             const int  *side_sets_elem_index,
                             const int  *side_sets_dist_index,
                             const int  *side_sets_elem_list,
                             const int  *side_sets_side_list,
                             const void *side_sets_dist_fact)
{
  char *cdum;
  int i, num_side_sets, cur_num_side_sets, dimid, varid, dims[1], *ss_stat;
  int iresult;
  long start[1], count[1]; 
  nclong *lptr;
  float fdum;
  const float *flt_dist_fact;
  const double *dbl_dist_fact;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  cdum = 0; /* initialize even though it is not used */

/* first check if any side sets are specified */

  if (ncdimid (exoid, DIM_NUM_SS) == -1)
  {
    if (ncerr == NC_EBADDIM)
    {
      exerrval = ncerr;
      sprintf(errmsg,
             "Error: no side sets defined for file id %d", exoid);
      ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    }
    else
    {
      exerrval = ncerr;
      sprintf(errmsg,
             "Error: failed to locate side sets defined in file id %d", exoid);
      ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    }
    return (EX_FATAL);
  }

/* inquire how many side sets are to be stored */

  if (ex_inquire(exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum) == -1)
  {
    sprintf(errmsg,
           "Error: failed to get number of side sets defined for file id %d",
            exoid);
    /* use error val from inquire */
    ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    return (EX_FATAL);
  }
/* fill out side set status array */

  /* First, allocate space for the side set status list */
  if (!(ss_stat= malloc(num_side_sets*sizeof(int))))
  {
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
    "Error: failed to allocate space for side set status array in file id %d",
            exoid);
    ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  for (i=0;i<num_side_sets;i++)
  {
    if (num_elem_per_set[i] == 0) /* Is this a NULL side set? */
      ss_stat[i] = 0; /* change side set status to NULL */
    else
      ss_stat[i] = 1; /* change side set status to TRUE */
  }

  /* Next, get variable id of status array */
  if ((varid = ncvarid (exoid, VAR_SS_STAT)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to locate side set status in file id %d", exoid);
    ex_err("ex_put_concat_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

/* this contortion is necessary because netCDF is expecting nclongs; fortunately
   it's necessary only when ints and nclongs aren't the same size */

  start[0] = 0;
  count[0] = num_side_sets;

  if (sizeof(int) == sizeof(nclong)) {
     iresult = ncvarput (exoid, varid, start, count, ss_stat);
  } else {
     lptr = itol (ss_stat, num_side_sets);
     iresult = ncvarput (exoid, varid, start, count, lptr);
     free(lptr);
  }

  if (iresult == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to store side set status array to file id %d",
            exoid);
    ex_err("ex_put_concat_side_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  free(ss_stat);

/* put netcdf file into define mode  */

  if (ncredef (exoid) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to put file id %d into define mode",
            exoid);
    ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* create side set definitions */
  for (i=0; i<num_side_sets; i++)
  {
/* Keep track of the total number of side sets defined using a counter stored
   in a linked list keyed by exoid.
   NOTE: ex_get_file_item  is used to find the number of side sets
         for a specific file and returns that value.
*/
    cur_num_side_sets=ex_get_file_item(exoid, &ss_ctr_list );
    if (cur_num_side_sets >= num_side_sets)
    {
      exerrval = EX_FATAL;
      sprintf(errmsg,
             "Error: exceeded number of side sets (%d) defined in file id %d",
              num_side_sets,exoid);
      ex_err("ex_put_concat_side_sets",errmsg,exerrval);
      goto error_ret;
    }

/*   NOTE: ex_inc_file_item  is used to find the number of side sets
         for a specific file and returns that value incremented. */

    cur_num_side_sets=ex_inc_file_item(exoid, &ss_ctr_list );

/*  define dimension for number of sides/elements per side set */

    if (num_elem_per_set[i] == 0) /* Is this a NULL side set? */
      continue; /* Do not create anything for NULL side sets! */


    if ((dimid = ncdimdef (exoid, DIM_NUM_SIDE_SS(cur_num_side_sets+1),
                   (long)num_elem_per_set[i])) == -1)
    {
      if (ncerr == NC_ENAMEINUSE)
      {
        exerrval = ncerr;
        sprintf(errmsg,
               "Error: side set side count %d already defined in file id %d",
                side_set_ids[i],exoid);
        ex_err("ex_put_concat_side_sets",errmsg,exerrval);
      }
      else
      {
        exerrval = ncerr;
        sprintf(errmsg,
             "Error: failed to define number of sides for set %d in file id %d",
                side_set_ids[i],exoid);
        ex_err("ex_put_concat_side_sets",errmsg,exerrval);
      }
      goto error_ret;
    }

    /* create element list variable for side set */

    dims[0] = dimid;
    if (ncvardef (exoid,VAR_ELEM_SS(cur_num_side_sets+1),NC_LONG,1,dims) == -1)
    {
      if (ncerr == NC_ENAMEINUSE)
      {
        exerrval = ncerr;
        sprintf(errmsg,
             "Error: element list already exists for side set %d in file id %d",
                side_set_ids[i],exoid);
        ex_err("ex_put_concat_side_sets",errmsg,exerrval);
      }
      else
      {
        exerrval = ncerr;
        sprintf(errmsg,
           "Error: failed to create element list for side set %d in file id %d",
                side_set_ids[i],exoid);
        ex_err("ex_put_concat_side_sets",errmsg,exerrval);
      }
      goto error_ret;            /* exit define mode and return */
    }

    /* create side list variable for side set */

    if (ncvardef (exoid,VAR_SIDE_SS(cur_num_side_sets+1),NC_LONG,1,dims) == -1)
    {
      if (ncerr == NC_ENAMEINUSE)
      {
        exerrval = ncerr;
        sprintf(errmsg,
               "Error: side list already exists for side set %d in file id %d",
                side_set_ids[i],exoid);
        ex_err("ex_put_concat_side_sets",errmsg,exerrval);
      }
      else
      {
        exerrval = ncerr;
        sprintf(errmsg,
              "Error: failed to create side list for side set %d in file id %d",
                side_set_ids[i],exoid);
        ex_err("ex_put_concat_side_sets",errmsg,exerrval);
      }
      goto error_ret;         /* exit define mode and return */

     }

/*  define dimension for number of dist factors/nodes per side set */

/*  NOTE: only define df count if  the dist factors exist! */

    if (num_dist_per_set[i] > 0)
    {

      if ((dimid = ncdimdef (exoid, DIM_NUM_DF_SS(cur_num_side_sets+1),
                              (long)num_dist_per_set[i])) == -1)
      {
        if (ncerr == NC_ENAMEINUSE)
        {
          exerrval = ncerr;
          sprintf(errmsg,
                 "Error: side set df count %d already defined in file id %d",
                  side_set_ids[i],exoid);
          ex_err("ex_put_concat_side_sets",errmsg,exerrval);
        }
        else
        {
          exerrval = ncerr;
          sprintf(errmsg,
           "Error: failed to define side set df count for set %d in file id %d",
                  side_set_ids[i],exoid);
          ex_err("ex_put_concat_side_sets",errmsg,exerrval);
        }
        goto error_ret;
      }

      /* create distribution factor list variable for side set */

      dims[0] = dimid;
      if (ncvardef (exoid, VAR_FACT_SS(cur_num_side_sets+1),
                    nc_flt_code(exoid), 1, dims) == -1)
      {
        if (ncerr == NC_ENAMEINUSE)
        {
          exerrval = ncerr;
          sprintf(errmsg,
         "Error: dist factor list already exists for side set %d in file id %d",
                  side_set_ids[i],exoid);
          ex_err("ex_put_concat_side_sets",errmsg,exerrval);
        }
        else
        {
          exerrval = ncerr;
          sprintf(errmsg,
       "Error: failed to create dist factor list for side set %d in file id %d",
                  side_set_ids[i],exoid);
          ex_err("ex_put_concat_side_sets",errmsg,exerrval);
        }
        goto error_ret;            /* exit define mode and return */
      }
    } /* end define dist factors */
  }

/* leave define mode  */

  if (ncendef (exoid) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to complete definition in file id %d",
            exoid);
    ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

/* Next, fill out side set ids array */

  /* first get id of side set ids array variable */

  if ((varid = ncvarid (exoid, VAR_SS_IDS)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to locate side set ids array in file id %d",
            exoid);
    ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* then, write out side set id list */

/* this contortion is necessary because netCDF is expecting nclongs; fortunately
   it's necessary only when ints and nclongs aren't the same size */

  start[0] = 0;
  count[0] = num_side_sets;

  if (sizeof(int) == sizeof(nclong)) {
     iresult = ncvarput (exoid, varid, start, count, side_set_ids);
  } else {
     lptr = itol (side_set_ids, num_side_sets);
     iresult = ncvarput (exoid, varid, start, count, lptr);
     free(lptr);
  }

  if (iresult == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to store side set id array in file id %d",
            exoid);
    ex_err("ex_put_concat_side_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* If the side_sets_elem_index is passed in as a NULL pointer, then
   *  the user only wants us to define the sidesets and not populate
   *  the data structures.
   */
  if (side_sets_elem_index == 0)
    return(EX_NOERR);
  
  /* Now, use ExodusII call to store side sets */
  for (i=0; i<num_side_sets; i++)
  {

    if (num_elem_per_set[i] == 0) /* Is this a NULL side set? */
      continue; /* Do not create anything for NULL side sets! */

    if (ex_comp_ws(exoid) == sizeof(float))
    {
      flt_dist_fact = side_sets_dist_fact;
      if (ex_put_side_set(exoid, side_set_ids[i], 
                         &(side_sets_elem_list[side_sets_elem_index[i]]),
                         &(side_sets_side_list[side_sets_elem_index[i]])) == -1)
         return(EX_FATAL); /* error will be reported by subroutine */
      if (num_dist_per_set[i] > 0)      /* store dist factors if required */
      {
        if (ex_put_side_set_dist_fact(exoid, side_set_ids[i],
                         &(flt_dist_fact[side_sets_dist_index[i]])) == -1)
        {
          sprintf(errmsg,
               "Error: failed to store side set %d dist factors for file id %d",
                  side_set_ids[i],exoid);
          /* use error val from exodusII routine */
          ex_err("ex_put_concat_side_sets",errmsg,exerrval);
          return (EX_FATAL);
        }
      }
    }
    else if (ex_comp_ws(exoid) == sizeof(double))
    {
      dbl_dist_fact = side_sets_dist_fact;
      if (ex_put_side_set(exoid, side_set_ids[i], 
                         &(side_sets_elem_list[side_sets_elem_index[i]]),
                         &(side_sets_side_list[side_sets_elem_index[i]])) == -1)
        return(EX_FATAL); /* error will be reported by subroutine */
      if (num_dist_per_set[i] > 0)             /* only store if they exist */
      {
        if (ex_put_side_set_dist_fact(exoid, side_set_ids[i],
                        &(dbl_dist_fact[side_sets_dist_index[i]])) == -1)
        {
          sprintf(errmsg,
               "Error: failed to store side set %d dist factors for file id %d",
                  side_set_ids[i],exoid);
          /* use error val from exodusII routine */
          ex_err("ex_put_concat_side_sets",errmsg,exerrval);
          return (EX_FATAL);
        }
      }
    }
    else
    {
      /* unknown floating point word size */
      exerrval = EX_BADPARAM;
      sprintf(errmsg,
             "Error: unsupported floating point word size %d for file id %d",
              ex_comp_ws(exoid), exoid);
      ex_err("ex_put_concat_side_sets", errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  return(EX_NOERR);


/* Fatal error: exit definition mode and return */
error_ret:
  if (ncendef (exoid) == -1)     /* exit define mode */
  {
    sprintf(errmsg,
           "Error: failed to complete definition for file id %d",
            exoid);
    ex_err("ex_put_concat_side_sets",errmsg,exerrval);
  }
  return (EX_FATAL);
}
コード例 #15
0
int ex_put_nodal_var (int   exoid,
                      int   time_step,
                      int   nodal_var_index,
                      int   num_nodes, 
                      const void *nodal_var_vals)

{
  int varid;
  long start[3], count[3];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  if (ex_large_model(exoid) == 0) {
    /* write values of the nodal variable */
    if ((varid = ncvarid (exoid, VAR_NOD_VAR)) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
              "Warning: could not find nodal variables in file id %d",
              exoid);
      ex_err("ex_put_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }
    start[0] = --time_step;
    start[1] = --nodal_var_index;
    start[2] = 0;

    count[0] = 1;
    count[1] = 1;
    count[2] = num_nodes;
  } else {
    /* nodal variables stored separately, find variable for this variable
       index */
    if ((varid = ncvarid (exoid, VAR_NOD_VAR_NEW(nodal_var_index))) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
              "Warning: could not find nodal variable %d in file id %d",
              nodal_var_index, exoid);
      ex_err("ex_put_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }

    start[0] = --time_step;
    start[1] = 0;

    count[0] = 1;
    count[1] = num_nodes;
  }

  if (ncvarput (exoid, varid, start, count,
                ex_conv_array(exoid,WRITE_CONVERT,nodal_var_vals,num_nodes)) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to store nodal variables in file id %d",
              exoid);
      ex_err("ex_put_nodal_var",errmsg,exerrval);
      return (EX_FATAL);
    }

  return (EX_NOERR);
}
コード例 #16
0
ファイル: expssv.c プロジェクト: hs9906/paraview
int ex_put_sset_var (int   exoid,
                     int   time_step,
                     int   sset_var_index,
                     int   sset_id,
                     int   num_faces_this_sset,
                     const void *sset_var_vals)
{
  int varid, dimid,time_dim, numelbdim, dims[2], sset_id_ndx;
  long num_ssets, num_sset_var, start[2], count[2];
  nclong *sset_var_tab;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* Determine index of sset_id in VAR_SS_ID array */
  sset_id_ndx = ex_id_lkup(exoid,VAR_SS_IDS,sset_id);
  if (exerrval != 0) 
  {
    if (exerrval == EX_NULLENTITY)
    {
      sprintf(errmsg,
              "Warning: no variables allowed for NULL sideset %d in file id %d",
              sset_id,exoid);
      ex_err("ex_put_sset_var",errmsg,EX_MSG);
      return (EX_WARN);
    }
    else
    {
    sprintf(errmsg,
        "Error: failed to locate sideset id %d in %s array in file id %d",
            sset_id, VAR_SS_IDS, exoid);
    ex_err("ex_put_sset_var",errmsg,exerrval);
    return (EX_FATAL);
    }
  }

  if ((varid = ncvarid (exoid,
                        VAR_SS_VAR(sset_var_index,sset_id_ndx))) == -1)
  {
    if (ncerr == NC_ENOTVAR) /* variable doesn't exist, create it! */
    {

/*    inquire previously defined dimensions */

      /* check for the existance of an sideset variable truth table */
      if ((varid = ncvarid (exoid, VAR_SSET_TAB)) != -1)
      {
        /* find out number of sidesets and sideset variables */
        if ((dimid = ncdimid (exoid, DIM_NUM_SS)) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
               "Error: failed to locate number of sidesets in file id %d",
                  exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
          return (EX_FATAL);
        }

        if (ncdiminq (exoid, dimid, (char *) 0, &num_ssets) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
                 "Error: failed to get number of sidesets in file id %d",
                  exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
          return (EX_FATAL);
        }

        if ((dimid = ncdimid (exoid, DIM_NUM_SSET_VAR)) == -1)
        {
          exerrval = EX_BADPARAM;
          sprintf(errmsg,
               "Error: no sideset variables stored in file id %d",
                  exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
          return (EX_FATAL);
        }

        if (ncdiminq (exoid, dimid, (char *) 0, &num_sset_var) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
               "Error: failed to get number of sideset variables in file id %d",
                  exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
          return (EX_FATAL);
        }

        if (!(sset_var_tab = malloc(num_ssets*num_sset_var*sizeof(nclong))))
        {
          exerrval = EX_MEMFAIL;
          sprintf(errmsg,
                 "Error: failed to allocate memory for sideset variable truth table in file id %d",
                  exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
          return (EX_FATAL);
        }

        /*   read in the sideset variable truth table */

        start[0] = 0;
        start[1] = 0;

        count[0] = num_ssets;
        count[1] = num_sset_var;

        if (ncvarget (exoid, varid, start, count, sset_var_tab) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
                 "Error: failed to get truth table from file id %d", exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
          return (EX_FATAL);
        }

        if(sset_var_tab[num_sset_var*(sset_id_ndx-1)+sset_var_index-1] 
           == 0L)
        {
          free(sset_var_tab);
          exerrval = EX_BADPARAM;
          sprintf(errmsg,
              "Error: Invalid sideset variable %d, sideset %d in file id %d",
                  sset_var_index, sset_id, exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
          return (EX_FATAL);
        }
        free(sset_var_tab);
      }

      if ((time_dim = ncdimid (exoid, DIM_TIME)) == -1)
      {
        exerrval = ncerr;
        sprintf(errmsg,
               "Error: failed to locate time dimension in file id %d", exoid);
        ex_err("ex_put_sset_var",errmsg,exerrval);
        goto error_ret;         /* exit define mode and return */
      }

      if ((numelbdim=ncdimid(exoid, DIM_NUM_SIDE_SS(sset_id_ndx))) == -1)
      {
        if (ncerr == NC_EBADDIM)
        {
          exerrval = ncerr;
          sprintf(errmsg,
      "Error: number of faces in sideset %d not defined in file id %d",
                  sset_id, exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
        }
        else
        {
          exerrval = ncerr;
          sprintf(errmsg,
 "Error: failed to locate number of sides in sideset %d in file id %d",
                  sset_id, exoid);
          ex_err("ex_put_sset_var",errmsg,exerrval);
        }
        goto error_ret;
      }

/*    variable doesn't exist so put file into define mode  */

      if (ncredef (exoid) == -1)
      {
        exerrval = ncerr;
        sprintf(errmsg,
               "Error: failed to put file id %d into define mode", exoid);
        ex_err("ex_put_sset_var",errmsg,exerrval);
        return (EX_FATAL);
      }


/*    define netCDF variable to store sideset variable values */

      dims[0] = time_dim;
      dims[1] = numelbdim;
      if ((varid = ncvardef(exoid,VAR_SS_VAR(sset_var_index,sset_id_ndx),
                            nc_flt_code(exoid), 2, dims)) == -1)
      {
        exerrval = ncerr;
        sprintf(errmsg,
               "Error: failed to define sideset variable %d in file id %d",
                sset_var_index,exoid);
        ex_err("ex_put_sset_var",errmsg,exerrval);
        goto error_ret;
      }


/*    leave define mode  */

      if (ncendef (exoid) == -1)
      {
        exerrval = ncerr;
        sprintf(errmsg,
       "Error: failed to complete sideset variable %s definition to file id %d",
                VAR_SS_VAR(sset_var_index,sset_id_ndx), exoid);
        ex_err("ex_put_sset_var",errmsg,exerrval);
        return (EX_FATAL);
      }
    }
    else
    {
      exerrval = ncerr;
      sprintf(errmsg,
             "Error: failed to locate sideset variable %s in file id %d",
              VAR_SS_VAR(sset_var_index,sset_id_ndx),exoid);
      ex_err("ex_put_sset_var",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

/* store sideset variable values */

  start[0] = --time_step;
  start[1] = 0;

  count[0] = 1;
  count[1] = num_faces_this_sset;

  if (ncvarput (exoid, varid, start, count, 
                ex_conv_array(exoid,WRITE_CONVERT,sset_var_vals,
                num_faces_this_sset)) == -1)
  {
    exerrval = ncerr;
    sprintf(errmsg,
           "Error: failed to store sideset variable %d in file id %d", 
            sset_var_index,exoid);
    ex_err("ex_put_sset_var",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  if (ncendef (exoid) == -1)     /* exit define mode */
  {
    sprintf(errmsg,
           "Error: failed to complete definition for file id %d",
            exoid);
    ex_err("ex_put_sset_var",errmsg,exerrval);
  }
  return (EX_FATAL);
}
コード例 #17
0
int ex_put_glob_vars (int   exoid,
                      int   time_step,
                      int   num_glob_vars,
                const void *glob_var_vals)
{
   int varid;
   long start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

/* if no variables are to be stored, return with warning */
   if (num_glob_vars == 0)
   {
     exerrval = EX_MSG;
     sprintf(errmsg,
            "Warning: no global variables specified for file id %d",
             exoid);
     ex_err("ex_put_glob_vars",errmsg,exerrval);

     return (EX_WARN);
   }


/* inquire previously defined variable */

   if ((varid = ncvarid (exoid, VAR_GLO_VAR)) == -1)
   {
     if (ncerr == NC_ENOTVAR)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: no global variables defined in file id %d",
               exoid);
       ex_err("ex_put_glob_vars",errmsg,exerrval);
     }
     else
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to get global variables parameters in file id %d",
               exoid);
       ex_err("ex_put_glob_vars",errmsg,exerrval);
     }
     return (EX_FATAL);
   } 


/* write values of global variables */

   start[0] = --time_step;
   start[1] = 0;

   count[0] = 1;
   count[1] = num_glob_vars;

   if (ncvarput (exoid, varid, start, count,
         ex_conv_array(exoid,WRITE_CONVERT,glob_var_vals,num_glob_vars)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store global variables in file id %d", 
             exoid);
     ex_err("ex_put_glob_vars",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);
}
コード例 #18
0
ファイル: expvnm.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_put_var_name (int   exoid,
                     const char *var_type,
                     int   var_num,
                     const char *var_name)
{
   int varid; 
   long  start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];
   int otype;
   const char* vname;
   const char* tname;

   exerrval = 0; /* clear error code */

/* inquire previously defined dimensions  */

   if ((ncdimid (exoid, DIM_STR)) < 0)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get string length in file id %d",exoid);
     ex_err("ex_put_var_name",errmsg,exerrval);
     return (EX_FATAL);
   }

/* inquire previously defined variables  */

   otype = tolower( *var_type );
   switch (otype) {
   case 'g': /* global var */
     vname = VAR_NAME_GLO_VAR;
     tname = "global";
     break;
   case 'n': /* node var */
     vname = VAR_NAME_NOD_VAR;
     tname = "nodal";
     break;
   case 'e': /* elem var */
     vname = VAR_NAME_ELE_VAR;
     tname = "element";
     break;
   case 'l': /* edge var */
     vname = VAR_NAME_EDG_VAR;
     tname = "edge";
     break;
   case 'f': /* face var */
     vname = VAR_NAME_FAC_VAR;
     tname = "face";
     break;
   case 'm': /* node set var */
     vname = VAR_NAME_NSET_VAR;
     tname = "node set";
     break;
   case 'd': /* edge set var */
     vname = VAR_NAME_ESET_VAR;
     tname = "edge set";
     break;
   case 'a': /* face set var */
     vname = VAR_NAME_FSET_VAR;
     tname = "face set";
     break;
   case 's': /* side set var */
     vname = VAR_NAME_SSET_VAR;
     tname = "side set";
     break;
   case 't': /* elem set var */
     vname = VAR_NAME_ELSET_VAR;
     tname = "element set";
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
       "Error: Invalid variable type %c specified in file id %d",
       *var_type, exoid);
     ex_err("ex_put_var_name",errmsg,exerrval);
     return (EX_WARN);
   }

   if ((varid = ncvarid (exoid, vname)) == -1) {
     exerrval = ncerr;
     sprintf( errmsg,
       "Warning: no %s variables names stored in file id %d", tname, exoid );
     ex_err("ex_put_var_name",errmsg,exerrval);
     return (EX_WARN);
   }

/* write EXODUS variable name */

   start[0] = var_num-1;
   start[1] = 0;

   count[0] = 1;
   count[1] = strlen(var_name) + 1;

   if (ncvarput (exoid, varid, start, count, (void*)var_name) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store %c variable name %d in file id %d",
             *var_type, var_num, exoid);
     ex_err("ex_put_var_name",errmsg,exerrval);
     return (EX_FATAL);
   }

   return(EX_NOERR);
}
コード例 #19
0
ファイル: expfrm.c プロジェクト: CPFDSoftware-Tony/gmv
/* -------------------- end of local defines -------------------- */
int ex_put_coordinate_frames( int exoid, int nframes, const int cf_ids[], 
                              void* pt_coordinates, const char* tags)
{
  int dim, dim9;                   /* dimension id for nframes, nframes*9 */
  char errmsg[MAX_ERR_LENGTH];     /* buffer for error messages      */
  int exerrval;                    /* returned error value           */
  int varcoords;                   /* variable id for the coordinates */
  int varids;                      /* variable id for the frame ids  */
  int vartags;                     /* variable id for the frame tags */
  long int start=0;                /* start value for varputs        */
  long int count=nframes;          /* number vars to put in varput   */
  long int count9=nframes*9;       /* ditto, but for coordinates     */
  int i;                           /* general indices */
  void* pt_c=0;                    /* pointer to size converted array */



  if ( exoid < 0 )
    return exoid;
  if ( nframes == 0 ) /* write nothing */
    return (EX_NOERR);
  if ( nframes<0 )
    return 1;
  assert( cf_ids!=0 );
  assert( pt_coordinates !=0 );
  assert( tags != 0 );

  /* make the definitions */
  /* go into define mode. define num_frames, num_frames9 */
  if (ncredef (exoid) == -1){
    exerrval = ncerr;
    sprintf(errmsg,"Error: failed to place file id %d into define mode",
            exoid);
    ex_err(PROCNAME,errmsg,exerrval);
    return (EX_FATAL);
  }

  if ( (dim=ncdimdef (exoid, NUM_CFRAMES, nframes)) == -1  ||
       (dim9=ncdimdef (exoid, NUM_CFRAME9, nframes*9))== -1 ){
    exerrval = ncerr;
    sprintf(errmsg,
         "Error: failed to define number of coordinate frames in file id %d",
            exoid);
    ex_err(PROCNAME,errmsg,exerrval);
    goto error_ret;
  }
 

  /* define the variables. coordinates, tags and ids */
  if ((varcoords=ncvardef (exoid, FRAME_COORDS,
                 nc_flt_code(exoid), 1, &dim9)) == -1  ||
      (varids=ncvardef (exoid, FRAME_IDS,NC_INT, 1, &dim)) == -1 ||
      (vartags=ncvardef(exoid, FRAME_TAGS,NC_CHAR,1,&dim)) == -1 ) {
    exerrval = ncerr;
    sprintf(errmsg,
            "Error:  failed to define coordinate frames in file id %d",
            exoid);
    ex_err(PROCNAME,errmsg,exerrval);
    goto error_ret;         /* exit define mode and return */
  }

  /* leave define mode */
  if (ncendef (exoid) == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
        "Error: failed to complete coordinate frame definition in file id %d", 
         exoid);
    ex_err(PROCNAME,errmsg,exerrval);
    return (EX_FATAL);
  }

  /* check variables consistency */
  exerrval = EX_NOERR;
  for (i=0;i<nframes;i++)
    if ( strchr("RrCcSs",tags[i])==0 ){
      sprintf(errmsg,"Warning: Unrecognized coordinate frame tag: '%c'.",
              tags[i]);
      exerrval=2;
      ex_err(PROCNAME,errmsg,exerrval);
    }
  /* could also check vectors. Leave this up to the application */

  /* put the variables into the file */
  pt_c = ex_conv_array(exoid,RTN_ADDRESS,pt_coordinates,count9);
  if (  ncvarput (exoid, vartags, &start, &count, tags) == -1 ||
        ncvarput (exoid, varids, &start, &count, cf_ids) == -1  ||
        ncvarput (exoid, varcoords, &start, &count9, pt_c )==-1 ){
    exerrval = ncerr;
    sprintf(errmsg,
            "Error: failed writing frame data in file id %d",exoid);
    ex_err(PROCNAME,errmsg,exerrval);
    return (EX_FATAL);
  }



  return (EX_NOERR);


 
error_ret:
  if (ncendef (exoid) == -1)     /* exit define mode */
    {
      sprintf(errmsg,
              "Error: failed to complete frame definition for file id %d",
              exoid);
      ex_err(PROCNAME,errmsg,exerrval);
    }
  return (EX_FATAL);


}
コード例 #20
0
ファイル: excopy.c プロジェクト: CPFDSoftware-Tony/gmv
int
cpy_var_val(int in_id,int out_id,char *var_nm)
/*
   int in_id: input netCDF input-file ID
   int out_id: input netCDF output-file ID
   char *var_nm: input variable name
 */
{
  /* Routine to copy the variable data from an input netCDF file
   * to an output netCDF file. 
   */

  int *dim_id;
  int idx;
  int nbr_dim;
  int var_in_id;
  int var_out_id;
  long *dim_cnt;
  long *dim_sz;
  long *dim_srt;
  long var_sz=1L;

  nc_type var_type_in, var_type_out;

  void *void_ptr;

  /* Get the var_id for the requested variable from both files. */
  var_in_id=ncvarid(in_id,var_nm);

  var_out_id=ncvarid(out_id,var_nm);
 
  /* Get the number of dimensions for the variable. */

  ncvarinq(out_id,var_out_id,(char *)NULL,&var_type_out,&nbr_dim,
                (int *)NULL,(int *)NULL);

  ncvarinq(in_id,var_in_id,(char *)NULL,&var_type_in,&nbr_dim,
                (int *)NULL,(int *)NULL);
 
  /* Allocate space to hold the dimension IDs */
  dim_cnt = malloc(nbr_dim*sizeof(long));

  dim_id=malloc(nbr_dim*sizeof(int));

  dim_sz=malloc(nbr_dim*sizeof(long));

  dim_srt=malloc(nbr_dim*sizeof(long));
 
  /* Get the dimension IDs from the input file */
  ncvarinq(in_id,var_in_id,(char *)NULL,(nc_type *)NULL,
                (int *)NULL,dim_id,(int *)NULL);
 
  /* Get the dimension sizes and names from the input file */
  for(idx=0;idx<nbr_dim;idx++){
  /* NB: For the unlimited dimension, ncdiminq() returns the maximum
     value used so far in writing data for that dimension.
     Thus if you read the dimension sizes from the output file, then
     the ncdiminq() returns dim_sz=0 for the unlimited dimension
     until a variable has been written with that dimension. This is
     the reason for always reading the input file for the dimension
     sizes. */

    ncdiminq(in_id,dim_id[idx],(char *)NULL,dim_cnt+idx);

    /* Initialize the indicial offset and stride arrays */
    dim_srt[idx]=0L;
    var_sz*=dim_cnt[idx];
  } /* end loop over dim */

  /* Allocate enough space to hold the variable */
  void_ptr=malloc(var_sz*nctypelen(var_type_in));

  /* Get the variable */

  /* if variable is float or double, convert if necessary */

  if(nbr_dim==0){  /* variable is a scalar */

    ncvarget1(in_id,var_in_id,0L,void_ptr);

    if ( ( (var_type_in == NC_FLOAT) && (var_type_out == NC_FLOAT) ) ||
         ( (var_type_in == NC_DOUBLE) && (var_type_out == NC_DOUBLE) ) ) {
      /* no conversion necessary */

      ncvarput1(out_id,var_out_id,0L,void_ptr);

    } else if ( (var_type_in == NC_FLOAT) && (var_type_out == NC_DOUBLE) ) {
      /* convert up */

      ncvarput1(out_id,var_out_id,0L,
                ex_conv_array (out_id, WRITE_CONVERT_UP, void_ptr, 1));

    } else if ( (var_type_in == NC_DOUBLE) && (var_type_out == NC_FLOAT) ) {
      /* convert down */

      ncvarput1(out_id,var_out_id,0L,
                ex_conv_array (out_id, WRITE_CONVERT_DOWN, void_ptr, 1));

    } else {  /* variable isn't float or double */

      /* no conversion necessary */

      ncvarput1(out_id,var_out_id,0L,void_ptr);

    }

  } else { /* variable is a vector */

    ncvarget(in_id,var_in_id,dim_srt,dim_cnt,void_ptr);

    if ( ( (var_type_in == NC_FLOAT) && (var_type_out == NC_FLOAT) ) ||
         ( (var_type_in == NC_DOUBLE) && (var_type_out == NC_DOUBLE) ) ) {
      /* no conversion necessary */

      ncvarput(out_id,var_out_id,dim_srt,dim_cnt,void_ptr);

    } else if ( (var_type_in == NC_FLOAT) && (var_type_out == NC_DOUBLE) ) {
      /* convert up */

      ncvarput(out_id,var_out_id,dim_srt,dim_cnt,
               ex_conv_array (out_id,WRITE_CONVERT_UP,void_ptr,var_sz));

    } else if ( (var_type_in == NC_DOUBLE) && (var_type_out == NC_FLOAT) ) {
      /* convert down */

      ncvarput(out_id,var_out_id,dim_srt,dim_cnt,
               ex_conv_array (out_id,WRITE_CONVERT_DOWN,void_ptr,var_sz));

    } else {  /* variable isn't float or double */

      /* no conversion necessary */

      ncvarput(out_id,var_out_id,dim_srt,dim_cnt,void_ptr);

    }

  } /* end if variable is an array */

  /* Free the space that held the dimension IDs */
  (void)free(dim_cnt);
  (void)free(dim_id);
  (void)free(dim_sz);
  (void)free(dim_srt);

  /* Free the space that held the variable */
  (void)free(void_ptr);

  return(EX_NOERR);

} /* end cpy_var_val() */
コード例 #21
0
ファイル: expnam.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_put_name (int   exoid,
		 int   obj_type,
		 int   entity_id,
		 const char *name)
{
   int varid, ent_ndx; 
   long  start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];
   const char *routine = "ex_put_name";
   
   exerrval = 0; /* clear error code */

   if (obj_type == EX_ELEM_BLOCK) {
     if ((varid = ncvarid (exoid, VAR_NAME_EL_BLK)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate element block names in file id %d",
	       exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     ent_ndx = ex_id_lkup(exoid, VAR_ID_EL_BLK, entity_id);
   }
   else if (obj_type == EX_NODE_SET) {
     if ((varid = ncvarid (exoid, VAR_NAME_NS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate nodeset names in file id %d",
	       exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
    ent_ndx = ex_id_lkup(exoid, VAR_NS_IDS, entity_id);
   }
   else if (obj_type == EX_SIDE_SET) {
     if ((varid = ncvarid (exoid, VAR_NAME_SS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate sideset names in file id %d",
	       exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
    ent_ndx = ex_id_lkup(exoid, VAR_SS_IDS, entity_id);
   }

   else if (obj_type == EX_NODE_MAP) {
     if ((varid = ncvarid (exoid, VAR_NAME_NM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate node map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     ent_ndx = ex_id_lkup(exoid, VAR_NM_PROP(1), entity_id);
   }

   else if (obj_type == EX_ELEM_MAP) {
     if ((varid = ncvarid (exoid, VAR_NAME_EM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate element map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     ent_ndx = ex_id_lkup(exoid, VAR_EM_PROP(1), entity_id);
   }

   else {/* invalid type */
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
	     "Error: Invalid type specified in file id %d", exoid);
     ex_err(routine,errmsg,exerrval);
     return(EX_FATAL);
   }
   
   /* If this is a null entity, then 'ent_ndx' will be negative.
    * We don't care in this routine, so make it positive and continue...
    */
   if (ent_ndx < 0) ent_ndx = -ent_ndx;
   
   /* write EXODUS entityname */
   start[0] = ent_ndx-1;
   start[1] = 0;
   
   count[0] = 1;
   count[1] = strlen(name) + 1;
   
   if (ncvarput (exoid, varid, start, count, (void*)name) == -1) {
     exerrval = ncerr;
     sprintf(errmsg,
	     "Error: failed to store entity name for id %d in file id %d",
	     ent_ndx, exoid);
     ex_err(routine,errmsg,exerrval);
     return (EX_FATAL);
   }
   return(EX_NOERR);
}
コード例 #22
0
ファイル: copy_data.c プロジェクト: BIC-MNI/minc
/* ----------------------------- MNI Header -----------------------------------
@NAME       : copy_the_chunk
@INPUT      : reshape_info - information for reshaping volume
              chunk_start - start of current block
              chunk_count - count for current block
              chunk_data - pointer to enough space for chunk
              fillvalue - pixel value to zero volume, if necessary.
@OUTPUT     : (none)
@RETURNS    : (nothing)
@DESCRIPTION: Copies the chunk from the input file to the output file.
@METHOD     :
@GLOBALS    :
@CALLS      :
@CREATED    : October 25, 1994 (Peter Neelin)
@MODIFIED   :
---------------------------------------------------------------------------- */
static void copy_the_chunk(Reshape_info *reshape_info,
                           long chunk_start[],
                           long chunk_count[],
                           void *chunk_data,
                           double fillvalue)
{
   int idim, odim, in_ndims, out_ndims;
   long input_start[MAX_VAR_DIMS], input_count[MAX_VAR_DIMS];
   long output_start[MAX_VAR_DIMS], output_count[MAX_VAR_DIMS];
   long input_imap[MAX_VAR_DIMS], output_imap[MAX_VAR_DIMS];
   void *output_origin;
   int datatype_size;
   long total_size, ipix, first, last;
   int zero_data, really_copy_the_data;
   union {
      char c; short s; long l; float f; double d;
   } value_buffer;

   /* Get number of dimensions */
   out_ndims = reshape_info->output_ndims;
   in_ndims = reshape_info->input_ndims;

   /* Get size of output datatype */
   datatype_size = nctypelen(reshape_info->output_datatype);

   /* Create input start and count */
   translate_output_to_input(reshape_info, chunk_start, chunk_count,
                             input_start, input_count);

   /* Find out if we need to zero the volume and if we need to copy any
      data */
   zero_data = FALSE;
   really_copy_the_data = TRUE;
   total_size = 1;
   for (idim=0; idim < in_ndims; idim++) {
      first = input_start[idim];
      last = input_start[idim] + input_count[idim] - 1;
      if ((first < 0) || (last >= reshape_info->input_size[idim]))
         zero_data = TRUE;
      if ((last < 0) || (first >= reshape_info->input_size[idim]))
         really_copy_the_data = FALSE;
      total_size *= input_count[idim];
   }

   /* Make sure that input vectors are legal and translate them back 
      to output */
   truncate_input_vectors(reshape_info, input_start, input_count);
   translate_input_to_output(reshape_info, input_start, input_count,
                             output_start, output_count);

   /* Write out zero data if needed */
   if (zero_data) {
      convert_value_from_double(fillvalue, 
                                reshape_info->output_datatype,
                                reshape_info->output_is_signed,
                                &value_buffer);
      for (ipix=0; ipix < total_size; ipix++) {
         (void) memcpy((char *)chunk_data + ipix*datatype_size,
                       &value_buffer, datatype_size);
      }
      (void) ncvarput(reshape_info->outmincid, reshape_info->outimgid,
                      chunk_start, chunk_count, chunk_data);
   }

   /* Set up hypothetical imap variable for input */
   for (idim=in_ndims-1; idim >= 0; idim--) {
      input_imap[idim] = ((idim == in_ndims-1) ? 
                          datatype_size :
                          input_imap[idim+1] * input_count[idim+1]);
   }

   /* Create output imap variable from input one (re-ordering dimensions and
      flipping). Also work out the chunk origin (point to byte for output
      [0,0,0...]). */
   output_origin = chunk_data;
   for (odim=0; odim < out_ndims; odim++) {
      idim = reshape_info->map_out_to_in[odim];
      if (reshape_info->input_count[idim] > 0) {
         output_imap[odim] = input_imap[idim];
      }
      else {
         output_imap[odim] = -input_imap[idim];
         output_origin = 
            (void *) ((char *)output_origin - 
                      (output_count[odim] - 1) * output_imap[odim]);
      }
   }

   /* Should we really copy the data? */
   if (really_copy_the_data) {

      /* Read in the data */
      (void) miicv_get(reshape_info->icvid, input_start, input_count, 
                       chunk_data);
   
      /* Write it out */
      (void) ncvarputg(reshape_info->outmincid, reshape_info->outimgid,
                       output_start, output_count, NULL, output_imap, 
                       output_origin);

   }

}
コード例 #23
0
ファイル: expvan.c プロジェクト: hs9906/paraview
int ex_put_var_names (int   exoid,
                      const char *var_type,
                      int   num_vars,
                      char* var_names[])
{
   int i, varid; 
   long  start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];
   int vartyp;

   exerrval = 0; /* clear error code */

   vartyp = tolower( *var_type );
   switch (vartyp) {
   case 'g':
     EX_PUT_NAMES(     "global",DIM_NUM_GLO_VAR,  VAR_NAME_GLO_VAR);
     break;
   case 'n':
     EX_PUT_NAMES(      "nodal",DIM_NUM_NOD_VAR,  VAR_NAME_NOD_VAR);
     break;
   case 'l':
     EX_PUT_NAMES(       "edge",DIM_NUM_EDG_VAR,  VAR_NAME_EDG_VAR);
     break;
   case 'f':
     EX_PUT_NAMES(       "face",DIM_NUM_FAC_VAR,  VAR_NAME_FAC_VAR);
     break;
   case 'e':
     EX_PUT_NAMES(    "element",DIM_NUM_ELE_VAR,  VAR_NAME_ELE_VAR);
     break;
   case 'm':
     EX_PUT_NAMES(   "node set",DIM_NUM_NSET_VAR, VAR_NAME_NSET_VAR);
     break;
   case 'd':
     EX_PUT_NAMES(   "edge set",DIM_NUM_ESET_VAR, VAR_NAME_ESET_VAR);
     break;
   case 'a':
     EX_PUT_NAMES(   "face set",DIM_NUM_FSET_VAR, VAR_NAME_FSET_VAR);
     break;
   case 's':
     EX_PUT_NAMES(   "side set",DIM_NUM_SSET_VAR, VAR_NAME_SSET_VAR);
     break;
   case 't':
     EX_PUT_NAMES("element set",DIM_NUM_ELSET_VAR,VAR_NAME_ELSET_VAR);
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
            "Error: Invalid variable type %c specified in file id %d",
             *var_type, exoid);
     ex_err("ex_put_var_names",errmsg,exerrval);
     return(EX_FATAL);
   }



/* write EXODUS variable names */

   for (i=0; i<num_vars; i++)
   {
     start[0] = i;
     start[1] = 0;

     count[0] = 1;
     count[1] = strlen(var_names[i]) + 1;

     if (ncvarput (exoid, varid, start, count, (void*) var_names[i]) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
               "Error: failed to store variable names in file id %d",
                exoid);
       ex_err("ex_put_var_names",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   return(EX_NOERR);

}
コード例 #24
0
int ex_put_node_map (int exoid,
                     int map_id,
                     const int *node_map)
{
   int dimid, varid, iresult;
   long start[1]; 
   nclong ldum, *lptr;
   long num_node_maps, num_nodes, count[1];
   int cur_num_node_maps;
   char *cdum;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   cdum = 0;


   /* Return if node nodes stored in this file */
   if ((dimid = (ncdimid (exoid, DIM_NUM_NODES))) == -1 ) {
     return (EX_NOERR);
   }

/* first check if any node maps are specified */

   if ((dimid = (ncdimid (exoid, DIM_NUM_NM))) == -1 )
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: no node maps specified in file id %d",
             exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Check for duplicate node map id entry */
   ex_id_lkup(exoid,VAR_NM_PROP(1),map_id);
   if (exerrval != EX_LOOKUPFAIL)   /* found the node map id */
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: node map %d already defined in file id %d",
             map_id,exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return(EX_FATAL);
   }

/* Get number of node maps initialized for this file */
   if ((ncdiminq (exoid,dimid,cdum,&num_node_maps)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of node maps in file id %d",
             exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Keep track of the total number of node maps defined using a counter stored
   in a linked list keyed by exoid.
   NOTE: ex_get_file_item  is used to find the number of node maps
         for a specific file and returns that value.
*/
   cur_num_node_maps = ex_get_file_item(exoid, &nm_ctr_list );
   if (cur_num_node_maps >= num_node_maps)
   {
     exerrval = EX_FATAL;
     sprintf(errmsg,
          "Error: exceeded number of node maps (%ld) specified in file id %d",
             num_node_maps,exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/*   NOTE: ex_inc_file_item  is used to find the number of node maps
         for a specific file and returns that value incremented. */

   cur_num_node_maps = ex_inc_file_item(exoid, &nm_ctr_list );

/* write out information to previously defined variable */

   /* first get id of variable */

   if ((varid = ncvarid (exoid, VAR_NM_PROP(1))) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate node map ids in file id %d",
             exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   /* then, write out node map id */

   start[0] = cur_num_node_maps;

   ldum = (nclong)map_id;
   if (ncvarput1 (exoid, varid, start, &ldum) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store node map id %d in file id %d",
             map_id,exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

/* determine number of nodes */

   if ((dimid = (ncdimid (exoid, DIM_NUM_NODES))) == -1 )
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: couldn't determine number of nodes in file id %d",
             exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (ncdiminq (exoid, dimid, (char *) 0, &num_nodes) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get number of nodes in file id %d",
             exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   /* find variable array in which to store the node map */
   if ((varid = ncvarid(exoid,VAR_NODE_MAP(cur_num_node_maps+1))) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
	       "Error: failed to locate node map %d in file id %d",
               map_id,exoid);
       ex_err("ex_put_node_map",errmsg,exerrval);
       return(EX_FATAL);
     }

/* write out the node map  */

/* this contortion is necessary because netCDF is expecting nclongs; fortunately
   it's necessary only when ints and nclongs aren't the same size */

   start[0] = 0;
   count[0] = num_nodes;

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarput (exoid, varid, start, count, node_map);
   } else {
      lptr = itol (node_map, (int)num_nodes);
      iresult = ncvarput (exoid, varid, start, count, lptr);
      free(lptr);
   }

   if (iresult == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store node map in file id %d",
             exoid);
     ex_err("ex_put_node_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);
}
コード例 #25
0
ファイル: example.c プロジェクト: Gilles86/afni
int
main() {			/* create example.cdf */

   int  ncid;			/* netCDF id */

   /* dimension ids */
   int  lat_dim, lon_dim, frtime_dim, timelen_dim;

   /* variable ids */
   int  P_id, lat_id, lon_id, frtime_id, reftime_id, scalarv_id;

   /* variable shapes */
   int dims[3];

   /* containers for scalar attributes */
   float  float_val;
   double  double_val;

   /* attribute vectors */
   float  P_valid_range[2];

   /* enter define mode */
   ncid = nccreate("example.nc", NC_CLOBBER);

   /* define dimensions */
   lat_dim = ncdimdef(ncid, "lat", 4L);
   lon_dim = ncdimdef(ncid, "lon", 3L);
   frtime_dim = ncdimdef(ncid, "frtime", NC_UNLIMITED);
   timelen_dim = ncdimdef(ncid, "timelen", 20L);

   /* define variables and assign attributes */

   dims[0] = frtime_dim;
   dims[1] = lat_dim;
   dims[2] = lon_dim;
   P_id = ncvardef (ncid, "P", NC_FLOAT, 3, dims);
   ncattput (ncid, P_id, "long_name", NC_CHAR, 24,
	     (void *)"pressure at maximum wind");
   ncattput (ncid, P_id, "units", NC_CHAR, 12,
	     (void *)"hectopascals");
   P_valid_range[0] = 0;
   P_valid_range[1] = 1500;
   ncattput (ncid, P_id, "valid_range", NC_FLOAT, 2,
	     (void *) P_valid_range);
   float_val = -9999;
   ncattput (ncid, P_id, "_FillValue", NC_FLOAT, 1,
	     (void *) &float_val);

   dims[0] = lat_dim;
   lat_id = ncvardef (ncid, "lat", NC_FLOAT, 1, dims);
   ncattput (ncid, lat_id, "long_name", NC_CHAR, 8,
	     (void *)"latitude");
   ncattput (ncid, lat_id, "units", NC_CHAR, 13,
	     (void *)"degrees_north");

   dims[0] = lon_dim;
   lon_id = ncvardef (ncid, "lon", NC_FLOAT, 1, dims);
   ncattput (ncid, lon_id, "long_name", NC_CHAR, 9,
	     (void *)"longitude");
   ncattput (ncid, lon_id, "units", NC_CHAR, 12,
	     (void *)"degrees_east");

   dims[0] = frtime_dim;
   frtime_id = ncvardef (ncid, "frtime", NC_LONG, 1, dims);
   ncattput (ncid, frtime_id, "long_name", NC_CHAR, 13,
	     (void *)"forecast time");
   ncattput (ncid, frtime_id, "units", NC_CHAR, 5,
	     (void *)"hours");

   dims[0] = timelen_dim;
   reftime_id = ncvardef (ncid, "reftime", NC_CHAR, 1, dims);
   ncattput (ncid, reftime_id, "long_name", NC_CHAR, 14,
	     (void *)"reference time");
   ncattput (ncid, reftime_id, "units", NC_CHAR, 9,
	     (void *)"text_time");

   scalarv_id = ncvardef (ncid, "scalarv", NC_LONG, 0, 0);
   double_val = 1;
   ncattput (ncid, scalarv_id, "scalar_att", NC_DOUBLE, 1,
	     (void *) &double_val);

   /* Global attributes */
   ncattput (ncid, NC_GLOBAL, "history", NC_CHAR, 41,
	     (void *)"created by Unidata LDM from NPS broadcast");
   ncattput (ncid, NC_GLOBAL, "title", NC_CHAR, 48,
	     (void *)"NMC Global Product Set: Pressure at Maximum Wind");

   /* leave define mode */
   ncendef (ncid);
  
   {			/* store lat */
    static long lat_start[] = {0};
    static long lat_edges[] = {4};
    static float lat[] = {-90, -87.5, -85, -82.5};
    ncvarput(ncid, lat_id, lat_start, lat_edges, (void *)lat);
   }

   {			/* store lon */
    static long lon_start[] = {0};
    static long lon_edges[] = {3};
    static float lon[] = {-180, -175, -170};
    ncvarput(ncid, lon_id, lon_start, lon_edges, (void *)lon);
   }

   {			/* store frtime */
    static long frtime_start[] = {0};
    static long frtime_edges[] = {1};
    static long frtime[] = {12};
    ncvarput(ncid, frtime_id, frtime_start, frtime_edges,
	     (void *)frtime);
   }

   {			/* store frtime */
    static long frtime_start[] = {1};
    static long frtime_edges[] = {1};
    static long frtime[] = {18};
    ncvarput(ncid, frtime_id, frtime_start, frtime_edges,
	     (void *)frtime);
   }

   {			/* store reftime */
    static long reftime_start[] = {0};
    static long reftime_edges[] = {20};
    static char reftime[] = {"1992 03 04 12:00"};
    ncvarput(ncid, reftime_id, reftime_start, reftime_edges,
	     (void *)reftime);
   }

   {			/* store P */
    static long P_start[] = {0, 0, 0};
    static long P_edges[] = {2, 4, 3};
    static float P[2][4][3] = {
	{{950, 951, 952}, {953, 954, 955}, {956, 957, 958}, {959, 960, 961}},
	{{962, 963, 964}, {965, 966, 967}, {968, 969, 970}, {971, 972, 973}}
      };
    ncvarput(ncid, P_id, P_start, P_edges, (void *)&P[0][0][0]);
   }

   {			/* store scalarv */
    static long scalarv = {-2147483647};
    ncvarput1(ncid, scalarv_id, (long *)0, (void *)&scalarv);
   }
   ncclose (ncid);
   return 0;
}
コード例 #26
0
ファイル: expnams.c プロジェクト: hs9906/paraview
int ex_put_names (int   exoid,
      int   obj_type,
      char* names[])
{
   int i, varid; 
   long num_entity;
   long  start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];
   const char *routine = "ex_put_names";
   
   exerrval = 0; /* clear error code */

   switch (obj_type) {
     /*  ======== BLOCKS ========= */
   case EX_EDGE_BLOCK:
     ex_get_dimension(exoid, DIM_NUM_ED_BLK, "edge block", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_ED_BLK)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate edge block names in file id %d",
         exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_FACE_BLOCK:
     ex_get_dimension(exoid, DIM_NUM_FA_BLK, "face block", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_FA_BLK)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate face block names in file id %d",
         exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_ELEM_BLOCK:
     ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element block", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_EL_BLK)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate element block names in file id %d",
         exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;

     /*  ======== SETS ========= */
   case EX_NODE_SET:
     ex_get_dimension(exoid, DIM_NUM_NS, "nodeset", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_NS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate nodeset names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_EDGE_SET:
     ex_get_dimension(exoid, DIM_NUM_ES, "edgeset", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_ES)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate edgeset names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_FACE_SET:
     ex_get_dimension(exoid, DIM_NUM_FS, "faceset", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_FS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate faceset names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_SIDE_SET:
     ex_get_dimension(exoid, DIM_NUM_SS, "sideset", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_SS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate sideset names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_ELEM_SET:
     ex_get_dimension(exoid, DIM_NUM_ELS, "elemset", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_ELS)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate elemset names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;

     /*  ======== MAPS ========= */
   case EX_NODE_MAP:
     ex_get_dimension(exoid, DIM_NUM_NM, "node map", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_NM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate node map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_EDGE_MAP:
     ex_get_dimension(exoid, DIM_NUM_EDM, "edge map", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_EDM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate edge map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_FACE_MAP:
     ex_get_dimension(exoid, DIM_NUM_FAM, "face map", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_FAM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate face map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;
   case EX_ELEM_MAP:
     ex_get_dimension(exoid, DIM_NUM_EM, "element map", &num_entity, routine);

     if ((varid = ncvarid (exoid, VAR_NAME_EM)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to locate element map names in file id %d", exoid);
       ex_err(routine,errmsg,exerrval);
       return (EX_FATAL);
     }
     break;

     /*  ======== ERROR (Invalid type) ========= */
   default:
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
       "Error: Invalid type specified in file id %d", exoid);
     ex_err(routine,errmsg,exerrval);
     return(EX_FATAL);
   }
   

   /* write EXODUS entity names */

   for ( i = 0; (long)i < num_entity; i++)
     {
     if ( names[i] != (char)'\0' ) {
       start[0] = i;
       start[1] = 0;

       count[0] = 1;
       count[1] = strlen(names[i]) + 1;

       if (ncvarput (exoid, varid, start, count, (void*) names[i]) == -1) {
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to store entity names in file id %d", exoid);
         ex_err(routine,errmsg,exerrval);
         return (EX_FATAL);
       }
     }
   }
   return(EX_NOERR);
}
コード例 #27
0
ファイル: excopy.c プロジェクト: CPFDSoftware-Tony/gmv
int
cpy_coord_val(int in_id,int out_id,char *var_nm,
              int in_large, int out_large)
/*
   int in_id: input netCDF input-file ID
   int out_id: input netCDF output-file ID
   char *var_nm: input variable name
 */
{
  /* Routine to copy the coordinate data from an input netCDF file
   * to an output netCDF file. 
   */

  const char *routine = NULL;
  int i;
  long spatial_dim, num_nodes;
  long start[2], count[2];
  nc_type var_type_in, var_type_out;

  void *void_ptr;

  /* Handle easiest situation first: in_large matches out_large */
  if (in_large == out_large)
    return cpy_var_val(in_id, out_id, var_nm);
  
  /* At this point, know that in_large != out_large, so will need to
     either copy a vector to multiple scalars or vice-versa.  Also
     will a couple dimensions, so get them now.*/
  ex_get_dimension(in_id, DIM_NUM_DIM, "dimension", &spatial_dim, routine);
  ex_get_dimension(in_id, DIM_NUM_NODES, "nodes",   &num_nodes, routine);

  if (in_large == 0 && out_large == 1) {
    /* output file will have coordx, coordy, coordz (if 3d). */
    /* Get the var_id for the requested variable from both files. */
    int var_in_id, var_out_id[3];
    var_in_id = ncvarid(in_id, VAR_COORD);
    var_out_id[0] = ncvarid(out_id,VAR_COORD_X);
    var_out_id[1] = ncvarid(out_id,VAR_COORD_Y);
    var_out_id[2] = ncvarid(out_id,VAR_COORD_Z);

    ncvarinq(in_id,var_in_id,(char *)NULL,&var_type_in,(int*)NULL,
                (int *)NULL,(int *)NULL);
    ncvarinq(out_id,var_out_id[0],(char *)NULL,&var_type_out,(int *)NULL,
                (int *)NULL,(int *)NULL);

    void_ptr=malloc(num_nodes * nctypelen(var_type_in));

    /* Copy each component of the variable... */
    for (i=0; i < spatial_dim; i++) {
      start[0] = i; start[1] = 0;
      count[0] = 1; count[1] = num_nodes;
      ncvarget(in_id, var_in_id, start, count, void_ptr);
      
      if (var_type_in == var_type_out) {
        if (var_type_out == NC_FLOAT) {
          nc_put_var_float(out_id, var_out_id[i], void_ptr);
        } else {
          nc_put_var_double(out_id, var_out_id[i], void_ptr);
        }
      } else if (var_type_in == NC_FLOAT && var_type_out == NC_DOUBLE) {
        nc_put_var_double(out_id, var_out_id[i],
                          ex_conv_array(out_id, WRITE_CONVERT_UP, void_ptr, num_nodes));
      } else if (var_type_in == NC_DOUBLE && var_type_out == NC_FLOAT) {
        nc_put_var_float(out_id, var_out_id[i],
                          ex_conv_array(out_id, WRITE_CONVERT_DOWN, void_ptr, num_nodes));
      }
    }
  }

  if (in_large == 1 && out_large == 0) {
    /* input file will have coordx, coordy, coordz (if 3d); output has
       only "coord" */
    int var_in_id[3], var_out_id;
    var_in_id[0] = ncvarid(in_id,  VAR_COORD_X);
    var_in_id[1] = ncvarid(in_id,  VAR_COORD_Y);
    var_in_id[2] = ncvarid(in_id,  VAR_COORD_Z);
    var_out_id   = ncvarid(out_id, VAR_COORD);
    
    ncvarinq(in_id,var_in_id[0],(char *)NULL,&var_type_in,(int *)NULL,
                (int *)NULL,(int *)NULL);

    ncvarinq(out_id,var_out_id,(char *)NULL,&var_type_out,(int*)NULL,
                (int *)NULL,(int *)NULL);

    void_ptr=malloc(num_nodes * nctypelen(var_type_in));

    /* Copy each component of the variable... */
    for (i=0; i < spatial_dim; i++) {
      if (var_type_in == NC_FLOAT) {
        nc_get_var_float(in_id, var_in_id[i], void_ptr);
      } else {
        nc_get_var_double(in_id, var_in_id[i], void_ptr);
      }

      start[0] = i; start[1] = 0;
      count[0] = 1; count[1] = num_nodes;
      if (var_type_in == var_type_out) {
        ncvarput(out_id, var_out_id, start, count, void_ptr);
      } else if (var_type_in == NC_FLOAT && var_type_out == NC_DOUBLE) {
        ncvarput(out_id, var_out_id, start, count,
                 ex_conv_array(out_id, WRITE_CONVERT_UP, void_ptr, num_nodes));
      } else if (var_type_in == NC_DOUBLE && var_type_out == NC_FLOAT) {
        ncvarput(out_id, var_out_id, start, count,
                 ex_conv_array(out_id, WRITE_CONVERT_DOWN, void_ptr, num_nodes));
      }
    }
  }

  /* Free the space that held the variable */
  (void)free(void_ptr);

  return(EX_NOERR);

} /* end cpy_coord_val() */
コード例 #28
0
ファイル: mppnccombine.c プロジェクト: rwills/fms-idealized
/* Copy all the data values in an input netCDF file */
int copy_nc_data(struct fileinfo *ncinfile, int outncfid,
                 unsigned char appendnc, unsigned char verbose)
{
    int v, d, r;  /* Loop variables */
    int dimid;  /* ID of a dimension */
    void *values;  /* Data values to copy */
    long instart[MAX_NC_DIMS], outstart[MAX_NC_DIMS];  /* Copy array sizes */
    long count[MAX_NC_DIMS];                           /*        "         */
    long nrecs;  /* Number of records */
    long recsize;  /* Number of values in a record */
    int varrecdim;  /* Position of a variable's record dimension */

    /* Loop over all the records */
    nrecs=ncinfile->dimsize[ncinfile->recdim];
    for (r=0; r < nrecs; r++)
    {
#if DEBUG==0
        if (verbose) printf("\n  record=%d",r+1);
#endif

        /* Loop over all the variables */
        for (v=0; v < ncinfile->nvars; v++)
        {
#if DEBUG==0
            if (verbose) printf("\n    variable=%s",ncinfile->varname[v]);
#endif

            /* Avoid multiple reads/writes of non-decomposed dimensions */
            if ((dimid=ncdimid(ncinfile->ncfid,ncinfile->varname[v]))!=(-1))
                if (appendnc && ncinfile->dimend[dimid]==(-1)) continue;

            /* Get read/write dimension sizes for the variable */
            recsize=1;
            varrecdim=(-1);
            for (d=0; d < ncinfile->varndims[v]; d++)
            {
                if (ncinfile->vardim[v][d]==ncinfile->recdim)
                {
                    count[d]=1;
                    varrecdim=d;
                }
                else
                {
                    count[d]=ncinfile->dimsize[ncinfile->vardim[v][d]];
                    recsize*=count[d];
                    instart[d]=0;
                    outstart[d]=ncinfile->dimstart[ncinfile->vardim[v][d]]-1;
                }
#if DEBUG==1
                printf("%d:  instart=%ld  ouststart=%ld  count=%ld\n",d,
                       instart[d],outstart[d],count[d]);
#endif
            }

            /* Avoid multiple reads/writes of non-record variables */
            if (varrecdim==(-1) && r > 0) continue;

#if DEBUG==0
            if (verbose) printf("  (read/write)");
#endif

            /* Allocate a buffer for the variable's record */
            if ((values=malloc(nctypelen(ncinfile->datatype[v])*recsize))==NULL)
            {
                fprintf(stderr,"Error: cannot allocate memory for variable \"%s\"'s values!\n",
                        ncinfile->varname[v]);
                return(1);
            }

            /* Copy the record */
            if (varrecdim!=(-1)) instart[varrecdim]=outstart[varrecdim]=r;
            if (ncvarget(ncinfile->ncfid,v,instart,count,values)==(-1))
            {
                fprintf(stderr,"Error: cannot read variable \"%s\"'s values!\n",
                        ncinfile->varname[v]);
                return(1);
            }
            if (ncvarput(outncfid,v,outstart,count,values)==(-1))
            {
                fprintf(stderr,"Error: cannot write variable \"%s\"'s values!\n",
                        ncinfile->varname[v]);
                return(1);
            }

            /* Deallocate the record buffer */
            free(values);
        }
    }
    return(0);
}
コード例 #29
0
ファイル: expenm.c プロジェクト: CPFDSoftware-Tony/gmv
int ex_put_elem_num_map (int  exoid,
                         const int *elem_map)
{
  int numelemdim, dims[1], mapid, iresult;
  long num_elem, start[1], count[1]; 
  nclong *lptr;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* inquire id's of previously defined dimensions  */

  /* determine number of elements. Return if zero... */
  if ((numelemdim = ncdimid (exoid, DIM_NUM_ELEM)) == -1)
    {
      return (EX_NOERR);
    }

  if (ncdiminq (exoid, numelemdim, (char *) 0, &num_elem) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to get number of elements in file id %d",
              exoid);
      ex_err("ex_put_elem_num_map",errmsg,exerrval);
      return (EX_FATAL);
    }


  /* put netcdf file into define mode  */

  if ((mapid = ncvarid (exoid, VAR_ELEM_NUM_MAP)) == -1) {
    if (ncredef (exoid) == -1)
      {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to put file id %d into define mode",
                exoid);
        ex_err("ex_put_elem_num_map",errmsg,exerrval);
        return (EX_FATAL);
      }


    /* create a variable array in which to store the element numbering map  */

    dims[0] = numelemdim;

    if ((mapid = ncvardef (exoid, VAR_ELEM_NUM_MAP, NC_LONG, 1, dims)) == -1)
      {
        if (ncerr == NC_ENAMEINUSE)
          {
            exerrval = ncerr;
            sprintf(errmsg,
                    "Error: element numbering map already exists in file id %d",
                    exoid);
            ex_err("ex_put_elem_num_map",errmsg,exerrval);
          }
        else
          {
            exerrval = ncerr;
            sprintf(errmsg,
                    "Error: failed to create element numbering map in file id %d",
                    exoid);
            ex_err("ex_put_elem_num_map",errmsg,exerrval);
          }
        goto error_ret;         /* exit define mode and return */
      }


    /* leave define mode  */

    if (ncendef (exoid) == -1)
      {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to complete definition in file id %d",
                exoid);
        ex_err("ex_put_elem_num_map",errmsg,exerrval);
        return (EX_FATAL);
      }
  }

  /* write out the element numbering map  */

  /* this contortion is necessary because netCDF is expecting nclongs; fortunately
     it's necessary only when ints and nclongs aren't the same size */

  start[0] = 0;
  count[0] = num_elem;

  if (sizeof(int) == sizeof(nclong)) {
    iresult = ncvarput (exoid, mapid, start, count, elem_map);
  } else {
    lptr = itol (elem_map, (int)num_elem);
    iresult = ncvarput (exoid, mapid, start, count, lptr);
    free(lptr);
  }

  if (iresult == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to store element numbering map in file id %d",
              exoid);
      ex_err("ex_put_elem_num_map",errmsg,exerrval);
      return (EX_FATAL);
    }


  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (ncendef (exoid) == -1)     /* exit define mode */
    {
      sprintf(errmsg,
              "Error: failed to complete definition for file id %d",
              exoid);
      ex_err("ex_put_elem_num_map",errmsg,exerrval);
    }
  return (EX_FATAL);
}
コード例 #30
0
ファイル: exppem.c プロジェクト: hs9906/paraview
/*!
 * writes an element map; this is a vector of integers of length number
 * of elements
 */
int ex_put_partial_elem_map (int exoid,
           int map_id,
           int ent_start,
           int ent_count, 
           const int *elem_map)
{
  int dimid, varid, iresult, map_ndx, map_exists;
  long start[1]; 
  nclong ldum, *lptr;
  long num_elem_maps, num_elem, count[1];
  int cur_num_elem_maps;
  char *cdum;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */
  map_exists = 0;
  cdum = 0;


  /* Make sure the file contains elements */
  if ((dimid = (ncdimid (exoid, DIM_NUM_ELEM))) == -1 )
    {
      return (EX_NOERR);
    }

  /* first check if any element maps are specified */

  if ((dimid = (ncdimid (exoid, DIM_NUM_EM))) == -1 )
    {
      exerrval = ncerr;
      sprintf(errmsg,
        "Error: no element maps specified in file id %d",
        exoid);
      ex_err("ex_put_partial_elem_map",errmsg,exerrval);
      return (EX_FATAL);
    }

  /* Check for duplicate element map id entry */
  map_ndx = ex_id_lkup(exoid,VAR_EM_PROP(1),map_id); 
  if (exerrval == EX_LOOKUPFAIL) {   /* did not find the element map id */
    map_exists = 0; /* Map is being defined */
    map_ndx    = -1;
  } else {
    map_exists = 1; /* A portion of this map has already been written */
  }

  if (!map_exists) {
    /* Get number of element maps initialized for this file */
    if ((ncdiminq (exoid,dimid,cdum,&num_elem_maps)) == -1)
      {
  exerrval = ncerr;
  sprintf(errmsg,
    "Error: failed to get number of element maps in file id %d",
    exoid);
  ex_err("ex_put_partial_elem_map",errmsg,exerrval);
  return (EX_FATAL);
      }

    /* Keep track of the total number of element maps defined using a
       counter stored in a linked list keyed by exoid.  NOTE:
       ex_get_file_item is used to find the number of element maps for a
       specific file and returns that value.
    */
    cur_num_elem_maps = ex_get_file_item(exoid, &em_ctr_list );
    if (cur_num_elem_maps >= num_elem_maps)
      {
  exerrval = EX_FATAL;
  sprintf(errmsg,
    "Error: exceeded number of element maps (%ld) specified in file id %d",
    num_elem_maps,exoid);
  ex_err("ex_put_partial_elem_map",errmsg,exerrval);
  return (EX_FATAL);
      }
    
    /*   NOTE: ex_inc_file_item  is used to find the number of element maps
   for a specific file and returns that value incremented. */
    
    cur_num_elem_maps = ex_inc_file_item(exoid, &em_ctr_list );
  } else {
    cur_num_elem_maps = map_ndx-1;
  }

  /* determine number of elements */
  if ((dimid = (ncdimid (exoid, DIM_NUM_ELEM))) == -1 )
    {
      exerrval = ncerr;
      sprintf(errmsg,
        "Error: couldn't determine number of elements in file id %d",
        exoid);
      ex_err("ex_put_partial_elem_map",errmsg,exerrval);
      return (EX_FATAL);
    }

  if (ncdiminq (exoid, dimid, (char *) 0, &num_elem) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
        "Error: failed to get number of elements in file id %d",
        exoid);
      ex_err("ex_put_partial_elem_map",errmsg,exerrval);
      return (EX_FATAL);
    }

  /* Check input parameters for a valid range of numbers */
  if (ent_start <= 0 || ent_start > num_elem) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: start count is invalid in file id %d",
      exoid);
    ex_err("ex_put_partial_elem_map",errmsg,exerrval);
    return (EX_FATAL);
  }
  if (ent_count < 0) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: Invalid count value in file id %d",
      exoid);
    ex_err("ex_put_partial_elem_map",errmsg,exerrval);
    return (EX_FATAL);
  }
  if (ent_start+ent_count-1 > num_elem) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: start+count-1 is larger than element count in file id %d",
      exoid);
    ex_err("ex_put_partial_elem_map",errmsg,exerrval);
    return (EX_FATAL);
  }
  

  /* write out information to previously defined variable */

  /* first get id of variable */
  if ((varid = ncvarid (exoid, VAR_EM_PROP(1))) == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
      "Error: failed to locate element map ids in file id %d",
      exoid);
    ex_err("ex_put_partial_elem_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* then, write out element map id */
  if (!map_exists) {
    start[0] = cur_num_elem_maps;

    ldum = (nclong)map_id;
    if (ncvarput1 (exoid, varid, start, &ldum) == -1)
      {
  exerrval = ncerr;
  sprintf(errmsg,
    "Error: failed to store element map id %d in file id %d",
    map_id,exoid);
  ex_err("ex_put_partial_elem_map",errmsg,exerrval);
  return (EX_FATAL);
      }
  }
  
  /* locate variable array in which to store the element map */
  if ((varid = 
       ncvarid(exoid,VAR_ELEM_MAP(cur_num_elem_maps+1))) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to locate element map %d in file id %d",
        map_id,exoid);
      ex_err("ex_put_partial_elem_map",errmsg,exerrval);
      return (EX_FATAL);
    }

  /* write out the element map  */

  /* this contortion is necessary because netCDF is expecting nclongs;
     fortunately it's necessary only when ints and nclongs aren't the
     same size */

  start[0] = ent_start-1;
  count[0] = ent_count;

  if (sizeof(int) == sizeof(nclong)) {
    iresult = ncvarput (exoid, varid, start, count, elem_map);
  } else {
    lptr = itol (elem_map, (int)ent_count);
    iresult = ncvarput (exoid, varid, start, count, lptr);
    free(lptr);
  }

  if (iresult == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
        "Error: failed to store element map in file id %d",
        exoid);
      ex_err("ex_put_partial_elem_map",errmsg,exerrval);
      return (EX_FATAL);
    }

  return (EX_NOERR);
}