Beispiel #1
0
int ex_get_varid_var(int   exoid,
                     int   time_step,
                     int   varid,
                     int   num_entity,
                     void *var_vals)
{
  long start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];
  void *array;
  
  exerrval = 0; /* clear error code */

  /* read values of element variable */

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

  array = ex_conv_array(exoid,RTN_ADDRESS,var_vals,num_entity);
  if (ncvarget (exoid, varid, start, count, array) == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
            "Error: failed to get variable with variable id %d in file id %d",
            varid,exoid);/*this msg needs to be improved*/
    ex_err("ex_get_varid_var",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (array != var_vals) {
    ex_conv_array(exoid, READ_CONVERT, var_vals, num_entity);
  }
  return (EX_NOERR);
}
Beispiel #2
0
int ex_get_glob_vars (int   exoid,
                      int   time_step,
                      int   num_glob_vars,
                      void *glob_var_vals)
{
   int varid;
   long start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

/* inquire previously defined variable */

   if ((varid = ncvarid (exoid, VAR_GLO_VAR)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Warning: failed to locate global variables in file id %d",
            exoid);
     ex_err("ex_get_glob_vars",errmsg,exerrval);
     return (EX_WARN);
   }


/* read values of global variables */

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

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

   if (ncvarget (exoid, varid, start, count,
           ex_conv_array(exoid,RTN_ADDRESS,glob_var_vals,num_glob_vars)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get global variable values from file id %d",
            exoid);
     ex_err("ex_get_glob_vars",errmsg,exerrval);
     return (EX_FATAL);
   }


   ex_conv_array( exoid, READ_CONVERT, glob_var_vals, num_glob_vars );

   return (EX_NOERR);
}
Beispiel #3
0
int ex_get_time (int   exoid,
                 int   time_step,
                 void *time_value)
{
   int varid;
   long start[1];
   char var_name[MAX_VAR_NAME_LENGTH+1];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0;        /* clear error code */

/* inquire previously defined dimensions  */

   strcpy (var_name, VAR_WHOLE_TIME);

/* inquire previously defined variable */

   if ((varid = ncvarid (exoid, var_name)) < 0)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate time variable in file id %d", exoid);
     ex_err("ex_get_time",errmsg,exerrval);
     return (EX_FATAL);
   }

