예제 #1
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 status;
   int varid;
   size_t start[2], count[2];
   float fdum;
   char *cdum = 0;
   char  errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   /* inquire previously defined variable */
   if ((status = nc_inq_varid (exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
     exerrval = status;
     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 ((status = ex_inquire (exoid, EX_INQ_TIME, &end_time_step, &fdum, cdum)) != NC_NOERR) {
       exerrval = status;
       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 (ex_comp_ws(exoid) == 4) {
     status = nc_get_vara_float(exoid, varid, start, count, glob_var_vals);
   } else {
     status = nc_get_vara_double(exoid, varid, start, count, glob_var_vals);
   }

   if (status != NC_NOERR) {
     exerrval = status;
     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);
   }
   return (EX_NOERR);
}
예제 #2
0
int ex_get_side_set_node_count(int exoid,
                               int side_set_id,
                               int *side_set_node_cnt_list)
{
  size_t m;
  int ii, i, j; 
  int  num_side_sets, num_elem_blks, num_df, ndim;
  int tot_num_elem = 0, tot_num_ss_elem = 0, side, elem;
  int *elem_blk_ids;
  int *ss_elem_ndx;
  int *side_set_elem_list, *side_set_side_list;
  int elem_ctr;
  int num_elem_in_blk, num_nodes_per_elem, num_attr;
  float fdum;
  char *cdum, elem_type[MAX_STR_LENGTH+1];

  struct elem_blk_parm  *elem_blk_parms;

  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 */
  /* inquire how many side sets have been 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 in file id %d",exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return(EX_FATAL);
  }

  if (num_side_sets == 0)
  {
    sprintf(errmsg,
           "Warning: no side sets defined in file id %d",exoid);
    ex_err("ex_get_side_set_node_count",errmsg,EX_WARN);
    return(EX_WARN);
  }

  /* Lookup index of side set id in VAR_SS_IDS array */
  ex_id_lkup(exoid,EX_SIDE_SET,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_node_count",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_node_count",errmsg,exerrval);
     return (EX_FATAL);
     }
  }

  if ((ex_inquire(exoid, EX_INQ_ELEM_BLK, &num_elem_blks, &fdum, cdum)) == -1)
  {
    sprintf(errmsg,
           "Error: failed to get number of element blocks in file id %d",exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return(EX_FATAL);
  }

  if ((ex_inquire(exoid, EX_INQ_ELEM, &tot_num_elem, &fdum, cdum)) == -1)
  {
    sprintf(errmsg,
           "Error: failed to get total number of elements in file id %d",exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return(EX_FATAL);
  }

  /* get the dimensionality of the coordinates;  this is necessary to
     distinguish between 2d TRIs and 3d TRIs */
  if ((ex_inquire(exoid, EX_INQ_DIM, &ndim, &fdum, cdum)) == -1)
  {
    sprintf(errmsg,
           "Error: failed to get dimensionality in file id %d",exoid);
    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
    return(EX_FATAL);
  }

  /* First determine the  # of elements in the side set*/
  if ((ex_get_side_set_param(exoid,side_set_id,&tot_num_ss_elem,&num_df)) == -1)
  {
    sprintf(errmsg,
         "Error: failed to get number of elements in side set %d in file id %d",
            side_set_id, exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return(EX_FATAL);
  }

  /* Allocate space for the side set element list */
  if (!(side_set_elem_list=malloc(tot_num_ss_elem*sizeof(int))))
  {
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
    "Error: failed to allocate space for side set element list for file id %d",
            exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Allocate space for the side set side list */
  if (!(side_set_side_list=malloc(tot_num_ss_elem*sizeof(int))))
  {
    free(side_set_elem_list);
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
    "Error: failed to allocate space for side set side list for file id %d",
            exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_get_side_set(exoid, side_set_id, 
                      side_set_elem_list, side_set_side_list) == -1)
  {
    free(side_set_elem_list);
    free(side_set_side_list);
    sprintf(errmsg,
    "Error: failed to get side set %d in file id %d",
            side_set_id, exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Allocate space for the ss element index array */
  if (!(ss_elem_ndx=malloc(tot_num_ss_elem*sizeof(int))))
  {
    free(side_set_elem_list);
    free(side_set_side_list);
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
            "Error: failed to allocate space for side set elem sort array for file id %d",
            exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Sort side set element list into index array  - non-destructive */
  for (i=0;i<tot_num_ss_elem;i++) {
    ss_elem_ndx[i] = i; /* init index array to current position */
  }
  ex_iqsort(side_set_elem_list, ss_elem_ndx,tot_num_ss_elem);


  /* Allocate space for the element block ids */
  if (!(elem_blk_ids=malloc(num_elem_blks*sizeof(int))))
  {
    exerrval = EX_MEMFAIL;
    free(ss_elem_ndx);
    free(side_set_side_list);
    free(side_set_elem_list);
    sprintf(errmsg,
            "Error: failed to allocate space for element block ids for file id %d",
            exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_get_elem_blk_ids(exoid, elem_blk_ids) == -1)
  {
    free(elem_blk_ids);
    free(ss_elem_ndx);
    free(side_set_side_list);
    free(side_set_elem_list);
    sprintf(errmsg,
            "Error: failed to get element block ids in file id %d",
            exoid);
    ex_err("ex_get_side_set_node_count",errmsg,EX_MSG);
    return(EX_FATAL);
  } 

  /* Allocate space for the element block params */
  if (!(elem_blk_parms=malloc(num_elem_blks*sizeof(struct elem_blk_parm))))
  {
    free(elem_blk_ids);
    free(ss_elem_ndx);
    free(side_set_side_list);
    free(side_set_elem_list);
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
      "Error: failed to allocate space for element block params for file id %d",
            exoid);
    ex_err("ex_get_side_set_node_count",errmsg,exerrval);
    return (EX_FATAL);
  }

  elem_ctr = 0;
  for (i=0; i<num_elem_blks; i++)
  {
    /* read in an element block parameter */
    if ((ex_get_elem_block (exoid, elem_blk_ids[i], elem_type, &num_elem_in_blk,
                            &num_nodes_per_elem, &num_attr)) == -1) {
      free(elem_blk_parms);
      free(elem_blk_ids);
      free(ss_elem_ndx);
      free(side_set_side_list);
      free(side_set_elem_list);
      sprintf(errmsg,
             "Error: failed to get element block %d parameters in file id %d",
              elem_blk_ids[i], exoid);
      ex_err("ex_get_side_set_node_count",errmsg,EX_MSG);
      return(EX_FATAL);
    }

    elem_blk_parms[i].num_elem_in_blk = num_elem_in_blk;
    elem_blk_parms[i].num_nodes_per_elem = num_nodes_per_elem;
    elem_blk_parms[i].num_attr = num_attr;

    for (m=0; m < strlen(elem_type); m++) {
      elem_blk_parms[i].elem_type[m] = toupper(elem_type[m]);
    }
    elem_blk_parms[i].elem_type[m] = '\0';

    if (strncmp(elem_blk_parms[i].elem_type,"CIRCLE",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_CIRCLE;
      elem_blk_parms[i].num_sides = 1;
      elem_blk_parms[i].num_nodes_per_side[0] = 1;
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"SPHERE",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_SPHERE;
      elem_blk_parms[i].num_sides = 1;
        elem_blk_parms[i].num_nodes_per_side[0] = 1;
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"QUAD",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_QUAD;
      elem_blk_parms[i].num_sides = 4;
      if (elem_blk_parms[i].num_nodes_per_elem == 4) {
        elem_blk_parms[i].num_nodes_per_side[0] = 2;
        elem_blk_parms[i].num_nodes_per_side[1] = 2;
        elem_blk_parms[i].num_nodes_per_side[2] = 2;
        elem_blk_parms[i].num_nodes_per_side[3] = 2;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 5) {
        elem_blk_parms[i].num_nodes_per_side[0] = 2;
        elem_blk_parms[i].num_nodes_per_side[1] = 2;
        elem_blk_parms[i].num_nodes_per_side[2] = 2;
        elem_blk_parms[i].num_nodes_per_side[3] = 2;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 9 ||
                 elem_blk_parms[i].num_nodes_per_elem == 8) {
        elem_blk_parms[i].num_nodes_per_side[0] = 3;
        elem_blk_parms[i].num_nodes_per_side[1] = 3;
        elem_blk_parms[i].num_nodes_per_side[2] = 3;
        elem_blk_parms[i].num_nodes_per_side[3] = 3;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"TRIANGLE",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_TRIANGLE;
      if (ndim == 2) { /* 2d TRIs */
        elem_blk_parms[i].num_sides = 3;
        if (elem_blk_parms[i].num_nodes_per_elem == 3) {
          elem_blk_parms[i].num_nodes_per_side[0] = 2;
          elem_blk_parms[i].num_nodes_per_side[1] = 2;
          elem_blk_parms[i].num_nodes_per_side[2] = 2;
        } else if (elem_blk_parms[i].num_nodes_per_elem == 6) {
          elem_blk_parms[i].num_nodes_per_side[0] = 3;
          elem_blk_parms[i].num_nodes_per_side[1] = 3;
          elem_blk_parms[i].num_nodes_per_side[2] = 3;
        }
      } else if (ndim == 3) { /* 3d TRIs -- triangular shell*/
        elem_blk_parms[i].num_sides = 5; /* 2 Faces and 3 Edges */
        if (elem_blk_parms[i].num_nodes_per_elem == 3) {
          elem_blk_parms[i].num_nodes_per_side[0] = 3;
          elem_blk_parms[i].num_nodes_per_side[1] = 3;
          elem_blk_parms[i].num_nodes_per_side[2] = 2;
          elem_blk_parms[i].num_nodes_per_side[3] = 2;
          elem_blk_parms[i].num_nodes_per_side[4] = 2;
        } else if (elem_blk_parms[i].num_nodes_per_elem == 6) {
          elem_blk_parms[i].num_nodes_per_side[0] = 6;
          elem_blk_parms[i].num_nodes_per_side[1] = 6;
          elem_blk_parms[i].num_nodes_per_side[2] = 3;
          elem_blk_parms[i].num_nodes_per_side[3] = 3;
          elem_blk_parms[i].num_nodes_per_side[4] = 3;
        } else {
          EL_NODE_COUNT_ERROR;
        }
      }
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"SHELL",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_SHELL;

      if (elem_blk_parms[i].num_nodes_per_elem == 2) {/* KLUDGE for 2D Shells*/
        elem_blk_parms[i].num_sides = 2; 
        elem_blk_parms[i].num_nodes_per_side[0] = 2;
        elem_blk_parms[i].num_nodes_per_side[1] = 2;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 4) {
        elem_blk_parms[i].num_sides = 6;  /* 2 Faces, 4 Edges */
        elem_blk_parms[i].num_nodes_per_side[0] = 4;
        elem_blk_parms[i].num_nodes_per_side[1] = 4;
        elem_blk_parms[i].num_nodes_per_side[2] = 2;
        elem_blk_parms[i].num_nodes_per_side[3] = 2;
        elem_blk_parms[i].num_nodes_per_side[4] = 2;
        elem_blk_parms[i].num_nodes_per_side[5] = 2;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 8 ||
                 elem_blk_parms[i].num_nodes_per_elem == 9) {
        elem_blk_parms[i].num_sides = 6;  /* 2 Faces, 4 Edges */
        elem_blk_parms[i].num_nodes_per_side[0] =
          elem_blk_parms[i].num_nodes_per_elem; /* 8 or 9 */
        elem_blk_parms[i].num_nodes_per_side[1] =
          elem_blk_parms[i].num_nodes_per_elem; /* 8 or 9 */
        elem_blk_parms[i].num_nodes_per_side[2] = 3;
        elem_blk_parms[i].num_nodes_per_side[3] = 3;
        elem_blk_parms[i].num_nodes_per_side[4] = 3;
        elem_blk_parms[i].num_nodes_per_side[5] = 3;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"HEX",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_HEX;
      elem_blk_parms[i].num_sides = 6;  
      /* determine side set node stride */
      if (elem_blk_parms[i].num_nodes_per_elem == 8) {  /* 8-node bricks */
        elem_blk_parms[i].num_nodes_per_side[0] = 4;
        elem_blk_parms[i].num_nodes_per_side[1] = 4;
        elem_blk_parms[i].num_nodes_per_side[2] = 4;
        elem_blk_parms[i].num_nodes_per_side[3] = 4;
        elem_blk_parms[i].num_nodes_per_side[4] = 4;
        elem_blk_parms[i].num_nodes_per_side[5] = 4;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 9) { /* 9-node bricks */
        elem_blk_parms[i].num_nodes_per_side[0] = 4;
        elem_blk_parms[i].num_nodes_per_side[1] = 4;
        elem_blk_parms[i].num_nodes_per_side[2] = 4;
        elem_blk_parms[i].num_nodes_per_side[3] = 4;
        elem_blk_parms[i].num_nodes_per_side[4] = 4;
        elem_blk_parms[i].num_nodes_per_side[5] = 4;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 12) { /* HEXSHELLS */
        elem_blk_parms[i].num_nodes_per_side[0] = 6;
        elem_blk_parms[i].num_nodes_per_side[1] = 6;
        elem_blk_parms[i].num_nodes_per_side[2] = 6;
        elem_blk_parms[i].num_nodes_per_side[3] = 6;
        elem_blk_parms[i].num_nodes_per_side[4] = 4;
        elem_blk_parms[i].num_nodes_per_side[5] = 4;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 20) { /* 20-node bricks */
        elem_blk_parms[i].num_nodes_per_side[0] = 8;
        elem_blk_parms[i].num_nodes_per_side[1] = 8;
        elem_blk_parms[i].num_nodes_per_side[2] = 8;
        elem_blk_parms[i].num_nodes_per_side[3] = 8;
        elem_blk_parms[i].num_nodes_per_side[4] = 8;
        elem_blk_parms[i].num_nodes_per_side[5] = 8;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 27) { /* 27-node bricks */
        elem_blk_parms[i].num_nodes_per_side[0] = 9;
        elem_blk_parms[i].num_nodes_per_side[1] = 9;
        elem_blk_parms[i].num_nodes_per_side[2] = 9;
        elem_blk_parms[i].num_nodes_per_side[3] = 9;
        elem_blk_parms[i].num_nodes_per_side[4] = 9;
        elem_blk_parms[i].num_nodes_per_side[5] = 9;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"TETRA",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_TETRA;
      elem_blk_parms[i].num_sides = 4;  
      /* determine side set node stride */
      if (elem_blk_parms[i].num_nodes_per_elem == 4) {
        elem_blk_parms[i].num_nodes_per_side[0] = 3;
        elem_blk_parms[i].num_nodes_per_side[1] = 3;
        elem_blk_parms[i].num_nodes_per_side[2] = 3;
        elem_blk_parms[i].num_nodes_per_side[3] = 3;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 8) {
        elem_blk_parms[i].num_nodes_per_side[0] = 4;
        elem_blk_parms[i].num_nodes_per_side[1] = 4;
        elem_blk_parms[i].num_nodes_per_side[2] = 4;
        elem_blk_parms[i].num_nodes_per_side[3] = 4;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 10) {
        elem_blk_parms[i].num_nodes_per_side[0] = 6;
        elem_blk_parms[i].num_nodes_per_side[1] = 6;
        elem_blk_parms[i].num_nodes_per_side[2] = 6;
        elem_blk_parms[i].num_nodes_per_side[3] = 6;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"WEDGE",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_WEDGE;
      elem_blk_parms[i].num_sides = 5;  
      if (elem_blk_parms[i].num_nodes_per_elem == 6) {
        elem_blk_parms[i].num_nodes_per_side[0] = 4;
        elem_blk_parms[i].num_nodes_per_side[1] = 4;
        elem_blk_parms[i].num_nodes_per_side[2] = 4;
        elem_blk_parms[i].num_nodes_per_side[3] = 3;
        elem_blk_parms[i].num_nodes_per_side[4] = 3;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 15){
        elem_blk_parms[i].num_nodes_per_side[0] = 8;
        elem_blk_parms[i].num_nodes_per_side[1] = 8;
        elem_blk_parms[i].num_nodes_per_side[2] = 8;
        elem_blk_parms[i].num_nodes_per_side[3] = 6;
        elem_blk_parms[i].num_nodes_per_side[4] = 6;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"PYRAMID",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_PYRAMID;
      elem_blk_parms[i].num_sides = 5;  
      if (elem_blk_parms[i].num_nodes_per_elem == 5) {
        elem_blk_parms[i].num_nodes_per_side[0] = 3;
        elem_blk_parms[i].num_nodes_per_side[1] = 3;
        elem_blk_parms[i].num_nodes_per_side[2] = 3;
        elem_blk_parms[i].num_nodes_per_side[3] = 3;
        elem_blk_parms[i].num_nodes_per_side[4] = 4;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 13){
        elem_blk_parms[i].num_nodes_per_side[0] = 6;
        elem_blk_parms[i].num_nodes_per_side[1] = 6;
        elem_blk_parms[i].num_nodes_per_side[2] = 6;
        elem_blk_parms[i].num_nodes_per_side[3] = 6;
        elem_blk_parms[i].num_nodes_per_side[4] = 8;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    else if (strncmp(elem_blk_parms[i].elem_type,"BEAM",3) == 0)
    {
      elem_blk_parms[i].elem_type_val = EX_EL_BEAM;
      elem_blk_parms[i].num_sides = 2;  

      if (elem_blk_parms[i].num_nodes_per_elem == 2) {
        elem_blk_parms[i].num_nodes_per_side[0] = 2;
        elem_blk_parms[i].num_nodes_per_side[1] = 2;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 3){
        elem_blk_parms[i].num_nodes_per_side[0] = 3;
        elem_blk_parms[i].num_nodes_per_side[1] = 3;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    else if ( (strncmp(elem_blk_parms[i].elem_type,"TRUSS",3) == 0) ||
              (strncmp(elem_blk_parms[i].elem_type,"BAR",3) == 0) ||
              (strncmp(elem_blk_parms[i].elem_type,"EDGE",3) == 0) )
    {
      elem_blk_parms[i].elem_type_val = EX_EL_TRUSS;
      elem_blk_parms[i].num_sides = 2;  

      if (elem_blk_parms[i].num_nodes_per_elem == 2) {
        elem_blk_parms[i].num_nodes_per_side[0] = 2;
        elem_blk_parms[i].num_nodes_per_side[1] = 2;
      } else if (elem_blk_parms[i].num_nodes_per_elem == 3) {
        elem_blk_parms[i].num_nodes_per_side[0] = 3;
        elem_blk_parms[i].num_nodes_per_side[1] = 3;
      } else {
        EL_NODE_COUNT_ERROR;
      }
    }
    /* Used for an empty block in a parallel decomposition */
    else if (strncmp(elem_blk_parms[i].elem_type,"NULL",3) == 0) {
      elem_blk_parms[i].elem_type_val = EX_EL_NULL_ELEMENT;
      elem_blk_parms[i].num_sides = 0;  
      elem_blk_parms[i].num_nodes_per_side[0] = 0;
      elem_blk_parms[i].num_elem_in_blk = 0;
    } else {
      /* unsupported element type; no problem if no sides specified for
         this element block */
      elem_blk_parms[i].elem_type_val = EX_EL_UNK;
      elem_blk_parms[i].num_sides = 0;  
      elem_blk_parms[i].num_nodes_per_side[0] = 0;
    }

    elem_blk_parms[i].elem_blk_id = elem_blk_ids[i];    /* save id */
    elem_ctr += elem_blk_parms[i].num_elem_in_blk;
    elem_blk_parms[i].elem_ctr = elem_ctr;      /* save elem number max */
  }


  /* Finally... Create the list of node counts for each face in the
   * side set.
   */

  j = 0; /* The current element block... */
  for (ii=0;ii<tot_num_ss_elem;ii++) {

    i = ss_elem_ndx[ii];
    elem = side_set_elem_list[i];
    side = side_set_side_list[i]-1; /* Convert to 0-based sides */

    /*
     * Since the elements are being accessed in sorted, order, the
     * block that contains the elements must progress sequentially
     * from block 0 to block[num_elem_blks-1]. Once we find an element
     * not in this block, find a following block that contains it...
     */       
    for ( ; j<num_elem_blks; j++) {
      if (elem <= elem_blk_parms[j].elem_ctr) {
        break;
      }
    }

    if (j < num_elem_blks) {
      assert(side < elem_blk_parms[j].num_sides);  
      side_set_node_cnt_list[i] = elem_blk_parms[j].num_nodes_per_side[side];
    } else {
      exerrval = EX_BADPARAM;
      sprintf(errmsg,
             "Error: Invalid element number %d found in side set %d in file %d",
              side_set_elem_list[i], side_set_id, exoid);
      free(elem_blk_parms);
      free(elem_blk_ids);
      free(ss_elem_ndx);
      free(side_set_side_list);
      free(side_set_elem_list);
      ex_err("ex_get_side_set_node_count",errmsg,EX_MSG);
      return (EX_FATAL);
    }
  }

  /* All done: release connectivity array space, element block ids
   * array, element block parameters array, and side set element index
   * array
   */
  free(elem_blk_ids);
  free(elem_blk_parms);
  free(ss_elem_ndx);
  free(side_set_side_list);
  free(side_set_elem_list);

  return(EX_NOERR);
}
예제 #3
0
파일: expsetp.c 프로젝트: 151706061/VTK
int ex_put_set_param (int exoid,
                      ex_entity_type set_type,
                      int set_id,
                      int num_entries_in_set,
                      int num_dist_fact_in_set)
{
  int status;
  size_t temp;
  int dimid, varid, set_id_ndx, dims[1]; 
  size_t start[1]; 
  int num_sets;
  int ldum;
  int cur_num_sets, set_stat;
  char errmsg[MAX_ERR_LENGTH];
  char* dimptr = NULL;
  char* idsptr = NULL;
  char* statptr = NULL;
  char* numentryptr = NULL;
  char* numdfptr = NULL;
  char* factptr = NULL;
  char* entryptr = NULL;
  char* extraptr = NULL;

  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) {
    dimptr = DIM_NUM_NS;
    idsptr = VAR_NS_IDS;
    statptr = VAR_NS_STAT;
  }
  else if (set_type == EX_EDGE_SET) {
    dimptr = DIM_NUM_ES;
    idsptr = VAR_ES_IDS;
    statptr = VAR_ES_STAT;
  }
  else if (set_type == EX_FACE_SET) {
    dimptr = DIM_NUM_FS;
    idsptr = VAR_FS_IDS;
    statptr = VAR_FS_STAT;
  }
  else if (set_type == EX_SIDE_SET) {
    dimptr = DIM_NUM_SS;
    idsptr = VAR_SS_IDS;
    statptr = VAR_SS_STAT;
  }
  else if (set_type == EX_ELEM_SET) {
    dimptr = DIM_NUM_ELS;
    idsptr = VAR_ELS_IDS;
    statptr = VAR_ELS_STAT;
  }
  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 of that set type is specified */

  if ((status = nc_inq_dimid(exoid, dimptr, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: no %ss specified in file id %d", ex_name_of_object(set_type),
      exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check for duplicate set id entry */
  ex_id_lkup(exoid, set_type, set_id);
  if (exerrval != EX_LOOKUPFAIL) {  /* found the side set id */
    sprintf(errmsg,
      "Error: %s %d already defined in file id %d", ex_name_of_object(set_type),
      set_id,exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return(EX_FATAL);
  }

  /* Get number of sets specified for this file */
  if ((status = nc_inq_dimlen(exoid,dimid,&temp)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get number of %ss in file id %d",
      ex_name_of_object(set_type), exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }
  num_sets = temp;


  /* Keep track of the total number of sets defined using a counter stored
     in a linked list keyed by exoid.
     NOTE: ex_get_file_item finds the maximum number of sets defined
     for a specific file and returns that value.
  */
  cur_num_sets=ex_get_file_item(exoid, ex_get_counter_list(set_type));
  if (cur_num_sets >= num_sets) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: exceeded number of %ss (%d) defined in file id %d",
      ex_name_of_object(set_type), num_sets,exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /*   NOTE: ex_inc_file_item finds the current number of sets defined
       for a specific file and returns that value incremented. */

  cur_num_sets=ex_inc_file_item(exoid, ex_get_counter_list(set_type));
  set_id_ndx = cur_num_sets + 1;

  /* setup more pointers based on set_type */
  if (set_type == EX_NODE_SET) {
    numentryptr = DIM_NUM_NOD_NS(set_id_ndx);
    entryptr = VAR_NODE_NS(set_id_ndx);
    extraptr = NULL;
    /* 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) {
    numentryptr = DIM_NUM_EDGE_ES(set_id_ndx);
    entryptr = VAR_EDGE_ES(set_id_ndx);
    extraptr = VAR_ORNT_ES(set_id_ndx);
    numdfptr = DIM_NUM_DF_ES(set_id_ndx);
    factptr = VAR_FACT_ES(set_id_ndx);
  }
  else if (set_type == EX_FACE_SET) {
    numentryptr = DIM_NUM_FACE_FS(set_id_ndx);
    entryptr = VAR_FACE_FS(set_id_ndx);
    extraptr = VAR_ORNT_FS(set_id_ndx);
    numdfptr = DIM_NUM_DF_FS(set_id_ndx);
    factptr = VAR_FACT_FS(set_id_ndx);
  }
  else if (set_type == EX_SIDE_SET) {
    numentryptr = DIM_NUM_SIDE_SS(set_id_ndx);
    entryptr = VAR_ELEM_SS(set_id_ndx);
    extraptr = VAR_SIDE_SS(set_id_ndx);
    numdfptr = DIM_NUM_DF_SS(set_id_ndx);
    factptr = VAR_FACT_SS(set_id_ndx);
  }
  if (set_type == EX_ELEM_SET) {
    numentryptr = DIM_NUM_ELE_ELS(set_id_ndx);
    entryptr = VAR_ELEM_ELS(set_id_ndx);
    extraptr = NULL;
    numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
    factptr = VAR_FACT_ELS(set_id_ndx);
  }

  /* write out information to previously defined variable */

  /* first: get id of set id variable */
  if ((status = nc_inq_varid(exoid, idsptr, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to locate %s %d in file id %d", ex_name_of_object(set_type),
      set_id, exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* write out set id */
  start[0] = cur_num_sets;

  ldum = (int)set_id;
  if ((status = nc_put_var1_int(exoid, varid, start, &ldum)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to store %s id %d in file id %d", ex_name_of_object(set_type),
      set_id, exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_entries_in_set == 0) /* Is this a NULL  set? */
    set_stat = 0; /* change set status to NULL */
  else
    set_stat = 1; /* change set status to TRUE */

  if ((status = nc_inq_varid(exoid, statptr, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to locate %s status in file id %d", ex_name_of_object(set_type),
      exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  ldum = (int)set_stat;
  if ((status = nc_put_var1_int(exoid, varid, start, &ldum)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to store %s %d status to file id %d", ex_name_of_object(set_type),
      set_id, exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_entries_in_set == 0) {/* Is this a NULL set? */
    return(EX_NOERR);
  }

  /* put netcdf file into define mode  */
  if ((status = nc_redef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to put file id %d into define mode",
      exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* define dimensions and variables */
  if ((status = nc_def_dim(exoid, numentryptr,
         num_entries_in_set, &dimid)) != NC_NOERR) {
    exerrval = status;
    if (status == NC_ENAMEINUSE)
      {
  sprintf(errmsg,
    "Error: %s %d size already defined in file id %d",
    ex_name_of_object(set_type), set_id,exoid);
  ex_err("ex_put_set_param",errmsg,exerrval);
      }
    else {
      sprintf(errmsg,
        "Error: failed to define number of entries in %s %d in file id %d",
        ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set_param",errmsg,exerrval);
    }
    goto error_ret;
  }

  /* create variable array in which to store the entry lists */

  dims[0] = dimid;
  if ((status = nc_def_var(exoid, entryptr, NC_INT, 1, dims, &varid)) != NC_NOERR) {
    exerrval = status;
    if (status == NC_ENAMEINUSE) {
      sprintf(errmsg,
        "Error: entry list already exists for %s %d in file id %d",
        ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set_param",errmsg,exerrval);
    } else {
      sprintf(errmsg,
        "Error: failed to create entry list for %s %d in file id %d",
        ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set_param",errmsg,exerrval);
    }
    goto error_ret;            /* exit define mode and return */
  }

  if (extraptr) {
    if ((status = nc_def_var(exoid, extraptr, NC_INT, 1, dims, &varid)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {
  sprintf(errmsg,
    "Error: extra list already exists for %s %d in file id %d",
    ex_name_of_object(set_type), set_id, exoid);
  ex_err("ex_put_set_param",errmsg,exerrval);
      } else {
  sprintf(errmsg,
    "Error: failed to create extra list for %s %d in file id %d",
    ex_name_of_object(set_type), set_id,exoid);
  ex_err("ex_put_set_param",errmsg,exerrval);
      }
      goto error_ret;         /* exit define mode and return */
           
    }
  }

  /* Create distribution factors variable if required */

  if (num_dist_fact_in_set > 0) {

    if (set_type == EX_NODE_SET) {
      /* but num_dist_fact_in_set must equal number of nodes */
      if (num_dist_fact_in_set != num_entries_in_set) {
  exerrval = EX_FATAL;
  sprintf(errmsg,
    "Error: # dist fact (%d) not equal to # nodes (%d) in node  set %d file id %d",
    num_dist_fact_in_set, num_entries_in_set, set_id, exoid);
  ex_err("ex_put_set_param",errmsg,exerrval);
  goto error_ret;    /* exit define mode and return */
      }

      /* resuse dimid from entry lists */

    } else {
      if ((status = nc_def_dim(exoid, numdfptr, 
             num_dist_fact_in_set, &dimid)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to define number of dist factors in %s %d in file id %d",
    ex_name_of_object(set_type), set_id,exoid);
  ex_err("ex_put_set_param",errmsg,exerrval);
  goto error_ret;          /* exit define mode and return */
      }
    }

    /* create variable array in which to store the set distribution factors
     */
    dims[0] = dimid;
    if ((status = nc_def_var(exoid, factptr, nc_flt_code(exoid), 1, dims, &varid)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {
  sprintf(errmsg,
    "Error: dist factors list already exists for %s %d in file id %d",
    ex_name_of_object(set_type), set_id,exoid);
  ex_err("ex_put_set_param",errmsg,exerrval);
      } else {
  sprintf(errmsg,
    "Error: failed to create dist factors list for %s %d in file id %d",
    ex_name_of_object(set_type), set_id,exoid);
  ex_err("ex_put_set_param",errmsg,exerrval);
      }
      goto error_ret;            /* exit define mode and return */
    }
  }

  /* leave define mode  */
  if ((status = nc_enddef (exoid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to complete definition in file id %d", exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
      "Error: failed to complete definition for file id %d",
      exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
  }
  return (EX_FATAL);
}
예제 #4
0
파일: exgvartab.c 프로젝트: 151706061/VTK
int ex_get_truth_table (int  exoid,
      ex_entity_type obj_type,
      int  num_blk,
      int  num_var,
      int *var_tab)
{
  int dimid, varid, tabid, i, j, status, status1;
  size_t num_entity = 0;
  size_t num_var_db = 0;
  char errmsg[MAX_ERR_LENGTH];
  const char* routine = "ex_get_truth_table";

  /*
   * The ent_type and the var_name are used to build the netcdf
   * variables name.  Normally this is done via a macro defined in
   * exodusII_int.h
   */
  const char* ent_type = NULL;
  const char* var_name = NULL;

  exerrval = 0; /* clear error code */

  switch (obj_type) {
  case EX_EDGE_BLOCK:
    status = ex_get_dimension(exoid, DIM_NUM_EDG_VAR,  "edge variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_EBLK_TAB, &tabid);
    var_name = "vals_edge_var";
    ent_type = "eb";
    break;
  case EX_FACE_BLOCK:
    status = ex_get_dimension(exoid, DIM_NUM_FAC_VAR,  "face variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_FBLK_TAB, &tabid);
    var_name = "vals_face_var";
    ent_type = "fb";
    break;
  case EX_ELEM_BLOCK:
    status = ex_get_dimension(exoid, DIM_NUM_ELE_VAR,  "element variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_ELEM_TAB, &tabid);
    var_name = "vals_elem_var";
    ent_type = "eb";
    break;
  case EX_NODE_SET:
    status = ex_get_dimension(exoid, DIM_NUM_NSET_VAR, "nodeset variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_NSET_TAB, &tabid);
    var_name = "vals_nset_var";
    ent_type = "ns";
    break;
  case EX_EDGE_SET:
    status = ex_get_dimension(exoid, DIM_NUM_ESET_VAR, "edgeset variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_ESET_TAB, &tabid);
    var_name = "vals_eset_var";
    ent_type = "es";
    break;
  case EX_FACE_SET:
    status = ex_get_dimension(exoid, DIM_NUM_FSET_VAR, "faceset variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_FSET_TAB, &tabid);
    var_name = "vals_fset_var";
    ent_type = "fs";
    break;
  case EX_SIDE_SET:
    status = ex_get_dimension(exoid, DIM_NUM_SSET_VAR, "sideset variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_SSET_TAB, &tabid);
    var_name = "vals_sset_var";
    ent_type = "ss";
    break;
  case EX_ELEM_SET:
    status = ex_get_dimension(exoid, DIM_NUM_ELSET_VAR, "elemset variables", &num_var_db, &varid, routine);
    status1 = nc_inq_varid (exoid, VAR_ELSET_TAB, &tabid);
    var_name = "vals_elset_var";
    ent_type = "es";
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
      "Error: Invalid variable type %d specified in file id %d",
      obj_type, exoid);
    ex_err(routine,errmsg,exerrval);
    return (EX_WARN);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    return (EX_WARN);
  }

  status  = ex_get_dimension(exoid, ex_dim_num_objects(obj_type),
           ex_name_of_object(obj_type), &num_entity, &dimid, routine);
  if (status != NC_NOERR) {
    exerrval = status;
    return (EX_FATAL);
  }

  if (num_entity != (size_t)num_blk) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: # of %s doesn't match those defined in file id %d",
      ex_name_of_object(obj_type), exoid);
    ex_err(routine,errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_var_db != (size_t)num_var) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
      "Error: # of %s variables doesn't match those defined in file id %d",
      ex_name_of_object(obj_type), exoid);
    ex_err(routine,errmsg,exerrval);
    return (EX_FATAL);
  }

  if (status1 != NC_NOERR) {
    /* since truth table isn't stored in the data file, derive it dynamically */
    for (j=0; j<num_blk; j++) {

      for (i=0; i<num_var; i++) {
        /* NOTE: names are 1-based */
        if (nc_inq_varid (exoid, ex_catstr2(var_name, i+1, ent_type, j+1), &tabid) == NC_NOERR) {
          /* variable exists; put a 1 in the truth table */
          var_tab[j*num_var+i] = 1;
        } else {
          /* variable doesn't exist; put a 0 in the truth table */
          var_tab[j*num_var+i] = 0;
        }
      }
    }
  } else {
    /* read in the truth table */
    status = nc_get_var_int(exoid, tabid, var_tab);

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to get %s truth table from file id %d",
        ex_name_of_object(obj_type), exoid);
      ex_err(routine,errmsg,exerrval);
      return (EX_FATAL);
    }
  } 
  return (EX_NOERR);
}
예제 #5
0
int ex_open_int (const char  *path,
		 int    mode,
		 int   *comp_ws,
		 int   *io_ws,
		 float *version,
		 int    run_version)
{
  int exoid;
  int status, stat_att, stat_dim;
  nc_type att_type = NC_NAT;
  size_t att_len = 0;
  int old_fill;
  int file_wordsize;
  int dim_str_name;
  int int64_status = 0;
  
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */
 
  /* set error handling mode to no messages, non-fatal errors */
  ex_opts(exoptval);    /* call required to set ncopts first time through */

  if (run_version != EX_API_VERS_NODOT && warning_output == 0) {
    int run_version_major = run_version / 100;
    int run_version_minor = run_version % 100;
    int lib_version_major = EX_API_VERS_NODOT / 100;
    int lib_version_minor = EX_API_VERS_NODOT % 100;
    fprintf(stderr, "EXODUS: Warning: This code was compiled with exodus version %d.%02d,\n          but was linked with exodus library version %d.%02d\n          This is probably an error in the build process of this code.\n",
	    run_version_major, run_version_minor, lib_version_major, lib_version_minor);
    warning_output = 1;
  }
  

  if ((mode & EX_READ) && (mode & EX_WRITE)) {
    exerrval = EX_BADFILEMODE;
    sprintf(errmsg,"Error: Cannot specify both EX_READ and EX_WRITE");
    ex_err("ex_open",errmsg,exerrval); 
    return (EX_FATAL);
  }

  /* The EX_READ mode is the default if EX_WRITE is not specified... */
  if (!(mode & EX_WRITE)) { /* READ ONLY */
#if defined(__LIBCATAMOUNT__)
    if ((status = nc_open (path, NC_NOWRITE, &exoid)) != NC_NOERR)
#else
      if ((status = nc_open (path, NC_NOWRITE|NC_SHARE, &exoid)) != NC_NOERR)
#endif
	{
	  /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
	  if (status == 0) {
	    exerrval = EX_FATAL;
	  }
	  else {
	    /* It is possible that the user is trying to open a netcdf4
	       file, but the netcdf4 capabilities aren't available in the
	       netcdf linked to this library. Note that we can't just use a
	       compile-time define since we could be using a shareable
	       netcdf library, so the netcdf4 capabilities aren't known
	       until runtime...
	  
	       Netcdf-4.X does not (yet?) have a function that can be
	       queried to determine whether the library being used was
	       compiled with --enable-netcdf4, so that isn't very
	       helpful.. 

	       At this time, query the beginning of the file and see if it
	       is an HDF-5 file and if it is assume that the open failure
	       is due to the netcdf library not enabling netcdf4 features...
	    */
	    int type = 0;
	    ex_check_file_type(path, &type);
	  
	    if (type == 5) {
	      /* This is an hdf5 (netcdf4) file. Since the nc_open failed,
		 the assumption is that the netcdf doesn't have netcdf4
		 capabilities enabled.  Tell the user...
	      */
	      fprintf(stderr,
		      "EXODUS: Error: Attempting to open the netcdf-4 file:\n\t'%s'\n\twith a netcdf library that does not support netcdf-4\n",
		      path);
	    }
	    exerrval = status;
	  }
	  sprintf(errmsg,"Error: failed to open %s read only",path);
	  ex_err("ex_open",errmsg,exerrval); 
	  return(EX_FATAL);
	} 
  }
  else /* (mode & EX_WRITE) READ/WRITE */
    {
#if defined(__LIBCATAMOUNT__)
      if ((status = nc_open (path, NC_WRITE, &exoid)) != NC_NOERR)
#else
	if ((status = nc_open (path, NC_WRITE|NC_SHARE, &exoid)) != NC_NOERR)
#endif
	  {
	    /* NOTE: netCDF returns an id of -1 on an error - but no error code! */
	    if (status == 0)
	      exerrval = EX_FATAL;
	    else
	      exerrval = status;
	    sprintf(errmsg,"Error: failed to open %s write only",path);
	    ex_err("ex_open",errmsg,exerrval); 
	    return(EX_FATAL);
	  } 

      /* turn off automatic filling of netCDF variables */
      if ((status = nc_set_fill (exoid, NC_NOFILL, &old_fill)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to set nofill mode in file id %d",
		exoid);
	ex_err("ex_open", errmsg, exerrval);
	return (EX_FATAL);
      }

      stat_att = nc_inq_att(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len);
      stat_dim = nc_inq_dimid(exoid, DIM_STR_NAME, &dim_str_name);
      if(stat_att != NC_NOERR || stat_dim != NC_NOERR) {
	nc_redef(exoid);
	if (stat_att != NC_NOERR) {
	  int max_so_far = 32;
	  nc_put_att_int(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, NC_INT, 1, &max_so_far);
	}

	/* If the DIM_STR_NAME variable does not exist on the database, we need to add it now. */
	if(stat_dim != NC_NOERR) {
	  /* Not found; set to default value of 32+1. */
	  int max_name = ex_default_max_name_length < 32 ? 32 : ex_default_max_name_length;
	  nc_def_dim(exoid, DIM_STR_NAME, max_name+1, &dim_str_name);
	}
	nc_enddef (exoid);
      }
    }

  /* determine version of EXODUS II file, and the word size of
   * floating point and integer values stored in the file
   */

  if ((status = nc_get_att_float(exoid, NC_GLOBAL, ATT_VERSION, version)) != NC_NOERR) {
    exerrval  = status;
    sprintf(errmsg,"Error: failed to get database version for file id: %d",
	    exoid);
    ex_err("ex_open",errmsg,exerrval);
    return(EX_FATAL);
  }
   
  /* check ExodusII file version - old version 1.x files are not supported */
  if (*version < 2.0) {
    exerrval  = EX_FATAL;
    sprintf(errmsg,"Error: Unsupported file version %.2f in file id: %d",
	    *version, exoid);
    ex_err("ex_open",errmsg,exerrval);
    return(EX_FATAL);
  }
   
  if (nc_get_att_int (exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, &file_wordsize) != NC_NOERR)
    {  /* try old (prior to db version 2.02) attribute name */
      if (nc_get_att_int (exoid,NC_GLOBAL,ATT_FLT_WORDSIZE_BLANK,&file_wordsize) != NC_NOERR)
	{
	  exerrval  = EX_FATAL;
	  sprintf(errmsg,"Error: failed to get file wordsize from file id: %d",
		  exoid);
	  ex_err("ex_open",errmsg,exerrval);
	  return(exerrval);
	}
    }

  /* See if int64 status attribute exists and if so, what data is stored as int64 
   * Older files don't have the attribute, so it is not an error if it is missing
   */
  if (nc_get_att_int (exoid, NC_GLOBAL, ATT_INT64_STATUS, &int64_status) != NC_NOERR) {
    int64_status = 0; /* Just in case it gets munged by a failed get_att_int call */
  }
  
  /* Merge in API int64 status flags as specified by caller of function... */
  int64_status |= (mode & EX_ALL_INT64_API);
  
  /* initialize floating point and integer size conversion. */
  if (ex_conv_ini( exoid, comp_ws, io_ws, file_wordsize, int64_status ) != EX_NOERR ) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: failed to initialize conversion routines in file id %d",
            exoid);
    ex_err("ex_open", errmsg, exerrval);
    return (EX_FATAL);
  }

  return (exoid);
}
예제 #6
0
int ex_get_prop_array (int   exoid,
                       int   obj_type,
                       const char *prop_name,
                       int  *values)
{
   int num_props, i, propid, dimid, iresult;
   int found = FALSE;
   long start[1], count[1], num_obj; 
   nclong *longs;
   char name[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_VAR_NAME_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 */

/* open appropriate variable, depending on obj_type and prop_name */

   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_get_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_get_prop_array",errmsg,exerrval);
         return(EX_FATAL);
     }

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

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

     memset(tmpstr, 0, MAX_VAR_NAME_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_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

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

/* if property is not found, return warning */

   if (!found)
   {
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
       "Warning: object type %d, property %s not defined in file id %d",
        obj_type, prop_name, exoid);
     ex_err("ex_get_prop_array",errmsg,exerrval);
     return (EX_WARN);
   }

   if ((dimid = ncdimid (exoid, dim_name)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
     "Error: failed to locate number of objects in file id %d",
              exoid);
     ex_err("ex_get_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_get_prop_array",errmsg, exerrval);
     return (EX_FATAL);
   }

/* read num_obj values from property variable */

/* application code has allocated an array of ints but netcdf is expecting
   a pointer to nclongs;  if ints are different sizes than nclongs,
   we must allocate an array of nclongs then convert them to ints with ltoi */

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

   if (sizeof(int) == sizeof(nclong)) {
      iresult = ncvarget (exoid, propid, start, count, values);
   } else {
     if (!(longs = static_cast<nclong*>(malloc(num_obj * sizeof(nclong))))) {
       exerrval = EX_MEMFAIL;
       sprintf(errmsg,
               "Error: failed to allocate memory for %s property array for file id %d",
               obj_stype, exoid);
       ex_err("ex_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }
     iresult = ncvarget (exoid, propid, start, count, longs);
   }

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

   if (sizeof(int) != sizeof(nclong)) {
      ltoi (longs, values, num_obj);
      free (longs);
   }

   return (EX_NOERR);
}
예제 #7
0
int ex_get_attr( int   exoid,
                 ex_entity_type obj_type,
                 ex_entity_id   obj_id,
                 void* attrib )

{
  int status;
  int attrid, obj_id_ndx;
  char errmsg[MAX_ERR_LENGTH];
  const char* vattrbname;

  exerrval = 0; /* clear error code */

  /* Determine index of obj_id in vobjids array */
  if (obj_type == EX_NODAL)
    obj_id_ndx = 0;
  else {
    obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id);
    
    if (exerrval != 0) {
      if (exerrval == EX_NULLENTITY) {
	sprintf(errmsg,
		"Warning: no attributes found for NULL %s %"PRId64" in file id %d",
		ex_name_of_object(obj_type),obj_id,exoid);
	ex_err("ex_get_attr",errmsg,EX_NULLENTITY);
	return (EX_WARN);              /* no attributes for this object */
      } else {
	sprintf(errmsg,
		"Warning: failed to locate %s id %"PRId64" in id array in file id %d",
		ex_name_of_object(obj_type),obj_id, exoid);
	ex_err("ex_get_attr",errmsg,exerrval);
	return (EX_WARN);
      }
    }
  }

  switch (obj_type) {
  case EX_SIDE_SET:
    vattrbname = VAR_SSATTRIB(obj_id_ndx);
    break;
  case EX_NODE_SET:
    vattrbname = VAR_NSATTRIB(obj_id_ndx);
    break;
  case EX_EDGE_SET:
    vattrbname = VAR_ESATTRIB(obj_id_ndx);
    break;
  case EX_FACE_SET:
    vattrbname = VAR_FSATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_SET:
    vattrbname = VAR_ELSATTRIB(obj_id_ndx);
    break;
  case EX_NODAL:
    vattrbname = VAR_NATTRIB;
    break;
  case EX_EDGE_BLOCK:
    vattrbname = VAR_EATTRIB(obj_id_ndx);
    break;
  case EX_FACE_BLOCK:
    vattrbname = VAR_FATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_BLOCK:
    vattrbname = VAR_ATTRIB(obj_id_ndx);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized object type in switch: %d in file id %d",
	    obj_type,exoid);
    ex_err("ex_get_attr",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }

  /* inquire id's of previously defined dimensions  */
  if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate attributes for %s %"PRId64" in file id %d",
            ex_name_of_object(obj_type), obj_id,exoid);
    ex_err("ex_get_attr",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* read in the attributes */
  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_var_float(exoid, attrid, attrib);
  } else {
    status = nc_get_var_double(exoid, attrid, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get attributes for %s %"PRId64" in file id %d",
            ex_name_of_object(obj_type),obj_id,exoid);
    ex_err("ex_get_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
예제 #8
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);
}
예제 #9
0
파일: expblk.c 프로젝트: hs9906/paraview
int ex_put_block( int         exoid,
                  int         blk_type,
                  int         blk_id,
                  const char* entry_descrip,
                  int         num_entries_this_blk,
                  int         num_nodes_per_entry,
                  int         num_edges_per_entry,
                  int         num_faces_per_entry,
                  int         num_attr_per_entry )
{
   int varid, dimid, dims[2], blk_id_ndx, blk_stat, strdim;
   long start[2], num_blk;
   nclong ldum;
   int cur_num_blk, numblkdim, numattrdim;
   int nnodperentdim, nedgperentdim = -1, nfacperentdim = -1;
   int connid, econnid, fconnid;
   char *cdum;
   char errmsg[MAX_ERR_LENGTH];
   const char* tname;
   const char* dnumblk;
   const char* vblkids;
   const char* vblksta;
   const char* vnodcon = 0;
   const char* vedgcon = 0;
   const char* vfaccon = 0;
   const char* vattnam = 0;
   const char* vblkatt = 0;
   const char* dneblk = 0;
   const char* dnape = 0;
   const char* dnnpe = 0;
   const char* dnepe = 0;
   const char* dnfpe = 0;
   struct list_item** ctr_list;

   exerrval  = 0; /* clear error code */

   cdum = 0;

   switch (blk_type) {
   case EX_EDGE_BLOCK:
     tname = "edge";
     dnumblk = DIM_NUM_ED_BLK;
     vblkids = VAR_ID_ED_BLK;
     vblksta = VAR_STAT_ED_BLK;
     ctr_list = &ed_ctr_list;
     break;
   case EX_FACE_BLOCK:
     tname = "face";
     dnumblk = DIM_NUM_FA_BLK;
     vblkids = VAR_ID_FA_BLK;
     vblksta = VAR_STAT_FA_BLK;
     ctr_list = &fa_ctr_list;
     break;
   case EX_ELEM_BLOCK:
     tname = "element";
     dnumblk = DIM_NUM_EL_BLK;
     vblkids = VAR_ID_EL_BLK;
     vblksta = VAR_STAT_EL_BLK;
     ctr_list = &eb_ctr_list;
     break;
   default:
     exerrval = EX_BADPARAM;
     sprintf( errmsg, "Error: Bad block type (%d) specified for file id %d",
       blk_type, exoid );
     ex_err( "ex_put_block", errmsg, exerrval );
     return (EX_FATAL);
   }

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

   if ((dimid = (ncdimid (exoid, dnumblk))) == -1 )
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: no element blocks defined in file id %d",
             exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

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

/* Next: Make sure that this is not a duplicate element block id by
         searching the vblkids array.
   WARNING: This must be done outside of define mode because id_lkup accesses
            the database to determine the position
*/

   if ((varid = ncvarid (exoid, vblkids)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to locate element block ids in file id %d", exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);

   }

   blk_id_ndx = ex_id_lkup(exoid,vblkids,blk_id);
   if (exerrval != EX_LOOKUPFAIL)   /* found the element block id */
   {
     exerrval = EX_FATAL;
     sprintf(errmsg,
            "Error: element block id %d already exists in file id %d",
             blk_id,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

/* Keep track of the total number of element blocks defined using a counter 
   stored in a linked list keyed by exoid.
   NOTE: ex_get_file_item  is a function that finds the number of element 
         blocks for a specific file and returns that value incremented.
*/
   cur_num_blk=ex_get_file_item(exoid, ctr_list);
   if (cur_num_blk >= num_blk)
   {
     exerrval = EX_FATAL;
     sprintf(errmsg,
          "Error: exceeded number of element blocks (%ld) defined in file id %d",
             num_blk,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }


/*   NOTE: ex_get_file_item  is a function that finds the number of element
         blocks for a specific file and returns that value incremented. */

   cur_num_blk=ex_inc_file_item(exoid, ctr_list);
   start[0] = (long)cur_num_blk;

/* write out element block id to previously defined id array variable*/

   ldum = (nclong)blk_id;
   if (ncvarput1 (exoid, varid, start, &ldum) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store element block id to file id %d",
             exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   blk_id_ndx = start[0]+1; /* element id index into vblkids array*/

   if (num_entries_this_blk == 0) /* Is this a NULL element block? */
     blk_stat = 0; /* change element block status to NULL */
   else
     blk_stat = 1; /* change element block status to TRUE */

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

   ldum = (nclong)blk_stat;
   if (ncvarput1 (exoid, varid, start, &ldum) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store element id %d status to file id %d",
             blk_id, exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (num_entries_this_blk == 0) /* Is this a NULL element block? */
   {
     return(EX_NOERR);
   }


   /*
    * Check that storage required for connectivity array is less
    * than 2GB which is maximum size permitted by netcdf
    * (in large file mode). 1<<29 == max number of integer items.
    */
   if (num_entries_this_blk * num_nodes_per_entry  > (1<<29)) {
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
             "Error: Size to store connectivity for element block %d exceeds 2GB in file id %d",
             blk_id, exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }

   /* 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_elem_block",errmsg,exerrval);
     return (EX_FATAL);
   }


   switch (blk_type) {
   case EX_EDGE_BLOCK:
     dneblk = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
     dnnpe = DIM_NUM_NOD_PER_ED(blk_id_ndx);
     dnepe = 0;
     dnfpe = 0;
     dnape = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
     vblkatt = VAR_EATTRIB(blk_id_ndx);
     vattnam = VAR_NAME_EATTRIB(blk_id_ndx);
     vnodcon = VAR_EBCONN(blk_id_ndx);
     vedgcon = 0;
     vfaccon = 0;
     break;
   case EX_FACE_BLOCK:
     dneblk = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
     dnnpe = DIM_NUM_NOD_PER_FA(blk_id_ndx);
     dnepe = 0;
     dnfpe = 0;
     dnape = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
     vblkatt = VAR_FATTRIB(blk_id_ndx);
     vattnam = VAR_NAME_FATTRIB(blk_id_ndx);
     vnodcon = VAR_FBCONN(blk_id_ndx);
     vedgcon = 0;
     vfaccon = 0;
     break;
   case EX_ELEM_BLOCK:
     dneblk = DIM_NUM_EL_IN_BLK(blk_id_ndx);
     dnnpe = DIM_NUM_NOD_PER_EL(blk_id_ndx);
     dnepe = DIM_NUM_EDG_PER_EL(blk_id_ndx);
     dnfpe = DIM_NUM_FAC_PER_EL(blk_id_ndx);
     dnape = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
     vblkatt = VAR_ATTRIB(blk_id_ndx);
     vattnam = VAR_NAME_ATTRIB(blk_id_ndx);
     vnodcon = VAR_CONN(blk_id_ndx);
     vedgcon = VAR_ECONN(blk_id_ndx);
     vfaccon = VAR_FCONN(blk_id_ndx);
     break;
   }
/* define some dimensions and variables*/

   if ((numblkdim = ncdimdef (exoid,dneblk,(long)num_entries_this_blk)) == -1)
   {
     if (ncerr == NC_ENAMEINUSE)        /* duplicate entry */
     {
       exerrval = ncerr;
       sprintf(errmsg,
             "Error: element block %d already defined in file id %d",
              blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
     }
     else
     {
       exerrval = ncerr;
       sprintf(errmsg,
    "Error: failed to define number of elements/block for block %d file id %d",
              blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
     }
     goto error_ret;         /* exit define mode and return */
   }

   if ((nnodperentdim = ncdimdef (exoid,dnnpe,(long)num_nodes_per_entry)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
   "Error: failed to define number of nodes/element for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     goto error_ret;         /* exit define mode and return */
   }

   if ( dnepe && num_edges_per_entry > 0 ) {
     if ((nedgperentdim = ncdimdef (exoid,dnepe,(long)num_edges_per_entry)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to define number of edges/element for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
   }

   if ( dnfpe && num_faces_per_entry > 0 ) {
     if ((nfacperentdim = ncdimdef (exoid,dnfpe,(long)num_faces_per_entry)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to define number of faces/element for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
   }

/* element attribute array */

   if (num_attr_per_entry > 0)
   {

     if ((numattrdim = ncdimdef (exoid, dnape, (long)num_attr_per_entry)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
      "Error: failed to define number of attributes in block %d in file id %d",
               blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }

     dims[0] = numblkdim;
     dims[1] = numattrdim;

     if ((ncvardef (exoid, vblkatt, nc_flt_code(exoid), 2, dims)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
       "Error:  failed to define attributes for element block %d in file id %d",
               blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }

     /* inquire previously defined dimensions  */
     if ((strdim = ncdimid (exoid, DIM_STR)) < 0) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to get string length in file id %d",exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       return (EX_FATAL);
     }
     
     /* Attribute names... */
     dims[0] = numattrdim;
     dims[1] = strdim;
      
     if (ncvardef (exoid, vattnam, NC_CHAR, 2, dims) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to define element attribute name array in file id %d",exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
     
   }

/* element connectivity array */

   dims[0] = numblkdim;
   dims[1] = nnodperentdim;

   if ((connid = ncvardef (exoid, vnodcon, NC_LONG, 2, dims)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
        "Error: failed to create connectivity array for block %d in file id %d",
             blk_id,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     goto error_ret;         /* exit define mode and return */
   }

/* store element type as attribute of connectivity variable */

   if ((ncattput (exoid, connid, ATT_NAME_ELB, NC_CHAR, strlen(entry_descrip)+1, 
             (void*) entry_descrip)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Error: failed to store element type name %s in file id %d",
             entry_descrip,exoid);
     ex_err("ex_put_elem_block",errmsg,exerrval);
     goto error_ret;         /* exit define mode and return */
   }

   if ( vedgcon && num_edges_per_entry ) {
     dims[0] = numblkdim;
     dims[1] = nedgperentdim;

     if ((econnid = ncvardef (exoid, vedgcon, NC_LONG, 2, dims)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to create edge connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",errmsg,exerrval);
       goto error_ret;         /* exit define mode and return */
     }
   }

   if ( vfaccon && num_faces_per_entry ) {
     dims[0] = numblkdim;
     dims[1] = nfacperentdim;

     if ((fconnid = ncvardef (exoid, vfaccon, NC_LONG, 2, dims)) == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
         "Error: failed to create face connectivity array for block %d in file id %d",
         blk_id,exoid);
       ex_err("ex_put_elem_block",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 element block definition in file id %d", 
        exoid);
     ex_err("ex_put_elem_block",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_block",errmsg,exerrval);
       }
       return (EX_FATAL);
}
int ex_get_entity_count_per_polyhedra (int            exoid,
				       ex_entity_type blk_type,
				       ex_entity_id   blk_id,
				       int     *entity_counts)
{
   int npeid=-1, blk_id_ndx, status;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
   if (exerrval != 0) 
     {
     if (exerrval == EX_NULLENTITY)
       {
       sprintf(errmsg,
         "Warning: entity_counts array not allowed for NULL %s block %"PRId64" in file id %d",
	       ex_name_of_object(blk_type),blk_id,exoid);
       ex_err("ex_get_entity_count_per_polyhedra",errmsg,EX_MSG);
       return (EX_WARN);
       }
     else
       {
       sprintf(errmsg,
         "Error: failed to locate %s block id %"PRId64" in id array in file id %d",
         ex_name_of_object(blk_type),blk_id, exoid);
       ex_err("ex_get_entity_count_per_polyhedra",errmsg,exerrval);
       return (EX_FATAL);
       }
     }

/* inquire id's of previously defined dimensions  */
   switch (blk_type) {
   case EX_ELEM_BLOCK:
     status = nc_inq_varid (exoid, VAR_EBEPEC(blk_id_ndx), &npeid);
     break;
   case EX_FACE_BLOCK:
     status = nc_inq_varid (exoid, VAR_FBEPEC(blk_id_ndx), &npeid);
     break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized block type in switch: %d in file id %d",
	    blk_type,exoid);
    ex_err("ex_get_entity_count_per_polyhedra",errmsg,EX_MSG);
    return (EX_FATAL);
   }
   if (status != NC_NOERR)
   {
     exerrval = status;
     sprintf(errmsg,
	     "Error: failed to locate entity_counts array for %s block %"PRId64" in file id %d",
             ex_name_of_object(blk_type),blk_id,exoid);
     ex_err("ex_get_entity_count_per_polyhedra",errmsg, exerrval);
     return(EX_FATAL);
   }

   status = nc_get_var_int(exoid, npeid, entity_counts); 
   if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
      "Error: failed to read node counts array for %s block %"PRId64" in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_entity_count_per_polyhedra",errmsg, exerrval);
      return(EX_FATAL);
   }
   return (EX_NOERR);
}
예제 #11
0
int ex_get_side_set_node_list(int exoid, ex_entity_id side_set_id, void_int *side_set_node_cnt_list,
                              void_int *side_set_node_list)
{
  size_t    i, j;
  int64_t   elem, side;
  int64_t   num_side_sets, num_elem_blks, num_df, ndim;
  int64_t   tot_num_elem = 0, tot_num_ss_elem = 0, elem_num = 0;
  size_t    connect_offset, side_num, node_pos;
  void_int *elem_blk_ids       = NULL;
  void_int *connect            = NULL;
  void_int *ss_elem_ndx        = NULL;
  void_int *ss_elem_node_ndx   = NULL;
  void_int *ss_parm_ndx        = NULL;
  void_int *side_set_elem_list = NULL;
  void_int *side_set_side_list = NULL;
  size_t    elem_ctr, node_ctr, elem_num_pos;
  size_t    num_nodes_per_elem;
  int       int_size, ids_size;

  int err_stat = EX_NOERR;
  int status;

  struct elem_blk_parm *elem_blk_parms = NULL;

  /* side to node translation tables -
     These tables are used to look up the side number based on the
     first and second node in the side/face list. The side node order
     is found in the original Exodus document, SAND87-2997. The element
     node order is found in the ExodusII document, SAND92-2137. These
     tables were generated by following the right-hand rule for determining
     the outward normal.
  */
  /* triangle */
  static int tri_table[3][3] = {
      {1, 2, 4}, /* side 1 */
      {2, 3, 5}, /* side 2 */
      {3, 1, 6}  /* side 3 */
  };

  /* triangle 3d */
  static int tri3_table[5][7] = {
      {1, 2, 3, 4, 5, 6, 7}, /* side 1 (face) */
      {3, 2, 1, 6, 5, 4, 7}, /* side 2 (face) */
      {1, 2, 4, 0, 0, 0, 0}, /* side 3 (edge) */
      {2, 3, 5, 0, 0, 0, 0}, /* side 4 (edge) */
      {3, 1, 6, 0, 0, 0, 0}  /* side 5 (edge) */
  };

  /* quad */
  static int quad_table[4][3] = {
      {1, 2, 5}, /* side 1 */
      {2, 3, 6}, /* side 2 */
      {3, 4, 7}, /* side 3 */
      {4, 1, 8}  /* side 4 */
  };

  /* shell */
  static int shell_table[6][9] = {
      {1, 2, 3, 4, 5, 6, 7, 8, 9}, /* side 1 (face) */
      {1, 4, 3, 2, 8, 7, 6, 5, 9}, /* side 2 (face) */
      {1, 2, 5, 0, 0, 0, 0, 0, 0}, /* side 3 (edge) */
      {2, 3, 6, 0, 0, 0, 0, 0, 0}, /* side 4 (edge) */
      {3, 4, 7, 0, 0, 0, 0, 0, 0}, /* side 5 (edge) */
      {4, 1, 8, 0, 0, 0, 0, 0, 0}  /* side 6 (edge) */
  };

  /* tetra */
  static int tetra_table[4][7] = {
      {1, 2, 4, 5, 9, 8, 14},  /* Side 1 nodes */
      {2, 3, 4, 6, 10, 9, 12}, /* Side 2 nodes */
      {1, 4, 3, 8, 10, 7, 13}, /* Side 3 nodes */
      {1, 3, 2, 7, 6, 5, 11}   /* Side 4 nodes */
  };

  /* wedge */
  /* wedge 6 or 7 */
  static int wedge6_table[5][4] = {
      {1, 2, 5, 4}, /* Side 1 nodes -- quad     */
      {2, 3, 6, 5}, /* Side 2 nodes -- quad     */
      {1, 4, 6, 3}, /* Side 3 nodes -- quad     */
      {1, 3, 2, 0}, /* Side 4 nodes -- triangle */
      {4, 5, 6, 0}  /* Side 5 nodes -- triangle */
  };

  /* wedge 15 or 16 */
  static int wedge15_table[5][8] = {
      {1, 2, 5, 4, 7, 11, 13, 10}, /* Side 1 nodes -- quad     */
      {2, 3, 6, 5, 8, 12, 14, 11}, /* Side 2 nodes -- quad     */
      {1, 4, 6, 3, 10, 15, 12, 9}, /* Side 3 nodes -- quad     */
      {1, 3, 2, 9, 8, 7, 0, 0},    /* Side 4 nodes -- triangle */
      {4, 5, 6, 13, 14, 15, 0, 0}  /* Side 5 nodes -- triangle */
  };

  /* wedge 20 */
  static int wedge20_table[5][9] = {
      {1, 2, 5, 4, 7, 11, 13, 10, 20}, /* Side 1 nodes -- quad     */
      {2, 3, 6, 5, 8, 12, 14, 11, 18}, /* Side 2 nodes -- quad     */
      {1, 4, 6, 3, 10, 15, 12, 9, 19}, /* Side 3 nodes -- quad     */
      {1, 3, 2, 9, 8, 7, 16, 0, 0},    /* Side 4 nodes -- triangle */
      {4, 5, 6, 13, 14, 15, 17, 0, 0}  /* Side 5 nodes -- triangle */
  };

  /* wedge 21 */
  static int wedge21_table[5][9] = {
      {1, 2, 5, 4, 7, 11, 13, 10, 21}, /* Side 1 nodes -- quad     */
      {2, 3, 6, 5, 8, 12, 14, 11, 19}, /* Side 2 nodes -- quad     */
      {1, 4, 6, 3, 10, 15, 12, 9, 20}, /* Side 3 nodes -- quad     */
      {1, 3, 2, 9, 8, 7, 17, 0, 0},    /* Side 4 nodes -- triangle */
      {4, 5, 6, 13, 14, 15, 18, 0, 0}  /* Side 5 nodes -- triangle */
  };

  /* wedge 18 */
  static int wedge18_table[5][9] = {
      {1, 2, 5, 4, 7, 11, 13, 10, 16}, /* Side 1 nodes -- quad     */
      {2, 3, 6, 5, 8, 12, 14, 11, 17}, /* Side 2 nodes -- quad     */
      {1, 4, 6, 3, 10, 15, 12, 9, 18}, /* Side 3 nodes -- quad     */
      {1, 3, 2, 9, 8, 7, 0, 0, 0},     /* Side 4 nodes -- triangle */
      {4, 5, 6, 13, 14, 15, 0, 0, 0}   /* Side 5 nodes -- triangle */
  };

  /* hex */
  static int hex_table[6][9] = {
      {1, 2, 6, 5, 9, 14, 17, 13, 26},  /* side 1 */
      {2, 3, 7, 6, 10, 15, 18, 14, 25}, /* side 2 */
      {3, 4, 8, 7, 11, 16, 19, 15, 27}, /* side 3 */
      {1, 5, 8, 4, 13, 20, 16, 12, 24}, /* side 4 */
      {1, 4, 3, 2, 12, 11, 10, 9, 22},  /* side 5 */
      {5, 6, 7, 8, 17, 18, 19, 20, 23}  /* side 6 */
  };

  /* pyramid */
  static int pyramid_table[5][9] = {
      {1, 2, 5, 0, 6, 11, 10, 0, 15}, /* side 1 (tri) */
      {2, 3, 5, 0, 7, 12, 11, 0, 16}, /* side 2 (tri) */
      {3, 4, 5, 0, 8, 13, 12, 0, 17}, /* side 3 (tri) */
      {1, 5, 4, 0, 10, 13, 9, 0, 18}, /* side 4 (tri) */
      {1, 4, 3, 2, 9, 8, 7, 6, 14}    /* side 5 (quad) */
  };

  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* first check if any side sets are specified */
  /* inquire how many side sets have been stored */
  num_side_sets = ex_inquire_int(exoid, EX_INQ_SIDE_SETS);
  if (num_side_sets < 0) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of side sets in file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    return (EX_FATAL);
  }

  if (num_side_sets == 0) {
    snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no side sets defined in file id %d", exoid);
    ex_err("ex_get_side_set_node_list", errmsg, EX_WARN);
    return (EX_WARN);
  }

  /* Lookup index of side set id in VAR_SS_IDS array */
  ex_id_lkup(exoid, EX_SIDE_SET, side_set_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      snprintf(errmsg, MAX_ERR_LENGTH, "Warning: side set %" PRId64 " is NULL in file id %d",
               side_set_id, exoid);
      ex_err("ex_get_side_set_node_list", errmsg, EX_NULLENTITY);
      return (EX_WARN);
    }

    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate side set %" PRId64 " in VAR_SS_IDS array in file id %d",
             side_set_id, exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    return (EX_FATAL);
  }

  num_elem_blks = ex_inquire_int(exoid, EX_INQ_ELEM_BLK);
  if (num_elem_blks < 0) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of element blocks in file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    return (EX_FATAL);
  }

  tot_num_elem = ex_inquire_int(exoid, EX_INQ_ELEM);
  if (tot_num_elem < 0) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get total number of elements in file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* get the dimensionality of the coordinates;  this is necessary to
     distinguish between 2d TRIs and 3d TRIs */
  ndim = ex_inquire_int(exoid, EX_INQ_DIM);
  if (ndim < 0) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get dimensionality in file id %d", exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    return (EX_FATAL);
  }

  int_size = sizeof(int);
  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    int_size = sizeof(int64_t);
  }

  ids_size = sizeof(int);
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    ids_size = sizeof(int64_t);
  }

  /* First determine the  # of elements in the side set*/
  if (int_size == sizeof(int64_t)) {
    status = ex_get_set_param(exoid, EX_SIDE_SET, side_set_id, &tot_num_ss_elem, &num_df);
  }
  else {
    int tot, df;
    status          = ex_get_set_param(exoid, EX_SIDE_SET, side_set_id, &tot, &df);
    tot_num_ss_elem = tot;
    num_df          = df;
  }

  if (status != EX_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get number of elements in side set %" PRId64 " in file id %d",
             side_set_id, exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Allocate space for the side set element list */
  if (!(side_set_elem_list = malloc(tot_num_ss_elem * int_size))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for side set element list "
                                     "for file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Allocate space for the side set side list */
  if (!(side_set_side_list = malloc(tot_num_ss_elem * int_size))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to allocate space for side set side list for file id %d", exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    err_stat = EX_FATAL;
    goto cleanup;
  }

  if (ex_get_set(exoid, EX_SIDE_SET, side_set_id, side_set_elem_list, side_set_side_list) == -1) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get side set %" PRId64 " in file id %d",
             side_set_id, exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    err_stat = EX_FATAL;
    goto cleanup;
  }

  /* Allocate space for the ss element index array */
  if (!(ss_elem_ndx = malloc(tot_num_ss_elem * int_size))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for side set elem sort "
                                     "array for file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    err_stat = EX_FATAL;
    goto cleanup;
  }

  /* Sort side set element list into index array  - non-destructive */
  if (int_size == sizeof(int64_t)) {
    /* Sort side set element list into index array  - non-destructive */
    int64_t *elems = (int64_t *)ss_elem_ndx;
    for (i = 0; i < tot_num_ss_elem; i++) {
      elems[i] = i; /* init index array to current position */
    }
    ex_iqsort64(side_set_elem_list, ss_elem_ndx, tot_num_ss_elem);
  }
  else {
    /* Sort side set element list into index array  - non-destructive */
    int *elems = (int *)ss_elem_ndx;
    for (i = 0; i < tot_num_ss_elem; i++) {
      elems[i] = i; /* init index array to current position */
    }
    ex_iqsort(side_set_elem_list, ss_elem_ndx, tot_num_ss_elem);
  }

  /* Allocate space for the element block ids */
  if (!(elem_blk_ids = malloc(num_elem_blks * ids_size))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to allocate space for element block ids for file id %d", exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    err_stat = EX_FATAL;
    goto cleanup;
  }

  if (ex_get_ids(exoid, EX_ELEM_BLOCK, elem_blk_ids) == -1) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get element block ids in file id %d", exoid);
    ex_err("ex_get_side_set_node_list", errmsg, EX_MSG);
    err_stat = EX_FATAL;
    goto cleanup;
  }

  /* Allocate space for the element block params */
  if (!(elem_blk_parms = malloc(num_elem_blks * sizeof(struct elem_blk_parm)))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for element block params "
                                     "for file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    err_stat = EX_FATAL;
    goto cleanup;
  }

  elem_ctr = 0;
  for (i = 0; i < num_elem_blks; i++) {
    ex_entity_id id;
    if (ids_size == sizeof(int64_t)) {
      id = ((int64_t *)elem_blk_ids)[i];
    }
    else {
      id = ((int *)elem_blk_ids)[i];
    }

    err_stat = ex_int_get_block_param(exoid, id, ndim, &elem_blk_parms[i]);
    if (err_stat != EX_NOERR) {
      goto cleanup;
    }

    elem_ctr += elem_blk_parms[i].num_elem_in_blk;
    elem_blk_parms[i].elem_ctr = elem_ctr; /* save elem number max */
  }

  /* Allocate space for the ss element to element block parameter index array */
  if (!(ss_parm_ndx = malloc(tot_num_ss_elem * int_size))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for side set elem parms "
                                     "index for file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);
    err_stat = EX_FATAL;
    goto cleanup;
  }

  /* Allocate space for the ss element to node list index array */
  if (!(ss_elem_node_ndx = malloc(tot_num_ss_elem * int_size))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for side set elem to node "
                                     "index for file id %d",
             exoid);
    ex_err("ex_get_side_set_node_list", errmsg, exerrval);

    err_stat = EX_FATAL;
    goto cleanup;
  }

  /* Build side set element to node list index and side set element
     parameter index.
  */
  node_ctr = 0;
  for (i = 0; i < tot_num_ss_elem; i++) {
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      elem = ((int64_t *)side_set_elem_list)[i];
      side = ((int64_t *)side_set_side_list)[i];
    }
    else {
      elem = ((int *)side_set_elem_list)[i];
      side = ((int *)side_set_side_list)[i];
    }

    for (j = 0; j < num_elem_blks; j++) {
      if (elem_blk_parms[j].elem_type_val != EX_EL_NULL_ELEMENT) {
        if (elem <= elem_blk_parms[j].elem_ctr) {
          break;
        }
      }
    }

    if (j >= num_elem_blks) {
      exerrval = EX_BADPARAM;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: Invalid element number %" PRId64 " found in side set %" PRId64 " in file %d",
               elem, side_set_id, exoid);
      ex_err("ex_get_side_set_node_list", errmsg, EX_MSG);
      err_stat = EX_FATAL;
      goto cleanup;
    }

    if (int_size == sizeof(int64_t)) {
      ((int64_t *)ss_parm_ndx)[i]      = j;        /* assign parameter block index */
      ((int64_t *)ss_elem_node_ndx)[i] = node_ctr; /* assign node list index */
    }
    else {
      ((int *)ss_parm_ndx)[i]      = j;        /* assign parameter block index */
      ((int *)ss_elem_node_ndx)[i] = node_ctr; /* assign node list index */
    }

    /* Update node_ctr (which points to next node in chain */
    node_ctr += elem_blk_parms[j].num_nodes_per_side[side - 1];
  }

  /* All setup, ready to go ... */

  elem_ctr = 0;

  for (j = 0; j < tot_num_ss_elem; j++) {
    int64_t elem_ndx;
    size_t  parm_ndx;
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      elem_ndx = ((int64_t *)ss_elem_ndx)[j];
      elem     = ((int64_t *)side_set_elem_list)[elem_ndx];
      side     = ((int64_t *)side_set_side_list)[elem_ndx];
      parm_ndx = ((int64_t *)ss_parm_ndx)[elem_ndx];
    }
    else {
      elem_ndx = ((int *)ss_elem_ndx)[j];
      elem     = ((int *)side_set_elem_list)[elem_ndx];
      side     = ((int *)side_set_side_list)[elem_ndx];
      parm_ndx = ((int *)ss_parm_ndx)[elem_ndx];
    }

    if (elem > elem_ctr) {
      /* release connectivity array space and get next one */
      if (elem_ctr > 0) {
        free(connect);
      }

      /* Allocate space for the connectivity array for new element block */
      if (!(connect = malloc(elem_blk_parms[parm_ndx].num_elem_in_blk *
                             elem_blk_parms[parm_ndx].num_nodes_per_elem * int_size))) {
        exerrval = EX_MEMFAIL;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for connectivity "
                                         "array for file id %d",
                 exoid);
        ex_err("ex_get_side_set_node_list", errmsg, exerrval);
        err_stat = EX_FATAL;
        goto cleanup;
      }

      /* get connectivity array */
      if (ex_get_conn(exoid, EX_ELEM_BLOCK, elem_blk_parms[parm_ndx].elem_blk_id, connect, NULL,
                      NULL) == -1) {
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to allocate space for connectivity "
                                         "array for file id %d",
                 exoid);
        ex_err("ex_get_side_set_node_list", errmsg, exerrval);
        err_stat = EX_FATAL;
        goto cleanup;
      }
      elem_ctr = elem_blk_parms[parm_ndx].elem_ctr;
    }

    if (connect == NULL) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: internal error -- connect pointer is NULL for file id %d", exoid);
      ex_err("ex_get_side_set_node_list", errmsg, exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }

    /*  For each side in side set, use the appropriate lookup table to
        determine the nodes from the connect array. */

    elem_num = elem - 1; /* element number 0-based*/
    /* calculate the relative element number position in it's block*/

    elem_num_pos =
        elem_num - (elem_blk_parms[parm_ndx].elem_ctr - elem_blk_parms[parm_ndx].num_elem_in_blk);

    /* calculate the beginning of the node list for this element by
       using the ss_elem_node_ndx index into the side_sets_node_index
       and adding the element number position * number of nodes per elem */

    num_nodes_per_elem = elem_blk_parms[parm_ndx].num_nodes_per_elem;
    connect_offset     = num_nodes_per_elem * elem_num_pos;
    side_num           = side - 1;

    if (int_size == sizeof(int64_t)) {
      node_pos = ((int64_t *)ss_elem_node_ndx)[elem_ndx];
    }
    else {
      node_pos = ((int *)ss_elem_node_ndx)[elem_ndx];
    }

    switch (elem_blk_parms[parm_ndx].elem_type_val) {
    case EX_EL_CIRCLE:
    case EX_EL_SPHERE: { /* Note: no side-node lookup table is used for this
                            simple case */
      get_nodes(exoid, side_set_node_list, node_pos, connect, connect_offset);
      set_count(exoid, side_set_node_cnt_list, elem_ndx, 1); /* 1 node object */
      break;
    }
    case EX_EL_TRUSS:
    case EX_EL_BEAM: { /* Note: no side-node lookup table is used for this
                          simple case */
      for (i = 0; i < num_nodes_per_elem; i++) {
        get_nodes(exoid, side_set_node_list, node_pos + i, connect, connect_offset + i);
      }
      set_count(exoid, side_set_node_cnt_list, elem_ndx, num_nodes_per_elem);
      break;
    }
    case EX_EL_TRIANGLE: {
      if (ndim == 2) { /* 2d TRIs */
        if (check_valid_side(side_num, 3, "triangle", exoid) != EX_NOERR) {
          goto cleanup;
        }

        get_nodes(exoid, side_set_node_list, node_pos, connect,
                  connect_offset + tri_table[side_num][0] - 1);
        get_nodes(exoid, side_set_node_list, node_pos + 1, connect,
                  connect_offset + tri_table[side_num][1] - 1);
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 2); /* 2 node object */
        if (num_nodes_per_elem > 3)                            /* 6-node TRI  */
        {
          get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                    connect_offset + tri_table[side_num][2] - 1);
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
        }
      }
      else if (ndim == 3) { /* 3d TRIs */
        if (check_valid_side(side_num, 5, "triangle", exoid) != EX_NOERR) {
          goto cleanup;
        }

        get_nodes(exoid, side_set_node_list, node_pos, connect,
                  connect_offset + tri3_table[side_num][0] - 1);
        get_nodes(exoid, side_set_node_list, node_pos + 1, connect,
                  connect_offset + tri3_table[side_num][1] - 1);
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 2); /* 2 node object */
        if (side_num + 1 <= 2)                                 /* 3, 4, 6, 7-node face */
        {
          if (num_nodes_per_elem == 3) /* 3-node face */
          {
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
            get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                      connect_offset + tri3_table[side_num][2] - 1);
          }
          else if (num_nodes_per_elem == 4) /* 4-node face */
          {
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 4); /* 4 node object */
            get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                      connect_offset + tri3_table[side_num][2] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                      connect_offset + 4 - 1); /* Center node of 4-noded face */
          }
          else if (num_nodes_per_elem == 6) /* 6-node face */
          {
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 6); /* 6 node object */
            get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                      connect_offset + tri3_table[side_num][2] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 3, connect,
                      connect_offset + tri3_table[side_num][3] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 4, connect,
                      connect_offset + tri3_table[side_num][4] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 5, connect,
                      connect_offset + tri3_table[side_num][5] - 1);
          }
          else if (num_nodes_per_elem == 7) /* 7-node face */
          {
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 7); /* 7 node object */
            get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                      connect_offset + tri3_table[side_num][2] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 3, connect,
                      connect_offset + tri3_table[side_num][3] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 4, connect,
                      connect_offset + tri3_table[side_num][4] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 5, connect,
                      connect_offset + tri3_table[side_num][5] - 1);
            get_nodes(exoid, side_set_node_list, node_pos + 6, connect,
                      connect_offset + tri3_table[side_num][6] - 1);
          }
          else {
            snprintf(errmsg, MAX_ERR_LENGTH,
                     "ERROR: %d is an unsupported number of nodes for the triangle element type",
                     (int)num_nodes_per_elem);
            ex_err("ex_get_side_set_node_list", errmsg, exerrval);
            err_stat = EX_FATAL;
            goto cleanup;
          }
        }
        else /* 2- or 3-node edge */
        {
          if (num_nodes_per_elem > 3) /* 3-node edge */
          {
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
            get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                      connect_offset + tri3_table[side_num][2] - 1);
          }
        }
      }
      break;
    }
    case EX_EL_QUAD: {
      if (check_valid_side(side_num, 4, "quad", exoid) != EX_NOERR) {
        goto cleanup;
      }

      get_nodes(exoid, side_set_node_list, node_pos + 0, connect,
                connect_offset + quad_table[side_num][0] - 1);
      get_nodes(exoid, side_set_node_list, node_pos + 1, connect,
                connect_offset + quad_table[side_num][1] - 1);
      set_count(exoid, side_set_node_cnt_list, elem_ndx, 2); /* 2 node object */
      if (num_nodes_per_elem > 5) {
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
        get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                  connect_offset + quad_table[side_num][2] - 1);
      }
      break;
    }
    case EX_EL_SHELL: {
      if (check_valid_side(side_num, 6, "shell", exoid) != EX_NOERR) {
        goto cleanup;
      }

      get_nodes(exoid, side_set_node_list, node_pos + 0, connect,
                connect_offset + shell_table[side_num][0] - 1);
      get_nodes(exoid, side_set_node_list, node_pos + 1, connect,
                connect_offset + shell_table[side_num][1] - 1);
      set_count(exoid, side_set_node_cnt_list, elem_ndx, 2);     /* 2 node object */
      if (num_nodes_per_elem > 2) {                              /*** KLUGE for 2D shells ***/
        if (side_num + 1 <= 2) {                                 /* 4-node face */
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 4); /* 4 node object */
          get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                    connect_offset + shell_table[side_num][2] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 3, connect,
                    connect_offset + shell_table[side_num][3] - 1);
        }
      }
      if (num_nodes_per_elem == 8) {
        if (side_num + 1 <= 2) {                                 /* 8-node face */
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 8); /* 8 node object */
          get_nodes(exoid, side_set_node_list, node_pos + 4, connect,
                    connect_offset + shell_table[side_num][4] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 5, connect,
                    connect_offset + shell_table[side_num][5] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 6, connect,
                    connect_offset + shell_table[side_num][6] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 7, connect,
                    connect_offset + shell_table[side_num][7] - 1);
        }
        else {
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node edge */
          get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                    connect_offset + shell_table[side_num][2] - 1);
        }
      }
      if (num_nodes_per_elem == 9) {
        if (side_num + 1 <= 2) {                                 /* 9-node face */
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 9); /* 9 node object */
          get_nodes(exoid, side_set_node_list, node_pos + 4, connect,
                    connect_offset + shell_table[side_num][4] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 5, connect,
                    connect_offset + shell_table[side_num][5] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 6, connect,
                    connect_offset + shell_table[side_num][6] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 7, connect,
                    connect_offset + shell_table[side_num][7] - 1);
          get_nodes(exoid, side_set_node_list, node_pos + 8, connect,
                    connect_offset + shell_table[side_num][8] - 1);
        }
        else {
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node edge */
          get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                    connect_offset + shell_table[side_num][2] - 1);
        }
      }
      break;
    }
    case EX_EL_TETRA: {
      if (check_valid_side(side_num, 4, "tetra", exoid) != EX_NOERR) {
        goto cleanup;
      }

      get_nodes(exoid, side_set_node_list, node_pos + 0, connect,
                connect_offset + tetra_table[side_num][0] - 1);
      get_nodes(exoid, side_set_node_list, node_pos + 1, connect,
                connect_offset + tetra_table[side_num][1] - 1);
      get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                connect_offset + tetra_table[side_num][2] - 1);
      set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
      if (num_nodes_per_elem == 8) {
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 4); /* 4 node object */
        get_nodes(exoid, side_set_node_list, node_pos + 3, connect,
                  connect_offset + tetra_table[side_num][3] - 1);
      }
      else if (num_nodes_per_elem > 8) {
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 6); /* 6 node object */
        get_nodes(exoid, side_set_node_list, node_pos + 3, connect,
                  connect_offset + tetra_table[side_num][3] - 1);
        get_nodes(exoid, side_set_node_list, node_pos + 4, connect,
                  connect_offset + tetra_table[side_num][4] - 1);
        get_nodes(exoid, side_set_node_list, node_pos + 5, connect,
                  connect_offset + tetra_table[side_num][5] - 1);
      }
      break;
    }
    case EX_EL_WEDGE: {
      int node_off = 0;
      if (check_valid_side(side_num, 5, "wedge", exoid) != EX_NOERR) {
        goto cleanup;
      }

      if (num_nodes_per_elem == 6 || num_nodes_per_elem == 7) {
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge6_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge6_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge6_table[side_num][node_off++] - 1);

        if (side_num == 3 || side_num == 4) {
          /* This is one of the triangular faces */
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node side */
          assert(node_off == 3);
        }
        else {
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge6_table[side_num][node_off++] - 1);
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 4); /* 4 node side */
          assert(node_off == 4);
        }
      }

      else if (num_nodes_per_elem == 15 || num_nodes_per_elem == 16) {
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge15_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge15_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge15_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge15_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge15_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge15_table[side_num][node_off++] - 1);

        if (side_num == 3 || side_num == 4) {
          /* This is one of the triangular faces */
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 6); /* 6 node side */
          assert(node_off == 6);
        }
        else {
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge15_table[side_num][node_off++] - 1);
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge15_table[side_num][node_off++] - 1);
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 8); /* 8 node side */
          assert(node_off == 8);
        }
      }
      else if (num_nodes_per_elem == 20) {
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge20_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge20_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge20_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge20_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge20_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge20_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge20_table[side_num][node_off++] - 1);

        if (side_num == 3 || side_num == 4) {
          /* This is one of the triangular faces */
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 7); /* 7 node side */
          assert(node_off == 7);
        }
        else {
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge20_table[side_num][node_off++] - 1);
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge20_table[side_num][node_off++] - 1);
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 9); /* 9 node side */
          assert(node_off == 9);
        }
      }
      else if (num_nodes_per_elem == 21) {
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge21_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge21_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge21_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge21_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge21_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge21_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge21_table[side_num][node_off++] - 1);

        if (side_num == 3 || side_num == 4) {
          /* This is one of the triangular faces */
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 7); /* 7 node side */
        }
        else {
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge21_table[side_num][node_off++] - 1);
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge21_table[side_num][node_off++] - 1);
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 9); /* 9 node side */
        }
      }
      else if (num_nodes_per_elem == 18) {
        /* Wedge 18 - 9-node quad faces (0,1,2) and 6-node tri faces (3,4) */
        /* All faces (quad or tri) have at least 6 nodes */
        /* This gets nodes 1-6 */
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge18_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge18_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge18_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge18_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge18_table[side_num][node_off++] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + wedge18_table[side_num][node_off++] - 1);

        if (side_num == 3 || side_num == 4) {
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 6); /* 6 node side */
          assert(node_off == 6);
        }
        else {
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge18_table[side_num][node_off++] - 1);
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge18_table[side_num][node_off++] - 1);
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + wedge18_table[side_num][node_off++] - 1);
          set_count(exoid, side_set_node_cnt_list, elem_ndx, 9); /* 9 node side */
          assert(node_off == 9);
        }
      }
      break;
    }
    case EX_EL_PYRAMID: {
      /*
       * node count:  5 -- 4-node quad, 3-node tri
       *             13    8            6
       *             14    9            6
       *             18    9            7
       *             19    9            7  + volume center node.
       */

      if (check_valid_side(side_num, 5, "pyramid", exoid) != EX_NOERR) {
        goto cleanup;
      }

      get_nodes(exoid, side_set_node_list, node_pos++, connect,
                connect_offset + pyramid_table[side_num][0] - 1);
      get_nodes(exoid, side_set_node_list, node_pos++, connect,
                connect_offset + pyramid_table[side_num][1] - 1);
      get_nodes(exoid, side_set_node_list, node_pos++, connect,
                connect_offset + pyramid_table[side_num][2] - 1);

      if (pyramid_table[side_num][3] == 0) {                   /* degenerate side? */
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node side */
      }
      else {
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + pyramid_table[side_num][3] - 1);
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 4); /* 4 node side */
      }

      if (num_nodes_per_elem > 5) {
        /* This gets the mid-edge nodes for three edges */
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + pyramid_table[side_num][4] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + pyramid_table[side_num][5] - 1);
        get_nodes(exoid, side_set_node_list, node_pos++, connect,
                  connect_offset + pyramid_table[side_num][6] - 1);

        if (side_num == 4) {
          int face_node_count = num_nodes_per_elem >= 14 ? 9 : 8;
          set_count(exoid, side_set_node_cnt_list, elem_ndx, face_node_count);

          /* Get the last mid-edge node if this is quad face topology */
          get_nodes(exoid, side_set_node_list, node_pos++, connect,
                    connect_offset + pyramid_table[side_num][7] - 1);

          if (num_nodes_per_elem >= 14) {
            /* Get the mid-face node for the quad */
            get_nodes(exoid, side_set_node_list, node_pos++, connect,
                      connect_offset + pyramid_table[side_num][8] - 1);
          }
        }
        else {
          /* Triangular faces... */
          int face_node_count = num_nodes_per_elem >= 18 ? 7 : 6;
          set_count(exoid, side_set_node_cnt_list, elem_ndx, face_node_count);

          if (num_nodes_per_elem >= 18) {
            /* Get the mid-face node for the tri */
            get_nodes(exoid, side_set_node_list, node_pos++, connect,
                      connect_offset + pyramid_table[side_num][8] - 1);
          }
        }
      }
      break;
    }
    case EX_EL_HEX: {
      if (check_valid_side(side_num, 6, "hex", exoid) != EX_NOERR) {
        goto cleanup;
      }

      get_nodes(exoid, side_set_node_list, node_pos + 0, connect,
                connect_offset + hex_table[side_num][0] - 1);
      get_nodes(exoid, side_set_node_list, node_pos + 1, connect,
                connect_offset + hex_table[side_num][1] - 1);
      get_nodes(exoid, side_set_node_list, node_pos + 2, connect,
                connect_offset + hex_table[side_num][2] - 1);
      get_nodes(exoid, side_set_node_list, node_pos + 3, connect,
                connect_offset + hex_table[side_num][3] - 1);
      set_count(exoid, side_set_node_cnt_list, elem_ndx, 4); /* 4 node object */
      if (num_nodes_per_elem > 12)                           /* more nodes than HEXSHELL */
      {
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 8); /* 8 node object */
        get_nodes(exoid, side_set_node_list, node_pos + 4, connect,
                  connect_offset + hex_table[side_num][4] - 1);
        get_nodes(exoid, side_set_node_list, node_pos + 5, connect,
                  connect_offset + hex_table[side_num][5] - 1);
        get_nodes(exoid, side_set_node_list, node_pos + 6, connect,
                  connect_offset + hex_table[side_num][6] - 1);
        get_nodes(exoid, side_set_node_list, node_pos + 7, connect,
                  connect_offset + hex_table[side_num][7] - 1);
      }
      if (num_nodes_per_elem == 27) /* 27-node brick */
      {
        set_count(exoid, side_set_node_cnt_list, elem_ndx, 9); /* 9 node object */
        get_nodes(exoid, side_set_node_list, node_pos + 8, connect,
                  connect_offset + hex_table[side_num][8] - 1);
      }
      break;
    }
    default: {
      exerrval = EX_BADPARAM;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s is an unsupported element type",
               elem_blk_parms[parm_ndx].elem_type);
      ex_err("ex_get_side_set_node_list", errmsg, exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }
    }
  }

