Example #1
0
int ex_put_block_params( int         exoid,
			 size_t      block_count,
			 const struct ex_block *blocks)
{
  size_t i;
  int conn_int_type;
  int status;
  int arbitrary_polyhedra = 0; /* 1 if block is arbitrary 2d polyhedra type; 2 if 3d polyhedra */
  int att_name_varid = -1;
  int varid, dimid, dims[2], blk_id_ndx, blk_stat, strdim;
  size_t start[2];
  size_t num_blk;
  int cur_num_blk, numblkdim, numattrdim;
  int nnodperentdim = -1;
  int nedgperentdim = -1;
  int nfacperentdim = -1;
  int connid;
  int npeid;
  char errmsg[MAX_ERR_LENGTH];
  char entity_type1[5];
  char entity_type2[5];
  int* blocks_to_define = NULL;
  const char* dnumblk = NULL;
  const char* vblkids = NULL;
  const char* vblksta = NULL;
  const char* vnodcon = NULL;
  const char* vnpecnt = NULL;
  const char* vedgcon = NULL;
  const char* vfaccon = NULL;
  const char* vconn   = NULL;
  const char* vattnam = NULL;
  const char* vblkatt = NULL;
  const char* dneblk  = NULL;
  const char* dnape   = NULL;
  const char* dnnpe   = NULL;
  const char* dnepe   = NULL;
  const char* dnfpe   = NULL;

  exerrval  = 0; /* clear error code */

  blocks_to_define = malloc(block_count*sizeof(int));

  for (i=0; i < block_count; i++) {
    switch (blocks[i].type) {
    case EX_EDGE_BLOCK:
      dnumblk = DIM_NUM_ED_BLK;
      vblkids = VAR_ID_ED_BLK;
      vblksta = VAR_STAT_ED_BLK;
      break;
    case EX_FACE_BLOCK:
      dnumblk = DIM_NUM_FA_BLK;
      vblkids = VAR_ID_FA_BLK;
      vblksta = VAR_STAT_FA_BLK;
      break;
    case EX_ELEM_BLOCK:
      dnumblk = DIM_NUM_EL_BLK;
      vblkids = VAR_ID_EL_BLK;
      vblksta = VAR_STAT_EL_BLK;
      break;
    default:
      exerrval = EX_BADPARAM;
      sprintf( errmsg, "Error: Bad block type (%d) specified for entry %d file id %d",
	       blocks[i].type, (int)i, exoid );
      ex_err( "ex_put_block_params", errmsg, exerrval );
      free(blocks_to_define);
      return (EX_FATAL);
    }

    /* first check if any blocks of that type are specified */
    if ((status = ex_get_dimension(exoid, dnumblk, ex_name_of_object(blocks[i].type),
				   &num_blk, &dimid, "ex_put_block_params")) != NC_NOERR) {
      sprintf(errmsg,
	      "Error: No %ss defined in file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return EX_FATAL;
    }

    /* Next: Make sure that there are not any duplicate block ids 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 ((status = nc_inq_varid(exoid, vblkids, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate %s ids in file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return EX_FATAL;
    }

    ex_id_lkup(exoid,blocks[i].type,blocks[i].id); /* Error value used, but don't need return value */
    if (exerrval != EX_LOOKUPFAIL) {   /* found the element block id */
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: %s id %"PRId64" already exists in file id %d",
	      ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      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.
    */
    cur_num_blk=ex_get_file_item(exoid, ex_get_counter_list(blocks[i].type));
    if (cur_num_blk >= (int)num_blk) {
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: exceeded number of %ss (%d) defined in file id %d",
	      ex_name_of_object(blocks[i].type), (int)num_blk,exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }

    /*   NOTE: ex_inc_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, ex_get_counter_list(blocks[i].type));
    start[0] = cur_num_blk;

    /* write out block id to previously defined id array variable*/
    status = nc_put_var1_longlong(exoid, varid, start, (long long*)&blocks[i].id);

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store %s id to file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }

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

    if (blocks[i].num_entry == 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 EX_EX_TRUE */

    if ((status = nc_inq_varid (exoid, vblksta, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate %s status in file id %d",
	      ex_name_of_object(blocks[i].type), exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }

    if ((status = nc_put_var1_int(exoid, varid, start, &blk_stat)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store %s id %"PRId64" status to file id %d",
	      ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      free(blocks_to_define);
      return (EX_FATAL);
    }
  }

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


  for (i=0; i < block_count; i++) {
    if (blocks[i].num_entry == 0) {/* Is this a NULL element block? */
      continue;
    }

    blk_id_ndx = blocks_to_define[i];

    switch (blocks[i].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);
      vnpecnt = VAR_FBEPEC(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);
      vnpecnt = VAR_EBEPEC(blk_id_ndx);
      vedgcon = VAR_ECONN(blk_id_ndx);
      vfaccon = VAR_FCONN(blk_id_ndx);
      break;
    default:
      goto error_ret;
    }

    /* define some dimensions and variables*/
    if ((status = nc_def_dim(exoid,dneblk,blocks[i].num_entry, &numblkdim )) != NC_NOERR) {
      if (status == NC_ENAMEINUSE) {        /* duplicate entry */
	exerrval = status;
	sprintf(errmsg,
		"Error: %s %"PRId64" already defined in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
      } else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of entities/block for %s %"PRId64" file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
      }
      goto error_ret;         /* exit define mode and return */
    }

    if ( dnnpe && blocks[i].num_nodes_per_entry > 0) {
      /* A nfaced block would not have any nodes defined... */
      if ((status = nc_def_dim(exoid,dnnpe,blocks[i].num_nodes_per_entry, &nnodperentdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of nodes/entity for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    if (dnepe && blocks[i].num_edges_per_entry > 0 ) {
      if ((status = nc_def_dim (exoid,dnepe,blocks[i].num_edges_per_entry, &nedgperentdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of edges/entity for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    if ( dnfpe && blocks[i].num_faces_per_entry > 0 ) {
      if ((status = nc_def_dim(exoid,dnfpe,blocks[i].num_faces_per_entry, &nfacperentdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of faces/entity for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    /* element attribute array */
    if (blocks[i].num_attribute > 0) {

      if ((status = nc_def_dim(exoid, dnape, blocks[i].num_attribute, &numattrdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of attributes in %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }

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

      if ((status = nc_def_var(exoid, vblkatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error:  failed to define attributes for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      ex_compress_variable(exoid, varid, 2);

      /* inquire previously defined dimensions  */
      if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get string length in file id %d",exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;
      }
     
      /* Attribute names... */
      dims[0] = numattrdim;
      dims[1] = strdim;
	    
      if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &att_name_varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define %s attribute name array in file id %d",
		ex_name_of_object(blocks[i].type), exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    }

    conn_int_type = NC_INT;
    if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
      conn_int_type = NC_INT64;
    }

    /* See if storing an 'nsided' element block (arbitrary 2d polyhedra or super element) */
    if (strlen(blocks[i].topology) >= 3) {
      if ((blocks[i].topology[0] == 'n' || blocks[i].topology[0] == 'N') &&
	  (blocks[i].topology[1] == 's' || blocks[i].topology[1] == 'S') &&
	  (blocks[i].topology[2] == 'i' || blocks[i].topology[2] == 'I'))
	arbitrary_polyhedra = 1;
      else if ((blocks[i].topology[0] == 'n' || blocks[i].topology[0] == 'N') &&
	       (blocks[i].topology[1] == 'f' || blocks[i].topology[1] == 'F') &&
	       (blocks[i].topology[2] == 'a' || blocks[i].topology[2] == 'A'))
	/* If a FACE_BLOCK, then we are dealing with the faces of the nfaced blocks[i]. */
	arbitrary_polyhedra = blocks[i].type == EX_FACE_BLOCK ? 1 : 2;
    }

    /* element connectivity array */
    if (arbitrary_polyhedra > 0) {
      if (blocks[i].type != EX_FACE_BLOCK && blocks[i].type != EX_ELEM_BLOCK) {
	exerrval = EX_BADPARAM;
	sprintf( errmsg, "Error: Bad block type (%d) for nsided/nfaced block in file id %d",
		 blocks[i].type, exoid );
	ex_err( "ex_put_block_params", errmsg, exerrval );
	goto error_ret;
      }

      if (arbitrary_polyhedra == 1) {
	dims[0] = nnodperentdim;
	vconn = vnodcon;

	/* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/
	strcpy(entity_type1, "NODE");
	if (blocks[i].type == EX_ELEM_BLOCK)
	  strcpy(entity_type2, "ELEM");
	else
	  strcpy(entity_type2, "FACE");
      } else if (arbitrary_polyhedra == 2) {
	dims[0] = nfacperentdim;
	vconn = vfaccon;

	/* store entity types as attribute of npeid variable -- node/elem, node/face, face/elem*/
	strcpy(entity_type1, "FACE");
	strcpy(entity_type2, "ELEM");
      }

      if ((status = nc_def_var(exoid, vconn, conn_int_type, 1, dims, &connid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to create connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    
      /* element face-per-element or node-per-element count array */
      dims[0] = numblkdim;
    
      if ((status = nc_def_var(exoid, vnpecnt, conn_int_type, 1, dims, &npeid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to create face- or node- per-entity count array for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }

      if ((status = nc_put_att_text(exoid, npeid, "entity_type1", strlen(entity_type1)+1,
				    entity_type1)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store entity type attribute text for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      if ((status = nc_put_att_text(exoid, npeid, "entity_type2", strlen(entity_type2)+1,
				    entity_type2)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store entity type attribute text for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id, exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
    } else {
      /* "Normal" (non-polyhedra) element block type */
      dims[0] = numblkdim;
      dims[1] = nnodperentdim;
    
      if ((status = nc_def_var(exoid, vnodcon, conn_int_type, 2, dims, &connid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to create connectivity array for %s %"PRId64" in file id %d",
		ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	ex_err("ex_put_block_params",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      ex_compress_variable(exoid, connid, 1);
    }
    /* store element type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(blocks[i].topology)+1, 
				  blocks[i].topology)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store %s type name %s in file id %d",
	      ex_name_of_object(blocks[i].type), blocks[i].topology,exoid);
      ex_err("ex_put_block_params",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    if (arbitrary_polyhedra == 0) {
      if (vedgcon && blocks[i].num_edges_per_entry ) {
	dims[0] = numblkdim;
	dims[1] = nedgperentdim;
      
	if ((status = nc_def_var(exoid, vedgcon, conn_int_type, 2, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to create edge connectivity array for %s %"PRId64" in file id %d",
		  ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	  ex_err("ex_put_block_params",errmsg,exerrval);
	  goto error_ret;         /* exit define mode and return */
	}
      }
    
      if ( vfaccon && blocks[i].num_faces_per_entry ) {
	dims[0] = numblkdim;
	dims[1] = nfacperentdim;
      
	if ((status = nc_def_var(exoid, vfaccon, conn_int_type, 2, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to create face connectivity array for %s %"PRId64" in file id %d",
		  ex_name_of_object(blocks[i].type), blocks[i].id,exoid);
	  ex_err("ex_put_block_params",errmsg,exerrval);
	  goto error_ret;         /* exit define mode and return */
	}
      }
    }
  }

  free(blocks_to_define);

  /* leave define mode  */
  if ((exerrval=nc_enddef (exoid)) != NC_NOERR) {
    sprintf(errmsg,
	    "Error: failed to complete %s definition in file id %d", 
	    ex_name_of_object(blocks[i].type), exoid);
    ex_err("ex_put_block_params",errmsg,exerrval);
    return (EX_FATAL);
  }


  for (i=0; i < block_count; i++) {
    switch (blocks[i].type) {
    case EX_EDGE_BLOCK:
      vblkids = VAR_ID_ED_BLK;
      break;
    case EX_FACE_BLOCK:
      vblkids = VAR_ID_FA_BLK;
      break;
    case EX_ELEM_BLOCK:
      vblkids = VAR_ID_EL_BLK;
      break;
    default:
      return (EX_FATAL); /* should have been handled earlier; quiet compiler here */
    }

    nc_inq_varid(exoid, vblkids, &att_name_varid);

    if (blocks[i].num_attribute > 0 && att_name_varid >= 0) {
      /* Output a dummy empty attribute name in case client code doesn't
	 write anything; avoids corruption in some cases.
      */
      size_t  count[2];
      char *text = "";
      size_t j;

      count[0] = 1;
      start[1] = 0;
      count[1] = strlen(text)+1;
  
      for (j = 0; j < blocks[i].num_attribute; j++) {
	start[0] = j;
	nc_put_vara_text(exoid, att_name_varid, start, count, text);
      }
    }
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  free(blocks_to_define);

  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_block_params",errmsg,exerrval);
  }
  return (EX_FATAL);
}
Example #2
0
int ex_get_coord (int exoid,
                  void *x_coor,
                  void *y_coor,
                  void *z_coor)
{
    int status;
    int coordid;
    int coordidx, coordidy, coordidz;

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

    exerrval = 0;

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

    if (ex_get_dimension(exoid, DIM_NUM_DIM, "dimensions",
                         &num_dim, &ndimdim, "ex_get_coord") != NC_NOERR) {
        return(EX_FATAL);
    }

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

    if ((status = nc_inq_dimlen(exoid, numnoddim, &num_nod)) != NC_NOERR)
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get number of nodes in file id %d",
                exoid);
        ex_err("ex_get_coord",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* read in the coordinates  */
    if (ex_large_model(exoid) == 0) {
        if ((status = nc_inq_varid (exoid, VAR_COORD, &coordid)) != NC_NOERR) {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to locate nodal coordinates in file id %d", exoid);
            ex_err("ex_get_coord",errmsg,exerrval);
            return (EX_FATAL);
        }

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

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

            if (i == 0 && x_coor != NULL) {
                which = "X";
                if (ex_comp_ws(exoid) == 4) {
                    status = nc_get_vara_float(exoid, coordid, start, count, x_coor);
                } else {
                    status = nc_get_vara_double(exoid, coordid, start, count, x_coor);
                }
            }
            else if (i == 1 && y_coor != NULL) {
                which = "Y";
                if (ex_comp_ws(exoid) == 4) {
                    status = nc_get_vara_float(exoid, coordid, start, count, y_coor);
                } else {
                    status = nc_get_vara_double(exoid, coordid, start, count, y_coor);
                }
            }
            else if (i == 2 && z_coor != NULL) {
                which = "Z";
                if (ex_comp_ws(exoid) == 4) {
                    status = nc_get_vara_float(exoid, coordid, start, count, z_coor);
                } else {
                    status = nc_get_vara_double(exoid, coordid, start, count, z_coor);
                }
            }

            if (status != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to get %s coord array in file id %d", which, exoid);
                ex_err("ex_get_coord",errmsg,exerrval);
                return (EX_FATAL);
            }
        }

    } else {
        if ((status = nc_inq_varid (exoid, VAR_COORD_X, &coordidx)) != NC_NOERR) {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to locate x nodal coordinates in file id %d", exoid);
            ex_err("ex_get_coord",errmsg,exerrval);
            return (EX_FATAL);
        }

        if (num_dim > 1) {
            if ((status = nc_inq_varid (exoid, VAR_COORD_Y, &coordidy)) != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to locate y nodal coordinates in file id %d", exoid);
                ex_err("ex_get_coord",errmsg,exerrval);
                return (EX_FATAL);
            }
        } else {
            coordidy = 0;
        }

        if (num_dim > 2) {
            if ((status = nc_inq_varid (exoid, VAR_COORD_Z, &coordidz)) != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to locate z nodal coordinates in file id %d", exoid);
                ex_err("ex_get_coord",errmsg,exerrval);
                return (EX_FATAL);
            }
        } else {
            coordidz = 0;
        }

        /* write out the coordinates  */
        for (i=0; i<num_dim; i++)
        {
            void *coor;
            char *which;

            if (i == 0) {
                coor = x_coor;
                which = "X";
                coordid = coordidx;
            } else if (i == 1) {
                coor = y_coor;
                which = "Y";
                coordid = coordidy;
            } else if (i == 2) {
                coor = z_coor;
                which = "Z";
                coordid = coordidz;
            }

            if (coor != NULL && coordid != 0) {
                if (ex_comp_ws(exoid) == 4) {
                    status = nc_get_var_float(exoid, coordid, coor);
                } else {
                    status = nc_get_var_double(exoid, coordid, coor);
                }

                if (status != NC_NOERR) {
                    exerrval = status;
                    sprintf(errmsg,
                            "Error: failed to get %s coord array in file id %d", which, exoid);
                    ex_err("ex_put_coord",errmsg,exerrval);
                    return (EX_FATAL);
                }
            }
        }
    }
    return (EX_NOERR);
}
Example #3
0
/*
 * reads the attributes for an edge, face, or element block
 */
int ex_get_one_attr( int   exoid,
                     ex_entity_type obj_type,
                     ex_entity_id   obj_id,
                     int   attrib_index,
                     void* attrib )

{
  int status;
  int attrid, obj_id_ndx;
  int temp;
  size_t num_entries_this_obj, num_attr;
  size_t start[2], count[2];
  ptrdiff_t stride[2];
  char errmsg[MAX_ERR_LENGTH];
  const char* dnumobjent;
  const char* dnumobjatt;
  const char* vattrbname;

  exerrval = 0; /* clear error code */

  /* Determine index of obj_id in vobjids array */
  if (obj_type != EX_NODAL) {
    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_one_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_one_attr",errmsg,exerrval);
	return (EX_WARN);
      }
    }
  }

  switch (obj_type) {
  case EX_SIDE_SET:
    dnumobjent = DIM_NUM_SIDE_SS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx);
    vattrbname = VAR_SSATTRIB(obj_id_ndx);
    break;
  case EX_NODE_SET:
    dnumobjent = DIM_NUM_NOD_NS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx);
    vattrbname = VAR_NSATTRIB(obj_id_ndx);
    break;
  case EX_EDGE_SET:
    dnumobjent = DIM_NUM_EDGE_ES(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx);
    vattrbname = VAR_ESATTRIB(obj_id_ndx);
    break;
  case EX_FACE_SET:
    dnumobjent = DIM_NUM_FACE_FS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx);
    vattrbname = VAR_FSATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_SET:
    dnumobjent = DIM_NUM_ELE_ELS(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx);
    vattrbname = VAR_ELSATTRIB(obj_id_ndx);
    break;
  case EX_NODAL:
    dnumobjent = DIM_NUM_NODES;
    dnumobjatt = DIM_NUM_ATT_IN_NBLK;
    vattrbname = VAR_NATTRIB;
    break;
  case EX_EDGE_BLOCK:
    dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
    vattrbname = VAR_EATTRIB(obj_id_ndx);
    break;
  case EX_FACE_BLOCK:
    dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
    vattrbname = VAR_FATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_BLOCK:
    dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx);
    vattrbname = VAR_ATTRIB(obj_id_ndx);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized object type in switch: %d in file id %d",
	    obj_type,exoid);
    ex_err("ex_get_one_attr",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }

  /* inquire id's of previously defined dimensions  */
  if (ex_get_dimension(exoid, dnumobjent,"entries", &num_entries_this_obj, &temp, "ex_get_one_attr") != NC_NOERR)
    return EX_FATAL;
  
  if (ex_get_dimension(exoid, dnumobjatt,"attributes", &num_attr, &temp, "ex_get_one_attr") != NC_NOERR)
    return EX_FATAL;

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

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


  /* read in the attributes */
  start[0] = 0;
  start[1] = attrib_index-1;

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

  stride[0] = 1;
  stride[1] = num_attr;
  
  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vars_float(exoid, attrid, start, count, stride, attrib);
  } else {
    status = nc_get_vars_double(exoid, attrid, start, count, stride, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get attribute %d for %s %"PRId64" in file id %d",
            attrib_index, ex_name_of_object(obj_type), obj_id,exoid);
    ex_err("ex_get_one_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
Example #4
0
int ex_get_names (int exoid,
                  ex_entity_type obj_type,
                  char **names)
{
    int status;
    int j, varid, temp;
    size_t num_entity, i;
    size_t start[2];
    char *ptr;
    char errmsg[MAX_ERR_LENGTH];
    const char *routine = "ex_get_names";

    exerrval = 0; /* clear error code */

    /* inquire previously defined dimensions and variables  */

    switch (obj_type) {
    /*  ======== BLOCKS ========= */
    case EX_EDGE_BLOCK:
        ex_get_dimension(exoid, DIM_NUM_ED_BLK, "edge block", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_ED_BLK, &varid);
        break;
    case EX_FACE_BLOCK:
        ex_get_dimension(exoid, DIM_NUM_FA_BLK, "face block", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_FA_BLK, &varid);
        break;
    case EX_ELEM_BLOCK:
        ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element block", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_EL_BLK, &varid);
        break;

    /*  ======== SETS ========= */
    case EX_NODE_SET:
        ex_get_dimension(exoid, DIM_NUM_NS, "nodeset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_NS, &varid);
        break;
    case EX_EDGE_SET:
        ex_get_dimension(exoid, DIM_NUM_ES, "edgeset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_ES, &varid);
        break;
    case EX_FACE_SET:
        ex_get_dimension(exoid, DIM_NUM_FS, "faceset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_FS, &varid);
        break;
    case EX_SIDE_SET:
        ex_get_dimension(exoid, DIM_NUM_SS, "sideset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_SS, &varid);
        break;
    case EX_ELEM_SET:
        ex_get_dimension(exoid, DIM_NUM_ELS, "elemset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_ELS, &varid);
        break;

    /*  ======== MAPS ========= */
    case EX_NODE_MAP:
        ex_get_dimension(exoid, DIM_NUM_NM, "node map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_NM, &varid);
        break;
    case EX_EDGE_MAP:
        ex_get_dimension(exoid, DIM_NUM_EDM, "edge map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_EDM, &varid);
        break;
    case EX_FACE_MAP:
        ex_get_dimension(exoid, DIM_NUM_FAM, "face map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_FAM, &varid);
        break;
    case EX_ELEM_MAP:
        ex_get_dimension(exoid, DIM_NUM_EM, "element map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_EM, &varid);
        break;

    /* invalid variable type */
    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_NOERR) {
        /* read the names */
        for (i=0; i<num_entity; i++) {
            start[0] = i;
            start[1] = 0;

            j = 0;
            ptr = names[i];

            if ((status = nc_get_var1_text(exoid, varid, start, ptr)) != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to get names in file id %d", exoid);
                ex_err("ex_get_names",errmsg,exerrval);
                return (EX_FATAL);
            }


            while ((*ptr++ != '\0') && (j < MAX_STR_LENGTH)) {
                start[1] = ++j;
                if ((status = nc_get_var1_text(exoid, varid, start, ptr)) != NC_NOERR) {
                    exerrval = status;
                    sprintf(errmsg,
                            "Error: failed to get names in file id %d", exoid);
                    ex_err("ex_get_names",errmsg,exerrval);
                    return (EX_FATAL);
                }
            }
            --ptr;
            if (ptr > names[i]) {
                while (--ptr >= names[i] && *ptr == ' ');      /*    get rid of trailing blanks */
            }
            *(++ptr) = '\0';
        }
    } else {
        /* Names variable does not exist on the database; probably since this is an
         * older version of the database.  Return an empty array...
         */
        for (i=0; i<num_entity; i++) {
            names[i][0] = '\0';
        }
    }
    return (EX_NOERR);
}
int ex_put_names (int   exoid,
		  ex_entity_type obj_type,
		  char* names[])
{
  int status;
  int varid; 
  size_t num_entity;
  char errmsg[MAX_ERR_LENGTH];

  const char *vname = NULL;
   
  const char *routine = "ex_put_names";
   
  exerrval = 0; /* clear error code */

  switch (obj_type) {
    /*  ======== BLOCKS ========= */
  case EX_EDGE_BLOCK:
    vname = VAR_NAME_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    vname = VAR_NAME_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    vname = VAR_NAME_EL_BLK;
    break;

    /*  ======== SETS ========= */
  case EX_NODE_SET:
    vname = VAR_NAME_NS;
    break;
  case EX_EDGE_SET:
    vname = VAR_NAME_ES;
    break;
  case EX_FACE_SET:
    vname = VAR_NAME_FS;
    break;
  case EX_SIDE_SET:
    vname = VAR_NAME_SS;
    break;
  case EX_ELEM_SET:
    vname = VAR_NAME_ELS;
    break;

    /*  ======== MAPS ========= */
  case EX_NODE_MAP:
    vname = VAR_NAME_NM;
    break;
  case EX_EDGE_MAP:
    vname = VAR_NAME_EDM;
    break;
  case EX_FACE_MAP:
    vname = VAR_NAME_FAM;
    break;
  case EX_ELEM_MAP:
    vname = VAR_NAME_EM;
    break;

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

  if ((status = nc_inq_varid(exoid, vname, &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);
  }

  /* write EXODUS entitynames */
  status = ex_put_names_internal(exoid, varid, num_entity, names, obj_type, "", routine);

  return(status);
}
int ex_get_object_truth_vector (int  exoid,
				ex_entity_type obj_type,
				ex_entity_id  entity_id,
				int  num_var,
				int *var_vec)
{
  int statust;
  int varid, tabid, i, status, ent_ndx;
  size_t num_var_db = 0;
  size_t start[2], count[2]; 
  char errmsg[MAX_ERR_LENGTH];
  const char* routine = "ex_get_object_truth_vector";

  /*
   * 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);
    statust = 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);
    statust = 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);
    statust = 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);
    statust = 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);
    statust = 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);
    statust = 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);
    statust = 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);
    statust = 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);
  }

  /* Determine index of entity_id in id array */
  ent_ndx = ex_id_lkup(exoid,obj_type,entity_id);
  if (exerrval != 0) {
    if (exerrval != EX_NULLENTITY) {
      sprintf(errmsg,
	      "Error: failed to locate %s id %"PRId64" in id variable in file id %d",
	      ex_name_of_object(obj_type), entity_id, exoid);
      ex_err(routine,errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* If this is a null entity, then 'ent_ndx' will be negative.
   * We don't care in this routine, so make it positive and continue...
   */
  if (ent_ndx < 0) ent_ndx = -ent_ndx;
  
  if ((int)num_var_db != num_var) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: # of variables doesn't match those defined in file id %d", exoid);
    ex_err("ex_get_object_truth_vector",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (statust != NC_NOERR) {
    /* since truth vector isn't stored in the data file, derive it dynamically */
    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, ent_ndx), &tabid) != NC_NOERR) {
	/* variable doesn't exist; put a 0 in the truth vector */
	var_vec[i] = 0;
      } else {
	/* variable exists; put a 1 in the truth vector */
	var_vec[i] = 1;
      }
    }
  } else {

    /* read in the truth vector */

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

    count[0] = 1;
    count[1] = num_var;

    status = nc_get_vara_int(exoid, tabid, start, count, var_vec);
     
    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get truth vector from file id %d", exoid);
      ex_err("ex_get_object_truth_vector",errmsg,exerrval);
      return (EX_FATAL);
    }
  } 
  return (EX_NOERR);
}
Example #7
0
int ex_put_all_var_param (int   exoid,
			  int   num_g,
			  int   num_n,
			  int   num_e,
			  int  *elem_var_tab,
			  int   num_m,
			  int  *nset_var_tab,
			  int   num_s,
			  int  *sset_var_tab)
{
  int in_define = 0;
  int time_dim, num_nod_dim, dimid, iresult;
  long num_elem_blk, num_nset, num_sset;
  int numelblkdim, numelvardim, numnsetdim, nsetvardim, numssetdim, ssetvardim;
  int i;

  int eblk_varid, nset_varid, sset_varid;
  
  int *eblk_ids = 0;
  int *nset_ids = 0;
  int *sset_ids = 0;

  nclong *eblk_stat = 0;
  nclong *nset_stat = 0;
  nclong *sset_stat = 0;
  
  int dims[3];
  char errmsg[MAX_ERR_LENGTH];
  const char* routine = "ex_put_all_var_param";

  exerrval = 0; /* clear error code */

  /* inquire previously defined dimensions  */

  if ((time_dim = ncdimid (exoid, DIM_TIME)) == -1) {
    exerrval = ncerr;
    sprintf(errmsg,
	    "Error: failed to locate time dimension in file id %d", exoid);
    ex_err("ex_put_all_var_param",errmsg,exerrval);
    goto error_ret;
  }

  if ((num_nod_dim = ncdimid (exoid, DIM_NUM_NODES)) == -1) {
    if (num_n > 0) {
      exerrval = ncerr;
      sprintf(errmsg,
	      "Error: failed to locate number of nodes in file id %d",
	      exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;
    }
  }

  /* Check this now so we can use it later without checking for errors */
  if (ncdimid (exoid, DIM_STR) < 0) {
    exerrval = ncerr;
    sprintf(errmsg,
	    "Error: failed to get string length in file id %d",exoid);
    ex_err("ex_put_all_var_param",errmsg,exerrval);
    goto error_ret;
  }

  if (num_e > 0) {
    numelblkdim = ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &num_elem_blk, routine);
    if (numelblkdim == -1)
      goto error_ret;
    
    /* get element block IDs */
    if (!(eblk_ids = static_cast<int*>(malloc(num_elem_blk*sizeof(int))))) {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate memory for element block id array for file id %d",
	      exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;
    }
    ex_get_elem_blk_ids (exoid, eblk_ids);

    /* Get element block status array for later use (allocates memory) */
    eblk_stat = get_status_array(exoid, num_elem_blk, VAR_STAT_EL_BLK, "element block");
    if (eblk_stat == NULL) {
      goto error_ret;
    }
  }

  if (num_m > 0) {
    numnsetdim = ex_get_dimension(exoid, DIM_NUM_NS, "nodesets", &num_nset, routine);
    if (numnsetdim == -1)
      goto error_ret;
    
    /* get nodeset IDs */
    if (!(nset_ids = static_cast<int*>(malloc(num_nset*sizeof(int))))) {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate memory for nodeset id array for file id %d",
	      exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;
    }
    ex_get_node_set_ids (exoid, nset_ids);

    /* Get nodeset status array for later use (allocates memory) */
    nset_stat = get_status_array(exoid, num_nset, VAR_NS_STAT, "nodeset");
    if (nset_stat == NULL) {
      goto error_ret;
    }
  }

  if (num_s > 0) {
    numssetdim = ex_get_dimension(exoid, DIM_NUM_SS, "sidesets", &num_sset, routine);
    if (numssetdim == -1)
      goto error_ret;
    
    /* get sideset IDs */
    if (!(sset_ids = static_cast<int*>(malloc(num_sset*sizeof(int))))) {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
	      "Error: failed to allocate memory for sideset id array for file id %d",
	      exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;
    }
    ex_get_side_set_ids (exoid, sset_ids);

    /* Get sideset status array for later use (allocates memory) */
    sset_stat = get_status_array(exoid, num_sset, VAR_SS_STAT, "sideset");
    if (sset_stat == NULL) {
      goto error_ret;
    }
  }

  /* put file into define mode  */
  if (ncredef (exoid) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to put file id %d into define mode", exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;
    }
  in_define = 1;

  /* define dimensions and variables */

  if (num_g > 0) 
    {
      dimid = define_dimension(exoid, DIM_NUM_GLO_VAR, num_g, "global");
      if (dimid == -1) goto error_ret;

      
      dims[0] = time_dim;
      dims[1] = dimid;
      if ((ncvardef (exoid, VAR_GLO_VAR, 
                     nc_flt_code(exoid), 2, dims)) == -1)
        {
          exerrval = ncerr;
          sprintf(errmsg,
                  "Error: failed to define global variables in file id %d",
                  exoid);
          ex_err("ex_put_all_var_param",errmsg,exerrval);
          goto error_ret;          /* exit define mode and return */
        }

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

  if (num_n > 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.
       */
      dimid = define_dimension(exoid, DIM_NUM_NOD_VAR, num_n, "nodal");
      if (dimid == -1) goto error_ret;

      if (ex_large_model(exoid) == 0) { /* Old way */
        dims[0] = time_dim;
        dims[1] = dimid;
        dims[2] = num_nod_dim;
        if ((ncvardef (exoid, VAR_NOD_VAR,
                       nc_flt_code(exoid), 3, dims)) == -1)
          {
            exerrval = ncerr;
            sprintf(errmsg,
                    "Error: failed to define nodal variables in file id %d",
                    exoid);
            ex_err("ex_put_all_var_param",errmsg,exerrval);
            goto error_ret;          /* exit define mode and return */
          }
      } else { /* Store new way */
        for (i = 1; i <= num_n; i++) {
          dims[0] = time_dim;
          dims[1] = num_nod_dim;
          if ((ncvardef (exoid, VAR_NOD_VAR_NEW(i),
                         nc_flt_code(exoid), 2, dims)) == -1)
            {
              exerrval = ncerr;
              sprintf(errmsg,
                      "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 */
            }
        }
      }

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

  if (num_e > 0) {
    numelvardim = define_dimension(exoid, DIM_NUM_ELE_VAR, num_e, "element");
    if (numelvardim == -1) goto error_ret;

    /* Now define element variable name variable */
    if (define_variable_name_variable(exoid, VAR_NAME_ELE_VAR, numelvardim, "element") == -1)
      goto error_ret;

    if (define_truth_table('e', exoid, num_elem_blk, num_e, elem_var_tab, eblk_stat, eblk_ids, "element block") == -1)
      goto error_ret;

    eblk_stat = static_cast<nclong*>(safe_free (eblk_stat));
    eblk_ids  = static_cast<int*>(   safe_free (eblk_ids));

    /* create a variable array in which to store the element variable truth
     * table
     */

    dims[0] = numelblkdim;
    dims[1] = numelvardim;

    if ((eblk_varid = ncvardef (exoid, VAR_ELEM_TAB, NC_LONG, 2, dims)) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
	      "Error: failed to define element variable truth table in file id %d",
	      exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;          /* exit define mode and return */
    }

  }

  if (num_m > 0) {
    nsetvardim = define_dimension(exoid, DIM_NUM_NSET_VAR, num_m, "nodeset");
    if (nsetvardim == -1) goto error_ret;

    /* Now define nodeset variable name variable */
    if (define_variable_name_variable(exoid, VAR_NAME_NSET_VAR, nsetvardim, "nodeset") == -1)
      goto error_ret;

    if (define_truth_table('m', exoid, num_nset, num_m, nset_var_tab, nset_stat, nset_ids, "nodeset") == -1)
      goto error_ret;

    nset_stat = static_cast<nclong*>(safe_free (nset_stat));
    nset_ids  = static_cast<int*>(safe_free (nset_ids));

    /* create a variable array in which to store the truth table
     */

    dims[0] = numnsetdim;
    dims[1] = nsetvardim;

    if ((nset_varid = ncvardef (exoid, VAR_NSET_TAB, NC_LONG, 2, dims)) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
	      "Error: failed to define nodeset variable truth table in file id %d",
	      exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;          /* exit define mode and return */
    }
  }

  if (num_s > 0) {
    ssetvardim = define_dimension(exoid, DIM_NUM_SSET_VAR, num_s, "sideset");
    if (ssetvardim == -1) goto error_ret;

    /* Now define sideset variable name variable */
    if (define_variable_name_variable(exoid, VAR_NAME_SSET_VAR, ssetvardim, "sideset") == -1)
      goto error_ret;

    if (define_truth_table('s', exoid, num_sset, num_s, sset_var_tab, sset_stat, sset_ids, "sideset") == -1)
      goto error_ret;
      
    sset_stat = static_cast<nclong*>(safe_free (sset_stat));
    sset_ids  = static_cast<int*>(safe_free (sset_ids));

    /* create a variable array in which to store the truth table
     */

    dims[0] = numssetdim;
    dims[1] = ssetvardim;

    if ((sset_varid = ncvardef (exoid, VAR_SSET_TAB, NC_LONG, 2, dims)) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
	      "Error: failed to define sideset variable truth table in file id %d",
	      exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;          /* exit define mode and return */
    }
  }

  /* leave define mode  */

  in_define = 0;
  if (ncendef (exoid) == -1)
    {
      exerrval = ncerr;
      sprintf(errmsg,
              "Error: failed to complete definition in file id %d",
              exoid);
      ex_err("ex_put_all_var_param",errmsg,exerrval);
      goto error_ret;
    }

  /* write out the variable truth tables */
  if (num_e > 0) {
    iresult = put_truth_table(exoid, num_elem_blk, num_e, eblk_varid, elem_var_tab, "element");
    if (iresult == -1) goto error_ret;
  }

  if (num_m > 0) {
    iresult = put_truth_table(exoid, num_nset, num_m, nset_varid, nset_var_tab, "nodeset");
    if (iresult == -1) goto error_ret;
  }

  if (num_s > 0) {
    iresult = put_truth_table(exoid, num_sset, num_s, sset_varid, sset_var_tab, "sideset");
    if (iresult == -1) goto error_ret;
  }

  return(EX_NOERR);
  
  /* Fatal error: exit definition mode and return */
 error_ret:
  if (in_define == 1) {
    if (ncendef (exoid) == -1)     /* exit define mode */
      {
	sprintf(errmsg,
		"Error: failed to complete definition for file id %d",
		exoid);
	ex_err("ex_put_all_var_param",errmsg,exerrval);
      }
  }
  safe_free(eblk_ids);
  safe_free(nset_ids);
  safe_free(sset_ids);

  safe_free(eblk_stat);
  safe_free(nset_stat);
  safe_free(sset_stat);
  return(EX_FATAL);
}
Example #8
0
int ex_get_names (int exoid,
                  ex_entity_type obj_type,
                  char **names)
{
    int status;
    int varid, temp;
    size_t num_entity, i;
    char errmsg[MAX_ERR_LENGTH];
    const char *routine = "ex_get_names";

    exerrval = 0; /* clear error code */

    /* inquire previously defined dimensions and variables  */

    switch (obj_type) {
    /*  ======== BLOCKS ========= */
    case EX_EDGE_BLOCK:
        ex_get_dimension(exoid, DIM_NUM_ED_BLK, "edge block", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_ED_BLK, &varid);
        break;
    case EX_FACE_BLOCK:
        ex_get_dimension(exoid, DIM_NUM_FA_BLK, "face block", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_FA_BLK, &varid);
        break;
    case EX_ELEM_BLOCK:
        ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element block", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_EL_BLK, &varid);
        break;

    /*  ======== SETS ========= */
    case EX_NODE_SET:
        ex_get_dimension(exoid, DIM_NUM_NS, "nodeset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_NS, &varid);
        break;
    case EX_EDGE_SET:
        ex_get_dimension(exoid, DIM_NUM_ES, "edgeset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_ES, &varid);
        break;
    case EX_FACE_SET:
        ex_get_dimension(exoid, DIM_NUM_FS, "faceset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_FS, &varid);
        break;
    case EX_SIDE_SET:
        ex_get_dimension(exoid, DIM_NUM_SS, "sideset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_SS, &varid);
        break;
    case EX_ELEM_SET:
        ex_get_dimension(exoid, DIM_NUM_ELS, "elemset", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_ELS, &varid);
        break;

    /*  ======== MAPS ========= */
    case EX_NODE_MAP:
        ex_get_dimension(exoid, DIM_NUM_NM, "node map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_NM, &varid);
        break;
    case EX_EDGE_MAP:
        ex_get_dimension(exoid, DIM_NUM_EDM, "edge map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_EDM, &varid);
        break;
    case EX_FACE_MAP:
        ex_get_dimension(exoid, DIM_NUM_FAM, "face map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_FAM, &varid);
        break;
    case EX_ELEM_MAP:
        ex_get_dimension(exoid, DIM_NUM_EM, "element map", &num_entity, &temp, routine);
        status = nc_inq_varid(exoid, VAR_NAME_EM, &varid);
        break;

    /* invalid variable type */
    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_NOERR) {
        if ((status = ex_get_names_internal(exoid, varid, num_entity, names,
                                            obj_type, "ex_get_names")) != EX_NOERR) {
            return status;
        }
    } else {
        /* Names variable does not exist on the database; probably since this is an
         * older version of the database.  Return an empty array...
         */
        for (i=0; i<num_entity; i++) {
            names[i][0] = '\0';
        }
    }
    return (EX_NOERR);
}
Example #9
0
int ex_get_name (int   exoid,
		 int   obj_type,
		 int   entity_id, 
		 char *name)
{
  int j, varid, ent_ndx;
  long num_entity, start[2];
  char *ptr;
  char errmsg[MAX_ERR_LENGTH];
  const char *routine = "ex_get_name";
   
  exerrval = 0;

  /* inquire previously defined dimensions and variables  */

  if (obj_type == EX_ELEM_BLOCK) {
    ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element block", &num_entity, routine);
    varid = ncvarid (exoid, VAR_NAME_EL_BLK);
    ent_ndx = ex_id_lkup(exoid, VAR_ID_EL_BLK, entity_id);
  }
  else if (obj_type == EX_NODE_SET) {
    ex_get_dimension(exoid, DIM_NUM_NS, "nodeset", &num_entity, routine);
    varid = ncvarid (exoid, VAR_NAME_NS);
    ent_ndx = ex_id_lkup(exoid, VAR_NS_IDS, entity_id);
  }
  else if (obj_type == EX_SIDE_SET) {
    ex_get_dimension(exoid, DIM_NUM_SS, "sideset", &num_entity, routine);
    varid = ncvarid (exoid, VAR_NAME_SS);
    ent_ndx = ex_id_lkup(exoid, VAR_SS_IDS, entity_id);
  }
  else if (obj_type == EX_NODE_MAP) {
    ex_get_dimension(exoid, DIM_NUM_NM, "node map", &num_entity, routine);
    varid = ncvarid (exoid, VAR_NAME_NM);
    ent_ndx = ex_id_lkup(exoid, VAR_NM_PROP(1), entity_id);
  }
  else if (obj_type == EX_ELEM_MAP) {
    ex_get_dimension(exoid, DIM_NUM_EM, "element map", &num_entity, routine);
    varid = ncvarid (exoid, VAR_NAME_EM);
    ent_ndx = ex_id_lkup(exoid, VAR_EM_PROP(1), entity_id);
  }
  else {/* 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 (varid != -1) {
    /* 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;
    
    /* read the name */
    start[0] = ent_ndx-1;
    start[1] = 0;
       
    j = 0;
    ptr = name;
       
    if (ncvarget1 (exoid, varid, start, ptr) == -1) {
      exerrval = ncerr;
      sprintf(errmsg,
	      "Error: failed to get entity name for id %d in file id %d",
	      ent_ndx, exoid);
      ex_err(routine,errmsg,exerrval);
      return (EX_FATAL);
    }
       
       
    while ((*ptr++ != '\0') && (j < MAX_STR_LENGTH)) {
      start[1] = ++j;
      if (ncvarget1 (exoid, varid, start, ptr) == -1) {
	exerrval = ncerr;
	sprintf(errmsg,
		"Error: failed to get name in file id %d", exoid);
	ex_err(routine,errmsg,exerrval);
	return (EX_FATAL);
      }
    }
    --ptr;
    if (ptr > name) {
      while (*(--ptr) == ' ');      /*    get rid of trailing blanks */
    }
    *(++ptr) = '\0';
  } 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);
}
Example #10
0
static int ex_inquire_internal (int      exoid,
				int      req_info,
				int64_t *ret_int,
				float   *ret_float,
				char    *ret_char)
{
  int dimid, varid, tmp_num;
  void_int *ids = NULL;
  size_t i;
  size_t ldum = 0;
  size_t num_sets, idum;
  int *stat_vals;
  char  errmsg[MAX_ERR_LENGTH];
  int status;
  char tmp_title[2048];

  exerrval = 0; /* clear error code */

  if (ret_char)  *ret_char  = '\0';  /* Only needs to be non-null for TITLE */
  
  if (!ret_int) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
	    "Warning: integer argument is NULL which is not allowed.");
    ex_err("ex_inquire",errmsg,exerrval);
    return (EX_FATAL);
  }
    

  switch (req_info) {
  case EX_INQ_FILE_TYPE:

    /* obsolete call */
    /*returns "r" for regular EXODUS II file or "h" for history EXODUS file*/
    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 (!ret_float) {
      exerrval = EX_BADPARAM;
      sprintf(errmsg,
	      "Warning: float argument is NULL for EX_INQ_API_VERS which is not allowed.");
      ex_err("ex_inquire",errmsg,exerrval);
      return (EX_FATAL);
    }

    if (nc_get_att_float(exoid, NC_GLOBAL, ATT_API_VERSION, ret_float) != NC_NOERR)
      {  /* try old (prior to db version 2.02) attribute name */
	if ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_API_VERSION_BLANK,ret_float)) != NC_NOERR) {
	  exerrval = status;
	  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 (!ret_float) {
      exerrval = EX_BADPARAM;
      sprintf(errmsg,
	      "Warning: float argument is NULL for EX_INQ_DB_VERS which is not allowed.");
      ex_err("ex_inquire",errmsg,exerrval);
      return (EX_FATAL);
    }

    if ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_VERSION, ret_float)) != NC_NOERR) {
      exerrval = status;
      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 */
    if (ret_float)
      flt_cvt(ret_float, EX_API_VERS);

    *ret_int = EX_API_VERS_NODOT;
    break;

  case EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH:
    /* Return the MAX_NAME_LENGTH size for this database
       It will not include the space for the trailing null, so if it
       is defined as 33 on the database, 32 will be returned.
    */
    if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &dimid)) != NC_NOERR) {
      /* If not found, then an older database */
      *ret_int = 32;
    }
    else {
      /* Get the name string length */
      size_t name_length = 0;
      if ((status = nc_inq_dimlen(exoid,dimid,&name_length)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get name string length in file id %d", exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }
      else {
	*ret_int = name_length-1;
      }
    }
    break;

  case EX_INQ_DB_FLOAT_SIZE:
    {
      nc_get_att_longlong(exoid, NC_GLOBAL, ATT_FLT_WORDSIZE, (long long*)ret_int);
    }
    break;
    
  case EX_INQ_DB_MAX_USED_NAME_LENGTH:
    /* Return the value of the ATT_MAX_NAME_LENGTH attribute (if it
       exists) which is the maximum length of any entity, variable,
       attribute, property name written to this database.  If the
       attribute does not exist, then '32' is returned.  The length
       does not include the trailing null.
    */
    {
      nc_type att_type = NC_NAT;
      size_t att_len = 0;
	
      *ret_int = 32; /* Default size consistent with older databases */

      status = nc_inq_att(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, &att_type, &att_len);
      if (status == NC_NOERR && att_type == NC_INT) {
	/* The attribute exists, return it... */
	nc_get_att_longlong(exoid, NC_GLOBAL, ATT_MAX_NAME_LENGTH, (long long*)ret_int);
      }
    }
    break;

  case EX_INQ_MAX_READ_NAME_LENGTH:
    {
      /* Returns the user-specified maximum size of names that will be
       * returned to the user by any of the ex_get_ routines.  If the
       * name is longer than this value, it will be truncated. The
       * default if not set by the client is 32 characters. The value
       * does not include the trailing null.
       */
      struct ex_file_item* file = ex_find_file_item(exoid);

      if (!file ) {
	exerrval = EX_BADFILEID;
	sprintf(errmsg,"Error: unknown file id %d for ex_inquire_int().",exoid);
	ex_err("ex_intquire",errmsg,exerrval);
	*ret_int = 0;
      }
      else {
	*ret_int = file->maximum_name_length;
      }
    }
    break;

  case EX_INQ_TITLE:
    if (!ret_char) {
      sprintf(errmsg,
	      "Error: Requested title, but character pointer was null for file id %d", exoid);
      ex_err("ex_inquire",errmsg,exerrval);
      return (EX_FATAL);
    } else {
      /* returns the title of the database */
      if ((status = nc_get_att_text (exoid, NC_GLOBAL, ATT_TITLE, tmp_title)) != NC_NOERR) {
	*ret_char = '\0';
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get database title for file id %d", exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      } else {
	strncpy(ret_char, tmp_title, MAX_LINE_LENGTH+1);
	ret_char[MAX_LINE_LENGTH] = '\0';
      }
    }
    break;

  case EX_INQ_DIM:
    /* returns the dimensionality (2 or 3, for 2-d or 3-d) of the database */
    if (ex_get_dimension(exoid, DIM_NUM_DIM, "database dimensionality", &ldum, &dimid, "ex_inquire") != NC_NOERR)
      return EX_FATAL;
    *ret_int = ldum;
    break;

  case EX_INQ_NODES:
    /* returns the number of nodes */
    if (ex_get_dimension(exoid, DIM_NUM_NODES, "nodes", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_ELEM:
    /* returns the number of elements */
    if (ex_get_dimension(exoid, DIM_NUM_ELEM, "elements", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_ELEM_BLK:
    /* returns the number of element blocks */
    if (ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_NODE_SETS:
    /* returns the number of node sets */
    if (ex_get_dimension(exoid, DIM_NUM_NS, "node sets", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_NS_NODE_LEN:
    /* returns the length of the concatenated node sets node list */
    ex_get_concat_set_len(exoid, ret_int,"node",EX_NODE_SET,DIM_NUM_NS,VAR_NS_STAT,"num_nod_ns",0);
    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:

      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 (nc_inq_dimid (exoid, DIM_NUM_NS, &dimid) == NC_NOERR) {
      if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of node sets in file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }


      for (i=0; i<num_sets; i++) {
	if ((status = nc_inq_varid (exoid, VAR_FACT_NS(i+1), &varid)) != NC_NOERR) {
	  if (status == NC_ENOTVAR) {
	    idum = 0;        /* this dist factor doesn't exist */
	  } else {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to locate number of dist fact for %"ST_ZU"'th node set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	} else {
	  if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(i+1), &dimid)) != NC_NOERR) {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to locate number of nodes in %"ST_ZU"'th node set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	  if ((status = nc_inq_dimlen (exoid, dimid, &idum)) != NC_NOERR) {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to get number of nodes in %"ST_ZU"'th node set in file id %d",
		    i,exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	}
	*ret_int += idum;
      }
    }

    break;

  case EX_INQ_SIDE_SETS:
    /* returns the number of side sets */
    if (ex_get_dimension(exoid, DIM_NUM_SS, "side sets", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *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 (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) {
      if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) {
	exerrval = status;
	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(int64_t)))) { /* May be getting 2x what is needed, but should be OK */
	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(int)))) {
	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 ((status = nc_inq_varid (exoid, VAR_SS_STAT, &varid)) == NC_NOERR) {
	/* if status array exists, use it, otherwise assume, object exists
	   to be backward compatible */

	if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) {
	  exerrval = status;
	  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++) {
	ex_entity_id id;
	if (stat_vals[i] == 0) /* is this object null? */
	  continue;

	if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	  int64_t tmp_len = 0;
	  id = ((int64_t*)ids)[i];
	  status = ex_get_side_set_node_list_len(exoid, id, &tmp_len);
	  if (status == NC_NOERR) *ret_int += tmp_len;
	}
	else {
	  int tmp_len = 0;
	  id = ((int*)ids)[i];
	  status = ex_get_side_set_node_list_len(exoid, id, &tmp_len);
	  if (status == NC_NOERR) *ret_int += tmp_len;
	}

	if (status != NC_NOERR) {
	  *ret_int = 0;
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to side set %"PRId64" node length in file id %d",
		  id,exoid);
	  ex_err("ex_inquire",errmsg,exerrval);
	  free(stat_vals);
	  free(ids);
	  return (EX_FATAL);
	}
      }

      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(exoid, ret_int,"side",EX_SIDE_SET,DIM_NUM_SS,VAR_SS_STAT,"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 (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) {
      if ((status = nc_inq_dimlen (exoid, dimid, &num_sets)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of side sets in file id %d",
		exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }

      for (i=0; i<num_sets; i++) {
	if ((status = nc_inq_dimid (exoid, DIM_NUM_DF_SS(i+1), &dimid)) != NC_NOERR) {
	  if (status == NC_EBADDIM) {
	    ldum = 0;        /* this dist factor doesn't exist */
	  } else {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to locate number of dist fact for %"ST_ZU"'th side set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	} else {
	  if ((status = nc_inq_dimlen (exoid, dimid, &ldum)) != NC_NOERR) {
	    *ret_int = 0;
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to get number of dist factors in %"ST_ZU"'th side set in file id %d",
		    i, exoid);
	    ex_err("ex_inquire",errmsg,exerrval);
	    return (EX_FATAL);
	  }
	}
	*ret_int += ldum;
      }
    }

    break;

  case EX_INQ_QA:
    /* returns the number of QA records */
    if (ex_get_dimension(exoid, DIM_NUM_QA, "QA records", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_INFO:
    /* returns the number of information records */
    if (ex_get_dimension(exoid, DIM_NUM_INFO, "info records", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_TIME:
    /*     returns the number of time steps stored in the database */
    if (ex_get_dimension(exoid, DIM_TIME, "time dimension", &ldum, &dimid, "ex_inquire") != NC_NOERR)
      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 (ex_get_dimension(exoid, DIM_NUM_EM, "element maps", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *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 (ex_get_dimension(exoid, DIM_NUM_NM, "node maps", &ldum, &dimid, NULL) != NC_NOERR)
      *ret_int = 0;
    else
      *ret_int = ldum;
    break;

  case EX_INQ_NM_PROP:
    /* returns the number of node 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). */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDGE, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_EDGE_BLK:
    /* returns the number of edge blocks. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ED_BLK, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_EDGE_SETS:
    /* returns the number of edge sets. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ES, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_ES_LEN:
    /* returns the length of the concatenated edge set edge list. */
    ex_get_concat_set_len(exoid, ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,"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(exoid, ret_int,"edge",EX_EDGE_SET,DIM_NUM_ES,VAR_ES_STAT,"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). */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FACE, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FACE_BLK:
    /* returns the number of face blocks. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FA_BLK, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FACE_SETS:
    /* returns the number of face sets. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FS, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FS_LEN:
    /* returns the length of the concatenated edge set edge list. */
    ex_get_concat_set_len(exoid, ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,"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(exoid, ret_int,"face",EX_FACE_SET,DIM_NUM_FS,VAR_FS_STAT,"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. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_ELS, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_ELS_LEN:
    /* returns the length of the concatenated element set element list. */
    ex_get_concat_set_len(exoid, ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,"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(exoid, ret_int,"element",EX_ELEM_SET,DIM_NUM_ELS,VAR_ELS_STAT,"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 maps. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_EDM, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_FACE_MAP:
    /*     returns the number of face maps. */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_FAM, 1) != EX_NOERR) return EX_FATAL;
    break;

  case EX_INQ_COORD_FRAMES:
    /* return the number of coordinate frames */
    if (ex_get_dimension_value(exoid, ret_int, 0, DIM_NUM_CFRAMES, 1) != EX_NOERR) return EX_FATAL;
    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);
}
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);
}
Example #12
0
int ex_get_init_ext (int   exoid,
                     ex_init_params *info)
{
  int dimid;
  size_t lnum;
  char errmsg[MAX_ERR_LENGTH];
  int status;
  size_t title_len;
  nc_type title_type;

  exerrval = 0; /* clear error code */

  if ((status = nc_inq_att(exoid, NC_GLOBAL, ATT_TITLE, &title_type, &title_len)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to inquire title in file id %d", exoid);
    ex_err("ex_get_init",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check title length to avoid overrunning clients memory space; include trailing null */
  if (title_len > MAX_LINE_LENGTH+1) {
    char *title = malloc(title_len+1);
    if ((status = nc_get_att_text(exoid, NC_GLOBAL, ATT_TITLE, title)) == NC_NOERR) {
      strncpy(info->title, title, MAX_LINE_LENGTH+1);
      info->title[MAX_LINE_LENGTH] = '\0';
    }
    free(title);
  } else {
    status = nc_get_att_text(exoid, NC_GLOBAL, ATT_TITLE, info->title);
    info->title[title_len] = '\0';
  }
  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get title in file id %d", exoid);
    ex_err("ex_get_init",errmsg,exerrval);
    return (EX_FATAL);
  }

  status = ex_get_dimension(exoid, DIM_NUM_DIM, "dimensions", &lnum, &dimid, "ex_get_init");
  if (status != NC_NOERR) return status;
  info->num_dim = lnum;


  /* Handle case with zero-nodes */
  if (ex_get_dim_value(exoid,   "nodes",DIM_NUM_NODES,dimid,&info->num_nodes) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,   "edges", DIM_NUM_EDGE,dimid,&info->num_edge) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,   "faces", DIM_NUM_FACE,dimid,&info->num_face) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"elements", DIM_NUM_ELEM,dimid,&info->num_elem) != EX_NOERR) return EX_FATAL;

  if (ex_get_dim_value(exoid,"element blocks", DIM_NUM_EL_BLK,dimid,&info->num_elem_blk) != EX_NOERR) return EX_FATAL;
  if (info->num_elem_blk == 0 && info->num_elem > 0) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate number of element blocks in file id %d",
            exoid);
    ex_err("ex_get_init",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_get_dim_value(exoid,"node sets", DIM_NUM_NS,dimid,&info->num_node_sets) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"edge sets", DIM_NUM_ES,dimid,&info->num_edge_sets) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"face sets", DIM_NUM_FS,dimid,&info->num_face_sets) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"side sets", DIM_NUM_SS,dimid,&info->num_side_sets) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"elem sets",DIM_NUM_ELS,dimid,&info->num_elem_sets) != EX_NOERR) return EX_FATAL;

  if (ex_get_dim_value(exoid,"node maps", DIM_NUM_NM,dimid,&info->num_node_maps) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"edge maps",DIM_NUM_EDM,dimid,&info->num_edge_maps) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"face maps",DIM_NUM_FAM,dimid,&info->num_face_maps) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"elem maps", DIM_NUM_EM,dimid,&info->num_elem_maps) != EX_NOERR) return EX_FATAL;

  /* Edge and face blocks are also optional (for backwards compatability) */
  if (ex_get_dim_value(exoid,"edge blocks",DIM_NUM_ED_BLK,dimid,&info->num_edge_blk) != EX_NOERR) return EX_FATAL;
  if (ex_get_dim_value(exoid,"face blocks",DIM_NUM_FA_BLK,dimid,&info->num_face_blk) != EX_NOERR) return EX_FATAL;

  return (EX_NOERR);
}
Example #13
0
static int
ex_look_up_var(int exoid, ex_entity_type var_type, int var_index, ex_entity_id obj_id, 
	       const char *VOBJID, const char *VOBJTAB, const char *DNUMOBJ,
	       const char *DNUMOBJVAR, int *varid)
{
  int status;
  int obj_id_ndx;
  int dimid,time_dim, numobjdim, dims[2];

  size_t num_obj;
  size_t num_obj_var;
  size_t num_entity;

  int *obj_var_truth_tab;
  char errmsg[MAX_ERR_LENGTH];

  /* Determine index of obj_id in VOBJID array */
  obj_id_ndx = ex_id_lkup(exoid,var_type,obj_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
	      "Warning: no variables allowed for NULL block %"PRId64" in file id %d",
	      obj_id,exoid);
      ex_err("ex_put_var",errmsg,EX_NULLENTITY);
      return (EX_WARN);
    }
    else {
      sprintf(errmsg,
	      "Error: failed to locate %s id %"PRId64" in %s array in file id %d",
	      ex_name_of_object(var_type), obj_id, VOBJID, exoid);
      ex_err("ex_put_var",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  if ((status = nc_inq_varid (exoid, ex_name_var_of_object(var_type, var_index, obj_id_ndx), varid)) != NC_NOERR) {
    if (status == NC_ENOTVAR) {/* variable doesn't exist, create it! */
      /* check for the existance of an TNAME variable truth table */
      if (nc_inq_varid(exoid, VOBJTAB, varid) == NC_NOERR) {
	/* find out number of TNAMEs and TNAME variables */
	status = ex_get_dimension(exoid, DNUMOBJ, ex_name_of_object(var_type), &num_obj, &dimid, "ex_put_var");
	if (status != NC_NOERR) return status;

	status = ex_get_dimension(exoid, DNUMOBJVAR, ex_name_of_object(var_type), &num_obj_var, &dimid, "ex_put_var");
	if (status != NC_NOERR) return status;

	if (!(obj_var_truth_tab = malloc(num_obj*num_obj_var*sizeof(int)))) {
	  exerrval = EX_MEMFAIL;
	  sprintf(errmsg,
		  "Error: failed to allocate memory for %s variable truth table in file id %d",
		  ex_name_of_object(var_type), exoid);
	  ex_err("ex_put_var",errmsg,exerrval);
	  return (EX_FATAL);
	}

	/*   read in the TNAME variable truth table */
	if ((status = nc_get_var_int (exoid, *varid, obj_var_truth_tab)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to get truth table from file id %d", exoid);
	  ex_err("ex_put_var",errmsg,exerrval);
	  return (EX_FATAL);
	}

	if(obj_var_truth_tab[num_obj_var*(obj_id_ndx-1)+var_index-1] == 0L) {
	  free(obj_var_truth_tab);
	  exerrval = EX_BADPARAM;
	  sprintf(errmsg,
		  "Error: Invalid %s variable %d, %s %"PRId64" in file id %d",
		  ex_name_of_object(var_type), var_index, ex_name_of_object(var_type), obj_id, exoid);
	  ex_err("ex_put_var",errmsg,exerrval);
	  return (EX_FATAL);
	}
	free(obj_var_truth_tab);
      }

      if ((status = nc_inq_dimid(exoid, DIM_TIME, &time_dim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate time dimension in file id %d", exoid);
	ex_err("ex_put_var",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }

      ex_get_dimension(exoid, ex_dim_num_entries_in_object(var_type, obj_id_ndx),
		       ex_name_of_object(var_type), &num_entity, &numobjdim,  "ex_put_var");

      /*    variable doesn't exist so put 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_var",errmsg,exerrval);
	return (EX_FATAL);
      }

      /* define netCDF variable to store TNAME variable values */
      dims[0] = time_dim;
      dims[1] = numobjdim;
      if ((status = nc_def_var(exoid, ex_name_var_of_object(var_type, var_index, obj_id_ndx),
			       nc_flt_code(exoid), 2, dims, varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define %s variable %d in file id %d",
		ex_name_of_object(var_type), var_index,exoid);
	ex_err("ex_put_var",errmsg,exerrval);
	goto error_ret;
      }
      ex_compress_variable(exoid, *varid, 2);

      /*    leave define mode  */
      if ((status = nc_enddef (exoid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to complete %s variable %s definition to file id %d",
		ex_name_of_object(var_type), ex_name_var_of_object(var_type, var_index, obj_id_ndx), exoid);
	ex_err("ex_put_var",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
    else {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate %s variable %s in file id %d",
	      ex_name_of_object(var_type), ex_name_var_of_object(var_type, var_index, obj_id_ndx), exoid);
      ex_err("ex_put_var",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_var",errmsg,exerrval);
  }
  return (EX_FATAL);
}
int ex_inquire (int   exoid,
                int   req_info,
                int  *ret_int,
                void *ret_float,
                char *ret_char)
{
  int dimid, varid, tmp_num, *ids;
  size_t ldum = 0;
  size_t num_sets, idum, i;
  int *stat_vals;
  char  errmsg[MAX_ERR_LENGTH];
  int status;
  
  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 (nc_get_att_float(exoid, NC_GLOBAL, ATT_API_VERSION, ret_float) != NC_NOERR)
	{  /* try old (prior to db version 2.02) attribute name */
	  if ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_API_VERSION_BLANK,ret_float)) != NC_NOERR) {
	    exerrval = status;
	    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 ((status = nc_get_att_float (exoid, NC_GLOBAL, ATT_VERSION, ret_float)) != NC_NOERR) {
	exerrval = status;
	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 */
      if (ret_float)
	flt_cvt((float *)ret_float, EX_API_VERS);

      if (ret_int)
	*ret_int = EX_API_VERS_NODOT;
      break;

    case EX_INQ_TITLE:
      /* returns the title of the database */
      if ((status = nc_get_att_text (exoid, NC_GLOBAL, ATT_TITLE, ret_char)) != NC_NOERR) {
	*ret_char = '\0';
	exerrval = status;
	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 (ex_get_dimension(exoid, DIM_NUM_DIM, "database dimensionality", &ldum, &dimid, "ex_inquire") != NC_NOERR)
	return EX_FATAL;
      *ret_int = ldum;
      break;

    case EX_INQ_NODES:
      /* returns the number of nodes */
      if (ex_get_dimension(exoid, DIM_NUM_NODES, "nodes", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*ret_int = ldum;
      break;

    case EX_INQ_ELEM:
      /* returns the number of elements */
      if (ex_get_dimension(exoid, DIM_NUM_ELEM, "elements", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*ret_int = ldum;
      break;

    case EX_INQ_ELEM_BLK:
      /* returns the number of element blocks */
      if (ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*ret_int = ldum;
      break;

    case EX_INQ_NODE_SETS:
      /* returns the number of node sets */
      if (ex_get_dimension(exoid, DIM_NUM_NS, "node sets", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*ret_int = ldum;
      break;

    case EX_INQ_NS_NODE_LEN:
      /* returns the length of the concatenated node sets node list */
      EX_GET_CONCAT_SET_LEN(ret_int,"node",EX_NODE_SET,DIM_NUM_NS,VAR_NS_STAT,DIM_NUM_NOD_NS,0);
      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 (nc_inq_dimid (exoid, DIM_NUM_NS, &dimid) == NC_NOERR) {
	if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) {
	  exerrval = status;
	  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 ((status = nc_inq_varid (exoid, VAR_FACT_NS(i+1), &varid)) != NC_NOERR) {
	    if (status == NC_ENOTVAR) {
	      idum = 0;        /* this dist factor doesn't exist */
	    } else {
	      *ret_int = 0;
	      exerrval = status;
	      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 ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(i+1), &dimid)) != NC_NOERR) {
	      *ret_int = 0;
	      exerrval = status;
	      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 ((status = nc_inq_dimlen (exoid, dimid, &idum)) != NC_NOERR) {
	      *ret_int = 0;
	      exerrval = status;
	      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 += idum;
	}
	free(ids);
      }

      break;

    case EX_INQ_SIDE_SETS:
      /* returns the number of side sets */
      if (ex_get_dimension(exoid, DIM_NUM_SS, "side sets", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*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 (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) {
	if ((status = nc_inq_dimlen(exoid, dimid, &num_sets)) != NC_NOERR) {
	  exerrval = status;
	  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(int)))) {
	  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 ((status = nc_inq_varid (exoid, VAR_SS_STAT, &varid)) == NC_NOERR) {
	  /* if status array exists, use it, otherwise assume, object exists
	     to be backward compatible */

	  if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) {
	    exerrval = status;
	    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 ((status = ex_get_side_set_node_list_len(exoid, ids[i], &tmp_num)) != NC_NOERR) {
	    *ret_int = 0;
	    exerrval = status;
	    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 (nc_inq_dimid (exoid, DIM_NUM_SS, &dimid) == NC_NOERR) {
	if ((status = nc_inq_dimlen (exoid, dimid, &num_sets)) != NC_NOERR) {
	  exerrval = status;
	  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 ((status = nc_inq_dimid (exoid, DIM_NUM_DF_SS(i+1), &dimid)) != NC_NOERR) {
	    if (status == NC_EBADDIM) {
	      ldum = 0;        /* this dist factor doesn't exist */
	    } else {
	      *ret_int = 0;
	      exerrval = status;
	      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 ((status = nc_inq_dimlen (exoid, dimid, &ldum)) != NC_NOERR) {
	      *ret_int = 0;
	      exerrval = status;
	      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 (ex_get_dimension(exoid, DIM_NUM_QA, "QA records", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*ret_int = ldum;
      break;

    case EX_INQ_INFO:
      /* returns the number of information records */
      if (ex_get_dimension(exoid, DIM_NUM_INFO, "info records", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*ret_int = ldum;
      break;

    case EX_INQ_TIME:
      /*     returns the number of time steps stored in the database */
      if (ex_get_dimension(exoid, DIM_TIME, "time dimension", &ldum, &dimid, "ex_inquire") != NC_NOERR)
	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 (ex_get_dimension(exoid, DIM_NUM_EM, "element maps", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*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 (ex_get_dimension(exoid, DIM_NUM_NM, "node maps", &ldum, &dimid, NULL) != NC_NOERR)
	*ret_int = 0;
      else
	*ret_int = ldum;
      break;

    case EX_INQ_NM_PROP:
      /* returns the number of node 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 face blocks. */
      EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_FA_BLK, 1);
      break;

    case EX_INQ_FACE_SETS:
      /* returns the number of face 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 maps. */
      EX_GET_DIMENSION_VALUE(ret_int, 0, DIM_NUM_EDM, 1);
      break;

    case EX_INQ_FACE_MAP:
      /*     returns the number of face maps. */
      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);
}
Example #15
0
/*! Calculate the number of words of storage required to store the
 * header information.  Total bytes can be obtained by multiplying
 * words by 4.  Size is slightly underestimated since it only
 * considers the bulk data storage...
 */
size_t ex_header_size(int exoid)
{
  const char *routine = NULL;
  int iows = 0;
  size_t ndim = 0;
  size_t num_nodes = 0;
  size_t num_elem = 0;
  size_t num_eblk = 0;
  size_t num_map  = 0;
  size_t num_nset = 0;
  size_t num_sset = 0;
  int mapid;
  int temp;
  
  size_t size = 0;
  /* Get word size (2 = 8-byte reals, 1 = 4-byte reals */
  
  if (nc_flt_code(exoid) == NC_DOUBLE) 
    iows = 2;
  else
    iows = 1;
  
  /* coordinates = (ndim * numnp)*iows + maps  */
  ex_get_dimension(exoid, DIM_NUM_DIM,   "dimension", &ndim,      &temp, routine);
  ex_get_dimension(exoid, DIM_NUM_NODES, "nodes",     &num_nodes, &temp, routine);
  size += iows * ndim * num_nodes;

  /* node maps */
  if (nc_inq_varid(exoid, VAR_NODE_NUM_MAP, &mapid) != -1)
    size += num_nodes;

  ex_get_dimension(exoid, DIM_NUM_NM,   "node maps", &num_map, &temp, routine);
  size += num_map * num_nodes;

  /* Element Data */
  ex_get_dimension(exoid, DIM_NUM_ELEM, "elements",  &num_elem, &temp, routine);
  
  /* Element order map */
  if (nc_inq_varid (exoid, VAR_MAP, &mapid) != -1)
    size += num_elem;
   
  if (nc_inq_varid (exoid, VAR_ELEM_NUM_MAP, &mapid) != -1)
    size += num_elem;

  /* Element map(s) */
  ex_get_dimension(exoid, DIM_NUM_EM,     "element maps",   &num_map, &temp, routine);
  size += num_map * num_elem;

  /* Element Blocks... */
  ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element blocks", &num_eblk, &temp, routine);
  if (num_eblk > 0) {
    /* Allocate storage for element block parameters... */
    int *ids = malloc(num_eblk * sizeof(int));
    size_t i;

    size += 2*num_eblk; /* status + ids */
    
    ex_get_ids(exoid, EX_ELEM_BLOCK, ids);
    for (i=0; i < num_eblk; i++) {
      int num_elem_this_blk = 0;
      int num_nodes_per_elem = 0;
      int num_attr = 0;
      char elem_type[MAX_STR_LENGTH+1];
      ex_get_elem_block(exoid, ids[i], elem_type, &num_elem_this_blk,
                        &num_nodes_per_elem, &num_attr);
      size += num_elem_this_blk * num_nodes_per_elem;
      size += num_elem_this_blk * num_attr * iows;
    }
    free(ids);
  }
  
  /* Nodesets */
  ex_get_dimension(exoid, DIM_NUM_NS, "nodesets", &num_nset, &temp, routine);
  if (num_nset > 0) {
    /* Allocate storage for nodeset parameters... */
    int *ids = malloc(num_nset * sizeof(int));
    size_t i;

    size += 2*num_nset; /* Status + ids */
    ex_get_ids(exoid, EX_NODE_SET, ids);
    for (i=0; i < num_nset; i++) {
      int num_nodes_in_set = 0;
      int num_df_in_set = 0;
      ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set);
      size += num_nodes_in_set;
      size += num_df_in_set * iows;
    }
    free(ids);
  }

  /* Sidesets */
  ex_get_dimension(exoid, DIM_NUM_SS, "sidesets", &num_sset, &temp, routine);
  if (num_sset > 0) {
    /* Allocate storage for sideset parameters... */
    int *ids = malloc(num_sset * sizeof(int));
    size_t i;

    size += 2*num_sset; /* Status + ids */
    ex_get_ids(exoid, EX_SIDE_SET, ids);
    for (i=0; i < num_sset; i++) {
      int num_sides_in_set = 0;
      int num_df_in_set = 0;
      ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set);
      size += num_sides_in_set * 2;
      size += num_df_in_set * iows;
    }
    free(ids);
  }

  if (ex_large_model(exoid) == 0 && size > (1<<29)) {

    fprintf(stderr, "ERROR: Size to store header information exceeds 2GB in file id %d\n       File is probably corrupt, rerun with environment variable EXODUS_LARGE_MODEL set.\n", exoid);
  }
  return size;
}
Example #16
0
int ex_get_var_tab (int  exoid,
		    const char *var_type,
		    int  num_blk,
		    int  num_var,
		    int *var_tab)
{
   int dimid, varid, tabid, i, j, iresult;
   long num_entity = -1;
   long num_var_db = -1;
   long start[2], count[2]; 
   nclong *longs;
   char errmsg[MAX_ERR_LENGTH];
   const char* routine = "ex_get_var_tab";

   /*
    * 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 */
   
   if (*var_type == 'e' || *var_type == 'E') {
     dimid = ex_get_dimension(exoid, DIM_NUM_EL_BLK,   "element", &num_entity, routine);
     varid = ex_get_dimension(exoid, DIM_NUM_ELE_VAR,  "element variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_ELEM_TAB);
     var_name = "vals_elem_var";
     ent_type = "eb";
   }
   else if (*var_type == 'm' || *var_type == 'M') {
     dimid = ex_get_dimension(exoid, DIM_NUM_NS,       "nodeset", &num_entity, routine);
     varid = ex_get_dimension(exoid, DIM_NUM_NSET_VAR, "nodeset variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_NSET_TAB);
     var_name = "vals_nset_var";
     ent_type = "ns";
   }
   else if (*var_type == 's' || *var_type == 'S') {
     dimid = ex_get_dimension(exoid, DIM_NUM_SS,       "sideset", &num_entity, routine);
     varid = ex_get_dimension(exoid, DIM_NUM_SSET_VAR, "sideset variables", &num_var_db, routine);
     tabid = ncvarid (exoid, VAR_SSET_TAB);
     var_name = "vals_sset_var";
     ent_type = "ss";
   }
   else {       /* invalid variable type */
     exerrval = EX_BADPARAM;
     sprintf(errmsg,
	     "Error: Invalid variable type %c specified in file id %d",
	     *var_type, exoid);
     ex_err("ex_get_varid",errmsg,exerrval);
     return (EX_WARN);
   }
   
   if (dimid == -1) {
     exerrval = ncerr;
     return (EX_FATAL);
   }

   if (varid == -1) {
     exerrval = ncerr;
     return (EX_WARN);
   }

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

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

   if (tabid == -1) {
     /* 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 ((tabid = ncvarid (exoid, ex_catstr2(var_name, i+1, ent_type, j+1))) == -1) {

	   /* variable doesn't exist; put a 0 in the truth table */
           var_tab[j*num_var+i] = 0;
	 } else {
	   
	   /* variable exists; put a 1 in the truth table */
           var_tab[j*num_var+i] = 1;
	 }
       }
     }
   } else {

     /* read in the truth table */

     /*
      * 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;
     start[1] = 0;

     count[0] = num_blk;
     count[1] = num_var;

     if (sizeof(int) == sizeof(nclong)) {
        iresult = ncvarget (exoid, tabid, start, count, var_tab);
     } else {
       if (!(longs = static_cast<nclong*>(malloc (num_blk*num_var * sizeof(nclong))))) {
         exerrval = EX_MEMFAIL;
         sprintf(errmsg,
                 "Error: failed to allocate memory for truth table for file id %d",
                 exoid);
         ex_err("ex_get_var_tab",errmsg,exerrval);
         return (EX_FATAL);
       }
       iresult = ncvarget (exoid, tabid, start, count, longs);
     }
     
     if (iresult == -1) {
       exerrval = ncerr;
       sprintf(errmsg,
               "Error: failed to get truth table from file id %d", exoid);
       ex_err("ex_get_var_tab",errmsg,exerrval);
       return (EX_FATAL);
     }

     if (sizeof(int) != sizeof(nclong)) {
       ltoi (longs, var_tab, num_blk*num_var);
       free (longs);
     }

   } 


   return (EX_NOERR);

}
Example #17
0
int ex_get_var_time(int exoid, ex_entity_type var_type, int var_index, int64_t id,
                    int beg_time_step, int end_time_step, void *var_vals)
{
  int         dimid, varid, numel = 0, offset;
  int         status;
  int *       stat_vals = NULL;
  size_t      num_obj, i;
  size_t      num_entries_this_obj = 0;
  size_t      start[2], count[2];
  char        errmsg[MAX_ERR_LENGTH];
  const char *varobjids;
  const char *varobstat;

  switch (var_type) {
  case EX_GLOBAL:
    return ex_get_glob_var_time_int(exoid, var_index, beg_time_step, end_time_step, var_vals);
  case EX_NODAL:
    return ex_get_nodal_var_time_int(exoid, var_index, id, beg_time_step, end_time_step, var_vals);
  case EX_EDGE_BLOCK:
    varobjids = VAR_ID_ED_BLK;
    varobstat = VAR_STAT_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    varobjids = VAR_ID_FA_BLK;
    varobstat = VAR_STAT_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    varobjids = VAR_ID_EL_BLK;
    varobstat = VAR_STAT_EL_BLK;
    break;
  case EX_NODE_SET:
    varobjids = VAR_NS_IDS;
    varobstat = VAR_NS_STAT;
    break;
  case EX_EDGE_SET:
    varobjids = VAR_ES_IDS;
    varobstat = VAR_ES_STAT;
    break;
  case EX_FACE_SET:
    varobjids = VAR_FS_IDS;
    varobstat = VAR_FS_STAT;
    break;
  case EX_SIDE_SET:
    varobjids = VAR_SS_IDS;
    varobstat = VAR_SS_STAT;
    break;
  case EX_ELEM_SET:
    varobjids = VAR_ELS_IDS;
    varobstat = VAR_ELS_STAT;
    break;
  default:
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid variable type (%d) specified for file id %d",
             var_type, exoid);
    ex_err("ex_get_var_time", errmsg, exerrval);
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

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

  /* find what object the entry is in */

  /* first, find out how many objects there are */
  status = ex_get_dimension(exoid, ex_dim_num_objects(var_type), ex_name_of_object(var_type),
                            &num_obj, &dimid, "ex_get_var_time");
  if (status != NC_NOERR) {
    return status;
  }

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

  if ((status = nc_inq_varid(exoid, varobjids, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s ids in file id %d",
             ex_name_of_object(var_type), exoid);
    ex_err("ex_get_var_time", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* allocate space for stat array */
  if (!(stat_vals = malloc((int)num_obj * sizeof(int)))) {
    exerrval = EX_MEMFAIL;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to allocate memory for %s status array for file id %d",
             ex_name_of_object(var_type), exoid);
    ex_err("ex_get_var_time", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* get variable id of status array */
  if (nc_inq_varid(exoid, varobstat, &varid) == NC_NOERR) {
    /* if status array exists, use it, otherwise assume, object exists
       to be backward compatible */

    if ((status = nc_get_var_int(exoid, varid, stat_vals)) != NC_NOERR) {
      exerrval = status;
      free(stat_vals);
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s status array from file id %d",
               ex_name_of_object(var_type), exoid);
      ex_err("ex_get_var_time", errmsg, exerrval);
      return (EX_FATAL);
    }
  }
  else { /* default: status is true */
    for (i = 0; i < num_obj; i++) {
      stat_vals[i] = 1;
    }
  }

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

  i = 0;
  if (stat_vals[i] != 0) {
    if ((status = nc_inq_dimid(exoid, ex_dim_num_entries_in_object(var_type, i + 1), &dimid)) !=
        NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to locate number of entries in %" ST_ZU "th %s in file id %d", i,
               ex_name_of_object(var_type), exoid);
      ex_err("ex_get_var_time", errmsg, exerrval);
      free(stat_vals);
      return (EX_FATAL);
    }

    if ((status = nc_inq_dimlen(exoid, dimid, &num_entries_this_obj)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to get number of entries in %" ST_ZU "th %s in file id %d", i,
               ex_name_of_object(var_type), exoid);
      ex_err("ex_get_var_time", errmsg, exerrval);
      free(stat_vals);
      return (EX_FATAL);
    }
  } /* End NULL object check */

  numel = num_entries_this_obj;

  while (numel <= id) {
    if (stat_vals[++i] != 0) {
      if ((status = nc_inq_dimid(exoid, ex_dim_num_entries_in_object(var_type, i + 1), &dimid)) !=
          NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to locate number of entries in %" ST_ZU "th %s in file id %d", i,
                 ex_name_of_object(var_type), exoid);
        ex_err("ex_get_var_time", errmsg, exerrval);
        free(stat_vals);
        return (EX_FATAL);
      }

      if ((status = nc_inq_dimlen(exoid, dimid, &num_entries_this_obj)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to get number of entries in %" ST_ZU "th %s in file id %d", i,
                 ex_name_of_object(var_type), exoid);
        ex_err("ex_get_var_time", errmsg, exerrval);
        free(stat_vals);
        return (EX_FATAL);
      }
      numel += num_entries_this_obj;
    }
  }
  offset = id - (numel - num_entries_this_obj);

  /* inquire previously defined variable */
  if ((status = nc_inq_varid(exoid, ex_name_var_of_object(var_type, var_index, i + 1), &varid)) !=
      NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate variable %" ST_ZU " for %dth %s in file id %d", i, var_index,
             ex_name_of_object(var_type), exoid);
    ex_err("ex_get_var_time", errmsg, exerrval);
    free(stat_vals);
    return (EX_FATAL);
  }

  free(stat_vals);

  /* Check that times are in range */
  {
    int num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME);
    if (beg_time_step <= 0 || beg_time_step > num_time_steps) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: beginning time_step is out-of-range. Value = %d, "
                                       "valid range is 1 to %d in file id %d",
               beg_time_step, num_time_steps, exoid);
      ex_err("ex_get_var_time", errmsg, EX_BADPARAM);
      return (EX_FATAL);
    }

    if (end_time_step < 0) {
      /* user is requesting the maximum time step;  we find this out using the
       * database inquire function to get the number of time steps;  the ending
       * time step number is 1 less due to 0 based array indexing in C
       */
      end_time_step = ex_inquire_int(exoid, EX_INQ_TIME);
    }
    else if (end_time_step < beg_time_step || end_time_step > num_time_steps) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: end time_step is out-of-range. Value = %d, valid "
                                       "range is %d to %d in file id %d",
               beg_time_step, end_time_step, num_time_steps, exoid);
      ex_err("ex_get_var_time", errmsg, EX_BADPARAM);
      return (EX_FATAL);
    }
  }

  /* read values of object variable */
  start[0] = --beg_time_step;
  start[1] = offset;

  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, var_vals);
  }
  else {
    status = nc_get_vara_double(exoid, varid, start, count, var_vals);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s variable values in file id %d",
             ex_name_of_object(var_type), exoid);
    ex_err("ex_get_var_time", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Example #18
0
int ex_put_truth_table (int  exoid,
                        ex_entity_type obj_type,
                        int  num_blk,
                        int  num_var,
                        int *var_tab)
{
    int numelblkdim, numelvardim, timedim, dims[2], varid;
    char *sta_type, *tab_type;
    size_t num_entity = 0;
    size_t num_var_db = 0;
    int *stat_vals;
    int i, j, k;
    int status;
    char errmsg[MAX_ERR_LENGTH];
    const char* routine = "ex_put_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;
    const char* ent_size = NULL;
    exerrval = 0; /* clear error code */

    ex_get_dimension(exoid, ex_dim_num_objects(obj_type),
                     ex_name_of_object(obj_type), &num_entity, &numelblkdim, routine);

    if (obj_type == EX_ELEM_BLOCK) {
        ex_get_dimension(exoid, DIM_NUM_ELE_VAR,  "element variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_ELEM_TAB, &varid);
        var_name = "vals_elem_var";
        ent_type = "eb";
        ent_size = "num_el_in_blk";
        sta_type = VAR_STAT_EL_BLK;
        tab_type = VAR_ELEM_TAB;
    }
    else if (obj_type == EX_EDGE_BLOCK) {
        ex_get_dimension(exoid, DIM_NUM_EDG_VAR, "edge block variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_EBLK_TAB, &varid);
        var_name = "vals_edge_var";
        ent_type = "eb";
        ent_size = "num_ed_in_blk";
        sta_type = VAR_STAT_ED_BLK;
        tab_type = VAR_EBLK_TAB;
    }
    else if (obj_type  == EX_FACE_BLOCK) {
        ex_get_dimension(exoid, DIM_NUM_FAC_VAR, "face block variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_FBLK_TAB, &varid);
        var_name = "vals_face_var";
        ent_type = "fb";
        ent_size = "num_fa_in_blk";
        sta_type = VAR_STAT_FA_BLK;
        tab_type = VAR_FBLK_TAB;
    }
    else if (obj_type == EX_SIDE_SET) {
        ex_get_dimension(exoid, DIM_NUM_SSET_VAR, "sideset variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_SSET_TAB, &varid);
        var_name = "vals_sset_var";
        ent_type = "ss";
        ent_size = "num_side_ss";
        sta_type = VAR_SS_STAT;
        tab_type = VAR_SSET_TAB;
    }
    else if (obj_type == EX_NODE_SET) {
        ex_get_dimension(exoid, DIM_NUM_NSET_VAR, "nodeset variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_NSET_TAB, &varid);
        var_name = "vals_nset_var";
        ent_type = "ns";
        ent_size = "num_nod_ns";
        sta_type = VAR_NS_STAT;
        tab_type = VAR_NSET_TAB;
    }
    else if (obj_type == EX_EDGE_SET) {
        ex_get_dimension(exoid, DIM_NUM_ESET_VAR, "edge set variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_ESET_TAB, &varid);
        var_name = "vals_eset_var";
        ent_type = "es";
        ent_size = "num_edge_es";
        sta_type = VAR_ES_STAT;
        tab_type = VAR_ESET_TAB;
    }
    else if (obj_type == EX_FACE_SET) {
        ex_get_dimension(exoid, DIM_NUM_FSET_VAR, "face set variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_FSET_TAB, &varid);
        var_name = "vals_fset_var";
        ent_type = "fs";
        ent_size = "num_face_fs";
        sta_type = VAR_FS_STAT;
        tab_type = VAR_FSET_TAB;
    }
    else if (obj_type == EX_ELEM_SET) {
        ex_get_dimension(exoid, DIM_NUM_ELSET_VAR, "element set variables",
                         &num_var_db, &numelvardim, routine);
        nc_inq_varid (exoid, VAR_ELSET_TAB, &varid);
        var_name = "vals_elset_var";
        ent_type = "es";
        ent_size = "num_ele_els";
        sta_type = VAR_ELS_STAT;
        tab_type = VAR_ELSET_TAB;
    }

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

    if ((int)num_entity != 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("ex_get_var_tab",errmsg,exerrval);
        return (EX_FATAL);
    }

    if ((int)num_var_db != 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("ex_get_var_tab",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* Get status array for later use */
    if (!(stat_vals = malloc(num_blk*sizeof(int)))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate memory for %s status array for file id %d",
                ex_name_of_object(obj_type), exoid);
        ex_err(routine,errmsg,exerrval);
        return (EX_FATAL);
    }

    status = nc_inq_varid (exoid, sta_type, &varid);

    /* get variable id of status array */
    if (status == NC_NOERR) {
        /* if status array exists (V 2.01+), use it, otherwise assume
           object exists to be backward compatible */

        if ((status = nc_get_var_int (exoid, varid, stat_vals)) != NC_NOERR) {
            exerrval = status;
            free(stat_vals);
            sprintf(errmsg,
                    "Error: failed to get %s status array from file id %d",
                    ex_name_of_object(obj_type), exoid);
            ex_err("put_var_tab",errmsg,exerrval);
            return (EX_FATAL);
        }
    } else {
        /* status array doesn't exist (V2.00), dummy one up for later checking */
        for(i=0; i<num_blk; i++)
            stat_vals[i] = 1;
    }

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

    /* inquire previously defined dimensions */
    if ((status = nc_inq_dimid (exoid, DIM_TIME, &timedim)) != NC_NOERR) {
        exerrval = status;
        free(stat_vals);
        sprintf(errmsg,
                "Error: failed to locate time variable in file id %d",
                exoid);
        ex_err(routine,errmsg,exerrval);
        goto error_ret;          /* exit define mode and return */
    }

    /* define netCDF variables in which to store EXODUS II element
     * variable values
     */

    k = 0;
    for (i=0; i<num_blk; i++) {
        for (j=1; j<=num_var; j++) {

            /* check if variables are to be put out for this entity */
            if (var_tab[k] != 0) {
                if (stat_vals[i] != 0) {/* check for NULL entity */
                    /* NOTE: This code used to zero out the var_tab entry
                       if the stat_vals[i] value was zero. However, in some
                       cases it is good to know that a variable was assigned to
                       an entity even if that entity is empty. The code was
                       changed to not modify the truth table.
                    */
                    dims[0] = timedim;

                    /* Determine number of entities in block */
                    if ((status = nc_inq_dimid(exoid, ex_catstr(ent_size, (i+1)), &dims[1])) != NC_NOERR) {
                        exerrval = status;
                        free(stat_vals);
                        sprintf(errmsg,
                                "Error: failed to locate number of entities in %d'th %s in file id %d",
                                i+1, ex_name_of_object(obj_type), exoid);
                        ex_err(routine,errmsg,exerrval);
                        goto error_ret;          /* exit define mode and return */
                    }


                    /* 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 II variable (which is part
                     * of the name of the netCDF variable) will begin at 1
                     * instead of 0
                     */

                    if ((status = nc_def_var(exoid, ex_catstr2(var_name, j, ent_type, i+1),
                                             nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) {
                        if (status != NC_ENAMEINUSE) {
                            exerrval = status;
                            free(stat_vals);
                            sprintf(errmsg,
                                    "Error: failed to define variable for %d'th %s in file id %d",
                                    i+1, ex_name_of_object(obj_type), exoid);
                            ex_err(routine,errmsg,exerrval);
                            goto error_ret;  /* exit define mode and return */
                        }
                        ex_compress_variable(exoid, varid, 2);
                    }
                }
            }  /* if */
            k++; /* increment element truth table pointer */
        }  /* for j */
    }  /* for i */

    free (stat_vals);

    /* create a variable array in which to store the truth table
     */

    dims[0] = numelblkdim;
    dims[1] = numelvardim;
    status = nc_def_var (exoid, tab_type, NC_INT, 2, dims, &varid);

    if (status != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to define %s variable truth table in file id %d",
                ex_name_of_object(obj_type), exoid);
        ex_err(routine,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 definitions in file id %d",
                exoid);
        ex_err(routine,errmsg,exerrval);
        return (EX_FATAL);
    }

    /* write out the element variable truth table */
    status = nc_put_var_int(exoid, varid, var_tab);

    if (status != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to store variable truth table in file id %d",
                exoid);
        ex_err(routine,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(routine,errmsg,exerrval);
    }
    return (EX_FATAL);
}