/* read time value */

   start[0] = --time_step;

   if (ncvarget1 (exoid, varid, start,
              ex_conv_array(exoid,RTN_ADDRESS,time_value,1)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get time value in file id %d", exoid);
     ex_err("ex_get_time",errmsg,exerrval);
     return (EX_FATAL);
   }


   ex_conv_array( exoid, READ_CONVERT, time_value, 1 );

   return (EX_NOERR);
}
Beispiel #4
0
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);
}
Beispiel #5
0
int ex_get_set_dist_fact (int   exoid,
			  int   set_type,
			  int   set_id,
			  void *set_dist_fact)
{

   int dimid, dist_id, set_id_ndx;
   long num_df_in_set, count[1], start[1];
   char errmsg[MAX_ERR_LENGTH];
   char* typeName;
   char* dimptr;
   char* idsptr;
   char* numdfptr;
   char* factptr;
 
   exerrval = 0; /* clear error code */

   /* setup pointers based on set_type 
    NOTE: there is another block that sets more stuff later ... */

   if (set_type == EX_NODE_SET) {
     typeName = "node";
     dimptr = DIM_NUM_NS;
     idsptr = VAR_NS_IDS;
   }
   else if (set_type == EX_EDGE_SET) {
     typeName = "edge";
     dimptr = DIM_NUM_ES;
     idsptr = VAR_ES_IDS;
   }
   else if (set_type == EX_FACE_SET) {
     typeName = "face";
     dimptr = DIM_NUM_FS;
     idsptr = VAR_FS_IDS;
   }
   else if (set_type == EX_SIDE_SET) {
     typeName = "side";
     dimptr = DIM_NUM_SS;
     idsptr = VAR_SS_IDS;
   }
   else if (set_type == EX_ELEM_SET) {
     typeName = "elem";
     dimptr = DIM_NUM_ELS;
     idsptr = VAR_ELS_IDS;
   }
   else {
     exerrval = EX_FATAL;
     sprintf(errmsg,
             "Error: invalid set type (%d)", set_type);
     ex_err("ex_put_set_param",errmsg,exerrval);
     return (EX_FATAL);
   }

/* first check if any sets are specified */

   if ((dimid = ncdimid (exoid, dimptr)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Warning: no %s sets stored in file id %d",
             typeName, exoid);
     ex_err("ex_get_set_dist_fact",errmsg,exerrval);
     return (EX_WARN);
   }

/* Lookup index of set id in VAR_*S_IDS array */

   set_id_ndx = ex_id_lkup(exoid,idsptr,set_id);
   if (exerrval != 0) 
   {
     if (exerrval == EX_NULLENTITY)
     {
       sprintf(errmsg,
              "Warning: %s set %d is NULL in file id %d",
               typeName, set_id,exoid);
       ex_err("ex_get_set_dist_fact",errmsg,EX_MSG);
       return (EX_WARN);
     }
     else
     {
       sprintf(errmsg,
     "Error: failed to locate %s set id %d in VAR_*S_IDS array in file id %d",
               typeName, set_id,exoid);
       ex_err("ex_get_set_dist_fact",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

  /* setup more pointers based on set_type */
   if (set_type == EX_NODE_SET) {
     /* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
     numdfptr = DIM_NUM_NOD_NS(set_id_ndx);
     factptr = VAR_FACT_NS(set_id_ndx);
   }
   else if (set_type == EX_EDGE_SET) {
     numdfptr = DIM_NUM_DF_ES(set_id_ndx);
     factptr = VAR_FACT_ES(set_id_ndx);
   }
   else if (set_type == EX_FACE_SET) {
     numdfptr = DIM_NUM_DF_FS(set_id_ndx);
     factptr = VAR_FACT_FS(set_id_ndx);
   }
   else if (set_type == EX_SIDE_SET) {
     numdfptr = DIM_NUM_DF_SS(set_id_ndx);
     factptr = VAR_FACT_SS(set_id_ndx);
   }
   if (set_type == EX_ELEM_SET) {
     numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
     factptr = VAR_FACT_ELS(set_id_ndx);
   }

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

   if ((dimid = ncdimid (exoid, numdfptr)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Warning: dist factors not stored for %s set %d in file id %d",
             typeName, set_id,exoid);
     ex_err("ex_get_set_dist_fact",errmsg,exerrval);
     return (EX_WARN);          /* complain - but not too loud */
   }

   if (ncdiminq (exoid, dimid, (char *) 0, &num_df_in_set) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Error: failed to get number of dist factors in %s set %d in file id %d",
             typeName, set_id,exoid);
     ex_err("ex_get_set_dist_fact",errmsg,exerrval);
     return (EX_FATAL);
   }


   if ((dist_id = ncvarid (exoid, factptr)) == -1)
   {
     exerrval = ncerr;
     /* not an error for node sets because this is how we check that df's exist */
     if (set_type == EX_NODE_SET)
     {
       sprintf(errmsg,
	       "Warning: dist factors not stored for %s set %d in file id %d",
	       typeName, set_id, exoid);
       ex_err("ex_get_set_dist_fact",errmsg,exerrval);
       return (EX_WARN);         /* complain - but not too loud */
     }
     /* is an error for other sets */
     else 
     {
       sprintf(errmsg,
	       "Error: failed to locate dist factors list for %s set %d in file id %d",
	       typeName, set_id,exoid);
       ex_err("ex_get_set_dist_fact",errmsg,exerrval);
       return (EX_FATAL);
     }
   }


/* read in the distribution factors array */

   start[0] = 0;

   count[0] = num_df_in_set;

   if (ncvarget (exoid, dist_id, start, count,
             ex_conv_array(exoid,RTN_ADDRESS,set_dist_fact,
                           (int)num_df_in_set)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
         "Error: failed to get dist factors list for %s set %d in file id %d",
             typeName, set_id,exoid);
     ex_err("ex_get_set_dist_fact",errmsg,exerrval);
     return (EX_FATAL);
   }


   ex_conv_array( exoid, READ_CONVERT, set_dist_fact, num_df_in_set );

   return (EX_NOERR);

}
Beispiel #6
0
int ex_get_side_set_dist_fact (int   exoid,
                               int   side_set_id,
                               void *side_set_dist_fact)
{

    int dimid, dist_id, side_set_id_ndx;
    long num_df_in_set, count[1], start[1];
    char errmsg[MAX_ERR_LENGTH];

    exerrval = 0; /* clear error code */

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

    if ((dimid = ncdimid (exoid, DIM_NUM_SS)) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Warning: no side sets stored in file id %d",
                exoid);
        ex_err("ex_get_side_set_dist_fact",errmsg,exerrval);
        return (EX_WARN);
    }

    /* Lookup index of side set id in VAR_SS_IDS array */

    side_set_id_ndx = ex_id_lkup(exoid,VAR_SS_IDS,side_set_id);
    if (exerrval != 0)
    {
        if (exerrval == EX_NULLENTITY)
        {
            sprintf(errmsg,
                    "Warning: side set %d is NULL in file id %d",
                    side_set_id,exoid);
            ex_err("ex_get_side_set_dist_fact",errmsg,EX_MSG);
            return (EX_WARN);
        }
        else
        {
            sprintf(errmsg,
                    "Error: failed to locate side set id %d in VAR_SS_IDS array in file id %d",
                    side_set_id,exoid);
            ex_err("ex_get_side_set_dist_fact",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

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

    if ((dimid = ncdimid (exoid, DIM_NUM_DF_SS(side_set_id_ndx))) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Warning: dist factors not stored for side set %d in file id %d",
                side_set_id,exoid);
        ex_err("ex_get_side_set_dist_fact",errmsg,exerrval);
        return (EX_WARN);          /* complain - but not too loud */
    }

    if (ncdiminq (exoid, dimid, (char *) 0, &num_df_in_set) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to get number of dist factors in side set %d in file id %d",
                side_set_id,exoid);
        ex_err("ex_get_side_set_dist_fact",errmsg,exerrval);
        return (EX_FATAL);
    }


    if ((dist_id = ncvarid (exoid, VAR_FACT_SS(side_set_id_ndx))) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to locate dist factors list for side set %d in file id %d",
                side_set_id,exoid);
        ex_err("ex_get_side_set_dist_fact",errmsg,exerrval);
        return (EX_FATAL);
    }


    /* read in the distribution factors array */

    start[0] = 0;

    count[0] = num_df_in_set;

    if (ncvarget (exoid, dist_id, start, count,
                  ex_conv_array(exoid,RTN_ADDRESS,side_set_dist_fact,
                                (int)num_df_in_set)) == -1)
    {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to get dist factors list for side set %d in file id %d",
                side_set_id,exoid);
        ex_err("ex_get_side_set_dist_fact",errmsg,exerrval);
        return (EX_FATAL);
    }


    ex_conv_array( exoid, READ_CONVERT, side_set_dist_fact, num_df_in_set );

    return (EX_NOERR);

}
Beispiel #7
0
int ex_get_glob_var_time (int   exoid,
                          int   glob_var_index,
                          int   beg_time_step,
                          int   end_time_step,
                          void *glob_var_vals)
{
   int varid;
   long start[2], count[2];
   float fdum;
   char *cdum;
   char  errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

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


/* inquire previously defined variable */

   if ((varid = ncvarid (exoid, VAR_GLO_VAR)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate global variables in file id %d",
             exoid);
     ex_err("ex_get_glob_var_time",errmsg,exerrval);
     return (EX_WARN);
   }

/* read values of global variables */

   start[0] = --beg_time_step;
   start[1] = --glob_var_index;

   if (end_time_step < 0)
   {

/* user is requesting the maximum time step;  we find this out using the
 * database inquire function to get the number of time steps
 */
     if (ex_inquire (exoid, EX_INQ_TIME, &end_time_step, &fdum, cdum) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
             "Error: failed to get number of time steps in file id %d",
               exoid);
       ex_err("ex_get_glob_var_time",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   end_time_step--;

   count[0] = end_time_step - beg_time_step + 1;
   count[1] = 1;

   if (ncvarget (exoid, varid, start, count,
             ex_conv_array(exoid,RTN_ADDRESS,glob_var_vals,count[0])) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to get global variable %d values from file id %d",
            glob_var_index, exoid);
     ex_err("ex_get_glob_var_time",errmsg,exerrval);
     return (EX_FATAL);
   }

   ex_conv_array( exoid, READ_CONVERT, glob_var_vals, count[0] );

   return (EX_NOERR);
}
Beispiel #8
0
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);
}
Beispiel #9
0
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() */
Beispiel #10
0
int ex_get_nodal_var_time (int   exoid,
                           int   nodal_var_index,
                           int   node_number,
                           int   beg_time_step, 
                           int   end_time_step,
                           void *nodal_var_vals)
{
  int varid;
  long start[3], count[3];
  float fdum;
  char *cdum; 
  char errmsg[MAX_ERR_LENGTH];

  /* inquire previously defined variable */

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

  if (end_time_step < 0)
    {

      /* user is requesting the maximum time step;  we find this out using the
       * database inquire function to get the number of time steps;  the ending
       * time step number is 1 less due to 0 based array indexing in C
       */
      if (ex_inquire (exoid, EX_INQ_TIME, &end_time_step, &fdum, cdum) == -1)
        {
  
          exerrval = ncerr;
          sprintf(errmsg,
                  "Error: failed to get number of time steps in file id %d",
                  exoid);
          ex_err("ex_get_nodal_var_time",errmsg,exerrval);
          return (EX_FATAL);
        }
    }

  end_time_step--;

  if (ex_large_model(exoid) == 0) {
    /* read values of the nodal variable;
     * assume node number is 1-based (first node is numbered 1);  adjust
     * so it is 0-based
     */
    if ((varid = ncvarid (exoid, VAR_NOD_VAR)) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
              "Warning: could not find nodal variable %d in file id %d",
              nodal_var_index, exoid);
      ex_err("ex_get_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }
    start[0] = --beg_time_step;
    start[1] = --nodal_var_index;
    start[2] = --node_number;

    count[0] = end_time_step - beg_time_step + 1;
    count[1] = 1;
    count[2] = 1;

  } else {
    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_get_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }

    /* read values of the nodal variable;
     * assume node number is 1-based (first node is numbered 1);  adjust
     * so it is 0-based
     */

    start[0] = --beg_time_step;
    start[1] = --node_number;

    count[0] = end_time_step - beg_time_step + 1;
    count[1] = 1;

  }
  if (ncvarget (exoid, varid, start, count,
                ex_conv_array(exoid,RTN_ADDRESS,nodal_var_vals,count[0])) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to get nodal variables in file id %d",
              exoid);
      ex_err("ex_get_nodal_var_time",errmsg,exerrval);
      return (EX_FATAL);
    }

  ex_conv_array( exoid, READ_CONVERT, nodal_var_vals, count[0] );

  return (EX_NOERR);
}
Beispiel #11
0
int ex_get_nodal_var (int   exoid,
                      int   time_step,
                      int   nodal_var_index,
                      int   num_nodes, 
                      void *nodal_var_vals)
{
  int varid;
  long start[3], count[3];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* inquire previously defined variable */

  if (ex_large_model(exoid) == 0) {
    /* read 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_get_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 {
    /* read values of the nodal variable  -- stored as separate variables... */
    /* Get the varid.... */
    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_get_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }

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

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

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

  ex_conv_array( exoid, READ_CONVERT,nodal_var_vals, num_nodes );

  return (EX_NOERR);
}
Beispiel #12
0
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);
}
Beispiel #13
0
int ex_get_elem_var (int   exoid,
                     int   time_step,
                     int   elem_var_index,
                     int   elem_blk_id, 
                     int   num_elem_this_blk,
                     void *elem_var_vals)
{
   int varid, elem_blk_id_ndx;
   long 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 element variables for NULL block %d in file id %d",
              elem_blk_id,exoid);
      ex_err("ex_get_elem_var",errmsg,EX_MSG);
      return (EX_WARN);
    }
    else
    {
      sprintf(errmsg,
     "Error: failed to locate element block id %d in %s variable in file id %d",
              elem_blk_id, VAR_ID_EL_BLK, exoid);
      ex_err("ex_get_elem_var",errmsg,exerrval);
      return (EX_FATAL);
    }
  }