/* All done: release connectivity array space, element block ids array,
   element block parameters array, and side set element index array */
cleanup:
  free(connect);
  free(ss_parm_ndx);
  free(elem_blk_ids);
  free(elem_blk_parms);
  free(ss_elem_ndx);
  free(ss_elem_node_ndx);
  free(side_set_side_list);
  free(side_set_elem_list);

  return (err_stat);
}
예제 #12
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);

}
예제 #13
0
파일: exgnv.c 프로젝트: FlorianChevassu/VTK
int ex_get_nodal_var (int   exoid,
                      int   time_step,
                      int   nodal_var_index,
                      int   num_nodes, 
                      void *nodal_var_vals)
{
  int varid;
  int status;
  size_t 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 ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
      exerrval = status;
      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 ((status = nc_inq_varid(exoid, VAR_NOD_VAR_NEW(nodal_var_index), &varid)) != NC_NOERR) {
      exerrval = status;
      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 (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, varid, start, count, nodal_var_vals);
  } else {
    status = nc_get_vara_double(exoid, varid, start, count, nodal_var_vals);
  }

  if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to get nodal variables in file id %d",
              exoid);
      ex_err("ex_get_nodal_var",errmsg,exerrval);
      return (EX_FATAL);
    }
  return (EX_NOERR);
}
예제 #14
0
int ex_get_name (int   exoid,
		 ex_entity_type obj_type,
		 ex_entity_id   entity_id, 
		 char *name)
{
  int status;
  int varid, ent_ndx;
  char errmsg[MAX_ERR_LENGTH];
  char *vobj = NULL;
  const char *routine = "ex_get_name";
   
  exerrval = 0;

  switch(obj_type) {
  case EX_ELEM_BLOCK:
    vobj = VAR_NAME_EL_BLK;
    break;
  case EX_EDGE_BLOCK:
    vobj = VAR_NAME_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    vobj = VAR_NAME_FA_BLK;
    break;
  case EX_NODE_SET:
    vobj = VAR_NAME_NS;
    break;
  case EX_SIDE_SET:
    vobj = VAR_NAME_SS;
    break;
  case EX_EDGE_SET:
    vobj = VAR_NAME_ES;
    break;
  case EX_FACE_SET:
    vobj = VAR_NAME_FS;
    break;
  case EX_ELEM_SET:
    vobj = VAR_NAME_ELS;
    break;
  case EX_NODE_MAP:
    vobj = VAR_NAME_NM;
    break;
  case EX_EDGE_MAP:
    vobj = VAR_NAME_EDM;
    break;
  case EX_FACE_MAP:
    vobj = VAR_NAME_FAM;
    break;
  case EX_ELEM_MAP:
    vobj = VAR_NAME_EM;
    break;
  default:
    /* invalid variable type */
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid type specified in file id %d", exoid);
    ex_err(routine,errmsg,exerrval);
    return(EX_FATAL);
  }
   
  if ((status = nc_inq_varid(exoid, vobj, &varid)) == NC_NOERR) {
    /* 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...
     */
    ent_ndx = ex_id_lkup(exoid, obj_type, entity_id);
    if (ent_ndx < 0) ent_ndx = -ent_ndx;
    
    /* read the name */
    {
      int db_name_size = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH);
      int api_name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH);
      int name_size = db_name_size < api_name_size ? db_name_size : api_name_size;

      status = ex_get_name_internal(exoid, varid, ent_ndx-1, name, name_size, obj_type, routine);
      if (status != NC_NOERR) {
	return (EX_FATAL);
      }
    }
  } else {
    /* Name variable does not exist on the database; probably since this is an
     * older version of the database.  Return an empty array...
     */
    name[0] = '\0';
  }
  return (EX_NOERR);
}
예제 #15
0
static int define_truth_table(ex_entity_type obj_type, int exoid, int num_ent, int num_var,
                              int *var_tab, int *status_tab, void_int *ids, const char *label)
{
  char errmsg[MAX_ERR_LENGTH];
  int  k = 0;
  int  i, j;
  int  time_dim;
  int  dims[2];
  int  varid;
  int  status;

  if ((status = nc_inq_dimid(exoid, DIM_TIME, &time_dim)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate time dimension in file id %d", exoid);
    ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
    return -1;
  }

  if (var_tab == NULL) {
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s variable truth table is NULL in file id %d", label,
             exoid);
    ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
    return -1;
  }

  for (i = 0; i < num_ent; i++) {
    int64_t id;
    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      id = ((int64_t *)ids)[i];
    }
    else {
      id = ((int *)ids)[i];
    }

    for (j = 1; j <= num_var; j++) {

      /* check if variables are to be put out for this block */
      if (var_tab[k] != 0) {
        if (status_tab[i] != 0) { /* only define variable if active */
          dims[0] = time_dim;

          /* Determine number of entities in entity */
          /* Need way to make this more generic... */
          status = nc_inq_dimid(exoid, ex_dim_num_entries_in_object(obj_type, i + 1), &dims[1]);
          if (status != NC_NOERR) {
            exerrval = status;
            snprintf(errmsg, MAX_ERR_LENGTH,
                     "ERROR: failed to locate number of entities in %s %" PRId64 " in file id %d",
                     label, id, exoid);
            ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
            return status;
          }

          /* define netCDF variable to store variable values;
           * the j index cycles from 1 through the number of variables so
           * that the index of the EXODUS variable (which is part of
           * the name of the netCDF variable) will begin at 1 instead of 0
           */
          status = nc_def_var(exoid, ex_name_var_of_object(obj_type, j, i + 1), nc_flt_code(exoid),
                              2, dims, &varid);
          if (status != NC_NOERR) {
            if (status != NC_ENAMEINUSE) {
              exerrval = status;
              snprintf(errmsg, MAX_ERR_LENGTH,
                       "ERROR: failed to define %s variable for %s %" PRId64 " in file id %d",
                       label, label, id, exoid);
              ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
              return status;
            }
          }
          ex_compress_variable(exoid, varid, 2);
        }
      }    /* if */
      k++; /* increment truth table pointer */
    }      /* for j */
  }        /* for i */
  return NC_NOERR;
}
예제 #16
0
int ex_put_prop (int   exoid,
                 ex_entity_type obj_type,
                 ex_entity_id   obj_id,
                 const char *prop_name,
                 ex_entity_id   value)
{
  int status;
  int oldfill = 0;
  int temp;
  int found = FALSE;
  int num_props, i, dimid, propid, dims[1];
  int int_type;
  size_t start[1]; 
  size_t prop_name_len, name_length;
  char name[MAX_VAR_NAME_LENGTH+1];
  char tmpstr[MAX_STR_LENGTH+1];
  char dim_name[MAX_VAR_NAME_LENGTH+1];
  long long vals[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);

  if (num_props > 1) {  /* any properties other than the default 1? */

    for (i=1; i<=num_props; i++) {
      switch (obj_type) {
      case EX_ELEM_BLOCK:
	strcpy (name, VAR_EB_PROP(i));
	break;
      case EX_EDGE_BLOCK:
	strcpy (name, VAR_ED_PROP(i));
	break;
      case EX_FACE_BLOCK:
	strcpy (name, VAR_FA_PROP(i));
	break;
      case EX_NODE_SET:
	strcpy (name, VAR_NS_PROP(i));
	break;
      case EX_EDGE_SET:
	strcpy (name, VAR_ES_PROP(i));
	break;
      case EX_FACE_SET:
	strcpy (name, VAR_FS_PROP(i));
	break;
      case EX_ELEM_SET:
	strcpy (name, VAR_ELS_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_FACE_MAP:
	strcpy (name, VAR_FAM_PROP(i));
	break;
      case EX_EDGE_MAP:
	strcpy (name, VAR_EDM_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",errmsg,exerrval);
	return(EX_FATAL);
      }

      if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get property array id in file id %d",
		exoid);
	ex_err("ex_put_prop",errmsg,exerrval);
	return (EX_FATAL);
      }

      /*   compare stored attribute name with passed property name   */
      memset(tmpstr, 0, MAX_STR_LENGTH+1);
      if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get property name in file id %d", exoid);
	ex_err("ex_put_prop",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) {

    name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH)+1;

    /* put netcdf file into define mode  */
    if ((status = nc_redef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      return (EX_FATAL);
    }

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

    switch (obj_type){
    case EX_ELEM_BLOCK:
      strcpy (name, VAR_EB_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_EL_BLK);
      break;
    case EX_FACE_BLOCK:
      strcpy (name, VAR_FA_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_FA_BLK);
      break;
    case EX_EDGE_BLOCK:
      strcpy (name, VAR_ED_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_ED_BLK);
      break;
    case EX_NODE_SET:
      strcpy (name, VAR_NS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_NS);
      break;
    case EX_EDGE_SET:
      strcpy (name, VAR_ES_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_ES);
      break;
    case EX_FACE_SET:
      strcpy (name, VAR_FS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_FS);
      break;
    case EX_ELEM_SET:
      strcpy (name, VAR_ELS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_ELS);
      break;
    case EX_SIDE_SET:
      strcpy (name, VAR_SS_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_SS);
      break;
    case EX_ELEM_MAP:
      strcpy (name, VAR_EM_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_EM);
      break;
    case EX_FACE_MAP:
      strcpy (name, VAR_FAM_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_FAM);
      break;
    case EX_EDGE_MAP:
      strcpy (name, VAR_EDM_PROP(num_props+1));
      strcpy (dim_name, DIM_NUM_EDM);
      break;
    case EX_NODE_MAP:
      strcpy (name, VAR_NM_PROP(num_props+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",errmsg,exerrval);
      goto error_ret;        /* Exit define mode and return */
    }

    /*   inquire id of previously defined dimension (number of objects) */
    if ((status = nc_inq_dimid(exoid, dim_name, &dimid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate number of objects in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg, exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

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

    int_type = NC_INT;
    if (ex_int64_status(exoid) & EX_IDS_INT64_DB) {
      int_type = NC_INT64;
    }

    if ((status = nc_def_var(exoid, name, int_type, 1, dims, &propid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to create property array variable in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

    vals[0] = 0; /* fill value */
    /*   create attribute to cause variable to fill with zeros per routine spec */
    if ((status = nc_put_att_longlong(exoid, propid, _FillValue, int_type, 1, vals)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to create property name fill attribute in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

    /*   Check that the property name length is less than MAX_NAME_LENGTH */
    prop_name_len = strlen(prop_name)+1;
    if (prop_name_len > name_length) {
      fprintf(stderr,
	      "Warning: The property name '%s' is too long.\n\tIt will be truncated from %d to %d characters\n",
	      prop_name, (int)prop_name_len-1, (int)name_length-1);
      prop_name_len = name_length;
    }

    /*   store property name as attribute of property array variable */
    if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, 
				  prop_name_len, (void*)prop_name)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store property name %s in file id %d",
	      prop_name,exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      goto error_ret;  /* Exit define mode and return */
    }

    ex_update_max_name_length(exoid, prop_name_len-1);
    
    /* leave define mode  */
    if ((status = nc_enddef (exoid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to leave define mode in file id %d",
	      exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      return (EX_FATAL);
    }

    nc_set_fill(exoid, oldfill, &temp); /* default: nofill */
  }

  /* find index into property array using obj_id; put value in property */
  /* array at proper index; ex_id_lkup returns an index that is 1-based,*/
  /* but netcdf expects 0-based arrays so subtract 1                    */

  /* special case: property name ID - check for duplicate ID assignment */
  if (strcmp("ID",prop_name) == 0) {
    start[0] = ex_id_lkup (exoid, obj_type, value);
    if (exerrval != EX_LOOKUPFAIL)   /* found the id */
      {
	exerrval = EX_BADPARAM;
	sprintf(errmsg,
		"Warning: attempt to assign duplicate %s ID %"PRId64" in file id %d",
		ex_name_of_object(obj_type), value, exoid);
	ex_err("ex_put_prop",errmsg,exerrval);
	return (EX_WARN);
      }
  }

  start[0] = ex_id_lkup (exoid, obj_type, obj_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
	      "Warning: no properties allowed for NULL %s id %"PRId64" in file id %d",
	      ex_name_of_object(obj_type), obj_id,exoid);
      ex_err("ex_put_prop",errmsg,EX_MSG);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "Error: failed to find value %"PRId64" in %s property array in file id %d",
	      obj_id, ex_name_of_object(obj_type), exoid);
      ex_err("ex_put_prop",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

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

  /* value is of type 'ex_entity_id' which is a typedef to int64_t or long long */
  status = nc_put_var1_longlong(exoid, propid, start, (long long*)&value);

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store property value in file id %d",
	    exoid);
    ex_err("ex_put_prop",errmsg,exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  nc_set_fill(exoid, oldfill, &temp); /* default: nofill */

  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_prop",errmsg,exerrval);
  }
  return (EX_FATAL);
}
예제 #17
0
int ex_put_all_var_param_ext(int exoid, const ex_var_params *vp)
{
  int    in_define = 0;
  int    status;
  int    temp;
  int    time_dim, num_nod_dim, dimid;
  size_t num_elem_blk, num_edge_blk, num_face_blk;
  size_t num_nset, num_eset, num_fset, num_sset, num_elset;
  int    numelblkdim, numelvardim, numedvardim, numedblkdim, numfavardim, numfablkdim, numnsetdim,
      nsetvardim, numesetdim, esetvardim, numfsetdim, fsetvardim, numssetdim, ssetvardim,
      numelsetdim, elsetvardim;
  int i;

  int edblk_varid, fablk_varid, eblk_varid, nset_varid, eset_varid, fset_varid, sset_varid,
      elset_varid, varid;

  void_int *eblk_ids  = NULL;
  void_int *edblk_ids = NULL;
  void_int *fablk_ids = NULL;
  void_int *nset_ids  = NULL;
  void_int *eset_ids  = NULL;
  void_int *fset_ids  = NULL;
  void_int *sset_ids  = NULL;
  void_int *elset_ids = NULL;

  int *eblk_stat  = NULL;
  int *edblk_stat = NULL;
  int *fablk_stat = NULL;
  int *nset_stat  = NULL;
  int *eset_stat  = NULL;
  int *fset_stat  = NULL;
  int *sset_stat  = NULL;
  int *elset_stat = NULL;

  int         dims[3];
  char        errmsg[MAX_ERR_LENGTH];
  const char *routine = "ex_put_all_var_param_ext";

  ex_check_valid_file_id(exoid);

  exerrval = 0; /* clear error code */

  /* inquire previously defined dimensions  */

  if ((status = nc_inq_dimid(exoid, DIM_TIME, &time_dim)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate time dimension in file id %d", exoid);
    ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
    goto error_ret;
  }

  if ((status = nc_inq_dimid(exoid, DIM_NUM_NODES, &num_nod_dim)) != NC_NOERR) {
    num_nod_dim = -1; /* There is probably no nodes on this file */
  }

  /* Check this now so we can use it later without checking for errors */
  if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &temp)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get string length in file id %d", exoid);
    ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
    goto error_ret;
  }

  EX_GET_IDS_STATUS("edge block", vp->num_edge, DIM_NUM_ED_BLK, numedblkdim, num_edge_blk,
                    edblk_ids, EX_EDGE_BLOCK, VAR_STAT_ED_BLK, edblk_stat);
  EX_GET_IDS_STATUS("face block", vp->num_face, DIM_NUM_FA_BLK, numfablkdim, num_face_blk,
                    fablk_ids, EX_FACE_BLOCK, VAR_STAT_FA_BLK, fablk_stat);
  EX_GET_IDS_STATUS("element block", vp->num_elem, DIM_NUM_EL_BLK, numelblkdim, num_elem_blk,
                    eblk_ids, EX_ELEM_BLOCK, VAR_STAT_EL_BLK, eblk_stat);
  EX_GET_IDS_STATUS("node set", vp->num_nset, DIM_NUM_NS, numnsetdim, num_nset, nset_ids,
                    EX_NODE_SET, VAR_NS_STAT, nset_stat);
  EX_GET_IDS_STATUS("edge set", vp->num_eset, DIM_NUM_ES, numesetdim, num_eset, eset_ids,
                    EX_EDGE_SET, VAR_ES_STAT, eset_stat);
  EX_GET_IDS_STATUS("face set", vp->num_fset, DIM_NUM_FS, numfsetdim, num_fset, fset_ids,
                    EX_FACE_SET, VAR_FS_STAT, fset_stat);
  EX_GET_IDS_STATUS("side set", vp->num_sset, DIM_NUM_SS, numssetdim, num_sset, sset_ids,
                    EX_SIDE_SET, VAR_SS_STAT, sset_stat);
  EX_GET_IDS_STATUS("element set", vp->num_elset, DIM_NUM_ELS, numelsetdim, num_elset, elset_ids,
                    EX_ELEM_SET, VAR_ELS_STAT, elset_stat);

  /* put file into define mode  */
  if ((status = nc_redef(exoid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", exoid);
    ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
    goto error_ret;
  }
  in_define = 1;

  /* define dimensions and variables */
  if (vp->num_glob > 0) {
    if (define_dimension(exoid, DIM_NUM_GLO_VAR, vp->num_glob, "global", &dimid) != NC_NOERR) {
      goto error_ret;
    }

    dims[0] = time_dim;
    dims[1] = dimid;
    if ((status = nc_def_var(exoid, VAR_GLO_VAR, nc_flt_code(exoid), 2, dims, &varid)) !=
        NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define global variables in file id %d",
               exoid);
      ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }
    ex_compress_variable(exoid, varid, 2);

    /* Now define global variable name variable */
    if (define_variable_name_variable(exoid, VAR_NAME_GLO_VAR, dimid, "global") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_node > 0) {
    /*
     * There are two ways to store the nodal variables. The old way *
     * was a blob (#times,#vars,#nodes), but that was exceeding the
     * netcdf maximum dataset size for large models. The new way is
     * to store #vars separate datasets each of size (#times,#nodes)
     *
     * We want this routine to be capable of storing both formats
     * based on some external flag.  Since the storage format of the
     * coordinates have also been changed, we key off of their
     * storage type to decide which method to use for nodal
     * variables. If the variable 'coord' is defined, then store old
     * way; otherwise store new.
     */
    if (define_dimension(exoid, DIM_NUM_NOD_VAR, vp->num_node, "nodal", &dimid) != NC_NOERR) {
      goto error_ret;
    }

    if (num_nod_dim > 0) {
      if (ex_large_model(exoid) == 0) { /* Old way */
        dims[0] = time_dim;
        dims[1] = dimid;
        dims[2] = num_nod_dim;
        if ((status = nc_def_var(exoid, VAR_NOD_VAR, nc_flt_code(exoid), 3, dims, &varid)) !=
            NC_NOERR) {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define nodal variables in file id %d",
                   exoid);
          ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
          goto error_ret; /* exit define mode and return */
        }
      }
      else { /* Store new way */
        for (i = 1; i <= vp->num_node; i++) {
          dims[0] = time_dim;
          dims[1] = num_nod_dim;
          if ((status = nc_def_var(exoid, VAR_NOD_VAR_NEW(i), nc_flt_code(exoid), 2, dims,
                                   &varid)) != NC_NOERR) {
            exerrval = status;
            snprintf(errmsg, MAX_ERR_LENGTH,
                     "ERROR: failed to define nodal variable %d in file id %d", i, exoid);
            ex_err("ex_put_var_param", errmsg, exerrval);
            goto error_ret; /* exit define mode and return */
          }
          ex_compress_variable(exoid, varid, 2);
        }
      }
    }

    /* Now define nodal variable name variable */
    if (define_variable_name_variable(exoid, VAR_NAME_NOD_VAR, dimid, "nodal") != NC_NOERR) {
      goto error_ret;
    }
  }

#define EX_DEFINE_VARS(TID, STNAME, TNAME, NUMVAR, DNAME, DID1, DID2, DVAL, VIDS, VNOV, VTV,       \
                       VSTATVAL, VTABVAL, VTABVAR)                                                 \
  if (NUMVAR > 0) {                                                                                \
    status = define_dimension(exoid, DNAME, NUMVAR, STNAME, &DID2);                                \
    if (status != NC_NOERR)                                                                        \
      goto error_ret;                                                                              \
                                                                                                   \
    /* Now define STNAME variable name variable */                                                 \
    if (define_variable_name_variable(exoid, VNOV, DID2, STNAME) != NC_NOERR)                      \
      goto error_ret;                                                                              \
                                                                                                   \
    if (define_truth_table(TID, exoid, DVAL, NUMVAR, VTABVAL, VSTATVAL, VIDS, TNAME) != NC_NOERR)  \
      goto error_ret;                                                                              \
                                                                                                   \
    free(VSTATVAL);                                                                                \
    VSTATVAL = NULL;                                                                               \
    free(VIDS);                                                                                    \
    VIDS = NULL;                                                                                   \
                                                                                                   \
    /* create a variable array in which to store the STNAME variable truth                         \
     * table                                                                                       \
     */                                                                                            \
                                                                                                   \
    dims[0] = DID1;                                                                                \
    dims[1] = DID2;                                                                                \
                                                                                                   \
    if ((status = nc_def_var(exoid, VTV, NC_INT, 2, dims, &VTABVAR)) != NC_NOERR) {                \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to define " STNAME " variable truth table in file id %d", exoid);    \
      ex_err("ex_put_all_var_param_ext", errmsg, exerrval);                                        \
      goto error_ret; /* exit define mode and return */                                            \
    }                                                                                              \
  }
  EX_DEFINE_VARS(EX_EDGE_BLOCK, "edge", "edge block", vp->num_edge, DIM_NUM_EDG_VAR, numedblkdim,
                 numedvardim, num_edge_blk, edblk_ids, VAR_NAME_EDG_VAR, VAR_EBLK_TAB, edblk_stat,
                 vp->edge_var_tab, edblk_varid);
  EX_DEFINE_VARS(EX_FACE_BLOCK, "face", "face block", vp->num_face, DIM_NUM_FAC_VAR, numfablkdim,
                 numfavardim, num_face_blk, fablk_ids, VAR_NAME_FAC_VAR, VAR_FBLK_TAB, fablk_stat,
                 vp->face_var_tab, fablk_varid);
  EX_DEFINE_VARS(EX_ELEM_BLOCK, "element", "element block", vp->num_elem, DIM_NUM_ELE_VAR,
                 numelblkdim, numelvardim, num_elem_blk, eblk_ids, VAR_NAME_ELE_VAR, VAR_ELEM_TAB,
                 eblk_stat, vp->elem_var_tab, eblk_varid);
  EX_DEFINE_VARS(EX_NODE_SET, "nodeset", "node set", vp->num_nset, DIM_NUM_NSET_VAR, numnsetdim,
                 nsetvardim, num_nset, nset_ids, VAR_NAME_NSET_VAR, VAR_NSET_TAB, nset_stat,
                 vp->nset_var_tab, nset_varid);
  EX_DEFINE_VARS(EX_EDGE_SET, "edgeset", "edge set", vp->num_eset, DIM_NUM_ESET_VAR, numesetdim,
                 esetvardim, num_eset, eset_ids, VAR_NAME_ESET_VAR, VAR_ESET_TAB, eset_stat,
                 vp->eset_var_tab, eset_varid);
  EX_DEFINE_VARS(EX_FACE_SET, "faceset", "face set", vp->num_fset, DIM_NUM_FSET_VAR, numfsetdim,
                 fsetvardim, num_fset, fset_ids, VAR_NAME_FSET_VAR, VAR_FSET_TAB, fset_stat,
                 vp->fset_var_tab, fset_varid);
  EX_DEFINE_VARS(EX_SIDE_SET, "sideset", "side set", vp->num_sset, DIM_NUM_SSET_VAR, numssetdim,
                 ssetvardim, num_sset, sset_ids, VAR_NAME_SSET_VAR, VAR_SSET_TAB, sset_stat,
                 vp->sset_var_tab, sset_varid);
  EX_DEFINE_VARS(EX_ELEM_SET, "elemset", "element set", vp->num_elset, DIM_NUM_ELSET_VAR,
                 numelsetdim, elsetvardim, num_elset, elset_ids, VAR_NAME_ELSET_VAR, VAR_ELSET_TAB,
                 elset_stat, vp->elset_var_tab, elset_varid);

  /* leave define mode  */

  in_define = 0;
  if ((status = nc_enddef(exoid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition in file id %d", exoid);
    ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
    goto error_ret;
  }

  /* write out the variable truth tables */
  if (vp->num_edge > 0) {
    if (put_truth_table(exoid, edblk_varid, vp->edge_var_tab, "edge") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_face > 0) {
    if (put_truth_table(exoid, fablk_varid, vp->face_var_tab, "face") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_elem > 0) {
    if (put_truth_table(exoid, eblk_varid, vp->elem_var_tab, "element") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_nset > 0) {
    if (put_truth_table(exoid, nset_varid, vp->nset_var_tab, "nodeset") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_eset > 0) {
    if (put_truth_table(exoid, eset_varid, vp->eset_var_tab, "edgeset") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_fset > 0) {
    if (put_truth_table(exoid, fset_varid, vp->fset_var_tab, "faceset") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_sset > 0) {
    if (put_truth_table(exoid, sset_varid, vp->sset_var_tab, "sideset") != NC_NOERR) {
      goto error_ret;
    }
  }

  if (vp->num_elset > 0) {
    if (put_truth_table(exoid, elset_varid, vp->elset_var_tab, "elemset") != NC_NOERR) {
      goto error_ret;
    }
  }

  return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  if (in_define == 1) {
    if (nc_enddef(exoid) != NC_NOERR) /* exit define mode */
    {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d",
               exoid);
      ex_err("ex_put_all_var_param_ext", errmsg, exerrval);
    }
  }
  free(eblk_ids);
  free(edblk_ids);
  free(fablk_ids);
  free(nset_ids);
  free(eset_ids);
  free(fset_ids);
  free(sset_ids);
  free(elset_ids);

  free(eblk_stat);
  free(edblk_stat);
  free(fablk_stat);
  free(nset_stat);
  free(eset_stat);
  free(fset_stat);
  free(sset_stat);
  free(elset_stat);
  return (EX_FATAL);
}
int ex_get_side_set_node_list(int exoid,
                              ex_entity_id side_set_id,
                              void_int *side_set_node_cnt_list,
                              void_int *side_set_node_list)
{
    size_t m;
    size_t i, j;
    int64_t elem, side;
    int64_t num_side_sets, num_elem_blks, num_df, ndim;
    int64_t tot_num_elem = 0, tot_num_ss_elem = 0, elem_num = 0;
    size_t connect_offset, side_num, node_pos;
    void_int *elem_blk_ids = NULL;
    void_int *connect = NULL;
    void_int *ss_elem_ndx = NULL;
    void_int *ss_elem_node_ndx = NULL;
    void_int *ss_parm_ndx = NULL;
    void_int *side_set_elem_list = NULL;
    void_int *side_set_side_list = NULL;
    size_t elem_ctr, node_ctr, elem_num_pos;
    size_t num_nodes_per_elem;
    int int_size, ids_size;

    int err_stat = EX_NOERR;
    int status;

    struct elem_blk_parm  *elem_blk_parms = NULL;

    /* side to node translation tables -
       These tables are used to look up the side number based on the
       first and second node in the side/face list. The side node order
       is found in the original Exodus document, SAND87-2997. The element
       node order is found in the ExodusII document, SAND92-2137. These
       tables were generated by following the right-hand rule for determining
       the outward normal.
    */
    /* triangle */
    static int tri_table[3][3] = {
        /*   1        2        3                                             side   */
        {1,2,4}, {2,3,5}, {3,1,6}                                       /* nodes  */
    };

    /* triangle 3d */
    static int tri3_table[5][7] = {
        /*       1                2                                          side   */
        {1,2,3,4,5,6,7}, {3,2,1,6,5,4,7},                               /* nodes  */
        /*       3              4              5                             side   */
        {1,2,4,0,0,0,0}, {2,3,5,0,0,0,0}, {3,1,6,0,0,0,0}               /* nodes  */
    };

    /* quad */
    static int quad_table[4][3] = {
        /*   1        2        3        4                                    side   */
        {1,2,5}, {2,3,6}, {3,4,7}, {4,1,8}                              /* nodes  */
    };

    /* shell */
    static int shell_table[6][8] = {
        /*        1                  2                                       side   */
        {1,2,3,4,5,6,7,8}, {1,4,3,2,8,7,6,5} ,                          /* nodes  */
        /*        3                  4                                       side   */
        {1,2,5,0,0,0,0,0}, {2,3,6,0,0,0,0,0} ,                          /* nodes  */
        /*        5                  6                                       side   */
        {3,4,7,0,0,0,0,0}, {4,1,8,0,0,0,0,0}                            /* nodes  */
    };

    /* tetra */
    static int tetra_table[4][6] = {
        /*      1              2               3               4            side   */
        {1,2,4,5,9,8}, {2,3,4,6,10,9}, {1,4,3,8,10,7}, {1,3,2,7,6,5}   /* nodes  */
    };

    /* wedge */
    static int wedge_table[5][8] = {
        /*        1                     2                     3              side   */
        {1,2,5,4,7,11,13,10}, {2,3,6,5,8,12,14,11}, {1,4,6,3,10,15,12,9},
        /*        4                  5                                       side   */
        {1,3,2,0,9,8,7,0}, {4,5,6,0,13,14,15,0}                         /* nodes  */
    };

    /* hex */
    static int hex_table[6][9] = {
        /*         1                        2                                side   */
        {1,2,6,5,9,14,17,13,26}, {2,3,7,6,10,15,18,14,25},              /* nodes  */
        /*         3                        4                                side   */
        {3,4,8,7,11,16,19,15,27}, {1,5,8,4,13,20,16,12,24},             /* nodes  */
        /*         5                        6                                side   */
        {1,4,3,2,12,11,10,9,22},  {5,6,7,8,17,18,19,20,23}              /* nodes  */
    };

    /* pyramid */
    static int pyramid_table[5][8] = {
        /*          1                   2                    3              side   */
        {1,2,5,0,6,11,10,0}, {2,3,5,0,7,12,11,0}, {3,4,5,0,8,13,12,0}, /* nodes  */
        /*          4                  5                                    side   */
        {1,5,4,0,10,13,9,0}, {1,4,3,2,9,8,7,6}                         /* nodes  */
    };


    char errmsg[MAX_ERR_LENGTH];

    exerrval = 0; /* clear error code */

    /* first check if any side sets are specified */
    /* inquire how many side sets have been stored */

    num_side_sets = ex_inquire_int(exoid, EX_INQ_SIDE_SETS);
    if (num_side_sets < 0) {
        sprintf(errmsg,
                "Error: failed to get number of side sets in file id %d",exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        return(EX_FATAL);
    }

    if (num_side_sets == 0) {
        sprintf(errmsg,
                "Warning: no side sets defined in file id %d",exoid);
        ex_err("ex_get_side_set_node_list",errmsg,EX_WARN);
        return(EX_WARN);
    }

    /* Lookup index of side set id in VAR_SS_IDS array */
    ex_id_lkup(exoid,EX_SIDE_SET,side_set_id);
    if (exerrval != 0)  {
        if (exerrval == EX_NULLENTITY) {
            sprintf(errmsg,
                    "Warning: side set %"PRId64" is NULL in file id %d",
                    side_set_id,exoid);
            ex_err("ex_get_side_set_node_list",errmsg,EX_NULLENTITY);
            return (EX_WARN);
        }
        else {

            sprintf(errmsg,
                    "Error: failed to locate side set %"PRId64" in VAR_SS_IDS array in file id %d",
                    side_set_id,exoid);
            ex_err("ex_get_side_set_node_list",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    num_elem_blks = ex_inquire_int(exoid, EX_INQ_ELEM_BLK);
    if (num_elem_blks < 0) {
        sprintf(errmsg,
                "Error: failed to get number of element blocks in file id %d",exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        return(EX_FATAL);
    }

    tot_num_elem = ex_inquire_int(exoid, EX_INQ_ELEM);
    if (tot_num_elem < 0) {
        sprintf(errmsg,
                "Error: failed to get total number of elements in file id %d",exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        return(EX_FATAL);
    }

    /* get the dimensionality of the coordinates;  this is necessary to
       distinguish between 2d TRIs and 3d TRIs */
    ndim = ex_inquire_int(exoid, EX_INQ_DIM);
    if (ndim < 0) {
        sprintf(errmsg,
                "Error: failed to get dimensionality in file id %d",exoid);
        ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
        return(EX_FATAL);
    }

    int_size = sizeof(int);
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
        int_size = sizeof(int64_t);
    }

    ids_size = sizeof(int);
    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
        ids_size = sizeof(int64_t);
    }

    /* First determine the  # of elements in the side set*/
    if (int_size == sizeof(int64_t)) {
        status = ex_get_set_param(exoid,EX_SIDE_SET, side_set_id,&tot_num_ss_elem,&num_df);
    } else {
        int tot, df;
        status = ex_get_set_param(exoid,EX_SIDE_SET, side_set_id,&tot,&df);
        tot_num_ss_elem = tot;
        num_df = df;
    }

    if (status != EX_NOERR) {
        sprintf(errmsg,
                "Error: failed to get number of elements in side set %"PRId64" in file id %d",
                side_set_id, exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        return(EX_FATAL);
    }

    /* Allocate space for the side set element list */
    if (!(side_set_elem_list=malloc(tot_num_ss_elem*int_size))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate space for side set element list for file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* Allocate space for the side set side list */
    if (!(side_set_side_list=malloc(tot_num_ss_elem*int_size))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate space for side set side list for file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        err_stat = EX_FATAL;
        goto cleanup;
    }

    if (ex_get_set(exoid, EX_SIDE_SET, side_set_id,
                   side_set_elem_list, side_set_side_list) == -1) {
        safe_free(side_set_elem_list);
        safe_free(side_set_side_list);
        sprintf(errmsg,
                "Error: failed to get side set %"PRId64" in file id %d",
                side_set_id, exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* Allocate space for the ss element index array */
    if (!(ss_elem_ndx= malloc(tot_num_ss_elem*int_size))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate space for side set elem sort array for file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        err_stat = EX_FATAL;
        goto cleanup;
    }

    /* Sort side set element list into index array  - non-destructive */
    if (int_size == sizeof(int64_t)) {
        /* Sort side set element list into index array  - non-destructive */
        int64_t *elems = (int64_t*)ss_elem_ndx;
        for (i=0; i<tot_num_ss_elem; i++) {
            elems[i] = i; /* init index array to current position */
        }
        ex_iqsort64(side_set_elem_list, ss_elem_ndx,tot_num_ss_elem);
    } else {
        /* Sort side set element list into index array  - non-destructive */
        int *elems = (int*)ss_elem_ndx;
        for (i=0; i<tot_num_ss_elem; i++) {
            elems[i] = i; /* init index array to current position */
        }
        ex_iqsort(side_set_elem_list, ss_elem_ndx,tot_num_ss_elem);
    }

    /* Allocate space for the element block ids */
    if (!(elem_blk_ids= malloc(num_elem_blks*ids_size))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate space for element block ids for file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        err_stat = EX_FATAL;
        goto cleanup;
    }

    if (ex_get_elem_blk_ids(exoid, elem_blk_ids) == -1) {
        sprintf(errmsg,
                "Error: failed to get element block ids in file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,EX_MSG);
        err_stat = EX_FATAL;
        goto cleanup;
    }

    /* Allocate space for the element block params */
    if (!(elem_blk_parms= malloc(num_elem_blks*sizeof(struct elem_blk_parm)))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate space for element block params for file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        err_stat = EX_FATAL;
        goto cleanup;
    }

    elem_ctr = 0;
    for (i=0; i<num_elem_blks; i++) {
        ex_block block;

        if (ids_size == sizeof(int64_t)) {
            block.id = ((int64_t*)elem_blk_ids)[i];
        } else {
            block.id = ((int*)elem_blk_ids)[i];
        }
        block.type = EX_ELEM_BLOCK;

        /* read in an element block parameter */
        if ((ex_get_block_param (exoid, &block)) == -1) {
            sprintf(errmsg,
                    "Error: failed to get element block %"PRId64" parameters in file id %d",
                    block.id, exoid);
            ex_err("ex_get_side_set_node_list",errmsg,EX_MSG);
            err_stat = EX_FATAL;
            goto cleanup;
        }

        elem_blk_parms[i].num_elem_in_blk = block.num_entry;
        elem_blk_parms[i].num_nodes_per_elem = block.num_nodes_per_entry;
        elem_blk_parms[i].num_attr = block.num_attribute;
        elem_blk_parms[i].elem_blk_id = block.id;

        for (m=0; m < strlen(block.topology); m++) {
            elem_blk_parms[i].elem_type[m] = toupper(block.topology[m]);
        }
        elem_blk_parms[i].elem_type[m] = '\0';

        if (strncmp(elem_blk_parms[i].elem_type,"CIRCLE",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_CIRCLE;
            /* set side set node stride */
            elem_blk_parms[i].num_nodes_per_side[0] = 1;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"SPHERE",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_SPHERE;
            /* set side set node stride */
            elem_blk_parms[i].num_nodes_per_side[0] = 1;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"QUAD",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_QUAD;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 4)
                elem_blk_parms[i].num_nodes_per_side[0] = 2;
            else if (elem_blk_parms[i].num_nodes_per_elem == 5)
                elem_blk_parms[i].num_nodes_per_side[0] = 2;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 3;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"TRIANGLE",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_TRIANGLE;
            /* set default side set node stride */
            if (ndim == 2)  /* 2d TRIs */
            {
                if (elem_blk_parms[i].num_nodes_per_elem == 3)
                    elem_blk_parms[i].num_nodes_per_side[0] = 2;
                else
                    elem_blk_parms[i].num_nodes_per_side[0] = 3;
            }
            else if (ndim == 3)  /* 3d TRIs */
            {
                if (elem_blk_parms[i].num_nodes_per_elem == 3)
                    elem_blk_parms[i].num_nodes_per_side[0] = 3;
                else
                    elem_blk_parms[i].num_nodes_per_side[0] = 6;
            }
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"SHELL",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_SHELL;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 2) /* KLUDGE for 2D Shells*/
                elem_blk_parms[i].num_nodes_per_side[0] = 2;
            else if (elem_blk_parms[i].num_nodes_per_elem == 4)
                elem_blk_parms[i].num_nodes_per_side[0] = 4;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 8;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"HEX",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_HEX;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 8)  /* 8-node bricks */
                elem_blk_parms[i].num_nodes_per_side[0] = 4;
            else if (elem_blk_parms[i].num_nodes_per_elem == 9)  /* 9-node bricks */
                elem_blk_parms[i].num_nodes_per_side[0] = 4;
            else if (elem_blk_parms[i].num_nodes_per_elem == 12)  /* HEXSHELLS */
                elem_blk_parms[i].num_nodes_per_side[0] = 4;
            else if (elem_blk_parms[i].num_nodes_per_elem == 27)  /* 27-node bricks */
                elem_blk_parms[i].num_nodes_per_side[0] = 9;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 8;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"TETRA",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_TETRA;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 4)
                elem_blk_parms[i].num_nodes_per_side[0] = 3;
            else if (elem_blk_parms[i].num_nodes_per_elem == 8)
                elem_blk_parms[i].num_nodes_per_side[0] = 4;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 6;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"WEDGE",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_WEDGE;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 6)
                elem_blk_parms[i].num_nodes_per_side[0] = 4;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 8;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"PYRAMID",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_PYRAMID;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 5)
                elem_blk_parms[i].num_nodes_per_side[0] = 4;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 8;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"BEAM",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_BEAM;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 2)
                elem_blk_parms[i].num_nodes_per_side[0] = 2;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 3;
        }
        else if ( (strncmp(elem_blk_parms[i].elem_type,"TRUSS",3) == 0) ||
                  (strncmp(elem_blk_parms[i].elem_type,"BAR",3) == 0) ||
                  (strncmp(elem_blk_parms[i].elem_type,"EDGE",3) == 0) )
        {
            elem_blk_parms[i].elem_type_val = EX_EL_TRUSS;
            /* determine side set node stride */
            if (elem_blk_parms[i].num_nodes_per_elem == 2)
                elem_blk_parms[i].num_nodes_per_side[0] = 2;
            else
                elem_blk_parms[i].num_nodes_per_side[0] = 3;
        }
        else if (strncmp(elem_blk_parms[i].elem_type,"NULL",3) == 0)
        {
            elem_blk_parms[i].elem_type_val = EX_EL_NULL_ELEMENT;
            elem_blk_parms[i].num_nodes_per_side[0] = 0;
            elem_blk_parms[i].num_elem_in_blk = 0;
        }
        else
        {   /* unsupported element type; no problem if no sides specified for
            this element block */
            elem_blk_parms[i].elem_type_val = EX_EL_UNK;
            elem_blk_parms[i].num_nodes_per_side[0] = 0;
        }
        elem_blk_parms[i].elem_blk_id = block.id;    /* save id */
        elem_ctr += elem_blk_parms[i].num_elem_in_blk;
        elem_blk_parms[i].elem_ctr = elem_ctr;      /* save elem number max */
    }


    /* Allocate space for the ss element to element block parameter index array */
    if (!(ss_parm_ndx=malloc(tot_num_ss_elem*int_size)))
    {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate space for side set elem parms index for file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);
        err_stat = EX_FATAL;
        goto cleanup;
    }


    /* Allocate space for the ss element to node list index array */
    if (!(ss_elem_node_ndx=malloc(tot_num_ss_elem*int_size)))
    {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate space for side set elem to node index for file id %d",
                exoid);
        ex_err("ex_get_side_set_node_list",errmsg,exerrval);

        err_stat = EX_FATAL;
        goto cleanup;
    }

    /* Build side set element to node list index and side set element
       parameter index.
    */
    node_ctr = 0;
    for (i=0; i<tot_num_ss_elem; i++) {
        if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
            elem = ((int64_t*)side_set_elem_list)[i];
            side = ((int64_t*)side_set_side_list)[i];
        } else {
            elem = ((int*)side_set_elem_list)[i];
            side = ((int*)side_set_side_list)[i];
        }

        for (j=0; j<num_elem_blks; j++) {
            if (elem_blk_parms[j].elem_type_val != EX_EL_NULL_ELEMENT)
                if (elem <= elem_blk_parms[j].elem_ctr)
                    break;
        }

        if (j >= num_elem_blks) {
            exerrval = EX_BADPARAM;
            sprintf(errmsg,
                    "Error: Invalid element number %"PRId64" found in side set %"PRId64" in file %d",
                    elem, side_set_id, exoid);
            ex_err("ex_get_side_set_node_list",errmsg,EX_MSG);
            err_stat = EX_FATAL;
            goto cleanup;
        }

        if (int_size == sizeof(int64_t)) {
            ((int64_t*)ss_parm_ndx)[i] = j; /* assign parameter block index */
            ((int64_t*)ss_elem_node_ndx)[i] = node_ctr;     /* assign node list index */
        } else {
            ((int*)ss_parm_ndx)[i] = j; /* assign parameter block index */
            ((int*)ss_elem_node_ndx)[i] = node_ctr;     /* assign node list index */
        }

        /* Update node_ctr (which points to next node in chain */

        /* WEDGEs with 3 node sides (side 4 or 5) are special cases */
        if (elem_blk_parms[j].elem_type_val == EX_EL_WEDGE &&
                (side == 4 || side == 5))
        {
            if (elem_blk_parms[j].num_nodes_per_elem == 6)
                node_ctr += 3;  /* 3 node side */
            else
                node_ctr += 6;  /* 6 node side */
        }
        /* PYRAMIDSs with 3 node sides (sides 1,2,3,4) are also special */
        else if (elem_blk_parms[j].elem_type_val == EX_EL_PYRAMID &&
                 (side < 5))
        {
            if (elem_blk_parms[j].num_nodes_per_elem == 5)
                node_ctr += 3;  /* 3 node side */
            else
                node_ctr += 6;  /* 6 node side */
        }
        /* side numbers 3,4,5,6 for SHELLs are also special */
        else if (elem_blk_parms[j].elem_type_val == EX_EL_SHELL &&
                 (side > 2 ))
        {
            if (elem_blk_parms[j].num_nodes_per_elem == 4)
                node_ctr += 2;  /* 2 node side */
            else
                node_ctr += 3;  /* 3 node side */
        }
        /* side numbers 3,4,5 for 3d TRIs are also special */
        else if (elem_blk_parms[j].elem_type_val == EX_EL_TRIANGLE &&
                 ndim == 3 &&
                 side > 2 )
        {
            if (elem_blk_parms[j].num_nodes_per_elem == 3)  /* 3-node TRI */
                node_ctr += 2;  /* 2 node side */
            else   /* 6-node TRI */
                node_ctr += 3;  /* 3 node side */
        }
        else /* all other element types */
            node_ctr += elem_blk_parms[j].num_nodes_per_side[0];
    }

    /* All setup, ready to go ... */

    elem_ctr=0;

    for (j=0; j < tot_num_ss_elem; j++) {
        int64_t elem_ndx;
        size_t parm_ndx;
        if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
            elem_ndx = ((int64_t*)ss_elem_ndx)[j];
            elem     = ((int64_t*)side_set_elem_list)[elem_ndx];
            side     = ((int64_t*)side_set_side_list)[elem_ndx];
            parm_ndx = ((int64_t*)ss_parm_ndx)[elem_ndx];
        } else {
            elem_ndx = ((int*)ss_elem_ndx)[j];
            elem     = ((int*)side_set_elem_list)[elem_ndx];
            side     = ((int*)side_set_side_list)[elem_ndx];
            parm_ndx = ((int*)ss_parm_ndx)[elem_ndx];
        }

        if (elem > elem_ctr) {
            /* release connectivity array space and get next one */
            if (elem_ctr > 0) {
                safe_free(connect);
            }

            /* Allocate space for the connectivity array for new element block */
            if (!(connect=malloc(elem_blk_parms[parm_ndx].num_elem_in_blk*
                                 elem_blk_parms[parm_ndx].num_nodes_per_elem*
                                 int_size)))
            {
                exerrval = EX_MEMFAIL;
                sprintf(errmsg,
                        "Error: failed to allocate space for connectivity array for file id %d",
                        exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            /* get connectivity array */
            if (ex_get_elem_conn(exoid,
                                 elem_blk_parms[parm_ndx].elem_blk_id,
                                 connect) == -1)
            {
                sprintf(errmsg,
                        "Error: failed to allocate space for connectivity array for file id %d",
                        exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }
            elem_ctr = elem_blk_parms[parm_ndx].elem_ctr;
        }
        /*  For each side in side set, use the appropriate lookup table to
        determine the nodes from the connect array. */

        elem_num = elem-1;/* element number 0-based*/
        /* calculate the relative element number position in it's block*/

        elem_num_pos = elem_num -
                       (elem_blk_parms[parm_ndx].elem_ctr -
                        elem_blk_parms[parm_ndx].num_elem_in_blk);

        /* calculate the beginning of the node list for this element by
           using the ss_elem_node_ndx index into the side_sets_node_index
           and adding the element number position * number of nodes per elem */

        num_nodes_per_elem = elem_blk_parms[parm_ndx].num_nodes_per_elem;
        connect_offset = num_nodes_per_elem*elem_num_pos;
        side_num = side-1;

        if (int_size == sizeof(int64_t)) {
            node_pos = ((int64_t*)ss_elem_node_ndx)[elem_ndx];
        } else {
            node_pos = ((int*)ss_elem_node_ndx)[elem_ndx];
        }

        switch (elem_blk_parms[parm_ndx].elem_type_val)
        {
        case EX_EL_CIRCLE:
        case EX_EL_SPHERE:
        {   /* Note: no side-node lookup table is used for this simple case */
            get_nodes(exoid, side_set_node_list, node_pos, connect, connect_offset);
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 1);   /* 1 node object */
            break;
        }
        case EX_EL_TRUSS:
        case EX_EL_BEAM:
        {   /* Note: no side-node lookup table is used for this simple case */
            for (i=0; i < num_nodes_per_elem; i++) {
                get_nodes(exoid, side_set_node_list, node_pos+i, connect, connect_offset+i);
            }
            set_count(exoid, side_set_node_cnt_list, elem_ndx, num_nodes_per_elem);
            break;
        }
        case EX_EL_TRIANGLE:
        {
            if (side_num+1 < 1 || side_num+1 > 5) /* side number range check */
            {
                exerrval = EX_BADPARAM;
                sprintf(errmsg,
                        "Error: Invalid triangle edge number %"ST_ZU" in file id %d",
                        side_num+1, exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            if (ndim == 2)   /* 2d TRIs */
            {
                get_nodes(exoid, side_set_node_list, node_pos,   connect, connect_offset+tri_table[side_num][0]-1);
                get_nodes(exoid, side_set_node_list, node_pos+1, connect, connect_offset+tri_table[side_num][1]-1);
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 2);   /* 2 node object */
                if (num_nodes_per_elem > 3)   /* 6-node TRI  */
                {
                    get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+tri_table[side_num][2]-1);
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
                }
            }
            else if (ndim == 3)  /* 3d TRIs */
            {
                get_nodes(exoid, side_set_node_list, node_pos,   connect, connect_offset+tri3_table[side_num][0]-1);
                get_nodes(exoid, side_set_node_list, node_pos+1, connect, connect_offset+tri3_table[side_num][1]-1);
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 2);   /* 2 node object */
                if (side_num+1 <= 2)  /* 3- or 6-node face */
                {
                    if (num_nodes_per_elem == 3)  /* 3-node face */
                    {
                        set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
                        get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+tri3_table[side_num][2]-1);
                    }
                    else   /* 6-node face */
                    {
                        set_count(exoid, side_set_node_cnt_list, elem_ndx, 6); /* 6 node object */
                        get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+tri3_table[side_num][2]-1);
                        get_nodes(exoid, side_set_node_list, node_pos+3, connect, connect_offset+tri3_table[side_num][3]-1);
                        get_nodes(exoid, side_set_node_list, node_pos+4, connect, connect_offset+tri3_table[side_num][4]-1);
                        get_nodes(exoid, side_set_node_list, node_pos+5, connect, connect_offset+tri3_table[side_num][5]-1);
                    }
                }
                else /* 2- or 3-node edge */
                {
                    if (num_nodes_per_elem > 3)  /* 3-node edge */
                    {
                        set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
                        get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+tri3_table[side_num][2]-1);
                    }
                }
            }
            break;
        }
        case EX_EL_QUAD:
        {
            if (side_num+1 < 1 || side_num+1 > 4) /* side number range check */
            {
                exerrval = EX_BADPARAM;
                sprintf(errmsg,
                        "Error: Invalid quad edge number %"ST_ZU" in file id %d",
                        side_num+1, exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            get_nodes(exoid, side_set_node_list, node_pos+0, connect, connect_offset+quad_table[side_num][0]-1);
            get_nodes(exoid, side_set_node_list, node_pos+1, connect, connect_offset+quad_table[side_num][1]-1);
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 2);   /* 2 node object */
            if (num_nodes_per_elem > 5)
            {
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node object */
                get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+quad_table[side_num][2]-1);
            }
            break;
        }
        case EX_EL_SHELL:
        {
            if (side_num+1 < 1 || side_num+1 > 6) /* side number range check */
            {
                exerrval = EX_BADPARAM;
                sprintf(errmsg,
                        "Error: Invalid shell face number %"ST_ZU" in file id %d",
                        side_num+1, exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            get_nodes(exoid, side_set_node_list, node_pos+0, connect, connect_offset+shell_table[side_num][0]-1);
            get_nodes(exoid, side_set_node_list, node_pos+1, connect, connect_offset+shell_table[side_num][1]-1);
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 2);   /* 2 node object */
            if (num_nodes_per_elem > 2) /*** KLUDGE for 2D shells ***/
            {
                if (side_num+1 <= 2)  /* 4-node face */
                {
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 4);   /* 4 node object */
                    get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+shell_table[side_num][2]-1);
                    get_nodes(exoid, side_set_node_list, node_pos+3, connect, connect_offset+shell_table[side_num][3]-1);
                }
            }
            if (num_nodes_per_elem == 8)
            {
                if (side_num+1 <= 2)  /* 8-node face */
                {
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 8); /* 8 node object */
                    get_nodes(exoid, side_set_node_list, node_pos+4, connect, connect_offset+shell_table[side_num][4]-1);
                    get_nodes(exoid, side_set_node_list, node_pos+5, connect, connect_offset+shell_table[side_num][5]-1);
                    get_nodes(exoid, side_set_node_list, node_pos+6, connect, connect_offset+shell_table[side_num][6]-1);
                    get_nodes(exoid, side_set_node_list, node_pos+7, connect, connect_offset+shell_table[side_num][7]-1);
                }
                else
                {
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 3); /* 3 node edge */
                    get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+shell_table[side_num][2]-1);
                }
            }
            break;
        }
        case EX_EL_TETRA:
        {
            if (side_num+1 < 1 || side_num+1 > 4) /* side number range check */
            {
                exerrval = EX_BADPARAM;
                sprintf(errmsg,
                        "Error: Invalid tetra face number %"ST_ZU" in file id %d",
                        side_num+1, exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            get_nodes(exoid, side_set_node_list, node_pos+0, connect, connect_offset+tetra_table[side_num][0]-1);
            get_nodes(exoid, side_set_node_list, node_pos+1, connect, connect_offset+tetra_table[side_num][1]-1);
            get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+tetra_table[side_num][2]-1);
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 3);   /* 3 node object */
            if (num_nodes_per_elem == 8)
            {
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 4); /* 4 node object */
                get_nodes(exoid, side_set_node_list, node_pos+3, connect, connect_offset+tetra_table[side_num][3]-1);
            }
            else if (num_nodes_per_elem > 8)
            {
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 6); /* 6 node object */
                get_nodes(exoid, side_set_node_list, node_pos+3, connect, connect_offset+tetra_table[side_num][3]-1);
                get_nodes(exoid, side_set_node_list, node_pos+4, connect, connect_offset+tetra_table[side_num][4]-1);
                get_nodes(exoid, side_set_node_list, node_pos+5, connect, connect_offset+tetra_table[side_num][5]-1);
            }
            break;
        }
        case EX_EL_WEDGE:
        {
            if (side_num+1 < 1 || side_num+1 > 5) /* side number range check */
            {
                exerrval = EX_BADPARAM;
                sprintf(errmsg,
                        "Error: Invalid wedge face number %"ST_ZU" in file id %d",
                        side_num+1, exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][0]-1);
            get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][1]-1);
            get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][2]-1);

            if (wedge_table[side_num][3] == 0) { /* degenerate side? */
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 3);   /* 3 node side */
            }
            else
            {
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][3]-1);
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 4);   /* 4 node side */
            }


            if (num_nodes_per_elem > 6)
            {
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][4]-1);
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][5]-1);
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][6]-1);

                if (wedge_table[side_num][7] == 0) /* degenerate side? */
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 7);   /* 6 node side */
                else
                {
                    get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+wedge_table[side_num][7]-1);
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 8);   /* 8 node side */
                }
            }
            break;
        }
        case EX_EL_PYRAMID:
        {
            if (side_num+1 < 1 || side_num+1 > 5) /* side number range check */
            {
                exerrval = EX_BADPARAM;
                sprintf(errmsg,
                        "Error: Invalid pyramid face number %"ST_ZU" in file id %d",
                        side_num+1, exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][0]-1);
            get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][1]-1);
            get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][2]-1);

            if (pyramid_table[side_num][3] == 0) { /* degenerate side? */
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 3);   /* 3 node side */
            }
            else
            {
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][3]-1);
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 4);   /* 4 node side */
            }


            if (num_nodes_per_elem > 5)
            {
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][4]-1);
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][5]-1);
                get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][6]-1);

                if (pyramid_table[side_num][7] == 0) /* degenerate side? */
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 7);   /* 6 node side */
                else
                {
                    get_nodes(exoid, side_set_node_list, node_pos++, connect, connect_offset+pyramid_table[side_num][7]-1);
                    set_count(exoid, side_set_node_cnt_list, elem_ndx, 8);   /* 8 node side */
                }
            }
            break;
        }
        case EX_EL_HEX:
        {
            if (side_num+1 < 1 || side_num+1 > 6) /* side number range check */
            {
                exerrval = EX_BADPARAM;
                sprintf(errmsg,
                        "Error: Invalid hex face number %"ST_ZU" in file id %d",
                        side_num+1, exoid);
                ex_err("ex_get_side_set_node_list",errmsg,exerrval);
                err_stat = EX_FATAL;
                goto cleanup;
            }

            get_nodes(exoid, side_set_node_list, node_pos+0, connect, connect_offset+hex_table[side_num][0]-1);
            get_nodes(exoid, side_set_node_list, node_pos+1, connect, connect_offset+hex_table[side_num][1]-1);
            get_nodes(exoid, side_set_node_list, node_pos+2, connect, connect_offset+hex_table[side_num][2]-1);
            get_nodes(exoid, side_set_node_list, node_pos+3, connect, connect_offset+hex_table[side_num][3]-1);
            set_count(exoid, side_set_node_cnt_list, elem_ndx, 4);   /* 4 node object */
            if (num_nodes_per_elem > 12)   /* more nodes than HEXSHELL */
            {
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 8); /* 8 node object */
                get_nodes(exoid, side_set_node_list, node_pos+4, connect, connect_offset+hex_table[side_num][4]-1);
                get_nodes(exoid, side_set_node_list, node_pos+5, connect, connect_offset+hex_table[side_num][5]-1);
                get_nodes(exoid, side_set_node_list, node_pos+6, connect, connect_offset+hex_table[side_num][6]-1);
                get_nodes(exoid, side_set_node_list, node_pos+7, connect, connect_offset+hex_table[side_num][7]-1);
            }
            if (num_nodes_per_elem == 27)                 /* 27-node brick */
            {
                set_count(exoid, side_set_node_cnt_list, elem_ndx, 9); /* 9 node object */
                get_nodes(exoid, side_set_node_list, node_pos+8, connect, connect_offset+hex_table[side_num][8]-1);
            }
            break;
        }
        default:
        {
            exerrval = EX_BADPARAM;
            sprintf(errmsg,
                    "Error: %s is an unsupported element type",
                    elem_blk_parms[parm_ndx].elem_type);
            ex_err("ex_get_side_set_node_list",errmsg,exerrval);
            return(EX_FATAL);
        }
        }
    }


    /* All done: release connectivity array space, element block ids array,
       element block parameters array, and side set element index array */