/* inquire previously defined variable */

   if((varid=ncvarid(exoid,VAR_ELEM_VAR(elem_var_index,elem_blk_id_ndx))) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
          "Error: failed to locate elem var %d for elem block %d in file id %d",
          elem_var_index,elem_blk_id,exoid); /* this msg needs to be improved */
     ex_err("ex_get_elem_var",errmsg,exerrval);
     return (EX_FATAL);
   }

/* read values of element variable */

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

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

   if (ncvarget (exoid, varid, start, count,
        ex_conv_array(exoid,RTN_ADDRESS,elem_var_vals,num_elem_this_blk)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to get elem var %d for block %d in file id %d",
             elem_var_index,elem_blk_id,exoid);/*this msg needs to be improved*/
     ex_err("ex_get_elem_var",errmsg,exerrval);
     return (EX_FATAL);
   }


   ex_conv_array( exoid, READ_CONVERT, elem_var_vals, num_elem_this_blk );

   return (EX_NOERR);
}
Beispiel #14
0
int ex_put_one_attr( int   exoid,
                     int   obj_type,
                     int   obj_id,
                     int   attrib_index,
                     const void *attrib )
{
  int numobjentdim, numattrdim, attrid, obj_id_ndx;
  long num_entries_this_obj, num_attr;
  size_t start[2], count[2];
  ptrdiff_t stride[2];
  int error;
  char errmsg[MAX_ERR_LENGTH];
  const char* tname;
  const char* vobjids;
  const char* dnumobjent = 0;
  const char* dnumobjatt = 0;
  const char* vattrbname = 0;

  switch (obj_type) {
  case EX_EDGE_BLOCK:
    tname = "edge block";
    vobjids = VAR_ID_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    tname = "face block";
    vobjids = VAR_ID_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    tname = "element block";
    vobjids = VAR_ID_EL_BLK;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Bad block type (%d) specified for file id %d",
      obj_type, exoid );
    ex_err("ex_put_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

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

  switch (obj_type) {
  case EX_EDGE_BLOCK:
    dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
    vattrbname = VAR_EATTRIB(obj_id_ndx);
    break;
  case EX_FACE_BLOCK:
    dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
    vattrbname = VAR_FATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_BLOCK:
    dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx);
    vattrbname = VAR_ATTRIB(obj_id_ndx);
    break;
  }

  /* inquire id's of previously defined dimensions  */
  if ((numobjentdim = ncdimid (exoid, dnumobjent)) == -1)
    {
      if (ncerr == NC_EBADDIM)
        {
          exerrval = ncerr;
          sprintf(errmsg,
                  "Error: no %s with id %d in file id %d",
                  tname, obj_id, exoid);
          ex_err("ex_put_one_attr",errmsg,exerrval);
          return (EX_FATAL);
        }
      else
        {
          exerrval = ncerr;
          sprintf(errmsg,
                  "Error: failed to locate number of entries for %s %d in file id %d",
                  tname, obj_id, exoid);
          ex_err("ex_put_one_attr",errmsg,exerrval);
          return (EX_FATAL);
        }
    }


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


  if ((numattrdim = ncdimid(exoid, dnumobjatt)) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: number of attributes not defined for %s %d in file id %d",
              tname,obj_id,exoid);
      ex_err("ex_put_one_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",
              obj_id,exoid);
      ex_err("ex_put_one_attr",errmsg,exerrval);
      return (EX_FATAL);
    }

  if (attrib_index < 1 || attrib_index > num_attr) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
            "Error: Invalid attribute index specified: %d.  Valid range is 1 to %ld for %s %d in file id %d",
            attrib_index, num_attr, tname, obj_id, exoid);
    ex_err("ex_put_one_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((attrid = ncvarid (exoid, vattrbname)) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to locate attribute variable for %s %d in file id %d",
              tname,obj_id,exoid);
      ex_err("ex_put_one_attr",errmsg,exerrval);
      return (EX_FATAL);
    }


  /* write out the attributes  */

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

  count[0] = num_entries_this_obj;
  count[1] = 1;

  stride[0] = 1;
  stride[1] = num_attr;
  
  if (nc_flt_code(exoid) == NC_FLOAT) {
    error = nc_put_vars_float(exoid, attrid, start, count, stride,
                              ex_conv_array(exoid,WRITE_CONVERT,attrib,
                                            (int)num_attr*num_entries_this_obj));
  } else {
    error = nc_put_vars_double(exoid, attrid, start, count, stride,
                               ex_conv_array(exoid,WRITE_CONVERT,attrib,
                                             (int)num_attr*num_entries_this_obj));
  }
  if (error == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
            "Error: failed to put attribute %d for %s %d in file id %d",
            attrib_index, tname, obj_id, exoid);
    ex_err("ex_put_one_attr",errmsg,exerrval);
    return (EX_FATAL);
  }


  return(EX_NOERR);

}
Beispiel #15
0
int ex_put_side_set_dist_fact (int   exoid,
                               int   side_set_id,
                               const void *side_set_dist_fact)
{
   int dimid, side_set_id_ndx;
   int dist_id;
   long num_df_in_set,  start[1], count[1];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

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

   if ((dimid = ncdimid (exoid, DIM_NUM_SS)) < 0)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: no side sets specified in file id %d",
             exoid);
     ex_err("ex_put_side_set_dist_fact",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Lookup index of side set id in VAR_SS_IDS array */

   side_set_id_ndx = ex_id_lkup(exoid,VAR_SS_IDS,side_set_id);
   if (exerrval != 0) 
   {
     if (exerrval == EX_NULLENTITY)
     {
       sprintf(errmsg,
              "Warning: no data allowed for NULL side set %d in file id %d",
               side_set_id,exoid);
       ex_err("ex_put_side_set_fact",errmsg,EX_MSG);
       return (EX_WARN);
     }
     else
     {
      sprintf(errmsg,
     "Error: failed to locate side set id %d in VAR_SS_IDS array in file id %d",
               side_set_id,exoid);
       ex_err("ex_put_side_set_dist_fact",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

/* inquire id's of previously defined dimension and variable */

   if ((dimid = ncdimid (exoid, DIM_NUM_DF_SS(side_set_id_ndx))) == -1)
   {
     if (ncerr == NC_EBADDIM)
     {
       exerrval = EX_BADPARAM;
       sprintf(errmsg,
              "Warning: no dist factors defined for side set %d in file id %d",
               side_set_id,exoid);
       ex_err("ex_put_side_set_dist_fact",errmsg,exerrval);
       return (EX_WARN);

     }
     else
     {
       exerrval = ncerr;
       sprintf(errmsg,
  "Error: failed to locate number of dist factors in side set %d in file id %d",
               side_set_id,exoid);
       ex_err("ex_put_side_set_dist_fact",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   if (ncdiminq (exoid, dimid, (char *) 0, &num_df_in_set) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Error: failed to get number of dist factors in side set %d in file id %d",
             side_set_id,exoid);
     ex_err("ex_put_side_set_dist_fact",errmsg,exerrval);
     return (EX_FATAL);
   }


   if ((dist_id = ncvarid (exoid, VAR_FACT_SS(side_set_id_ndx))) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
      "Error: failed to locate dist factors list for side set %d in file id %d",
             side_set_id,exoid);
     ex_err("ex_put_side_set_dist_fact",errmsg,exerrval);
     return (EX_FATAL);
   }


/* write out the distribution factors array */

   start[0] = 0;

   count[0] = num_df_in_set;

   if (ncvarput (exoid, dist_id, start, count,
             ex_conv_array(exoid,WRITE_CONVERT,side_set_dist_fact,
                           (int)num_df_in_set)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store dist factors for side set %d in file id %d",
             side_set_id,exoid);
     ex_err("ex_put_side_set_dist_fact",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);

}
Beispiel #16
0
/* -------------------- 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);


}
Beispiel #17
0
int ex_get_nset_var (int   exoid,
                     int   time_step,
                     int   nset_var_index,
                     int   nset_id, 
                     int   num_node_this_nset,
                     void *nset_var_vals)
{
   int varid, nset_id_ndx;
   long start[2], count[2];
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

  /* Determine index of nset_id in VAR_NS_IDS array */
  nset_id_ndx = ex_id_lkup(exoid,VAR_NS_IDS,nset_id);
  if (exerrval != 0) 
  {
    if (exerrval == EX_NULLENTITY)
    {
      sprintf(errmsg,
              "Warning: no nodeset variables for NULL nodeset %d in file id %d",
              nset_id,exoid);
      ex_err("ex_get_nset_var",errmsg,EX_MSG);
      return (EX_WARN);
    }
    else
    {
      sprintf(errmsg,
     "Error: failed to locate nodeset id %d in %s variable in file id %d",
              nset_id, VAR_ID_EL_BLK, exoid);
      ex_err("ex_get_nset_var",errmsg,exerrval);
      return (EX_FATAL);
    }
  }


/* inquire previously defined variable */

   if((varid=ncvarid(exoid,VAR_NS_VAR(nset_var_index,nset_id_ndx))) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
          "Error: failed to locate nodeset variable %d for nodeset %d in file id %d",
          nset_var_index,nset_id,exoid); /* this msg needs to be improved */
     ex_err("ex_get_nset_var",errmsg,exerrval);
     return (EX_FATAL);
   }

/* read values of nodeset variable */

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

   count[0] = 1;
   count[1] = num_node_this_nset;

   if (ncvarget (exoid, varid, start, count,
        ex_conv_array(exoid,RTN_ADDRESS,nset_var_vals,num_node_this_nset)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to get nodeset variable %d for nodeset %d in file id %d",
             nset_var_index,nset_id,exoid);/*this msg needs to be improved*/
     ex_err("ex_get_nset_var",errmsg,exerrval);
     return (EX_FATAL);
   }


   ex_conv_array( exoid, READ_CONVERT, nset_var_vals, num_node_this_nset );

   return (EX_NOERR);
}
Beispiel #18
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);
}
Beispiel #19
0
int ex_get_var_time( int   exoid,
                     int   var_type,
                     int   var_index,
                     int   id,
                     int   beg_time_step, 
                     int   end_time_step,
                     void* var_vals )
{
  int i, dimid, varid, numel = 0, offset;
  nclong *obj_ids, *stat_vals;
  long num_obj, num_entries_this_obj = 0, start[2], count[2];
  float fdum;
  char *cdum;
  char errmsg[MAX_ERR_LENGTH];
  const char* tname;
  const char* dimnumobj;
  const char* varobjids;
  const char* varobstat;

  switch (var_type) {
  case EX_GLOBAL:
    return ex_get_glob_var_time( exoid, var_index, beg_time_step, end_time_step, var_vals );
  case EX_NODAL:
    return ex_get_nodal_var_time( exoid, var_index, id, beg_time_step, end_time_step, var_vals );
  case EX_EDGE_BLOCK:
    tname = "edge block";
    dimnumobj =  DIM_NUM_ED_BLK;
    varobjids =   VAR_ID_ED_BLK; 
    varobstat = VAR_STAT_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    tname = "face block";
    dimnumobj =  DIM_NUM_FA_BLK;
    varobjids =   VAR_ID_FA_BLK; 
    varobstat = VAR_STAT_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    tname = "element block";
    dimnumobj =  DIM_NUM_EL_BLK;
    varobjids =   VAR_ID_EL_BLK; 
    varobstat = VAR_STAT_EL_BLK;
    break;
  case EX_NODE_SET:
    tname = "node set";
    dimnumobj =  DIM_NUM_NSET_VAR;
    varobjids =      VAR_NS_IDS; 
    varobstat =      VAR_NS_STAT;
    break;
  case EX_EDGE_SET:
    tname = "edge set";
    dimnumobj =  DIM_NUM_ESET_VAR;
    varobjids =      VAR_ES_IDS;
    varobstat =      VAR_ES_STAT;
    break;
  case EX_FACE_SET:
    tname = "face set";
    dimnumobj =  DIM_NUM_FSET_VAR;
    varobjids =      VAR_FS_IDS; 
    varobstat =      VAR_FS_STAT;
    break;
  case EX_SIDE_SET:
    tname = "side set";
    dimnumobj =  DIM_NUM_SSET_VAR;
    varobjids =      VAR_SS_IDS; 
    varobstat =      VAR_SS_STAT;
    break;
  case EX_ELEM_SET:
    tname = "element set";
    dimnumobj =  DIM_NUM_ELSET_VAR;
    varobjids =      VAR_ELS_IDS; 
    varobstat =      VAR_ELS_STAT;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Error: Invalid variable type (%d) specified for file id %d", var_type, exoid );
    ex_err( "ex_get_var_time", errmsg, exerrval );
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

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

  /* assume entry number is 1-based (the first entry of an object is 1, not 0);
   * adjust so it is 0-based
   */
  id--;

  /* find what object the entry is in */

  /* first, find out how many objects there are */

  if ((dimid = ncdimid (exoid, dimnumobj)) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to locate number of %ss in file id %d", 
              tname,exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      return (EX_FATAL);
    }

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

  /* get the array of object ids */
  /* don't think we need this anymore since the netcdf variable names 
     associated with objects don't contain the object ids */

  if (!(obj_ids = malloc(num_obj*sizeof(nclong))))
    {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
              "Error: failed to allocate memory for %s ids for file id %d",
              tname,exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      return (EX_FATAL);
    }


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


  start[0] = 0;
  count[0] = num_obj;
  if (ncvarget (exoid, varid, start, count, obj_ids) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to get %s ids from file id %d", tname,exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      return (EX_FATAL);
    }

  /* allocate space for stat array */
  if (!(stat_vals = malloc((int)num_obj*sizeof(nclong))))
    {
      exerrval = EX_MEMFAIL;
      free (obj_ids);
      sprintf(errmsg,
              "Error: failed to allocate memory for %s status array for file id %d",
              tname,exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      return (EX_FATAL);
    }

  /* get variable id of status array */
  if ((varid = ncvarid (exoid, varobstat)) != -1)
    {
      /* if status array exists, use it, otherwise assume, object exists
         to be backward compatible */

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

      if (ncvarget (exoid, varid, start, count, (void *)stat_vals) == -1)
        {
          exerrval = ncerr;
          free (obj_ids);
          free(stat_vals);
          sprintf(errmsg,
                  "Error: failed to get %s status array from file id %d",
                  tname,exoid);
          ex_err("ex_get_var_time",errmsg,exerrval);
          return (EX_FATAL);
        }
    }
  else /* default: status is true */
    for(i=0;i<num_obj;i++)
      stat_vals[i]=1;


  /* loop through each object until id is found;  since entry
   * numbers are sequential (beginning with 1) id is in obj_i
   * when id_first_i <= id <= id_last_i, where
   * id_first_i is the entry number of the first entry in 
   * obj_i and id_last_i is the entry number of the last
   * entry in obj_i
   */

  i = 0;
  if (stat_vals[i] != 0)  {
    if ((dimid = ncdimid (exoid, ex_dim_num_entries_in_object(var_type,i+1))) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to locate number of entries in %s %d in file id %d",
              tname, obj_ids[i], exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      free(stat_vals);
      free(obj_ids);
      return (EX_FATAL);
    }

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

  } /* End NULL object check */

  numel = num_entries_this_obj;

  while (numel <= id) {
    if (stat_vals[++i] != 0) {
      if ((dimid = ncdimid(exoid,ex_dim_num_entries_in_object(var_type,i+1))) == -1) {
        exerrval = ncerr;
        sprintf(errmsg,
                "Error: failed to locate number of entries in %s %d in file id %d",
                tname, obj_ids[i], exoid);
        ex_err("ex_get_var_time",errmsg,exerrval);
        free(stat_vals);
        free(obj_ids);
        return (EX_FATAL);
      }

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

      numel += num_entries_this_obj;
    }
  }

  offset = id - (numel - num_entries_this_obj);

  /* inquire previously defined variable */

  if((varid=ncvarid(exoid,ex_name_var_of_object(var_type,var_index,i+1))) == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
            "Error: failed to locate variable %d for %s %d in file id %d",
            var_index,tname,obj_ids[i],exoid);
    ex_err("ex_get_var_time",errmsg,exerrval);
    free(stat_vals);
    free(obj_ids);
    return (EX_FATAL);
  }

  free(stat_vals);
  free(obj_ids);

  /* read values of object variable */

  start[0] = --beg_time_step;
  start[1] = offset;

  if (end_time_step < 0) {

    /* user is requesting the maximum time step;  we find this out using the
     * database inquire function to get the number of time steps;  the ending
     * time step number is 1 less due to 0 based array indexing in C
     */
    if (ex_inquire (exoid, EX_INQ_TIME, &end_time_step, &fdum, cdum) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to get maximum time step in file id %d",
              exoid);
      ex_err("ex_get_var_time",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  end_time_step--;

  count[0] = end_time_step - beg_time_step + 1;
  count[1] = 1;

  if (ncvarget (exoid, varid, start, count,
                ex_conv_array(exoid,RTN_ADDRESS,var_vals,count[0])) == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
            "Error: failed to get %s variable values in file id %d", tname,exoid);
    ex_err("ex_get_var_time",errmsg,exerrval);
    return (EX_FATAL);
  }

  ex_conv_array( exoid, READ_CONVERT, var_vals, count[0] );

  return (EX_NOERR);
}
Beispiel #20
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);
}
Beispiel #21
0
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() */
Beispiel #22
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);

}