cleanup:
    safe_free(connect);
    safe_free(ss_parm_ndx);
    safe_free(elem_blk_ids);
    safe_free(elem_blk_parms);
    safe_free(ss_elem_ndx);
    safe_free(ss_elem_node_ndx);
    safe_free(side_set_side_list);
    safe_free(side_set_elem_list);

    return(err_stat);
}
예제 #19
0
int ex_get_prop_array (int   exoid,
                       ex_entity_type obj_type,
                       const char *prop_name,
                       void_int  *values)
{
   int num_props, i, propid, status;
   int found = FALSE;
   char name[MAX_VAR_NAME_LENGTH+1];
   char tmpstr[MAX_STR_LENGTH+1];

   char errmsg[MAX_ERR_LENGTH];

   exerrval  = 0; /* clear error code */

/* open appropriate variable, depending on obj_type and prop_name */

   num_props = ex_get_num_props(exoid, obj_type);

   for (i=1; i<=num_props; i++)
   {
     switch (obj_type){
       case EX_ELEM_BLOCK:
         strcpy (name, VAR_EB_PROP(i));
         break;
       case EX_EDGE_BLOCK:
         strcpy (name, VAR_ED_PROP(i));
         break;
       case EX_FACE_BLOCK:
         strcpy (name, VAR_FA_PROP(i));
         break;
       case EX_NODE_SET:
         strcpy (name, VAR_NS_PROP(i));
         break;
       case EX_EDGE_SET:
         strcpy (name, VAR_ES_PROP(i));
         break;
       case EX_FACE_SET:
         strcpy (name, VAR_FS_PROP(i));
         break;
       case EX_ELEM_SET:
         strcpy (name, VAR_ELS_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_FACE_MAP:
         strcpy (name, VAR_FAM_PROP(i));
         break;
       case EX_EDGE_MAP:
         strcpy (name, VAR_EDM_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_get_prop_array",errmsg,exerrval);
         return(EX_FATAL);
     }

     if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
          "Error: failed to locate property array %s in file id %d",
               name, exoid);
       ex_err("ex_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

     /*   compare stored attribute name with passed property name   */
     memset(tmpstr, 0, MAX_STR_LENGTH+1);
     if ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
              "Error: failed to get property name in file id %d", exoid);
       ex_err("ex_get_prop_array",errmsg,exerrval);
       return (EX_FATAL);
     }

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

   /* if property is not found, return warning */
   if (!found) {
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
       "Warning: object type %d, property %s not defined in file id %d",
        obj_type, prop_name, exoid);
     ex_err("ex_get_prop_array",errmsg,exerrval);
     return (EX_WARN);
   }

   /* read num_obj values from property variable */
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    status = nc_get_var_longlong(exoid, propid, values);
  } else {
    status = nc_get_var_int(exoid, propid, values);
  }

   if (status != NC_NOERR) {
     exerrval = status;
     sprintf(errmsg,
            "Error: failed to read values in %s property array in file id %d",
             ex_name_of_object(obj_type), exoid);
     ex_err("ex_get_prop_array",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);
}
예제 #20
0
int ex_put_qa(int exoid, int num_qa_records, char *qa_record[][4])
{
  int    status;
  int    i, j, strdim, num_qa_dim, varid, n4dim;
  int    dims[3];
  size_t start[3], count[3];
  char   errmsg[MAX_ERR_LENGTH];

  int rootid = exoid & EX_FILE_ID_MASK;

  ex_check_valid_file_id(exoid);

  exerrval = 0; /* clear error code */

  /* only do this if there are records */

  if (num_qa_records > 0) {
    /* See if the number of qa records has already been defined.
       Assume that if the DIM_NUM_QA dimension exists, then the
       VAR_QA_TITLE variable also exists...
     */
    status = nc_inq_dimid(rootid, DIM_NUM_QA, &num_qa_dim);
    if (status != NC_NOERR) {

      /*   inquire previously defined dimensions  */
      if ((status = nc_inq_dimid(rootid, DIM_STR, &strdim)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate string length in file id %d",
                 rootid);
        ex_err("ex_put_qa", errmsg, exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimid(rootid, DIM_N4, &n4dim)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate record length in file id %d",
                 rootid);
        ex_err("ex_put_qa", errmsg, exerrval);
        return (EX_FATAL);
      }

      /*   put file into define mode  */
      if ((status = nc_redef(rootid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode",
                 rootid);
        ex_err("ex_put_qa", errmsg, exerrval);
        return (EX_FATAL);
      }

      /*   define dimensions */
      if ((status = nc_def_dim(rootid, DIM_NUM_QA, num_qa_records, &num_qa_dim)) != NC_NOERR) {
        if (status == NC_ENAMEINUSE) { /* duplicate entry? */
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: qa records already exist in file id %d", rootid);
          ex_err("ex_put_qa", errmsg, exerrval);
        }
        else {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH,
                   "ERROR: failed to define qa record array size in file id %d", rootid);
          ex_err("ex_put_qa", errmsg, exerrval);
        }

        goto error_ret; /* exit define mode and return */
      }

      /*   define variable  */
      dims[0] = num_qa_dim;
      dims[1] = n4dim;
      dims[2] = strdim;

      if ((status = nc_def_var(rootid, VAR_QA_TITLE, NC_CHAR, 3, dims, &varid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define qa record array in file id %d",
                 rootid);
        ex_err("ex_put_qa", errmsg, exerrval);
        goto error_ret; /* exit define mode and return */
      }

      /*   leave define mode  */
      if ((status = nc_enddef(rootid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition in file id %d",
                 rootid);
        ex_err("ex_put_qa", errmsg, exerrval);
        return (EX_FATAL);
      }
    }
    else {
      if ((status = nc_inq_varid(rootid, VAR_QA_TITLE, &varid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find qa records variable in file id %d",
                 rootid);
        ex_err("ex_put_qa", errmsg, exerrval);
        return (EX_FATAL);
      }
    }

    if (qa_record != NULL) {
      /*   write out QA records */

      for (i = 0; i < num_qa_records; i++) {
        for (j = 0; j < 4; j++) {
          start[0] = i;
          start[1] = j;
          start[2] = 0;

          count[0] = 1;
          count[1] = 1;
          count[2] = strlen(qa_record[i][j]) + 1;

          if ((status = nc_put_vara_text(rootid, varid, start, count, qa_record[i][j])) !=
              NC_NOERR) {
            exerrval = status;
            snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store qa record in file id %d",
                     rootid);
            ex_err("ex_put_qa", errmsg, exerrval);
            return (EX_FATAL);
          }
        }
      }
    }
    else if (ex_is_parallel(rootid)) {
      /* In case we are in a collective mode, all processors need to call */
      const char dummy[] = " ";
      for (i = 0; i < num_qa_records; i++) {
        for (j = 0; j < 4; j++) {
          start[0] = start[1] = start[2] = 0;
          count[0] = count[1] = count[2] = 0;
          nc_put_vara_text(rootid, varid, start, count, dummy);
        }
      }
    }
  }
  return (EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  if (nc_enddef(rootid) != NC_NOERR) { /* exit define mode */
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", rootid);
    ex_err("ex_put_qa", errmsg, exerrval);
  }
  return (EX_FATAL);
}
예제 #21
0
파일: exgcset.c 프로젝트: hs9906/paraview
int ex_get_concat_sets (int   exoid,
                        int   set_type,
                        struct ex_set_specs* set_specs)
{
   int  *set_ids = set_specs->sets_ids;
   int  *num_entries_per_set = set_specs->num_entries_per_set;
   int  *num_dist_per_set = set_specs->num_dist_per_set;
   int  *sets_entry_index = set_specs->sets_entry_index;
   int  *sets_dist_index = set_specs->sets_dist_index;
   int  *sets_entry_list = set_specs->sets_entry_list;
   int  *sets_extra_list = set_specs->sets_extra_list;
   void *sets_dist_fact = set_specs->sets_dist_fact;
   char *cdum;
   int num_sets, i;
   float fdum;
   float  *flt_dist_fact;
   double *dbl_dist_fact;
   char errmsg[MAX_ERR_LENGTH];
   char* typeName;
   char* dimptr;
   char* idsptr;
   int ex_inq_val;
   int *extra_list;   

   exerrval = 0; /* clear error code */

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

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

   if (set_type == EX_NODE_SET) {
     typeName = "node";
     ex_inq_val = EX_INQ_NODE_SETS;
     dimptr = DIM_NUM_NS;
     idsptr = VAR_NS_IDS;
   }
   else if (set_type == EX_EDGE_SET) {
     typeName = "edge";
     ex_inq_val = EX_INQ_EDGE_SETS;
     dimptr = DIM_NUM_ES;
     idsptr = VAR_ES_IDS;
   }
   else if (set_type == EX_FACE_SET) {
     typeName = "face";
     ex_inq_val = EX_INQ_FACE_SETS;
     dimptr = DIM_NUM_FS;
     idsptr = VAR_FS_IDS;
   }
   else if (set_type == EX_SIDE_SET) {
     typeName = "side";
     ex_inq_val = EX_INQ_SIDE_SETS;
     dimptr = DIM_NUM_SS;
     idsptr = VAR_SS_IDS;
   }
   else if (set_type == EX_ELEM_SET) {
     typeName = "elem";
     ex_inq_val = EX_INQ_ELEM_SETS;
     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 (ncdimid (exoid, dimptr)  == -1)
   {
     if (ncerr == NC_EBADDIM)
     {
       exerrval = ncerr;
       sprintf(errmsg,
               "Warning: no %s sets defined for file id %d", typeName, exoid);
       ex_err("ex_get_concat_sets",errmsg,exerrval);
       return (EX_WARN);
     }
     else
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to locate %s sets defined in file id %d", 
               typeName, exoid);
       ex_err("ex_get_concat_sets",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

/* inquire how many sets have been stored */

   if (ex_inquire(exoid, ex_inq_val, &num_sets, &fdum, cdum) == -1)
   {
     sprintf(errmsg,
            "Error: failed to get number of %s sets defined for file id %d",
             typeName, exoid);
     /* use error val from inquire */
     ex_err("ex_get_concat_sets",errmsg,exerrval);
     return (EX_FATAL);
   }

   if (ex_get_ids (exoid, set_type, set_ids) == -1)
   {
     sprintf(errmsg,
            "Error: failed to get %s set ids for file id %d",
             typeName, exoid);
     /* use error val from inquire */
     ex_err("ex_get_concat_sets",errmsg,exerrval);
     return (EX_FATAL);
   }

   sets_entry_index[0] = 0;
   sets_dist_index[0] = 0;

   for (i=0; i<num_sets; i++)
   {
     if (ex_get_set_param(exoid, set_type, set_ids[i], 
                       &(num_entries_per_set[i]), &(num_dist_per_set[i])) == -1)
       return(EX_FATAL); /* error will be reported by sub */

     if (i < num_sets-1)
     {
       /* fill in entry and dist factor index arrays */
       sets_entry_index[i+1] = sets_entry_index[i]+num_entries_per_set[i];
       sets_dist_index[i+1] = sets_dist_index[i]+num_dist_per_set[i];
     }

     if (num_entries_per_set[i] == 0) /* NULL  set? */
       continue;

     /* Now, use ExodusII call to get sets */

     if (set_type == EX_EDGE_SET || set_type == EX_FACE_SET ||
         set_type == EX_SIDE_SET)
       extra_list = &(sets_extra_list[sets_entry_index[i]]);
     else
       extra_list = NULL;

     if (ex_comp_ws(exoid) == sizeof(float))
     {
       if (ex_get_set(exoid, set_type, set_ids[i],
                         &(sets_entry_list[sets_entry_index[i]]),
                         &(sets_extra_list[sets_entry_index[i]])) == -1)
         return(EX_FATAL); /* error will be reported by subroutine */

       /* get distribution factors for this set */
       flt_dist_fact = sets_dist_fact;
       if (num_dist_per_set[i] > 0)       /* only get df if they exist */
       {
         if (ex_get_set_dist_fact(exoid, set_type, set_ids[i],
                               &(flt_dist_fact[sets_dist_index[i]])) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get %s set %d dist factors in file id %d",
                   typeName, set_ids[i], exoid);
           ex_err("ex_get_concat_sets",errmsg,exerrval);
           return(EX_FATAL);
         }
       } else {  /* fill distribution factor array with 1's */
       }
     }
     else if (ex_comp_ws(exoid) == sizeof(double))
     {
       if (ex_get_set(exoid, set_type, set_ids[i],
                      &(sets_entry_list[sets_entry_index[i]]),
                      &(sets_extra_list[sets_entry_index[i]])) == -1)
         return(EX_FATAL); /* error will be reported by subroutine */

       /* get distribution factors for this set */
       dbl_dist_fact = sets_dist_fact;
       if (num_dist_per_set[i] > 0)       /* only get df if they exist */
       {
         if (ex_get_set_dist_fact(exoid, set_type, set_ids[i],
                               &(dbl_dist_fact[sets_dist_index[i]])) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get %s set %d dist factors in file id %d",
                   typeName, set_ids[i], exoid);
           ex_err("ex_get_concat_sets",errmsg,exerrval);
           return(EX_FATAL);
         }
       } else {  /* fill distribution factor array with 1's */
       }
     }
   }

   return(EX_NOERR);

}
int ex_get_partial_elem_attr (int   exoid,
                        ex_entity_id   elem_blk_id,
                        int64_t   start_elem_num,
                        int64_t   num_elems,
                        void *attrib)

{
  int numelbdim, numattrdim, attrid, elem_blk_id_ndx, status;
  size_t 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 */
  if ((elem_blk_id_ndx = ex_id_lkup(exoid, EX_ELEM_BLOCK, elem_blk_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
              "Warning: no attributes found for NULL block %"PRId64" in file id %d",
              elem_blk_id,exoid);
      ex_err("ex_get_partial_elem_attr",errmsg,EX_NULLENTITY);
      return (EX_WARN);              /* no attributes for this element block */
    } 
      sprintf(errmsg,
      "Warning: failed to locate element block %"PRId64" in %s array in file id %d",
              elem_blk_id,VAR_ID_EL_BLK, exoid);
      ex_err("ex_get_partial_elem_attr",errmsg,exerrval);
      return (EX_WARN);
    
  }


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

  if ((status = nc_inq_dimid(exoid, DIM_NUM_EL_IN_BLK(elem_blk_id_ndx), &numelbdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
        "Error: failed to locate number of elements for block %"PRId64" in file id %d",
            elem_blk_id, exoid);
    ex_err("ex_get_partial_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, numelbdim, &num_elem_this_blk)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
           "Error: failed to get number of elements for block %"PRId64" in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_get_partial_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(elem_blk_id_ndx), &numattrdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no attributes found for block %"PRId64" in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_get_partial_elem_attr",errmsg,EX_MSG);
    return (EX_WARN);              /* no attributes for this element block */
  }

  if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
         "Error: failed to get number of attributes for block %"PRId64" in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_get_partial_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid(exoid, VAR_ATTRIB(elem_blk_id_ndx), &attrid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate attributes for block %"PRId64" in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_get_partial_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* do some error checking */
  if (num_elem_this_blk < (start_elem_num + num_elems - 1)) {
    exerrval = status;
    sprintf(errmsg,
      "Error: requested attributes from too many elements in this block, %"PRId64"",
            elem_blk_id);
    ex_err("ex_get_partial_elem_attr",errmsg, exerrval);
    return(EX_FATAL);
  }

/* read in the attributes */

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

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

  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, attrid, start, count, attrib);
  } else {
    status = nc_get_vara_double(exoid, attrid, start, count, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get attributes for block %"PRId64" in file id %d",
            elem_blk_id,exoid);
    ex_err("ex_get_partial_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
예제 #23
0
파일: ex_copy.c 프로젝트: certik/exodus
int ex_copy (int in_exoid, int out_exoid)
{
   int status;
   int ndims;                   /* number of dimensions */
   int nvars;                   /* number of variables */
   int ngatts;                  /* number of global attributes */
   int recdimid;                /* id of unlimited dimension */
   int dimid;                   /* dimension id */
   int dim_out_id;              /* dimension id */
   int varid;                   /* variable id */
   int var_out_id;              /* variable id */
   struct ncvar var;            /* variable */
   struct ncatt att;            /* attribute */
   nc_type att_type = NC_NAT;
   size_t att_len = 0;
   size_t i;
   size_t numrec;
   size_t dim_sz;
   char dim_nm[NC_MAX_NAME];
   int in_large, out_large;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   /*
    * Get exodus_large_model setting on both input and output
    * databases so know how to handle coordinates.
    */
   in_large  = ex_large_model(in_exoid);
   out_large = ex_large_model(out_exoid);
   
   /*
    * get number of dimensions, number of variables, number of global
    * atts, and dimension id of unlimited dimension, if any
    */

   (void)nc_inq(in_exoid, &ndims, &nvars, &ngatts, &recdimid);
   (void)nc_inq_dimlen(in_exoid, recdimid, &numrec);

   /* put output file into define mode */
   (void)nc_redef(out_exoid);

   /* copy global attributes */
   for (i = 0; i < (size_t)ngatts; i++) {

     (void)nc_inq_attname(in_exoid, NC_GLOBAL, i, att.name);
        
     /* if attribute exists in output file, don't overwrite it; compute 
      * word size, I/O word size etc. are global attributes stored when
      * file is created with ex_create;  we don't want to overwrite those
      */
     if ((status = nc_inq_att(out_exoid, NC_GLOBAL, att.name, &att.type, &att.len)) != NC_NOERR) {

        /* The "last_written_time" attribute is a special attribute
           used by the Sierra IO system to determine whether a
           timestep has been fully written to the database in order to
           try to detect a database crash that happens in the middle
           of a database output step. Don't want to copy that attribute.
        */
        if (strcmp(att.name,"last_written_time") != 0) {
          /* attribute doesn't exist in new file so OK to create it */
          nc_copy_att(in_exoid,NC_GLOBAL,att.name,out_exoid,NC_GLOBAL);
        }
      }
   }

   /* copy dimensions */

   /* Get the dimension sizes and names */

   for(dimid = 0; dimid < ndims; dimid++){

     (void)nc_inq_dim(in_exoid,dimid,dim_nm,&dim_sz);

     /* If the dimension isn't one we specifically don't want 
      * to copy (ie, number of QA or INFO records) and it 
      * hasn't been defined, copy it */
     
     if ( ( strcmp(dim_nm,DIM_NUM_QA)        != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_INFO)      != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_NOD_VAR)   != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_EDG_VAR)   != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_FAC_VAR)   != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_ELE_VAR)   != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_NSET_VAR)  != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_ESET_VAR)  != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_FSET_VAR)  != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_SSET_VAR)  != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_ELSET_VAR) != 0) &&
	  ( strcmp(dim_nm,DIM_NUM_GLO_VAR)   != 0) ) {
       
       /* See if the dimension has already been defined */
       status = nc_inq_dimid(out_exoid, dim_nm, &dim_out_id);
       
       if(status != NC_NOERR) {
	 if(dimid != recdimid) {
	   status = nc_def_dim(out_exoid, dim_nm, dim_sz,       &dim_out_id);
	 } else {
	   status = nc_def_dim(out_exoid, dim_nm, NC_UNLIMITED, &dim_out_id);
	 } /* end else */
	 if (status != NC_NOERR) {
	   exerrval = status;
	   sprintf(errmsg,
		   "Error: failed to define %s dimension in file id %d",
		   dim_nm, out_exoid);
	   ex_err("ex_copy",errmsg,exerrval);
	   return (EX_FATAL);
	 }
       } /* end if */
     } /* end if */
   } /* end loop over dim */

   /* DIM_STR_NAME is a newly added dimension required by current API.
    * If it doesn't exist on the source database, we need to add it to
    * the target...
    */
   status = nc_inq_dimid(in_exoid, DIM_STR_NAME, &dim_out_id);
   if (status != NC_NOERR) {
     /* Not found; set to default value of 32+1. */
     if ((status = nc_def_dim(out_exoid, DIM_STR_NAME, 33, &dim_out_id)) != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
	       "Error: failed to define string name dimension in file id %d",
	       out_exoid);
       ex_err("ex_copy",errmsg,exerrval);
       return (EX_FATAL);
     }
   }

   status = nc_inq_att(in_exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len);
   if (status != NC_NOERR) {
      int max_so_far = 32;
      nc_put_att_int(out_exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, NC_INT, 1, &max_so_far);
    }

   /* copy variable definitions and variable attributes */
   for (varid = 0; varid < nvars; varid++) {

     (void)nc_inq_var(in_exoid, varid, var.name, &var.type, &var.ndims, 
		 var.dims, &var.natts);

      /* we don't want to copy some variables because there is not a
       * simple way to add to them;
       * QA records, info records and all results variables (nodal
       * element, and global results) are examples
       */

      if ( ( strcmp(var.name,VAR_QA_TITLE)      != 0) &&
           ( strcmp(var.name,VAR_INFO)          != 0) &&
           ( strcmp(var.name,VAR_EBLK_TAB)      != 0) &&
           ( strcmp(var.name,VAR_FBLK_TAB)      != 0) &&
           ( strcmp(var.name,VAR_ELEM_TAB)      != 0) &&
           ( strcmp(var.name,VAR_ELSET_TAB)     != 0) &&
           ( strcmp(var.name,VAR_SSET_TAB)      != 0) &&
           ( strcmp(var.name,VAR_FSET_TAB)      != 0) &&
           ( strcmp(var.name,VAR_ESET_TAB)      != 0) &&
           ( strcmp(var.name,VAR_NSET_TAB)      != 0) &&
           ( strcmp(var.name,VAR_NAME_GLO_VAR)  != 0) &&
           ( strcmp(var.name,VAR_GLO_VAR)       != 0) &&
           ( strcmp(var.name,VAR_NAME_NOD_VAR)  != 0) &&
           ( strcmp(var.name,VAR_NOD_VAR)       != 0) &&
           ( strcmp(var.name,VAR_NAME_EDG_VAR)  != 0) &&
           ( strcmp(var.name,VAR_NAME_FAC_VAR)  != 0) &&
           ( strcmp(var.name,VAR_NAME_ELE_VAR)  != 0) &&
           ( strcmp(var.name,VAR_NAME_NSET_VAR) != 0) &&
           ( strcmp(var.name,VAR_NAME_ESET_VAR) != 0) &&
           ( strcmp(var.name,VAR_NAME_FSET_VAR) != 0) &&
           ( strcmp(var.name,VAR_NAME_SSET_VAR) != 0) &&
           ( strcmp(var.name,VAR_NAME_ELSET_VAR) != 0)&&
           ( strncmp(var.name,"vals_elset_var", 14) != 0) &&
           ( strncmp(var.name,"vals_sset_var",  13) != 0) &&
           ( strncmp(var.name,"vals_fset_var",  13) != 0) &&
           ( strncmp(var.name,"vals_eset_var",  13) != 0) &&
           ( strncmp(var.name,"vals_nset_var",  13) != 0) &&
           ( strncmp(var.name,"vals_nod_var",   12) != 0) &&
           ( strncmp(var.name,"vals_edge_var",  13) != 0) &&
           ( strncmp(var.name,"vals_face_var",  13) != 0) &&
           ( strncmp(var.name,"vals_elem_var",  13) != 0) ) {

        if (strncmp(var.name,VAR_COORD,5) == 0) {
          var_out_id = cpy_coord_def (in_exoid, out_exoid, recdimid, var.name,
                                      in_large, out_large);
        } else {
          var_out_id = cpy_var_def (in_exoid, out_exoid, recdimid, var.name);
        }

         /* copy the variable's attributes */
         (void) cpy_att (in_exoid, out_exoid, varid, var_out_id);

      }
   }

   /* take the output file out of define mode */
   if ((exerrval=nc_enddef (out_exoid)) != NC_NOERR) {
     sprintf(errmsg,
	     "Error: failed to complete definition in file id %d", 
	     out_exoid);
     ex_err("ex_copy",errmsg,exerrval);
     return (EX_FATAL);
   }

   /* output variable data */

   for (varid = 0; varid < nvars; varid++) {
     (void)nc_inq_var(in_exoid, varid, var.name, &var.type, &var.ndims,
		 var.dims, &var.natts);

      /* we don't want to copy some variable values;
       * QA records and info records shouldn't be copied because there
       * isn't an easy way to add to them;
       * the time value array ("time_whole") and any results variables
       * (nodal, elemental, or global) shouldn't be copied 
       */

      if ( ( strcmp(var.name,VAR_QA_TITLE) != 0)        &&
           ( strcmp(var.name,VAR_INFO) != 0)            &&
           ( strcmp(var.name,VAR_EBLK_TAB) != 0)        &&
           ( strcmp(var.name,VAR_FBLK_TAB) != 0)        &&
           ( strcmp(var.name,VAR_ELEM_TAB) != 0)        &&
           ( strcmp(var.name,VAR_ELSET_TAB) != 0)       &&
           ( strcmp(var.name,VAR_SSET_TAB) != 0)        &&
           ( strcmp(var.name,VAR_FSET_TAB) != 0)        &&
           ( strcmp(var.name,VAR_ESET_TAB) != 0)        &&
           ( strcmp(var.name,VAR_NSET_TAB) != 0)        &&
           ( strcmp(var.name,VAR_NAME_GLO_VAR) != 0)    &&
           ( strcmp(var.name,VAR_GLO_VAR) != 0)         &&
           ( strcmp(var.name,VAR_NAME_NOD_VAR) != 0)    &&
           ( strcmp(var.name,VAR_NOD_VAR) != 0)         &&
           ( strcmp(var.name,VAR_NAME_EDG_VAR) != 0)    &&
           ( strcmp(var.name,VAR_NAME_FAC_VAR) != 0)    &&
           ( strcmp(var.name,VAR_NAME_ELE_VAR) != 0)    &&
           ( strcmp(var.name,VAR_NAME_NSET_VAR) != 0)   &&
           ( strcmp(var.name,VAR_NAME_ESET_VAR) != 0)   &&
           ( strcmp(var.name,VAR_NAME_FSET_VAR) != 0)   &&
           ( strcmp(var.name,VAR_NAME_SSET_VAR) != 0)   &&
           ( strcmp(var.name,VAR_NAME_ELSET_VAR) != 0)  &&
           ( strncmp(var.name,"vals_elset_var", 14) != 0)&&
           ( strncmp(var.name,"vals_sset_var", 13) != 0)&&
           ( strncmp(var.name,"vals_fset_var", 13) != 0)&&
           ( strncmp(var.name,"vals_eset_var", 13) != 0)&&
           ( strncmp(var.name,"vals_nset_var", 13) != 0)&&
           ( strncmp(var.name,"vals_nod_var", 12) != 0) &&
           ( strncmp(var.name,"vals_edge_var",13) != 0) &&
           ( strncmp(var.name,"vals_face_var",13) != 0) &&
           ( strncmp(var.name,"vals_elem_var",13) != 0) &&
           ( strcmp(var.name,VAR_WHOLE_TIME) != 0) ) {

        if (strncmp(var.name,VAR_COORD,5) == 0) {
          (void) cpy_coord_val (in_exoid, out_exoid, var.name,
                                in_large, out_large);
        } else {
          (void) cpy_var_val (in_exoid, out_exoid, var.name);
        }

      }
   }

   /* ensure internal data structures are updated */

   /* if number of blocks > 0 */
   update_internal_structs( out_exoid, EX_INQ_EDGE_BLK, ex_get_counter_list(EX_EDGE_BLOCK));
   update_internal_structs( out_exoid, EX_INQ_FACE_BLK, ex_get_counter_list(EX_FACE_BLOCK));
   update_internal_structs( out_exoid, EX_INQ_ELEM_BLK, ex_get_counter_list(EX_ELEM_BLOCK));

   /* if number of sets > 0 */
   update_internal_structs( out_exoid, EX_INQ_NODE_SETS, ex_get_counter_list(EX_NODE_SET));
   update_internal_structs( out_exoid, EX_INQ_EDGE_SETS, ex_get_counter_list(EX_EDGE_SET));
   update_internal_structs( out_exoid, EX_INQ_FACE_SETS, ex_get_counter_list(EX_FACE_SET));
   update_internal_structs( out_exoid, EX_INQ_SIDE_SETS, ex_get_counter_list(EX_SIDE_SET));
   update_internal_structs( out_exoid, EX_INQ_ELEM_SETS, ex_get_counter_list(EX_ELEM_SET));

   /* if number of maps > 0 */
   update_internal_structs( out_exoid, EX_INQ_NODE_MAP, ex_get_counter_list(EX_NODE_MAP));
   update_internal_structs( out_exoid, EX_INQ_EDGE_MAP, ex_get_counter_list(EX_EDGE_MAP));
   update_internal_structs( out_exoid, EX_INQ_FACE_MAP, ex_get_counter_list(EX_FACE_MAP));
   update_internal_structs( out_exoid, EX_INQ_ELEM_MAP, ex_get_counter_list(EX_ELEM_MAP));

   return(EX_NOERR);
}
int ex_put_prop_array (int   exoid,
                       ex_entity_type obj_type,
                       const char *prop_name,
                       const int  *values)
{
  int oldfill, temp;
  int num_props, i, propid, dimid, dims[1], status;
  int found = FALSE;
  size_t num_obj; 
  char name[MAX_VAR_NAME_LENGTH+1];
  char tmpstr[MAX_STR_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);

  /* inquire id of previously defined dimension (number of objects) */
  status = ex_get_dimension(exoid, ex_dim_num_objects(obj_type), ex_name_of_object(obj_type),
			    &num_obj, &dimid, "ex_put_prop_array");
  if (status != NC_NOERR) return status;

  for (i=1; i<=num_props; i++) {
    switch (obj_type){
    case EX_ELEM_BLOCK:
      strcpy (name, VAR_EB_PROP(i));
      break;
    case EX_FACE_BLOCK:
      strcpy (name, VAR_FA_PROP(i));
      break;
    case EX_EDGE_BLOCK:
      strcpy (name, VAR_ED_PROP(i));
      break;
    case EX_NODE_SET:
      strcpy (name, VAR_NS_PROP(i));
      break;
    case EX_EDGE_SET:
      strcpy (name, VAR_ES_PROP(i));
      break;
    case EX_FACE_SET:
      strcpy (name, VAR_FS_PROP(i));
      break;
    case EX_ELEM_SET:
      strcpy (name, VAR_ELS_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_FACE_MAP:
      strcpy (name, VAR_FAM_PROP(i));
      break;
    case EX_EDGE_MAP:
      strcpy (name, VAR_EDM_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 ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
      exerrval = status;
      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 ((status = nc_get_att_text(exoid, propid, ATT_PROP_NAME, tmpstr)) != NC_NOERR) {
      exerrval = status;
      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 ((status = nc_redef (exoid)) != NC_NOERR) {
      exerrval = status;
      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_FACE_BLOCK:
      strcpy (name, VAR_FA_PROP(num_props+1));
      break;
    case EX_EDGE_BLOCK:
      strcpy (name, VAR_ED_PROP(num_props+1));
      break;
    case EX_NODE_SET:
      strcpy (name, VAR_NS_PROP(num_props+1));
      break;
    case EX_EDGE_SET:
      strcpy (name, VAR_ES_PROP(num_props+1));
      break;
    case EX_FACE_SET:
      strcpy (name, VAR_FS_PROP(num_props+1));
      break;
    case EX_ELEM_SET:
      strcpy (name, VAR_ELS_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_FACE_MAP:
      strcpy (name, VAR_FAM_PROP(num_props+1));
      break;
    case EX_EDGE_MAP:
      strcpy (name, VAR_EDM_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;
    nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */

    if ((status = nc_def_var(exoid, name, NC_INT, 1, dims, &propid)) != NC_NOERR) {
      exerrval = status;
      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 */
    }
    nc_set_fill(exoid, oldfill, &temp); /* default: nofill */


    /*   store property name as attribute of property array variable */
    if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, 
				  strlen(prop_name)+1, prop_name)) != NC_NOERR) {
      exerrval = status;
      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 ((status = nc_enddef (exoid)) != NC_NOERR) {
      exerrval = status;
      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 */
  status = nc_put_var_int(exoid, propid, values);

  if (status != NC_NOERR) {
    exerrval = status;
    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:
  nc_set_fill(exoid, oldfill, &temp); /* default: nofill */
  if (nc_enddef (exoid) != NC_NOERR) {    /* 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);
}
예제 #25
0
int ex_inquire (int   exoid,
                int   req_info,
                int  *ret_int,
                void *ret_float,
                char *ret_char)
{
   int dimid, varid, i, tmp_num, *ids;
   long ldum, num_sets, start[2], count[2];
   nclong *stat_vals;
   char  errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

   switch (req_info)
   {
     case EX_INQ_FILE_TYPE:

       /* obsolete call */
       /*returns "r" for regular EXODUS II file or "h" for history EXODUS file*/

       *ret_char = '\0';
       exerrval = EX_BADPARAM;
       sprintf(errmsg,
              "Warning: file type inquire is obsolete");
       ex_err("ex_inquire",errmsg,exerrval);
       return (EX_WARN);

     case EX_INQ_API_VERS:

/*     returns the EXODUS II API version number */

       if (ncattget (exoid, NC_GLOBAL, ATT_API_VERSION, ret_float) == -1)
       {  /* try old (prior to db version 2.02) attribute name */
         if (ncattget (exoid, NC_GLOBAL, ATT_API_VERSION_BLANK,ret_float) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
             "Error: failed to get EXODUS API version for file id %d", exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
       }

       break;

     case EX_INQ_DB_VERS:

/*     returns the EXODUS II database version number */

       if (ncattget (exoid, NC_GLOBAL, ATT_VERSION, ret_float) == -1)
       {
         exerrval = ncerr;
         sprintf(errmsg,
          "Error: failed to get EXODUS database version for file id %d", exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       break;

     case EX_INQ_LIB_VERS:

/*     returns the EXODUS II Library version number */

       flt_cvt((float *)ret_float, EX_API_VERS);

       break;

     case EX_INQ_TITLE:

/*     returns the title of the database */

       if (ncattget (exoid, NC_GLOBAL, ATT_TITLE, ret_char) == -1)
       {
         *ret_char = '\0';
         exerrval = ncerr;
         sprintf(errmsg,
             "Error: failed to get database title for file id %d", exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       break;

     case EX_INQ_DIM:

/*     returns the dimensionality (2 or 3, for 2-d or 3-d) of the database */

       if ((dimid = ncdimid (exoid, DIM_NUM_DIM)) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
                "Error: failed to locate database dimensionality in file id %d",
                exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
            "Error: failed to get database dimensionality for file id %d",
            exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;

     case EX_INQ_NODES:

/*     returns the number of nodes */

       if ((dimid = ncdimid (exoid, DIM_NUM_NODES)) == -1)
       {
         *ret_int = 0;
       } else {

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

     case EX_INQ_ELEM:

/*     returns the number of elements */

       if ((dimid = ncdimid (exoid, DIM_NUM_ELEM)) == -1)
       {
         *ret_int = 0;
       } else {

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

     case EX_INQ_ELEM_BLK:

/*     returns the number of element blocks */

       if ((dimid = ncdimid (exoid, DIM_NUM_EL_BLK)) == -1)
       {
         *ret_int = 0;
       } else {

         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
                     "Error: failed to get number of element blocks for file id %d",
                     exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             return (EX_FATAL);
           }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_NODE_SETS:

/*     returns the number of node sets */

       if ((dimid = ncdimid (exoid, DIM_NUM_NS)) < 0)
         *ret_int = 0;      /* no node sets defined */
       else
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           *ret_int = 0;
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of node sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_NS_NODE_LEN:

/*     returns the length of the concatenated node sets node list */

       *ret_int = 0;       /* default value if no node sets are defined */
       if ((dimid = ncdimid (exoid, DIM_NUM_NS)) != -1 )
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of node sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids =  malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for node set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_node_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                   "Error: failed to get node sets in file id %d",
                    exoid);
           /* pass back error code from ex_get_node_set_ids (in exerrval) */
           ex_err("ex_inquire",errmsg,exerrval);
           free (ids);
           return (EX_FATAL);
         }
         /* allocate space for stat array */
         if (!(stat_vals = malloc((int)num_sets*sizeof(nclong))))
         {
           exerrval = EX_MEMFAIL;
           free (ids);
           sprintf(errmsg,
    "Error: failed to allocate memory for node set status array for file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

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

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

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

         for (i=0; i<num_sets; i++)
         {

           if (stat_vals[i] == 0) /* is this object null? */
              continue;

           if ((dimid = ncdimid (exoid, DIM_NUM_NOD_NS(i+1))) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
         "Error: failed to locate number of nodes in node set %d in file id %d",
                  ids[i],exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             free (ids);
             free (stat_vals);
             return (EX_FATAL);
           }

           if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
            "Error: failed to get number of nodes in node set %d in file id %d",
                  ids[i],exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             free (stat_vals);
             free (ids);
             return (EX_FATAL);
           }

           *ret_int += ldum;
         }

         free (stat_vals);
         free (ids);
       }

       break;

     case EX_INQ_NS_DF_LEN:

/*     returns the length of the concatenated node sets dist factor list */

/*
     Determine the concatenated node sets distribution factor length:

        1. Get the node set ids list.
        2. Check see if the dist factor variable for a node set id exists.
        3. If it exists, goto step 4, else the length is zero.
        4. Get the dimension of the number of nodes in the node set -0
             use this value as the length as by definition they are the same.
        5. Sum the individual lengths for the total list length.
*/

       *ret_int = 0;    /* default value if no node sets defined */

       if ((dimid = ncdimid (exoid, DIM_NUM_NS))  != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of node sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids = malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for node set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_node_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                   "Error: failed to get node sets in file id %d",
                    exoid);
           /* pass back error code from ex_get_node_set_ids (in exerrval) */
           ex_err("ex_inquire",errmsg,exerrval);
           free (ids);
           return (EX_FATAL);
         }

         for (i=0; i<num_sets; i++)
         {
           if (ncvarid (exoid, VAR_FACT_NS(i+1)) == -1)
           {
             if (ncerr == NC_ENOTVAR)
             {
               ldum = 0;        /* this dist factor doesn't exist */
             }
             else
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
    "Error: failed to locate number of dist fact for node set %d in file id %d",
                        ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
           }
           else
           {
             if ((dimid = ncdimid (exoid, DIM_NUM_NOD_NS(i+1))) == -1)
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
         "Error: failed to locate number of nodes in node set %d in file id %d",
                       ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
             if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
            "Error: failed to get number of nodes in node set %d in file id %d",
                       ids[i],exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free(ids);
               return (EX_FATAL);
             }
           }
           *ret_int += ldum;
         }
         free(ids);
       }

       break;

     case EX_INQ_SIDE_SETS:

/*     returns the number of side sets */

       *ret_int = 0;     /* default return value */

       if ((dimid = ncdimid (exoid, DIM_NUM_SS)) != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of side sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_SS_NODE_LEN:

/*     returns the length of the concatenated side sets node list */

       *ret_int = 0;     /* default return value */

       if ((dimid = ncdimid (exoid, DIM_NUM_SS)) != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of side sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids = malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for side set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_side_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                  "Error: failed to get side set ids in file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           free(ids);
           return (EX_FATAL);
         }

         /* allocate space for stat array */
         if (!(stat_vals = malloc((int)num_sets*sizeof(nclong))))
         {
           exerrval = EX_MEMFAIL;
           free (ids);
           sprintf(errmsg,
    "Error: failed to allocate memory for side set status array for file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         /* get variable id of status array */
         if ((varid = ncvarid (exoid, VAR_SS_STAT)) != -1)
         {
         /* if status array exists, use it, otherwise assume, object exists
            to be backward compatible */

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

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

         /* walk id list, get each side set node length and sum for total */

         for (i=0; i<num_sets; i++)
         {
           if (stat_vals[i] == 0) /* is this object null? */
             continue;

           if (ex_get_side_set_node_list_len(exoid, ids[i], &tmp_num) == -1)
           {
             *ret_int = 0;
             exerrval = ncerr;
             sprintf(errmsg,
                 "Error: failed to side set %d node length in file id %d",
                  ids[i],exoid);
             ex_err("ex_inquire",errmsg,exerrval);
             free(stat_vals);
             free(ids);
             return (EX_FATAL);
           }
           *ret_int += tmp_num;
         }

         free(stat_vals);
         free (ids);
       }

       break;

     case EX_INQ_SS_ELEM_LEN:
/*     returns the length of the concatenated side sets element list */
       EX_GET_CONCAT_SET_LEN(ret_int,"side",EX_SIDE_SET,DIM_NUM_SS,VAR_SS_STAT,DIM_NUM_SIDE_SS,0);
       break;

     case EX_INQ_SS_DF_LEN:

/*     returns the length of the concatenated side sets dist factor list */

/*
     Determine the concatenated side sets distribution factor length:

        1. Get the side set ids list.
        2. Check see if the dist factor dimension for a side set id exists.
        3. If it exists, goto step 4, else set the individual length to zero.
        4. Sum the dimension value into the running total length.
*/

       *ret_int = 0;

       /* first check see if any side sets exist */

       if ((dimid = ncdimid (exoid, DIM_NUM_SS))  != -1)
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &num_sets) == -1)
         {
           exerrval = ncerr;
           sprintf(errmsg,
                 "Error: failed to get number of side sets in file id %d",
                  exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }


         if (!(ids = malloc(num_sets*sizeof(int))))
         {
           exerrval = EX_MEMFAIL;
           sprintf(errmsg,
             "Error: failed to allocate memory for side set ids for file id %d",
              exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }

         if (ex_get_side_set_ids (exoid, ids) == EX_FATAL)
         {
           sprintf(errmsg,
                   "Error: failed to get side sets in file id %d",
                    exoid);
           /* pass back error code from ex_get_side_set_ids (in exerrval) */
           ex_err("ex_inquire",errmsg,exerrval);
           free (ids);
           return (EX_FATAL);
         }

         for (i=0; i<num_sets; i++)
         {
           if ((dimid = ncdimid (exoid, DIM_NUM_DF_SS(i+1))) == -1)
           {
             if (ncerr == NC_EBADDIM)
             {
               ldum = 0;        /* this dist factor doesn't exist */
             }
             else
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
    "Error: failed to locate number of dist fact for side set %d in file id %d",
                        ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
           }
           else
           {
             if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
             {
               *ret_int = 0;
               exerrval = ncerr;
               sprintf(errmsg,
     "Error: failed to get number of dist factors in side set %d in file id %d",
                       ids[i], exoid);
               ex_err("ex_inquire",errmsg,exerrval);
               free (ids);
               return (EX_FATAL);
             }
           }
           *ret_int += ldum;
         }
         free (ids);
       }

       break;

     case EX_INQ_QA:

/*     returns the number of QA records */

       if ((dimid = ncdimid (exoid, DIM_NUM_QA)) < 0)
         *ret_int = 0;      /* no QA records stored */
       else
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           *ret_int = 0;
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get number of QA records in file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }

       break;

     case EX_INQ_INFO:

/*     returns the number of information records */

       if ((dimid = ncdimid (exoid, DIM_NUM_INFO)) < 0)
         *ret_int = 0;        /* no information records stored */
       else
       {
         if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
         {
           *ret_int = 0;
           exerrval = ncerr;
           sprintf(errmsg,
                  "Error: failed to get number of info records in file id %d",
                   exoid);
           ex_err("ex_inquire",errmsg,exerrval);
           return (EX_FATAL);
         }
         *ret_int = ldum;
       }
       break;

     case EX_INQ_TIME:

/*     returns the number of time steps stored in the database; we find 
 *     this out by inquiring the maximum record number of the "unlimited" 
 *     dimension
 */

       if ((dimid = ncdimid (exoid, DIM_TIME)) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
                "Error: failed to locate time dimension in file id %d", exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
                "Error: failed to get time dimension in file id %d",
                 exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;
     case EX_INQ_EB_PROP:

/*     returns the number of element block properties */

       *ret_int = ex_get_num_props (exoid, EX_ELEM_BLOCK);
       break;

     case EX_INQ_NS_PROP:

/*     returns the number of node set properties */

       *ret_int = ex_get_num_props (exoid, EX_NODE_SET);
       break;

     case EX_INQ_SS_PROP:

/*     returns the number of side set properties */

       *ret_int = ex_get_num_props (exoid, EX_SIDE_SET);
       break;

     case EX_INQ_ELEM_MAP:

/*     returns the number of element maps */

       if ((dimid = ncdimid (exoid, DIM_NUM_EM)) == -1)
       {
         /* no element maps so return 0 */

         *ret_int = 0;
         return (EX_NOERR);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of element maps for file id %d",
           exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;

     case EX_INQ_EM_PROP:

/*     returns the number of element map properties */

       *ret_int = ex_get_num_props (exoid, EX_ELEM_MAP);
       break;

     case EX_INQ_NODE_MAP:

/*     returns the number of node maps */

       if ((dimid = ncdimid (exoid, DIM_NUM_NM)) == -1)
       {
         /* no node maps so return 0 */

         *ret_int = 0;
         return (EX_NOERR);
       }

       if (ncdiminq (exoid, dimid, (char *) 0, &ldum) == -1)
       {
         *ret_int = 0;
         exerrval = ncerr;
         sprintf(errmsg,
           "Error: failed to get number of node maps for file id %d",
           exoid);
         ex_err("ex_inquire",errmsg,exerrval);
         return (EX_FATAL);
       }
       *ret_int = ldum;

       break;

     case EX_INQ_NM_PROP:
/*     returns the number of element map properties */
       *ret_int = ex_get_num_props (exoid, EX_NODE_MAP);
       break;

     case EX_INQ_EDGE:
/*     returns the number of edges (defined across all edge blocks). */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_EDGE, 1);
       break;

     case EX_INQ_EDGE_BLK:
/*     returns the number of edge blocks. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ED_BLK, 1);
       break;

     case EX_INQ_EDGE_SETS:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ES, 1);
       break;

     case EX_INQ_ES_LEN:
/*     returns the length of the concatenated edge set edge list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,DIM_NUM_EDGE_ES,0);
       break;

     case EX_INQ_ES_DF_LEN:
/*     returns the length of the concatenated edge set distribution factor list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,DIM_NUM_DF_ES,1);
       break;

     case EX_INQ_EDGE_PROP:
/*     returns the number of integer properties stored for each edge block. This includes the "ID" property. */
       *ret_int = ex_get_num_props( exoid, EX_EDGE_BLOCK );
       break;

     case EX_INQ_ES_PROP:
/*     returns the number of integer properties stored for each edge set.. This includes the "ID" property */
       *ret_int = ex_get_num_props( exoid, EX_EDGE_SET );
       break;

     case EX_INQ_FACE:
/*     returns the number of faces (defined across all face blocks). */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FACE, 1);
       break;

     case EX_INQ_FACE_BLK:
/*     returns the number of edge blocks. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FA_BLK, 1);
       break;

     case EX_INQ_FACE_SETS:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FS, 1);
       break;

     case EX_INQ_FS_LEN:
/*     returns the length of the concatenated edge set edge list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,DIM_NUM_FACE_FS,0);
       break;

     case EX_INQ_FS_DF_LEN:
/*     returns the length of the concatenated edge set distribution factor list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,DIM_NUM_DF_FS,1);
       break;

     case EX_INQ_FACE_PROP:
/*     returns the number of integer properties stored for each edge block. This includes the "ID" property. */
       *ret_int = ex_get_num_props( exoid, EX_FACE_BLOCK );
       break;

     case EX_INQ_FS_PROP:
/*     returns the number of integer properties stored for each edge set.. This includes the "ID" property */
       *ret_int = ex_get_num_props( exoid, EX_FACE_SET );
       break;

     case EX_INQ_ELEM_SETS:
/*     returns the number of element sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_ELS, 1);
       break;

     case EX_INQ_ELS_LEN:
/*     returns the length of the concatenated element set element list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,DIM_NUM_ELE_ELS,0);
       break;

     case EX_INQ_ELS_DF_LEN:
/*     returns the length of the concatenated element set distribution factor list. */
       EX_GET_CONCAT_SET_LEN(ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,DIM_NUM_DF_ELS,1);
       break;

    case EX_INQ_ELS_PROP:
/*     returns the number of integer properties stored for each element set. */
       *ret_int = ex_get_num_props( exoid, EX_ELEM_SET );
       break;

    case EX_INQ_EDGE_MAP:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_EDM, 1);
       break;

    case EX_INQ_FACE_MAP:
/*     returns the number of edge sets. */
       EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FAM, 1);
       break;


     default:
       *ret_int = 0;
       exerrval = EX_FATAL;
       sprintf(errmsg, "Error: invalid inquiry %d", req_info);
       ex_err("ex_inquire",errmsg,exerrval);
       return(EX_FATAL);
   }
   return (EX_NOERR);
}
예제 #26
0
파일: exgvarnams.c 프로젝트: 151706061/VTK
int ex_get_variable_names (int   exoid,
         ex_entity_type obj_type,
         int   num_vars,
         char *var_names[])
{
  int varid, status;
  char errmsg[MAX_ERR_LENGTH];
  const char* vvarname;

  exerrval = 0; /* clear error code */

  switch (obj_type) {
  case EX_NODAL:
    vvarname = VAR_NAME_NOD_VAR;
    break;
  case EX_EDGE_BLOCK:
    vvarname = VAR_NAME_EDG_VAR;
    break;
  case EX_FACE_BLOCK:
    vvarname = VAR_NAME_FAC_VAR;
    break;
  case EX_ELEM_BLOCK:
    vvarname = VAR_NAME_ELE_VAR;
    break;
  case EX_NODE_SET:
    vvarname = VAR_NAME_NSET_VAR;
    break;
  case EX_EDGE_SET:
    vvarname = VAR_NAME_ESET_VAR;
    break;
  case EX_FACE_SET:
    vvarname = VAR_NAME_FSET_VAR;
    break;
  case EX_SIDE_SET:
    vvarname = VAR_NAME_SSET_VAR;
    break;
  case EX_ELEM_SET:
    vvarname = VAR_NAME_ELSET_VAR;
    break;
  case EX_GLOBAL:
    vvarname = VAR_NAME_GLO_VAR;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
      "Warning: invalid variable type %d requested from file id %d",
      obj_type, exoid);
    ex_err("ex_get_variable_names",errmsg,exerrval);
    return (EX_WARN);
  }

  /* inquire previously defined variables  */
  if ((status = nc_inq_varid(exoid, vvarname, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg, "Warning: no %s variables names stored in file id %d",
      ex_name_of_object(obj_type),exoid);
    ex_err("ex_get_variable_names",errmsg,exerrval);
    return (EX_WARN);
  }

  /* read the variable names */
  status = ex_get_names_internal(exoid, varid, num_vars, var_names, obj_type, "ex_get_variable_names");
  if (status != NC_NOERR) {
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
예제 #27
0
int ex_put_n_nodal_var (int   exoid,
                        int   time_step,
                        int   nodal_var_index,
                        int   start_node,
                        int   num_nodes, 
                        const void *nodal_var_vals)

{
  int status;
  int varid;
  size_t 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 ((status = nc_inq_varid(exoid, VAR_NOD_VAR, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Warning: could not find nodal variables in file id %d",
              exoid);
      ex_err("ex_put_n_nodal_var",errmsg,exerrval);
      return (EX_WARN);
    }
    start[0] = --time_step;
    start[1] = --nodal_var_index;
    start[2] = --start_node;

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

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

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

  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, varid, start, count, nodal_var_vals);
  } else {
    status = nc_put_vara_double(exoid, varid, start, count, nodal_var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to store nodal variables in file id %d",
            exoid);
    ex_err("ex_put_n_nodal_var",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
예제 #28
0
int ex_get_info (int    exoid,
                 char **info)
{
   int i, j, dimid, varid;
   long num_info, start[2];
   char *ptr;
   char  errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

/* inquire previously defined dimensions and variables  */

   if ((dimid = ncdimid (exoid, DIM_NUM_INFO)) == -1)
   {
     exerrval = ncerr;
     sprintf(errmsg,
            "Warning: failed to locate number of info records in file id %d",
             exoid);
     ex_err("ex_get_info",errmsg,exerrval);
     return (EX_WARN);
   }

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


/* do this only if there are any information records */

   if (num_info > 0)
   {
     if ((varid = ncvarid (exoid, VAR_INFO)) == -1)
     {
       exerrval = ncerr;
       sprintf(errmsg,
              "Error: failed to locate info record data in file id %d", exoid);
       ex_err("ex_get_info",errmsg,exerrval);
       return (EX_FATAL);
     }


/* read the information records */

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

        j = 0;
        ptr = info[i];

        if (ncvarget1 (exoid, varid, start, ptr) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
              "Error: failed to get info record data in file id %d", exoid);
          ex_err("ex_get_info",errmsg,exerrval);
          return (EX_FATAL);
        }


        while ((*ptr++ != '\0') && (j < MAX_LINE_LENGTH))
        {
          start[1] = ++j;
          if (ncvarget1 (exoid, varid, start, ptr) == -1)
          {
            exerrval = ncerr;
            sprintf(errmsg,
                "Error: failed to get info record data in file id %d", exoid);
            ex_err("ex_get_info",errmsg,exerrval);
            return (EX_FATAL);
          }

        }
/* delete trailing blanks */
        --ptr;
        while ( --ptr >= info[i] && *ptr == ' ' );
        *(++ptr) = '\0';
      }

   }

   return (EX_NOERR);

}
예제 #29
0
int ex_cvt_nodes_to_sides(int exoid,
                          void_int *num_elem_per_set,
                          void_int *num_nodes_per_set,
                          void_int *side_sets_elem_index, /* unused */
                          void_int *side_sets_node_index, /* unused */
                          void_int *side_sets_elem_list,
                          void_int *side_sets_node_list,
                          void_int *side_sets_side_list)
{
  size_t i, j, k, n;
  int  num_side_sets, num_elem_blks;
  int64_t  tot_num_elem = 0, tot_num_ss_elem = 0, elem_num = 0, ndim;
  void_int *elem_blk_ids = NULL;
  void_int *connect = NULL;
  void_int *ss_elem_ndx = NULL;
  void_int *ss_elem_node_ndx = NULL;
  void_int *ss_parm_ndx = NULL;
  size_t elem_ctr, node_ctr, elem_num_pos;
  int num_nodes_per_elem, num_node_per_side;

  int *same_elem_type = NULL;
  int el_type = 0;

  int int_size;
  int ids_size;

  struct elem_blk_parm  *elem_blk_parms = NULL;

  int err_stat = EX_NOERR;

  /* node to side translation tables -
     These tables are used to look up the side number based on the
     first and second node in the side/face list. The side node order
     is found in the original Exodus document, SAND87-2997. The element
     node order is found in the ExodusII document, SAND92-2137. These
     tables were generated by following the right-hand rule for determining
     the outward normal. Note: Only the more complex 3-D shapes require
     these tables, the simple shapes are trivial - the first node found
     is also the side number.
  */

  /*    1     2   3    4                                          node 1 */
  static int shell_table[2][8]  = {
    {2,4, 3,1, 4,2, 1,3},                                    /* node 2 */
    {1,2, 1,2, 1,2, 1,2}                                     /* side # */
  };

  /*    1     2   3    4                                          node 1 */
  static int shell_edge_table[2][8]  = {
    {2,4, 3,1, 4,2, 1,3},                                    /* node 2 */
    {3,6, 4,3, 5,4, 6,5}                                     /* side # */
  };

  /*    1     2   3                                               node 1 */
  static int trishell_table[2][6]  = {
    {2,3, 3,1, 1,2},                                         /* node 2 */
    {1,2, 1,2, 1,2}                                          /* side # */
  };

  /*     1      2      3      4                                   node 1 */
  static int tetra_table[2][12]  = {
    {2,3,4, 1,3,4, 4,1,2, 1,2,3},                            /* node 2 */
    {1,4,3, 4,2,1, 2,3,4, 1,2,3}                             /* side # */
  };

#if 0
  static int wedge_table[2][18]  = {
    /*     1      2      3      4      5      6                     node 1 */
    {2,4,3, 5,1,3, 6,1,2, 1,6,5, 6,2,4, 4,3,5},              /* node 2 */
    {1,3,4, 1,4,2, 2,3,4, 1,3,5, 5,2,1, 5,3,2}               /* side # */
  };
#endif

  static int hex_table[2][24]  = {
    /*     1      2      3      4      5      6      7      8       node 1 */
    {4,2,5, 1,3,6, 7,4,2, 3,1,8, 6,8,1, 5,2,7, 8,6,3, 7,5,4},/* node 2 */
    {5,1,4, 5,2,1, 2,3,5, 5,4,3, 6,4,1, 1,2,6, 6,2,3, 3,6,4} /* side # */
  };

  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* first check if any side sets are specified */
  /* inquire how many side sets have been stored */

  num_side_sets = ex_inquire_int(exoid, EX_INQ_SIDE_SETS);
  if (num_side_sets < 0) {
    sprintf(errmsg,
	    "Error: failed to get number of side sets in file id %d",exoid);
    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
    return(EX_FATAL);
  }

  if (num_side_sets == 0)
    {
      sprintf(errmsg,
	      "Warning: no side sets defined in file id %d",exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,EX_WARN);
      return(EX_WARN);
    }

  num_elem_blks = ex_inquire_int(exoid, EX_INQ_ELEM_BLK);
  if (num_elem_blks < 0) {
    sprintf(errmsg,
	    "Error: failed to get number of element blocks in file id %d",exoid);
    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
    return(EX_FATAL);
  }

  tot_num_elem = ex_inquire_int(exoid, EX_INQ_ELEM);
  if (tot_num_elem < 0) {
    sprintf(errmsg,
	    "Error: failed to get total number of elements in file id %d",exoid);
    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
    return(EX_FATAL);
  }

  /* get the dimensionality of the coordinates;  this is necessary to
     distinguish between 2d TRIs and 3d TRIs */
  ndim = ex_inquire_int(exoid, EX_INQ_DIM);

  int_size = sizeof(int);
  if (ex_int64_status(exoid) & EX_BULK_INT64_API)
    int_size = sizeof(int64_t);

  /* First count up # of elements in the side sets*/
  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    for (i=0;i<num_side_sets;i++)
      tot_num_ss_elem += ((int64_t*)num_elem_per_set)[i];
  } else {
    for (i=0;i<num_side_sets;i++)
      tot_num_ss_elem += ((int*)num_elem_per_set)[i];
  }

  /* Allocate space for the ss element index array */
  if (!(ss_elem_ndx=malloc(tot_num_ss_elem*int_size)))
    {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate space for side set elem sort array for file id %d",
	      exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }

  if (int_size == sizeof(int64_t)) {
    /* Sort side set element list into index array  - non-destructive */
    int64_t *elems = (int64_t*)ss_elem_ndx;
    for (i=0;i<tot_num_ss_elem;i++) {
      elems[i] = i; /* init index array to current position */
    }
    ex_iqsort64(side_sets_elem_list, elems, tot_num_ss_elem);
  } else {
    /* Sort side set element list into index array  - non-destructive */
    int *elems = (int*)ss_elem_ndx;
    for (i=0;i<tot_num_ss_elem;i++) {
      elems[i] = i; /* init index array to current position */
    }
    ex_iqsort(side_sets_elem_list, elems,tot_num_ss_elem);
  }

  /* Allocate space for the element block ids */
  ids_size = sizeof(int);
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    ids_size = sizeof(int64_t);
  }

  if (!(elem_blk_ids=malloc(num_elem_blks*ids_size)))
    {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate space for element block ids for file id %d",
	      exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }

  if (ex_get_elem_blk_ids(exoid, elem_blk_ids))
    {
      sprintf(errmsg,
	      "Error: failed to get element block ids in file id %d",
	      exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,EX_MSG);
      err_stat = EX_FATAL;
      goto cleanup;
    }

  /* Allocate space for the element block params */
  if (!(elem_blk_parms=malloc(num_elem_blks*sizeof(struct elem_blk_parm))))
    {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate space for element block params for file id %d",
	      exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }
  elem_ctr = 0;
  for (i=0; i<num_elem_blks; i++)
    {
      ex_entity_id id;
      if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	id = ((int64_t*)elem_blk_ids)[i];
      } else {
	id = ((int*)elem_blk_ids)[i];
      }

      err_stat = ex_int_get_block_param(exoid, id, ndim, &elem_blk_parms[i]);
      if (err_stat != EX_NOERR) {
	goto cleanup;
      }

      elem_ctr += elem_blk_parms[i].num_elem_in_blk;
      elem_blk_parms[i].elem_ctr = elem_ctr;      /* save elem number max */
    }


  /* Allocate space for the ss element to element block parameter index array */
  if (!(ss_parm_ndx=malloc(tot_num_ss_elem*int_size)))
    {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate space for side set elem parms index for file id %d",
	      exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }


  /* Allocate space for the ss element to node list index array */
  if (!(ss_elem_node_ndx=malloc((tot_num_ss_elem+1)*int_size)))
    {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate space for side set elem to node index for file id %d",
	      exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }

  /* determine if each side set has uniform element types; this will
     be used to help determine the stride through the node list
  */

  /* Allocate space for same element type flag array*/
  if (!(same_elem_type=malloc(num_side_sets*sizeof(int))))
    {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate space for element type flag array for file id %d",
	      exoid);
      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
      err_stat = EX_FATAL;
      goto cleanup;
    }


  same_elem_type[0] = EX_TRUE;
  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    elem_ctr = ((int64_t*)num_elem_per_set)[0];
    for (i=0,k=0;i<tot_num_ss_elem;i++) {
      int64_t elem = ((int64_t*)side_sets_elem_list)[i];
      for (j=0; j<num_elem_blks; j++) {
	if (elem <= elem_blk_parms[j].elem_ctr) break;
      }

      if (j >= num_elem_blks) {
	exerrval = EX_INTERNAL;
	sprintf(errmsg,
		"Error: internal logic error for file id %d",
		exoid);
	ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	err_stat = EX_FATAL;
	goto cleanup;
      }
      
      if (i==0) {
	el_type = elem_blk_parms[j].elem_type_val;
      }

      /* determine which side set this element is in; assign to kth side set */
      if (i >= elem_ctr) {
	elem_ctr += ((int64_t*)num_elem_per_set)[++k];

	el_type = elem_blk_parms[j].elem_type_val;
	same_elem_type[k] = EX_TRUE;
      }

      if (el_type != elem_blk_parms[j].elem_type_val) same_elem_type[k] = EX_FALSE;
    }

    /* Build side set element to node list index and side set element
       parameter index.
    */
    node_ctr = 0;
    elem_ctr = ((int64_t*)num_elem_per_set)[0];
    for (i=0,k=0;i<tot_num_ss_elem;i++) {
      int64_t elem = ((int64_t*)side_sets_elem_list)[i];

      for (j=0; j<num_elem_blks; j++) {
	if (elem <= elem_blk_parms[j].elem_ctr) {
	  break;
	}
      }
      if (j >= num_elem_blks) {
	exerrval = EX_INTERNAL;
	sprintf(errmsg,
		"Error: internal logic error for file id %d",
		exoid);
	ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	err_stat = EX_FATAL;
	goto cleanup;
      }

      ((int64_t*)ss_parm_ndx)[i] = j;     /* assign parameter block index */
      ((int64_t*)ss_elem_node_ndx)[i] = node_ctr;     /* assign node list index */

      /* determine which side set this element is in; assign to kth side set */
      if (i >= elem_ctr) {
	/* skip over NULL side sets */
	while ( ((int64_t*)num_elem_per_set)[++k] == 0);
	elem_ctr += ((int64_t*)num_elem_per_set)[k];
      }

      /* determine number of nodes per side */
      if (((((int64_t*)num_nodes_per_set)[k] % ((int64_t*)num_elem_per_set)[k]) == 0) &&
	  (same_elem_type[k] == EX_TRUE)) {  /* all side set elements are same type */
	node_ctr += ((int64_t*)num_nodes_per_set)[k] /((int64_t*)num_elem_per_set)[k];
      } else {
	node_ctr += elem_blk_parms[j].num_nodes_per_side[0];
      }
    }
    ((int64_t*)ss_elem_node_ndx)[i] = node_ctr;       /* assign node list index */
  } else {
    elem_ctr = ((int*)num_elem_per_set)[0];
    for (i=0,k=0;i<tot_num_ss_elem;i++) {
      int elem = ((int*)side_sets_elem_list)[i];

      for (j=0; j<num_elem_blks; j++) {
	if (elem <= elem_blk_parms[j].elem_ctr) break;
      }

      if (j >= num_elem_blks) {
	exerrval = EX_INTERNAL;
	sprintf(errmsg,
		"Error: internal logic error for file id %d",
		exoid);
	ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	err_stat = EX_FATAL;
	goto cleanup;
      }

      if (i==0) {
	el_type = elem_blk_parms[j].elem_type_val;
      }

      /* determine which side set this element is in; assign to kth side set */
      if (i >= elem_ctr) {
	elem_ctr += ((int*)num_elem_per_set)[++k];

	el_type = elem_blk_parms[j].elem_type_val;
	same_elem_type[k] = EX_TRUE;
      }

      if (el_type != elem_blk_parms[j].elem_type_val) same_elem_type[k] = EX_FALSE;
    }

    /* Build side set element to node list index and side set element
       parameter index.
    */
    node_ctr = 0;
    elem_ctr = ((int*)num_elem_per_set)[0];
    for (i=0,k=0;i<tot_num_ss_elem;i++) {
      int elem = ((int*)side_sets_elem_list)[i];

      for (j=0; j<num_elem_blks; j++) {
	if (elem <= elem_blk_parms[j].elem_ctr) {
	  break;
	}
      }
      if (j >= num_elem_blks) {
	exerrval = EX_INTERNAL;
	sprintf(errmsg,
		"Error: internal logic error for file id %d",
		exoid);
	ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	err_stat = EX_FATAL;
	goto cleanup;
      }

      ((int*)ss_parm_ndx)[i] = j;     /* assign parameter block index */
      ((int*)ss_elem_node_ndx)[i] = node_ctr;     /* assign node list index */

      /* determine which side set this element is in; assign to kth side set */
      if (i >= elem_ctr) {
	/* skip over NULL side sets */
	while ( ((int*)num_elem_per_set)[++k] == 0);
	elem_ctr += ((int*)num_elem_per_set)[k];
      }

      /* determine number of nodes per side */
      if (((((int*)num_nodes_per_set)[k] % ((int*)num_elem_per_set)[k]) == 0) &&
	  (same_elem_type[k])) {  /* all side set elements are same type */
	node_ctr += ((int*)num_nodes_per_set)[k] /((int*)num_elem_per_set)[k];
      } else {
	node_ctr += elem_blk_parms[j].num_nodes_per_side[0];
      }
    }
    ((int*)ss_elem_node_ndx)[i] = node_ctr;       /* assign node list index */
  }

  /* All setup, ready to go ... */

  elem_ctr=0;

  for (j=0; j < tot_num_ss_elem; j++)
    {
      int64_t elem;
      int64_t idx;
      int64_t ss_node0, ss_node1;
      int64_t p_ndx;
      if (int_size == sizeof(int64_t)) {
	idx =  ((int64_t*)ss_elem_ndx)[j];
	elem = ((int64_t*)side_sets_elem_list)[idx];
	ss_node0 = ((int64_t*)side_sets_node_list)[((int64_t*)ss_elem_node_ndx)[idx]];
	ss_node1 = ((int64_t*)side_sets_node_list)[((int64_t*)ss_elem_node_ndx)[idx]+1];
	p_ndx    = ((int64_t*)ss_parm_ndx)[idx];
      } else {
	idx =  ((int*)ss_elem_ndx)[j];
	elem = ((int*)side_sets_elem_list)[idx];
	ss_node0 = ((int*)side_sets_node_list)[((int*)ss_elem_node_ndx)[idx]];
	ss_node1 = ((int*)side_sets_node_list)[((int*)ss_elem_node_ndx)[idx]+1];
	p_ndx    = ((int*)ss_parm_ndx)[idx];
      }
      elem_num = elem-1;

      if (elem > elem_ctr)
	{
	  /* release connectivity array space and get next one */
	  if (elem_ctr > 0)
	    ex_safe_free(connect);

	  /* Allocate space for the connectivity array for new element block */
	  if (!(connect= malloc(elem_blk_parms[p_ndx].num_elem_in_blk*
				elem_blk_parms[p_ndx].num_nodes_per_elem*
				int_size)))
	    {
	      exerrval = EX_MEMFAIL;
	      sprintf(errmsg,
		      "Error: failed to allocate space for connectivity array for file id %d",
		      exoid);
	      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	      err_stat = EX_FATAL;
	      goto cleanup;
	    }

	  /* get connectivity array */
	  if (ex_get_elem_conn(
			       exoid,
			       elem_blk_parms[p_ndx].elem_blk_id,
			       connect) == -1)
	    {
	      sprintf(errmsg,
		      "Error: failed to get connectivity array for elem blk %"PRId64" for file id %d",
		      elem_blk_parms[p_ndx].elem_blk_id,
		      exoid);
	      ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	      err_stat = EX_FATAL;
	      goto cleanup;
	    }
	  elem_ctr = elem_blk_parms[p_ndx].elem_ctr;
	}
      /*  For the first node of each side in side set, using a linear search
	  (of up to num_nodes_per_elem) of the connectivity array,
	  locate the node position in the element. The first node position
	  and the second node position are used with a element type specific
	  table to determine the side. */

      if (connect == NULL) {
	sprintf(errmsg,
		"Error: logic error. Connect pointer is null for elem blk %"PRId64" for file id %d",
		elem_blk_parms[p_ndx].elem_blk_id,
		exoid);
	ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	err_stat = EX_FATAL;
	goto cleanup;
      }

      /* calculate the relative element number position in it's block*/
      elem_num_pos = elem_num -
	(elem_blk_parms[p_ndx].elem_ctr -
	 elem_blk_parms[p_ndx].num_elem_in_blk);
      /* calculate the beginning of the node list for this element by
         using the ss_elem_node_ndx index into the side_sets_node_index
         and adding the element number position * number of nodes per elem */

      num_nodes_per_elem = elem_blk_parms[p_ndx].num_nodes_per_elem;

      for (n=0; n<num_nodes_per_elem; n++) {
	/* find node in connectivity array that matches first node in side set */
	if ( ((int_size == sizeof(int64_t)) &&
	      (ss_node0 == ((int64_t*)connect)[num_nodes_per_elem*(elem_num_pos)+n])) ||
	     ((int_size == sizeof(int)) &&
	      (ss_node0 == ((int*)connect)[num_nodes_per_elem*(elem_num_pos)+n])) ) {
	  switch (elem_blk_parms[p_ndx].elem_type_val)
	    {
	    case EX_EL_CIRCLE:
	    case EX_EL_SPHERE:
	      {
		/* simple case: 1st node number is same as side # */
		put_side(side_sets_side_list,idx, n+1, int_size);
		break;
	      }
	    case EX_EL_QUAD:
	    case EX_EL_TRIANGLE:
	    case EX_EL_TRUSS:
	    case EX_EL_BEAM:
	      {
		/* simple case: 1st node number is same as side # */
		put_side(side_sets_side_list,idx,n+1, int_size);
		break;
	      }
	    case EX_EL_TRISHELL:
	      {
		/* use table to find which node to compare to next */
		if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					 (trishell_table[0][2*n]-1),int_size))
		  {
		    /* Assume only front or back, no edges... */
		    put_side(side_sets_side_list,idx, trishell_table[1][2*n],int_size);
		  }
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (trishell_table[0][2*n+1]-1),int_size))
		  {
		    /* Assume only front or back, no edges... */
		    put_side(side_sets_side_list,idx,trishell_table[1][2*n+1],int_size);
		  }
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (trishell_table[0][2*n+2]-1),int_size))
		  {
		    /* Assume only front or back, no edges... */
		    put_side(side_sets_side_list,idx,trishell_table[1][2*n+2],int_size);
		  }
		else
		  {
		    exerrval = EX_BADPARAM;
		    sprintf(errmsg,
			    "Error: failed to find TRIANGULAR SHELL element %"PRId64", node %"PRId64" in connectivity array %"PRId64" for file id %d",
			    elem_num+1,
			    ss_node1,
			    elem_blk_parms[p_ndx].elem_blk_id,
			    exoid);
		    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
		    err_stat = EX_FATAL;
		    goto cleanup;
		  }
		break;

	      }
	    case EX_EL_SHELL:
	      {
		/* use table to find which node to compare to next */

		if (ex_int64_status(exoid) & EX_BULK_INT64_API)
		  num_node_per_side = ((int64_t*)ss_elem_node_ndx)[idx+1] - ((int64_t*)ss_elem_node_ndx)[idx];
		else
		  num_node_per_side = ((int*)ss_elem_node_ndx)[idx+1] - ((int*)ss_elem_node_ndx)[idx];


		if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					 (shell_table[0][2*n]-1),int_size))
		  {
		    if (num_node_per_side >= 4)
		      /* 4- or 8-node side (front or back face) */
		      put_side(side_sets_side_list,idx,shell_table[1][2*n],int_size);
		    else
		      /* 2- or 3-node side (edge of shell) */
		      put_side(side_sets_side_list,idx,shell_edge_table[1][2*n],int_size);
		  }
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (shell_table[0][2*n+1]-1),int_size))
		  {
		    if (num_node_per_side >= 4)
		      /* 4- or 8-node side (front or back face) */
		      put_side(side_sets_side_list,idx,shell_table[1][2*n+1],int_size);
		    else
		      /* 2- or 3-node side (edge of shell) */
		      put_side(side_sets_side_list,idx,shell_edge_table[1][2*n+1],int_size);
		  }
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (shell_table[0][2*n+2]-1),int_size))
		  {
		    if (num_node_per_side >= 4)
		      /* 4- or 8-node side (front or back face) */
		      put_side(side_sets_side_list,idx,shell_table[1][2*n+2],int_size);
		    else
		      /* 2- or 3-node side (edge of shell) */
		      put_side(side_sets_side_list,idx,shell_edge_table[1][2*n+2],int_size);
		  }
		else
		  {
		    exerrval = EX_BADPARAM;
		    sprintf(errmsg,
			    "Error: failed to find SHELL element %"PRId64", node %"PRId64" in connectivity array %"PRId64" for file id %d",
			    elem_num+1,
			    ss_node1,
			    elem_blk_parms[p_ndx].elem_blk_id,
			    exoid);
		    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
		    err_stat = EX_FATAL;
		    goto cleanup;
		  }
		break;

	      }
	    case EX_EL_HEX:
	      {
		/* use table to find which node to compare to next */

		if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					 (hex_table[0][3*n]-1),int_size))
		  put_side(side_sets_side_list,idx,hex_table[1][3*n],int_size);
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (hex_table[0][3*n+1]-1),int_size))
		  put_side(side_sets_side_list,idx,hex_table[1][3*n+1],int_size);
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (hex_table[0][3*n+2]-1),int_size))
		  put_side(side_sets_side_list,idx,hex_table[1][3*n+2],int_size);
		else
		  {
		    exerrval = EX_BADPARAM;
		    sprintf(errmsg,
			    "Error: failed to find HEX element %"PRId64", node %"PRId64" in connectivity array %"PRId64" for file id %d",
			    elem_num+1,
			    ss_node1,
			    elem_blk_parms[p_ndx].elem_blk_id,
			    exoid);
		    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
		    err_stat = EX_FATAL;
		    goto cleanup;
		  }
		break;
	      }
	    case EX_EL_TETRA:
	      {
		/* use table to find which node to compare to next */

		if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					 (tetra_table[0][3*n]-1),int_size))
		  put_side(side_sets_side_list,idx,tetra_table[1][3*n],int_size);
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (tetra_table[0][3*n+1]-1),int_size))
		  put_side(side_sets_side_list,idx,tetra_table[1][3*n+1],int_size);
		else if (ss_node1 == get_node(connect,num_nodes_per_elem*(elem_num_pos)+
					      (tetra_table[0][3*n+2]-1),int_size))
		  put_side(side_sets_side_list,idx,tetra_table[1][3*n+2],int_size);
		else
		  {
		    exerrval = EX_BADPARAM;
		    sprintf(errmsg,
			    "Error: failed to find TETRA element %"PRId64", node %"PRId64" in connectivity array %"PRId64" for file id %d",
			    elem_num+1,
			    ss_node1,
			    elem_blk_parms[p_ndx].elem_blk_id,
			    exoid);
		    ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
		    err_stat = EX_FATAL;
		    goto cleanup;
		  }
		break;
	      }
	    case EX_EL_PYRAMID:
	      {
		/* NOTE: PYRAMID elements in side set node lists are currently not supported */
		exerrval = EX_BADPARAM;
		sprintf(errmsg,
			"ERROR: unsupported PYRAMID element found in side set node list in file id %d",
			exoid);
		ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
		err_stat = EX_FATAL;
		goto cleanup;
	      }
	    case EX_EL_WEDGE:
	      {
		/* NOTE: WEDGE elements in side set node lists are currently not supported */
		exerrval = EX_BADPARAM;
		sprintf(errmsg,
			"ERROR: unsupported WEDGE element found in side set node list in file id %d",
			exoid);
		ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
		err_stat = EX_FATAL;
		goto cleanup;
	      }
	    default:
	      {
		exerrval = EX_BADPARAM;
		sprintf(errmsg,
			"Error: %s is an unsupported element type",
			elem_blk_parms[p_ndx].elem_type);
		ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
		err_stat = EX_FATAL;
		goto cleanup;
	      }
	    }
	  break; /* done with this element */
	}
      }
      if (n >= num_nodes_per_elem) /* did we find the node? */
	{
	  exerrval = EX_BADPARAM;
	  sprintf(errmsg,
		  "Error: failed to find element %"PRId64", node %"PRId64" in element block %"PRId64" for file id %d",
		  elem_num+1, ss_node0,
		  elem_blk_parms[p_ndx].elem_blk_id,
		  exoid);
	  ex_err("ex_cvt_nodes_to_sides",errmsg,exerrval);
	  err_stat = EX_FATAL;
	  goto cleanup;
	}

    }

  /* All done: release connectivity array space, element block ids array,
     element block parameters array, and side set element index array */
 cleanup:
  ex_safe_free(connect);
  ex_safe_free(ss_elem_node_ndx);
  ex_safe_free(ss_parm_ndx);
  ex_safe_free(elem_blk_parms);
  ex_safe_free(elem_blk_ids);
  ex_safe_free(ss_elem_ndx);
  ex_safe_free(same_elem_type);
  
  return (err_stat);
}
예제 #30
0
파일: expnam.c 프로젝트: 151706061/VTK
int ex_put_name (int   exoid,
     ex_entity_type obj_type,
     int   entity_id,
     const char *name)
{
  int status;
  int varid, ent_ndx; 
  char errmsg[MAX_ERR_LENGTH];
  const char *routine = "ex_put_name";
  const char *vobj;
   
  exerrval = 0; /* clear error code */

  switch(obj_type) {
  case EX_EDGE_BLOCK:
    vobj = VAR_NAME_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    vobj = VAR_NAME_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    vobj = VAR_NAME_EL_BLK;
    break;
  case EX_NODE_SET:
    vobj = VAR_NAME_NS;
    break;
  case EX_SIDE_SET:
    vobj = VAR_NAME_SS;
    break;
  case EX_EDGE_SET:
    vobj = VAR_NAME_ES;
    break;
  case EX_FACE_SET:
    vobj = VAR_NAME_FS;
    break;
  case EX_ELEM_SET:
    vobj = VAR_NAME_ELS;
    break;
  case EX_NODE_MAP:
    vobj = VAR_NAME_NM;
    break;
  case EX_EDGE_MAP:
    vobj = VAR_NAME_EDM;
    break;
  case EX_FACE_MAP:
    vobj = VAR_NAME_FAM;
    break;
  case EX_ELEM_MAP:
    vobj = VAR_NAME_EM;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
      "Error: Invalid type specified in file id %d", exoid);
    ex_err(routine,errmsg,exerrval);
    return(EX_FATAL);
  }
   
  if ((status = nc_inq_varid(exoid, vobj, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to locate %s names in file id %d",
      ex_name_of_object(obj_type), exoid);
    ex_err(routine,errmsg,exerrval);
    return (EX_FATAL);
  }

  ent_ndx = ex_id_lkup(exoid, obj_type, entity_id);

  /* 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 */
  status = ex_put_name_internal(exoid, varid, ent_ndx-1, name, obj_type, "", routine);

  return(status);
}