예제 #1
0
int ne_put_elem_var_slab (int   neid,
		          int   time_step,
		          int   elem_var_index,
		          int   elem_blk_id,
                          int   start_pos,
		          int   num_vals,
		          void *elem_var_vals)
{
  int status;
  int varid, dimid,time_dim, numelbdim, dims[2], elem_blk_id_ndx;
  size_t num_elem_blk, num_elem_var, start[2], count[2];
  int *elem_var_tab;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  /* Determine index of elem_blk_id in VAR_ID_EL_BLK array */
  if ((elem_blk_id_ndx = ex_id_lkup(neid, EX_ELEM_BLOCK, elem_blk_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
	      "Warning: no variables allowed for NULL block %d in file id %d",
	      elem_blk_id, neid);
      ex_err("ne_put_elem_var_slab", errmsg, EX_MSG);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "Error: failed to locate element block id %d in %s array in file id %d",
	      elem_blk_id, VAR_ID_EL_BLK, neid);
      ex_err("ne_put_elem_var_slab", errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  if ((status = nc_inq_varid (neid,
			      VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx), &varid)) != NC_NOERR) {
    if (status == NC_ENOTVAR) { /* variable doesn't exist, create it! */

      /*    inquire previously defined dimensions */

      /* check for the existance of an element variable truth table */
      if ((status = nc_inq_varid (neid, VAR_ELEM_TAB, &varid)) == NC_NOERR) {
	/* find out number of element blocks and element variables */
	if ((status = nc_inq_dimid (neid, DIM_NUM_EL_BLK, &dimid)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to locate number of element blocks in file id %d",
		  neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

	if ((status = nc_inq_dimlen(neid, dimid, &num_elem_blk)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to get number of element blocks in file id %d",
		  neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

	if ((status = nc_inq_dimid (neid, DIM_NUM_ELE_VAR, &dimid)) != NC_NOERR) {
	  exerrval = EX_BADPARAM;
	  sprintf(errmsg,
		  "Error: no element variables stored in file id %d",
		  neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

	if ((status = nc_inq_dimlen(neid, dimid, &num_elem_var)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to get number of element variables in file id %d",
		  neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

	if (!(elem_var_tab =
	      (int *)malloc(num_elem_blk*num_elem_var*sizeof(int)))) {
	  exerrval = EX_MEMFAIL;
	  sprintf(errmsg,
		  "Error: failed to allocate memory for element variable truth table in file id %d",
		  neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}

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

	if (elem_var_tab[num_elem_var*(elem_blk_id_ndx-1)+elem_var_index-1] == 0L) {
	  free(elem_var_tab);
	  exerrval = EX_BADPARAM;
	  sprintf(errmsg,
		  "Error: Invalid element variable %d, block %d in file id %d",
		  elem_var_index, elem_blk_id, neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	  return (EX_FATAL);
	}
	free(elem_var_tab);
      }

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

      if ((status = nc_inq_dimid(neid, DIM_NUM_EL_IN_BLK(elem_blk_id_ndx), &numelbdim)) != NC_NOERR) {
	if (status == NC_EBADDIM) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: number of elements in element block %d not defined in file id %d",
		  elem_blk_id, neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	} else {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to locate number of elements in element block %d in file id %d",
		  elem_blk_id, neid);
	  ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	}
	goto error_ret;
      }

      /*    variable doesn't exist so put file into define mode  */
      if ((status = nc_redef (neid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to put file id %d into define mode", neid);
	ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	return (EX_FATAL);
      }


      /*    define netCDF variable to store element variable values */
      dims[0] = time_dim;
      dims[1] = numelbdim;
      if ((status = nc_def_var(neid, VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx),
			       nc_flt_code(neid), 2, dims, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define element variable %d in file id %d",
		elem_var_index, neid);
	ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	goto error_ret;
      }


      /*    leave define mode  */
      if ((status = nc_enddef(neid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to complete element variable %s definition to file id %d",
		VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx), neid);
	ex_err("ne_put_elem_var_slab", errmsg, exerrval);
	return (EX_FATAL);
      }
    } else {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate element variable %s in file id %d",
	      VAR_ELEM_VAR(elem_var_index, elem_blk_id_ndx),neid);
      ex_err("ne_put_elem_var_slab", errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  /* store element variable values */
  start[0] = --time_step;
  start[1] = --start_pos;

  count[0] = 1;
  count[1] = num_vals;

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

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store element variable %d in file id %d", 
	    elem_var_index, neid);
    ex_err("ne_put_elem_var_slab", errmsg, exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (neid) != NC_NOERR)     /* exit define mode */
    {
      sprintf(errmsg,
	      "Error: failed to complete definition for file id %d", neid);
      ex_err("ne_put_elem_var_slab", errmsg, exerrval);
    }
  return (EX_FATAL);
}
예제 #2
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);
}
예제 #3
0
파일: exgblk.c 프로젝트: 0004c/VTK
int ex_get_block( int exoid,
      ex_entity_type blk_type,
      int blk_id,
      char* elem_type,
      int* num_entries_this_blk,
      int* num_nodes_per_entry,
      int* num_edges_per_entry,
      int* num_faces_per_entry,
      int* num_attr_per_entry )
{
  int dimid, connid, blk_id_ndx;
  size_t len;
  char *ptr;
  char  errmsg[MAX_ERR_LENGTH];
  int status;
  const char* dnument;
  const char* dnumnod;
  const char* dnumedg;
  const char* dnumfac;
  const char* dnumatt;
  const char* ablknam;
  const char* vblkcon;

  exerrval = 0;

  /* First, locate index of element block id in VAR_ID_EL_BLK array */
  blk_id_ndx = ex_id_lkup(exoid,blk_type,blk_id);
  if (exerrval != 0)  {
    if (exerrval == EX_NULLENTITY) {    /* NULL element block?    */
      if ( elem_type )
  strcpy(elem_type, "NULL");     /* NULL element type name */
      *num_entries_this_blk = 0;       /* no elements            */
      *num_nodes_per_entry = 0;        /* no nodes               */
      *num_attr_per_entry = 0;         /* no attributes          */
      return (EX_NOERR);
    } else {
      sprintf(errmsg,
        "Error: failed to locate %s id %d in id array in file id %d",
        ex_name_of_object(blk_type), blk_id,exoid);
      ex_err("ex_get_block",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  switch (blk_type) {
  case EX_EDGE_BLOCK:
    dnument = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_ED(blk_id_ndx);
    dnumedg = 0;
    dnumfac = 0;
    dnumatt = DIM_NUM_ATT_IN_EBLK(blk_id_ndx);
    vblkcon = VAR_EBCONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  case EX_FACE_BLOCK:
    dnument = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_FA(blk_id_ndx);
    dnumedg = 0; /* it is possible this might be non-NULL some day */
    dnumfac = 0;
    dnumatt = DIM_NUM_ATT_IN_FBLK(blk_id_ndx);
    vblkcon = VAR_FBCONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  case EX_ELEM_BLOCK:
    dnument = DIM_NUM_EL_IN_BLK(blk_id_ndx);
    dnumnod = DIM_NUM_NOD_PER_EL(blk_id_ndx);
    dnumedg = DIM_NUM_EDG_PER_EL(blk_id_ndx);
    dnumfac = DIM_NUM_FAC_PER_EL(blk_id_ndx);
    dnumatt = DIM_NUM_ATT_IN_BLK(blk_id_ndx);
    vblkcon = VAR_CONN(blk_id_ndx);
    ablknam = ATT_NAME_ELB;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Bad block type parameter (%d) specified for file id %d.",
       blk_type, exoid );
    return (EX_FATAL);
  }

  /* inquire values of some dimensions */
  if ( num_entries_this_blk ) {
    if ((status = nc_inq_dimid (exoid, dnument, &dimid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to locate number of entities in %s %d in file id %d",
        ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_block",errmsg, exerrval);
      return(EX_FATAL);
    }

    if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to get number of %ss in block %d in file id %d",
        ex_name_of_object(blk_type),blk_id, exoid);
      ex_err("ex_get_block",errmsg, exerrval);
      return(EX_FATAL);
    }
    *num_entries_this_blk = len;
  }

  if ( num_nodes_per_entry ) {
    if ((status = nc_inq_dimid (exoid, dnumnod, &dimid)) != NC_NOERR) {
      /* undefined => no node entries per element */
      len = 0;
    } else {
      if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to get number of nodes/entity in %s %d in file id %d",
    ex_name_of_object(blk_type),blk_id, exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }
    }
    *num_nodes_per_entry = len;
  }

  if ( num_edges_per_entry ) {
    if ( blk_type != EX_ELEM_BLOCK ) {
      exerrval = (EX_WARN);
      sprintf(errmsg,
        "Warning: non-NULL pointer passed to num_edges_per_entry for %s query in file id %d",
        ex_name_of_object(blk_type),exoid);
      ex_err("ex_get_block",errmsg,exerrval);
    } else {
      if ((status = nc_inq_dimid (exoid, dnumedg, &dimid)) != NC_NOERR) {
  /* undefined => no edge entries per element */
  len = 0;
      } else {
  if ((status = nc_inq_dimlen (exoid, dimid, &len)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to get number of edges/entry in %s %d in file id %d",
      ex_name_of_object(blk_type),blk_id, exoid);
    ex_err("ex_get_block",errmsg, exerrval);
    return(EX_FATAL);
  }
      }
      *num_edges_per_entry = len;
    }
  }

  if ( num_faces_per_entry ) {
    if ( blk_type != EX_ELEM_BLOCK ) {
      exerrval = (EX_WARN);
      sprintf(errmsg,
        "Warning: non-NULL pointer passed to num_faces_per_entry for %s query in file id %d",
        ex_name_of_object(blk_type),exoid);
      ex_err("ex_get_block",errmsg,exerrval);
    } else {
      if ((status = nc_inq_dimid (exoid, dnumfac, &dimid)) != NC_NOERR) {
  /* undefined => no face entries per element */
  len = 0;
      } else {
  if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
      "Error: failed to get number of faces/entity in %s %d in file id %d",
      ex_name_of_object(blk_type),blk_id, exoid);
    ex_err("ex_get_block",errmsg, exerrval);
    return(EX_FATAL);
  }
      }
      *num_faces_per_entry = len;
    }
  }

  if ( num_attr_per_entry ) {
    if ((status = nc_inq_dimid (exoid, dnumatt, &dimid)) != NC_NOERR) {
      /* dimension is undefined */
      *num_attr_per_entry = 0;
    } else {
      if ((status = nc_inq_dimlen(exoid, dimid, &len)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to get number of attributes in %s %d in file id %d",
    ex_name_of_object(blk_type),blk_id, exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }
      *num_attr_per_entry = len;
    }
  }

  if ( elem_type ) {
    if (*num_nodes_per_entry > 0) {
      ; /* Do nothing, vblkcon should be correctly set already */
    } else if (*num_edges_per_entry > 0) {
      vblkcon = VAR_EBCONN(blk_id_ndx);
    } else if (*num_faces_per_entry > 0) {
      vblkcon = VAR_FCONN(blk_id_ndx);
    }

    if (vblkcon) {
      /* look up connectivity array for this element block id */
      if ((status = nc_inq_varid (exoid, vblkcon, &connid)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to locate connectivity array for %s %d in file id %d",
    ex_name_of_object(blk_type), blk_id,exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }

      if ((status = nc_inq_attlen (exoid, connid, ablknam, &len)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,
    "Error: failed to get %s %d type in file id %d",
    ex_name_of_object(blk_type), blk_id,exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }

      if (len > (MAX_STR_LENGTH+1)) {
  len = MAX_STR_LENGTH;
  sprintf (errmsg,
     "Warning: %s %d type will be truncated to %ld chars", 
     ex_name_of_object(blk_type), blk_id, (long)len);
  ex_err("ex_get_block",errmsg,EX_MSG);
      }
      
      /* get the element type name */
      if ((status = nc_get_att_text (exoid, connid, ablknam, elem_type)) != NC_NOERR) {
  exerrval = status;
  sprintf(errmsg,"Error: failed to get %s %d type in file id %d",
    ex_name_of_object(blk_type), blk_id, exoid);
  ex_err("ex_get_block",errmsg, exerrval);
  return(EX_FATAL);
      }
      
      /* get rid of trailing blanks */
      ptr = elem_type;
      /* fprintf(stderr,"[exgblk] %s, len: %d\n",ptr,len); */
      while (ptr < elem_type + len && *ptr != ' ') {
  ptr++;
      }
      *(ptr) = '\0';
    }
  }
  return (EX_NOERR);
}
int ex_put_prop_names (int   exoid,
                       ex_entity_type obj_type,
                       int   num_props,
                       char **prop_names)
{
  int status;
  int oldfill, temp;
  int i, propid, dimid, dims[1];
  char name[MAX_VAR_NAME_LENGTH+1];
  int vals[1];

  char errmsg[MAX_ERR_LENGTH];

  exerrval  = 0; /* clear error code */

  /* inquire id of previously defined dimension (number of objects) */
  if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(obj_type), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate number of %s in file id %d",
	    ex_name_of_object(obj_type), exoid);
    ex_err("ex_put_prop_names",errmsg, exerrval);
    return(EX_FATAL);
  }

  nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */

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

  /* define num_props variables; we postpend the netcdf variable name with  */
  /* a counter starting at 2 because "xx_prop1" is reserved for the id array*/
  dims[0] = dimid;

  for (i=0; i<num_props; i++) {
    switch (obj_type) {
    case EX_ELEM_BLOCK:
      strcpy (name, VAR_EB_PROP(i+2));
      break;
    case EX_FACE_BLOCK:
      strcpy (name, VAR_FA_PROP(i+2));
      break;
    case EX_EDGE_BLOCK:
      strcpy (name, VAR_ED_PROP(i+2));
      break;
    case EX_NODE_SET:
      strcpy (name, VAR_NS_PROP(i+2));
      break;
    case EX_SIDE_SET:
      strcpy (name, VAR_SS_PROP(i+2));
      break;
    case EX_EDGE_SET:
      strcpy (name, VAR_ES_PROP(i+2));
      break;
    case EX_FACE_SET:
      strcpy (name, VAR_FS_PROP(i+2));
      break;
    case EX_ELEM_SET:
      strcpy (name, VAR_ELS_PROP(i+2));
      break;
    case EX_ELEM_MAP:
      strcpy (name, VAR_EM_PROP(i+2));
      break;
    case EX_FACE_MAP:
      strcpy (name, VAR_FAM_PROP(i+2));
      break;
    case EX_EDGE_MAP:
      strcpy (name, VAR_EDM_PROP(i+2));
      break;
    case EX_NODE_MAP:
      strcpy (name, VAR_NM_PROP(i+2));
      break;
    default:
      exerrval = EX_BADPARAM;
      sprintf(errmsg, "Error: object type %d not supported; file id %d",
	      obj_type, exoid);
      ex_err("ex_put_prop_names",errmsg,exerrval);
      goto error_ret;        /* Exit define mode and return */
    }

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

    vals[0] = 0; /* fill value */

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

    /*   store property name as attribute of property array variable */
    if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME,
				  strlen(prop_names[i])+1, prop_names[i])) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
              "Error: failed to store property name %s in file id %d",
	      prop_names[i],exoid);
      ex_err("ex_put_prop_names",errmsg,exerrval);
      goto error_ret;  /* Exit define mode and return */
    }
  }

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

  nc_set_fill(exoid, oldfill, &temp); /* default: turn off fill */
  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_prop_names",errmsg,exerrval);
  }
  return (EX_FATAL);
}
예제 #5
0
int ne_get_init_info(int   neid,
                     int  *num_proc,
                     int  *num_proc_in_f,
                     char *ftype
		     )
{
  char *func_name="ne_get_init_info";

  int   dimid, status;
  size_t ltempsv;

  char   errmsg[MAX_ERR_LENGTH];
  /*-----------------------------Execution begins-----------------------------*/

  exerrval = 0; /* clear error code */

  /* Get the file type */
  if (ne_get_file_type(neid, ftype) != EX_NOERR) {
    exerrval = EX_MSG;
    sprintf(errmsg,
            "Error: failed to get file type for file ID %d",
            neid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  if ((status = nc_inq_dimid(neid, DIM_NUM_PROCS, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find dimension ID for \"%s\" in file ID %d",
            DIM_NUM_PROCS, neid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the value of the number of processors */
  if ((status = nc_inq_dimlen(neid, dimid, &ltempsv)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find length of dimension \"%s\" in file ID %d",
            DIM_NUM_PROCS, neid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }
  *num_proc = ltempsv;

  /* Get the dimension ID of processors that have info in this file */
  if ((status = nc_inq_dimid(neid, DIM_NUM_PROCS_F, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find dimension ID for \"%s\" in file ID %d",
            DIM_NUM_PROCS_F, neid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the value of the number of processors that have info in this file */
  if ((status = nc_inq_dimlen(neid, dimid, &ltempsv)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find length of dimension \"%s\" in file ID %d",
            DIM_NUM_PROCS_F, neid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }
  *num_proc_in_f = ltempsv;

  return (EX_NOERR);
}
예제 #6
0
int ne_get_n_coord (int   neid,
                    int   start_node_num,
                    int   num_nodes,
                    void *x_coor,
                    void *y_coor,
                    void *z_coor)
{
  int coordidx, coordidy, coordidz;
  int coordid;
  int status;
  char *which = NULL;

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

  exerrval = 0;

  if ((status = nc_inq_dimid(neid, DIM_NUM_DIM, &ndimdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to find dimension ID for \"%s\" in file id %d",
	    DIM_NUM_DIM, neid);
    ex_err("ne_get_n_coord",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(neid, ndimdim, &num_dim)) != NC_NOERR) {
    sprintf(errmsg,
            "Error: failed to get number of dimensions in file id %d",
	    neid);
    ex_err("ne_get_n_coord",errmsg,exerrval);
    return (EX_FATAL);
  }


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

    start_node_num--; /* do this here so it is only decremented once */
    for (i=0; i<num_dim; i++) {
      start[0] = i;
      start[1] = start_node_num;

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

      if (i == 0 && x_coor != NULL) {
	which = "X";
	if (ex_comp_ws(neid) == 4) {
	  status = nc_get_vara_float(neid, coordid, start, count, x_coor);
	} else {
	  status = nc_get_vara_double(neid, coordid, start, count, x_coor);
	}
      }
      else if (i == 1 && y_coor != NULL) {
	which = "Y";
	if (ex_comp_ws(neid) == 4) {
	  status = nc_get_vara_float(neid, coordid, start, count, y_coor);
	} else {
	  status = nc_get_vara_double(neid, coordid, start, count, y_coor);
	}
      }
      else if (i == 2 && z_coor != NULL) {
	which = "Z";
	if (ex_comp_ws(neid) == 4) {
	  status = nc_get_vara_float(neid, coordid, start, count, z_coor);
	} else {
	  status = nc_get_vara_double(neid, 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, neid);
	ex_err("ne_get_n_coord",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
  } else {

    start_node_num--; /* do this here so it is only decremented once */
    for (i=0; i<num_dim; i++) {
      start[0] = start_node_num;
      count[0] = num_nodes;

      if (i == 0 && x_coor != NULL) {
	which = "X";
	if ((status = nc_inq_varid (neid, VAR_COORD_X, &coordidx)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Warning: failed to locate %s-nodal coordinates in file id %d", which , neid);
	  ex_err("ne_get_n_coord",errmsg,exerrval);
	  return (EX_WARN);
	}
	if (ex_comp_ws(neid) == 4) {
	  status = nc_get_vara_float(neid, coordidx, start, count, x_coor);
	} else {
	  status = nc_get_vara_double(neid, coordidx, start, count, x_coor);
	}
      }
      else if (i == 1 && y_coor != NULL) {
	which = "Y";
	if ((status = nc_inq_varid (neid, VAR_COORD_Y, &coordidy)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Warning: failed to locate %s-nodal coordinates in file id %d", which , neid);
	  ex_err("ne_get_n_coord",errmsg,exerrval);
	  return (EX_WARN);
	}
	if (ex_comp_ws(neid) == 4) {
	  status = nc_get_vara_float(neid, coordidy, start, count, y_coor);
	} else {
	  status = nc_get_vara_double(neid, coordidy, start, count, y_coor);
	}
      }
      else if (i == 2 && z_coor != NULL) {
	which = "Z";
	if ((status = nc_inq_varid (neid, VAR_COORD_Z, &coordidz)) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Warning: failed to locate %s-nodal coordinates in file id %d", which , neid);
	  ex_err("ne_get_n_coord",errmsg,exerrval);
	  return (EX_WARN);
	}
	if (ex_comp_ws(neid) == 4) {
	  status = nc_get_vara_float(neid, coordidz, start, count, z_coor);
	} else {
	  status = nc_get_vara_double(neid, coordidz, start, count, z_coor);
	}
      }
      if (status != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get %s coord array in file id %d", which, neid);
	ex_err("ne_get_n_coord",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
  }
  return (EX_NOERR);
}
예제 #7
0
int ex_put_node_cmap(int exoid, ex_entity_id map_id, void_int *node_ids, void_int *proc_ids,
                     int processor)
{
  const char *func_name = "ex_put_node_cmap";

  int     map_idx, varid, dimid, status;
  size_t  start[1], count[1], ret_val;
  int64_t varidx[2];
  int     value;

  char errmsg[MAX_ERR_LENGTH];
  /*-----------------------------Execution begins-----------------------------*/

  exerrval = 0; /* clear error code */

  /* get the index for the comm map information variables */
  if (ex_get_idx(exoid, VAR_N_COMM_INFO_IDX, varidx, processor) == -1) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
             VAR_N_COMM_INFO_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* Get the index for this map_id */
  if ((map_idx = ne_id_lkup(exoid, VAR_N_COMM_IDS, varidx, map_id)) == -1) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to find index for variable \"%s\" in file ID %d", VAR_N_COMM_IDS,
             exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /*
   * Find out if this is a NULL comm map by checking it's entry in
   * the status vector.
   */
  if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
             VAR_N_COMM_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  start[0] = map_idx;
  if ((status = nc_get_var1_int(exoid, varid, start, &value)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to get variable \"%s\" from file ID %d",
             VAR_N_COMM_STAT, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (value == 0) {
    return (EX_NOERR); /* NULL set */
  }

  /* now I need to get the comm map data index */
  if (ex_get_idx(exoid, VAR_N_COMM_DATA_IDX, varidx, map_idx) == -1) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find index variable, \"%s\", in file ID %d",
             VAR_N_COMM_DATA_IDX, exoid);
    ex_err(func_name, errmsg, exerrval);

    return (EX_FATAL);
  }

  /* check if I need to get the dimension of the cmap data */
  if (varidx[1] == -1) {
    /* Get the size of the comm maps */
    if ((status = nc_inq_dimid(exoid, DIM_NCNT_CMAP, &dimid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get dimension ID for \"%s\" in file ID %d",
               DIM_NCNT_CMAP, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    if ((status = nc_inq_dimlen(exoid, dimid, &ret_val)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NCNT_CMAP,
               exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    varidx[1] = ret_val;
  } /* "if (varidx[1]==-1)" */

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

  /* Output the node IDs for this comm map */
  if ((status = nc_inq_varid(exoid, VAR_N_COMM_NIDS, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
             VAR_N_COMM_NIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_put_vara_longlong(exoid, varid, start, count, node_ids);
  }
  else {
    status = nc_put_vara_int(exoid, varid, start, count, node_ids);
  }
  if (status != NC_NOERR) {
    fprintf(stderr, "Start, Count = %" ST_ZU "\t%" ST_ZU "\n", start[0], count[0]);
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output vector \"%s\" in file ID %d",
             VAR_N_COMM_NIDS, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Output the processor IDs for this map */
  if ((status = nc_inq_varid(exoid, VAR_N_COMM_PROC, &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
             VAR_N_COMM_PROC, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_put_vara_longlong(exoid, varid, start, count, proc_ids);
  }
  else {
    status = nc_put_vara_int(exoid, varid, start, count, proc_ids);
  }
  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable \"%s\" in file ID %d",
             VAR_N_COMM_PROC, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  return (EX_NOERR);
}
예제 #8
0
int ex_get_n_node_set (int   exoid,
                       ex_entity_id node_set_id,
                       int64_t   start_node_num,
                       int64_t   num_nodes,
                       void_int  *node_set_node_list)
{
  int     dimid, node_list_id, node_set_id_ndx, status;
  size_t  num_nodes_in_set, start[1], count[1];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

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

  if ((status = nc_inq_dimid (exoid, DIM_NUM_NS, &dimid))  != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no node sets defined in file id %d",
            exoid);
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_WARN);
  }

  /* Lookup index of node set id in VAR_NS_IDS array */
  if ((node_set_id_ndx = ex_id_lkup(exoid, EX_NODE_SET, node_set_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
              "Warning: node set %"PRId64" is NULL in file id %d",
              node_set_id,exoid);
      ex_err("ex_get_n_node_set",errmsg,EX_MSG);
      return (EX_WARN);
    } else {

      sprintf(errmsg,
              "Error: failed to locate node set %"PRId64" in %s in file id %d",
              node_set_id,VAR_NS_IDS,exoid);
      ex_err("ex_get_n_node_set",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* inquire id's of previously defined dimensions and variables */
  if ((status = nc_inq_dimid (exoid, DIM_NUM_NOD_NS(node_set_id_ndx), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
         "Error: failed to locate number of nodes in node set %"PRId64" in file id %d",
            node_set_id,exoid);
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, dimid, &num_nodes_in_set)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get number of nodes in set %"PRId64" in file id %d",
            node_set_id, exoid);
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check input parameters for a valid range of numbers */
  if (start_node_num < 0 || start_node_num > num_nodes_in_set) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid input");
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_nodes < 0) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid number of nodes in nodes set!");
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* start_node_num now starts at 1, not 0 */
  if ((start_node_num + num_nodes - 1) > num_nodes_in_set) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: request larger than number of nodes in set!");
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid (exoid, VAR_NODE_NS(node_set_id_ndx), &node_list_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to locate node set %"PRId64" node list in file id %d",
            node_set_id,exoid);
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* read in the node list array */
  start[0] = --start_node_num;
  count[0] = num_nodes;

  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    status = nc_get_vara_longlong(exoid, node_list_id, start, count, node_set_node_list);
  } else {
    status = nc_get_vara_int(exoid, node_list_id, start, count, node_set_node_list);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get node set node list in file id %d",
            exoid);
    ex_err("ex_get_n_node_set",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
예제 #9
0
/*!
 * writes the parameters used to describe all element, edge, and face blocks
 * \param     exoid          exodus file id
 * \param     param         block parameters structure
 */
int ex_put_concat_all_blocks(int exoid, const ex_block_params *param)
{
  int    varid, dimid, dims[2], strdim, *eb_stat, *ed_stat, *fa_stat;
  int    temp;
  size_t iblk;
  size_t i;
  int    status;
  size_t num_elem_blk = 0;
  size_t num_edge_blk = 0;
  size_t num_face_blk = 0;
  int    cur_num_elem_blk, nelnoddim, numelbdim, numattrdim, connid = -1;
  int    cur_num_edge_blk, numedbdim, nednoddim, cur_num_face_blk, numfabdim, nfanoddim;
  int    neledgdim = -1, nelfacdim = -1;
  char   errmsg[MAX_ERR_LENGTH];
  int    elem_work = 0; /* is DIM_NUM_EL_BLK defined? If so, there's work to do */
  int    edge_work = 0; /* is DIM_NUM_ED_BLK defined? If so, there's work to do */
  int    face_work = 0; /* is DIM_NUM_FA_BLK defined? If so, there's work to do */

  int *edge_id_int = NULL;
  int *face_id_int = NULL;
  int *elem_id_int = NULL;

  int64_t *edge_id_int64 = NULL;
  int64_t *face_id_int64 = NULL;
  int64_t *elem_id_int64 = NULL;

  int ids_int64 = ex_int64_status(exoid) & EX_IDS_INT64_API;

  static const char *dim_num_maps[] = {
      DIM_NUM_NM, DIM_NUM_EDM, DIM_NUM_FAM, DIM_NUM_EM,
  };
  static const char *dim_size_maps[] = {
      DIM_NUM_NODES, DIM_NUM_EDGE, DIM_NUM_FACE, DIM_NUM_ELEM,
  };
  static const ex_entity_type map_enums[] = {EX_NODE_MAP, EX_EDGE_MAP, EX_FACE_MAP, EX_ELEM_MAP};

  /* If param->define_maps is true, we must fill these with values from
     ex_put_init_ext
     before entering define mode */
  size_t num_maps[sizeof(dim_num_maps) / sizeof(dim_num_maps[0])];
  size_t num_map_dims = sizeof(dim_num_maps) / sizeof(dim_num_maps[0]);

  if (ids_int64) {
    edge_id_int64 = param->edge_blk_id;
    face_id_int64 = param->face_blk_id;
    elem_id_int64 = param->elem_blk_id;
  }
  else {
    edge_id_int = param->edge_blk_id;
    face_id_int = param->face_blk_id;
    elem_id_int = param->elem_blk_id;
  }

  exerrval = 0; /* clear error code */

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

  if (param->define_maps) {
    for (i = 0; i < num_map_dims; ++i) {
      if ((status = nc_inq_dimid(exoid, dim_num_maps[i], &dimid)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find node map size of file id %d",
                 exoid);
        ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
        return (EX_FATAL);
      }
      if ((status = nc_inq_dimlen(exoid, dimid, num_maps + i)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to retrieve node map size of file id %d",
                 exoid);
        ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
        return (EX_FATAL);
      }
    }
  }

#define EX_PREPARE_BLOCK(TNAME, WNAME, DNUMNAME, VSTATNAME, VIDNAME, LNUMNAME, SNUMNAME, SIDNAME,  \
                         GSTAT)                                                                    \
  /* first check if any TNAME blocks are specified                                                 \
   * OK if zero...                                                                                 \
   */                                                                                              \
  if ((status = (nc_inq_dimid(exoid, DNUMNAME, &dimid))) == NC_NOERR) {                            \
    WNAME = 1;                                                                                     \
                                                                                                   \
    /* Get number of TNAME blocks defined for this file */                                         \
    if ((status = nc_inq_dimlen(exoid, dimid, &LNUMNAME)) != NC_NOERR) {                           \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to get number of " TNAME " blocks in file id %d", exoid);            \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
                                                                                                   \
    /* Fill out the TNAME block status array */                                                    \
    if (!(GSTAT = malloc(LNUMNAME * sizeof(int)))) {                                               \
      exerrval = EX_MEMFAIL;                                                                       \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to allocate space for " TNAME " block status array in file id %d",   \
               exoid);                                                                             \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
                                                                                                   \
    for (i = 0; i < LNUMNAME; i++) {                                                               \
      if (SNUMNAME[i] == 0) /* Is this a NULL TNAME block? */                                      \
        GSTAT[i] = 0;       /* change TNAME block status to NULL */                                \
      else                                                                                         \
        GSTAT[i] = 1; /* change TNAME block status to EX_TRUE */                                   \
    }                                                                                              \
                                                                                                   \
    /* Next, get variable id of status array */                                                    \
    if ((status = nc_inq_varid(exoid, VSTATNAME, &varid)) != NC_NOERR) {                           \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to locate " TNAME " block status in file id %d", exoid);             \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      ex_safe_free(GSTAT);                                                                         \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
                                                                                                   \
    status = nc_put_var_int(exoid, varid, GSTAT);                                                  \
                                                                                                   \
    if (status != NC_NOERR) {                                                                      \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to store " TNAME " block status array to file id %d", exoid);        \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      ex_safe_free(GSTAT);                                                                         \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
                                                                                                   \
    free(GSTAT);                                                                                   \
                                                                                                   \
    /* Next, fill out ids array */                                                                 \
    /* first get id of ids array variable */                                                       \
    if ((status = nc_inq_varid(exoid, VIDNAME, &varid)) != NC_NOERR) {                             \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to locate " TNAME " block ids array in file id %d", exoid);          \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
                                                                                                   \
    /* then, write out id list */                                                                  \
    if (ids_int64) {                                                                               \
      status = nc_put_var_longlong(exoid, varid, SIDNAME);                                         \
    }                                                                                              \
    else {                                                                                         \
      status = nc_put_var_int(exoid, varid, SIDNAME);                                              \
    }                                                                                              \
                                                                                                   \
    if (status != NC_NOERR) {                                                                      \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to store " TNAME " block id array in file id %d", exoid);            \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
  }

  EX_PREPARE_BLOCK("element", elem_work, DIM_NUM_EL_BLK, VAR_STAT_EL_BLK, VAR_ID_EL_BLK,
                   num_elem_blk, param->num_elem_this_blk, param->elem_blk_id, eb_stat);
  EX_PREPARE_BLOCK("edge", edge_work, DIM_NUM_ED_BLK, VAR_STAT_ED_BLK, VAR_ID_ED_BLK, num_edge_blk,
                   param->num_edge_this_blk, param->edge_blk_id, ed_stat);
  EX_PREPARE_BLOCK("face", face_work, DIM_NUM_FA_BLK, VAR_STAT_FA_BLK, VAR_ID_FA_BLK, num_face_blk,
                   param->num_face_this_blk, param->face_blk_id, fa_stat);

  if (elem_work == 0 && edge_work == 0 && face_work == 0 && param->define_maps == 0) {
    /* Nothing to do. This is not an error, but we can save
     * ourselves from entering define mode by returning here.
     */
    return (EX_NOERR);
  }
  /* put netcdf file into define mode  */
  if ((status = nc_redef(exoid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to place file id %d into define mode", exoid);
    ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
    return (EX_FATAL);
  }

#define EX_PREPARE_ATTRIB_ARRAY(TNAME, CURBLK, DNAME, DVAL, ID, VANAME, VADIM0, VADIM1, VANNAME)   \
  if (DVAL[iblk] > 0) {                                                                            \
    if ((status = nc_def_dim(exoid, DNAME(CURBLK + 1), DVAL[iblk], &VADIM1)) != NC_NOERR) {        \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of attributes in " TNAME    \
                                       " block %" PRId64 " in file id %d",                         \
               ID, exoid);                                                                         \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      goto error_ret; /* exit define mode and return */                                            \
    }                                                                                              \
                                                                                                   \
    dims[0] = VADIM0;                                                                              \
    dims[1] = VADIM1;                                                                              \
                                                                                                   \
    if ((status = nc_def_var(exoid, VANAME(CURBLK + 1), nc_flt_code(exoid), 2, dims, &temp)) !=    \
        NC_NOERR) {                                                                                \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR:  failed to define attributes for " TNAME            \
                                       " block %" PRId64 " in file id %d",                         \
               ID, exoid);                                                                         \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      goto error_ret; /* exit define mode and return */                                            \
    }                                                                                              \
    ex_compress_variable(exoid, temp, 2);                                                          \
                                                                                                   \
    /* Attribute names... */                                                                       \
    dims[0] = VADIM1;                                                                              \
    dims[1] = strdim;                                                                              \
                                                                                                   \
    if ((status = nc_def_var(exoid, VANNAME(CURBLK + 1), NC_CHAR, 2, dims, &temp)) != NC_NOERR) {  \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "ERROR: failed to define " TNAME " attribute name array in file id %d", exoid);     \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      goto error_ret; /* exit define mode and return */                                            \
    }                                                                                              \
  }

#define EX_PREPARE_CONN(TNAME, BLK, BLKID, BLKSZ, VNAME, DNAME)                                    \
  if (DNAME > 0) {                                                                                 \
    int conn_int_type = NC_INT;                                                                    \
    if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {                                               \
      conn_int_type = NC_INT64;                                                                    \
    }                                                                                              \
    dims[0] = BLKSZ;                                                                               \
    dims[1] = DNAME;                                                                               \
                                                                                                   \
    if ((status = nc_def_var(exoid, VNAME(BLK + 1), conn_int_type, 2, dims, &connid)) !=           \
        NC_NOERR) {                                                                                \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to create " TNAME                            \
                                       " connectivity array for block %" PRId64 " in file id %d",  \
               BLKID, exoid);                                                                      \
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);                                        \
      goto error_ret; /* exit define mode and return */                                            \
    }                                                                                              \
    ex_compress_variable(exoid, connid, 1);                                                        \
  }

  /* Iterate over edge blocks ... */
  for (iblk = 0; iblk < num_edge_blk; ++iblk) {
    ex_entity_id eb_id;
    if (ids_int64) {
      eb_id = edge_id_int64[iblk];
    }
    else {
      eb_id = edge_id_int[iblk];
    }

    cur_num_edge_blk = ex_get_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK));
    if (cur_num_edge_blk >= (int)num_edge_blk) {
      exerrval = EX_FATAL;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: exceeded number of edge blocks (%ld) defined in file id %d",
               (long)num_edge_blk, exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret;
    }

    /* NOTE: ex_inc_file_item  is used to find the number of edge blocks
       for a specific file and returns that value incremented. */
    cur_num_edge_blk = ex_inc_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK));

    if (param->num_edge_this_blk[iblk] == 0) { /* Is this a NULL edge block? */
      continue;
    }

    /* define some dimensions and variables*/
    if ((status = nc_def_dim(exoid, DIM_NUM_ED_IN_EBLK(cur_num_edge_blk + 1),
                             param->num_edge_this_blk[iblk], &numedbdim)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) { /* duplicate entry */
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: edge block %" PRId64 " already defined in file id %d", eb_id, exoid);
      }
      else {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define number of edges/block for block %" PRId64 " file id %d",
                 eb_id, exoid);
      }
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }

    if ((status = nc_def_dim(exoid, DIM_NUM_NOD_PER_ED(cur_num_edge_blk + 1),
                             param->num_nodes_per_edge[iblk], &nednoddim)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to define number of nodes/edge for block %" PRId64 " in file id %d",
               eb_id, exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }

    /* edge attribute array */
    EX_PREPARE_ATTRIB_ARRAY("edge", cur_num_edge_blk, DIM_NUM_ATT_IN_EBLK, param->num_attr_edge,
                            eb_id, VAR_EATTRIB, numedbdim, numattrdim, VAR_NAME_EATTRIB);

    EX_PREPARE_CONN("edge block", cur_num_edge_blk, eb_id, numedbdim, VAR_EBCONN, nednoddim);

    /* store edge type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->edge_type[iblk]) + 1,
                                  (void *)param->edge_type[iblk])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store edge type name %s in file id %d",
               param->edge_type[iblk], exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }
  }

  /* Iterate over face blocks ... */
  for (iblk = 0; iblk < num_face_blk; ++iblk) {
    ex_entity_id fb_id;
    if (ids_int64) {
      fb_id = face_id_int64[iblk];
    }
    else {
      fb_id = face_id_int[iblk];
    }

    cur_num_face_blk = ex_get_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK));
    if (cur_num_face_blk >= (int)num_face_blk) {
      exerrval = EX_FATAL;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: exceeded number of face blocks (%ld) defined in file id %d",
               (long)num_face_blk, exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret;
    }

    /* NOTE: ex_inc_file_item  is used to find the number of edge blocks
       for a specific file and returns that value incremented. */
    cur_num_face_blk = ex_inc_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK));

    if (param->num_face_this_blk[iblk] == 0) { /* Is this a NULL face block? */
      continue;
    }

    /* define some dimensions and variables*/
    if ((status = nc_def_dim(exoid, DIM_NUM_FA_IN_FBLK(cur_num_face_blk + 1),
                             param->num_face_this_blk[iblk], &numfabdim)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) { /* duplicate entry */
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: face block %" PRId64 " already defined in file id %d", fb_id, exoid);
      }
      else {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define number of faces/block for block %" PRId64 " file id %d",
                 fb_id, exoid);
      }
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }

    if ((status = nc_def_dim(exoid, DIM_NUM_NOD_PER_FA(cur_num_face_blk + 1),
                             param->num_nodes_per_face[iblk], &nfanoddim)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to define number of nodes/face for block %" PRId64 " in file id %d",
               fb_id, exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }

    /* face attribute array */
    EX_PREPARE_ATTRIB_ARRAY("face", cur_num_face_blk, DIM_NUM_ATT_IN_FBLK, param->num_attr_face,
                            fb_id, VAR_FATTRIB, numfabdim, numattrdim, VAR_NAME_FATTRIB);

    EX_PREPARE_CONN("face block", cur_num_face_blk, fb_id, numfabdim, VAR_FBCONN, nfanoddim);

    /* store face type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->face_type[iblk]) + 1,
                                  (void *)param->face_type[iblk])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store face type name %s in file id %d",
               param->face_type[iblk], exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }
  }

  /* Iterate over element blocks ... */
  for (iblk = 0; iblk < num_elem_blk; ++iblk) {
    ex_entity_id eb_id;
    if (ids_int64) {
      eb_id = elem_id_int64[iblk];
    }
    else {
      eb_id = elem_id_int[iblk];
    }

    cur_num_elem_blk = ex_get_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));
    if (cur_num_elem_blk >= (int)num_elem_blk) {
      exerrval = EX_FATAL;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: exceeded number of element blocks (%ld) defined "
                                       "in file id %d",
               (long)num_elem_blk, exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret;
    }

    /* NOTE: ex_inc_file_item  is used to find the number of element blocks
       for a specific file and returns that value incremented. */
    cur_num_elem_blk = ex_inc_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));

    if (param->num_elem_this_blk[iblk] == 0) { /* Is this a NULL element block? */
      continue;
    }

    /* define some dimensions and variables*/
    if ((status = nc_def_dim(exoid, DIM_NUM_EL_IN_BLK(cur_num_elem_blk + 1),
                             param->num_elem_this_blk[iblk], &numelbdim)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) { /* duplicate entry */
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: element block %" PRId64 " already defined in file id %d", eb_id, exoid);
      }
      else {
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of elements/block for "
                                         "block %" PRId64 " file id %d",
                 eb_id, exoid);
      }
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }

    /* Always define DIM_NUM_NOD_PER_EL, even if zero.
     * Do not define DIM_NUM_EDG_PER_EL or DIM_NUM_FAC_PER_EL unless > 0.
     */
    if ((status = nc_def_dim(exoid, DIM_NUM_NOD_PER_EL(cur_num_elem_blk + 1),
                             param->num_nodes_per_elem[iblk], &nelnoddim)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to define number of nodes/element for block %" PRId64
               " in file id %d",
               eb_id, exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }

    if (param->num_edges_per_elem[iblk] > 0) {
      if ((status = nc_def_dim(exoid, DIM_NUM_EDG_PER_EL(cur_num_elem_blk + 1),
                               param->num_edges_per_elem[iblk], &neledgdim)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define number of edges/element for block %" PRId64
                 " in file id %d",
                 eb_id, exoid);
        ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
        goto error_ret; /* exit define mode and return */
      }
    }

    if (param->num_faces_per_elem[iblk] > 0) {
      if ((status = nc_def_dim(exoid, DIM_NUM_FAC_PER_EL(cur_num_elem_blk + 1),
                               param->num_faces_per_elem[iblk], &nelfacdim)) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define number of faces/element for block %" PRId64
                 " in file id %d",
                 eb_id, exoid);
        ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
        goto error_ret; /* exit define mode and return */
      }
    }

    EX_PREPARE_ATTRIB_ARRAY("element", cur_num_elem_blk, DIM_NUM_ATT_IN_BLK, param->num_attr_elem,
                            eb_id, VAR_ATTRIB, numelbdim, numattrdim, VAR_NAME_ATTRIB);

    EX_PREPARE_CONN("nodal", cur_num_elem_blk, eb_id, numelbdim, VAR_CONN, nelnoddim);

    /* store element type as attribute of connectivity variable */
    if ((status = nc_put_att_text(exoid, connid, ATT_NAME_ELB, strlen(param->elem_type[iblk]) + 1,
                                  (void *)param->elem_type[iblk])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store element type name %s in file id %d",
               param->elem_type[iblk], exoid);
      ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      goto error_ret; /* exit define mode and return */
    }

    EX_PREPARE_CONN("edge", cur_num_elem_blk, eb_id, numelbdim, VAR_ECONN, neledgdim);
    EX_PREPARE_CONN("face", cur_num_elem_blk, eb_id, numelbdim, VAR_FCONN, nelfacdim);
  }

  /* Define the element map here to avoid a later redefine call */
  if (param->define_maps != 0) {
    size_t map_type;
    for (map_type = 0; map_type < num_map_dims; ++map_type) {
      if ((status = nc_inq_dimid(exoid, dim_size_maps[map_type], &dims[0])) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: could not find map size dimension %s in file id %d",
                 dim_size_maps[map_type], exoid);
        ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
      }
      for (i = 1; i <= num_maps[map_type]; ++i) {
        const char *mapname = ex_name_of_map(map_enums[map_type], i);
        if (nc_inq_varid(exoid, mapname, &temp) != NC_NOERR) {
          int map_int_type = NC_INT;
          if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) {
            map_int_type = NC_INT64;
          }

          if ((status = nc_def_var(exoid, mapname, map_int_type, 1, dims, &temp)) != NC_NOERR) {
            exerrval = status;
            if (status == NC_ENAMEINUSE) {
              snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: number map %s already exists in file id %d",
                       mapname, exoid);
            }
            else {
              snprintf(errmsg, MAX_ERR_LENGTH,
                       "ERROR: failed to create number map array %s in file id %d", mapname, exoid);
            }
            ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
            goto error_ret; /* exit define mode and return */
          }
          ex_compress_variable(exoid, temp, 1);
        }
      }
    }
  }

  /* leave define mode  */
  if ((status = nc_enddef(exoid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to complete element block definition in file id %d", exoid);
    ex_err("ex_put_concat_all_blocks", 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 */
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid);
    ex_err("ex_put_concat_all_blocks", errmsg, exerrval);
  }
  return (EX_FATAL);
}
예제 #10
0
int ex_get_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, void_int *set_entry_list,
               void_int *set_extra_list) /* NULL if dont want to retrieve data */
{

  int   dimid, entry_list_id, extra_list_id, status;
  int   set_id_ndx;
  char  errmsg[MAX_ERR_LENGTH];
  char *entryptr = NULL;
  char *extraptr = NULL;

  exerrval = 0; /* clear error code */

  /* first check if any sets are specified */
  if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss stored in file id %d",
             ex_name_of_object(set_type), exoid);
    ex_err("ex_get_set", errmsg, exerrval);
    return (EX_WARN);
  }

  /* Lookup index of set id in VAR_*S_IDS array */
  set_id_ndx = ex_id_lkup(exoid, set_type, set_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      snprintf(errmsg, MAX_ERR_LENGTH, "Warning: %s %" PRId64 " is NULL in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err("ex_get_set", errmsg, EX_NULLENTITY);
      return (EX_WARN);
    }

    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate %s id %" PRId64 " in VAR_*S_IDS array in file id %d",
             ex_name_of_object(set_type), set_id, exoid);
    ex_err("ex_get_set", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* setup more pointers based on set_type */
  if (set_type == EX_NODE_SET) {
    entryptr = VAR_NODE_NS(set_id_ndx);
    extraptr = NULL;
  }
  else if (set_type == EX_EDGE_SET) {
    entryptr = VAR_EDGE_ES(set_id_ndx);
    extraptr = VAR_ORNT_ES(set_id_ndx);
  }
  else if (set_type == EX_FACE_SET) {
    entryptr = VAR_FACE_FS(set_id_ndx);
    extraptr = VAR_ORNT_FS(set_id_ndx);
  }
  else if (set_type == EX_SIDE_SET) {
    entryptr = VAR_ELEM_SS(set_id_ndx);
    extraptr = VAR_SIDE_SS(set_id_ndx);
  }
  if (set_type == EX_ELEM_SET) {
    entryptr = VAR_ELEM_ELS(set_id_ndx);
    extraptr = NULL;
  }

  /* inquire id's of previously defined dimensions and variables */
  if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate entry list for %s %" PRId64 " in file id %d",
             ex_name_of_object(set_type), set_id, exoid);
    ex_err("ex_get_set", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* If client doet not pass in an array to store the
     extra list, don't access it at all */

  /* only do extra list for edge, face and side sets */
  if (set_extra_list) {
    if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to locate extra list for %s %" PRId64 " in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err("ex_get_set", errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  /* read in the entry list and extra list arrays unless they are NULL */
  if (set_entry_list) {
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_var_longlong(exoid, entry_list_id, set_entry_list);
    }
    else {
      status = nc_get_var_int(exoid, entry_list_id, set_entry_list);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to get entry list for %s %" PRId64 " in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err("ex_get_set", errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  /* only do extra list for edge, face and side sets */
  if (set_extra_list) {
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_get_var_longlong(exoid, extra_list_id, set_extra_list);
    }
    else {
      status = nc_get_var_int(exoid, extra_list_id, set_extra_list);
    }

    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to get extra list for %s %" PRId64 " in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err("ex_get_set", errmsg, exerrval);
      return (EX_FATAL);
    }
  }
  return (EX_NOERR);
}
예제 #11
0
int ex_put_cmap_params_cc(int exoid, void_int *node_cmap_ids, void_int *node_cmap_node_cnts,
                          void_int *node_proc_ptrs, void_int *elem_cmap_ids,
                          void_int *elem_cmap_elem_cnts, void_int *elem_proc_ptrs)
{
  const char *func_name = "ex_put_cmap_params_cc";

  size_t num_n_comm_maps, num_e_comm_maps, num_procs_in_file;
  int    status, icm, n_varid[2], e_varid[2], iproc;
  int    varid, n_dimid[1], e_dimid[1];
  int    n_varid_idx, e_varid_idx;
  int    num_icm;
  size_t start[1], count[1];
  size_t ecnt_cmap, ncnt_cmap;

  long long nl_ecnt_cmap, nl_ncnt_cmap;
  void_int *n_var_idx = NULL;
  void_int *e_var_idx = NULL;

  int nmstat;

  char errmsg[MAX_ERR_LENGTH];
  int  format;
  int  index_type, bulk_type;
  /*-----------------------------Execution begins-----------------------------*/

  ex_check_valid_file_id(exoid);

  exerrval = 0; /* clear error code */

  /* See if using NC_FORMAT_NETCDF4 format... */
  nc_inq_format(exoid, &format);
  if ((ex_int64_status(exoid) & EX_BULK_INT64_DB) || (format == NC_FORMAT_NETCDF4)) {
    index_type = NC_INT64;
  }
  else {
    index_type = NC_INT;
  }
  if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
    bulk_type = NC_INT64;
  }
  else {
    bulk_type = NC_INT;
  }

  /* Get the number of processors in the file */
  if ((status = nc_inq_dimid(exoid, DIM_NUM_PROCS_F, &n_dimid[0])) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get dimension ID for \"%s\" in file ID %d",
             DIM_NUM_PROCS_F, exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_procs_in_file)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_PROCS_F,
             exoid);
    ex_err(func_name, errmsg, exerrval);
    return (EX_FATAL);
  }

  /*
   * since I cannot get variables while in define mode, I need to
   * get the cmap information index variables before I go into
   * define mode
   */

  /* Check to see if there are nodal communications maps in the file */
  if (nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &n_dimid[0]) != NC_NOERR) {
    num_n_comm_maps = 0;
  }
  else {
    if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_n_comm_maps)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find length of dimension \"%s\" in \
file ID %d",
               DIM_NUM_N_CMAPS, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  if (num_n_comm_maps > 0) {
    /* Get the variable ID for the comm map index vector */
    if ((status = nc_inq_varid(exoid, VAR_N_COMM_INFO_IDX, &n_varid_idx)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_N_COMM_INFO_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* allocate space for the index variable */
    if (index_type == NC_INT64) {
      n_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long));
    }
    else {
      n_var_idx = malloc((num_procs_in_file + 1) * sizeof(int));
    }
    if (!n_var_idx) {
      exerrval = EX_MSG;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: insufficient memory to read index variable from file ID %d", exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* and set the last value of the index */

    /* get the communication map info index */
    if (index_type == NC_INT64) {
      ((long long *)n_var_idx)[0] = 0;
      status = nc_get_var_longlong(exoid, n_varid_idx, &((long long *)n_var_idx)[1]);
    }
    else {
      ((int *)n_var_idx)[0] = 0;
      status                = nc_get_var_int(exoid, n_varid_idx, &((int *)n_var_idx)[1]);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_N_COMM_INFO_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* "if (num_n_comm_maps > 0)" */

  /* Check to see if there are elemental communications maps in the file */
  if ((status = nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &e_dimid[0])) != NC_NOERR) {
    num_e_comm_maps = 0;
  }
  else {
    if ((status = nc_inq_dimlen(exoid, e_dimid[0], &num_e_comm_maps)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find length of dimension \"%s\" in \
file ID %d",
               DIM_NUM_E_CMAPS, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  }

  if (num_e_comm_maps > 0) {
    /* Get the variable ID for the comm map index vector */
    if ((status = nc_inq_varid(exoid, VAR_E_COMM_INFO_IDX, &e_varid_idx)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_E_COMM_INFO_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* allocate space for the index variable */
    if (index_type == NC_INT64) {
      e_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long));
    }
    else {
      e_var_idx = malloc((num_procs_in_file + 1) * sizeof(int));
    }
    if (!e_var_idx) {
      exerrval = EX_MSG;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: insufficient memory to read index variable from file ID %d", exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* get the communication map info index */
    if (index_type == NC_INT64) {
      ((long long *)e_var_idx)[0] = 0;
      status = nc_get_var_longlong(exoid, e_varid_idx, &((long long *)e_var_idx)[1]);
    }
    else {
      ((int *)e_var_idx)[0] = 0;
      status                = nc_get_var_int(exoid, e_varid_idx, &((int *)e_var_idx)[1]);
    }
    if (status != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
               VAR_E_COMM_INFO_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }
  } /* "if (num_e_comm_maps >0)" */

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

  /*
   * Add dimensions for the size of the number of nodal
   * communication maps.
   */
  if (num_n_comm_maps > 0) {
    /* add the communications data index variable */
    if ((status = nc_def_var(exoid, VAR_N_COMM_DATA_IDX, index_type, 1, n_dimid, &n_varid_idx)) !=
        NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
               VAR_N_COMM_DATA_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }

    /* now add up all of the nodal communications maps */
    ncnt_cmap = 0;
    for (iproc = 0; iproc < num_procs_in_file; iproc++) {
      if (index_type == NC_INT64) {
        num_icm = ((int64_t *)n_var_idx)[iproc + 1] - ((int64_t *)n_var_idx)[iproc];
      }
      else {
        num_icm = ((int *)n_var_idx)[iproc + 1] - ((int *)n_var_idx)[iproc];
      }
      for (icm = 0; icm < num_icm; icm++) {
        if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
          ncnt_cmap += ((int64_t *)node_cmap_node_cnts)[((int64_t *)node_proc_ptrs)[iproc] + icm];
        }
        else {
          ncnt_cmap += ((int *)node_cmap_node_cnts)[((int *)node_proc_ptrs)[iproc] + icm];
        }
      }
    }

    if ((status = nc_def_dim(exoid, DIM_NCNT_CMAP, ncnt_cmap, &n_dimid[0])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to add dimension for \"%s\" of size %" ST_ZU " in file ID %d",
               DIM_NCNT_CMAP, ncnt_cmap, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }

    /* Define variables for the nodal IDS and processor vectors */
    if ((status = nc_def_var(exoid, VAR_N_COMM_NIDS, bulk_type, 1, n_dimid, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
               VAR_N_COMM_NIDS, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }
    ex_compress_variable(exoid, varid, 1);

    if ((status = nc_def_var(exoid, VAR_N_COMM_PROC, NC_INT, 1, n_dimid, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
               VAR_N_COMM_PROC, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }
    ex_compress_variable(exoid, varid, 1);

  } /* End "if (num_n_comm_maps > 0)" */

  /*
   * Add dimensions for the size of the number of elemental
   * communication maps.
   */
  if (num_e_comm_maps > 0) {
    /* add the communications data index variable */
    if ((status = nc_def_var(exoid, VAR_E_COMM_DATA_IDX, index_type, 1, e_dimid, &e_varid_idx)) !=
        NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
               VAR_E_COMM_DATA_IDX, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }

    /* now add up all of the nodal communications maps */
    ecnt_cmap = 0;
    for (iproc = 0; iproc < num_procs_in_file; iproc++) {
      if (index_type == NC_INT64) {
        num_icm = ((int64_t *)e_var_idx)[iproc + 1] - ((int64_t *)e_var_idx)[iproc];
      }
      else {
        num_icm = ((int *)e_var_idx)[iproc + 1] - ((int *)e_var_idx)[iproc];
      }
      for (icm = 0; icm < num_icm; icm++) {
        if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
          ecnt_cmap += ((int64_t *)elem_cmap_elem_cnts)[((int64_t *)elem_proc_ptrs)[iproc] + icm];
        }
        else {
          ecnt_cmap += ((int *)elem_cmap_elem_cnts)[((int *)elem_proc_ptrs)[iproc] + icm];
        }
      }
    }

    /* Add dimensions for elemental communications maps */
    if ((status = nc_def_dim(exoid, DIM_ECNT_CMAP, ecnt_cmap, &e_dimid[0])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add dimension for \"%s\" in file ID %d",
               DIM_ECNT_CMAP, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }

    /* Define variables for the element IDS and processor vectors */
    if ((status = nc_def_var(exoid, VAR_E_COMM_EIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
               VAR_E_COMM_EIDS, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }
    ex_compress_variable(exoid, varid, 1);

    if ((status = nc_def_var(exoid, VAR_E_COMM_PROC, NC_INT, 1, e_dimid, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
               VAR_E_COMM_PROC, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }
    ex_compress_variable(exoid, varid, 1);

    if ((status = nc_def_var(exoid, VAR_E_COMM_SIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
               VAR_E_COMM_SIDS, exoid);
      ex_err(func_name, errmsg, exerrval);
      /* Leave define mode before returning */
      ex_leavedef(exoid, func_name);

      return (EX_FATAL);
    }
    ex_compress_variable(exoid, varid, 1);

  } /* End "if (num_e_comm_maps > 0)" */

  /* Exit define mode */
  ex_leavedef(exoid, func_name);

  /* Set the status of the nodal communication maps */
  if (num_n_comm_maps > 0) {

    /* need to get the two "n_comm_*" variable ids */

    if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &n_varid[0])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_N_COMM_STAT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* Get the variable ID for the comm map IDs vector */
    if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &n_varid[1])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_N_COMM_IDS, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* reset the index variable */
    nl_ncnt_cmap = 0;

    for (iproc = 0; iproc < num_procs_in_file; iproc++) {
      size_t proc_ptr;
      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
        proc_ptr = ((int64_t *)node_proc_ptrs)[iproc];
      }
      else {
        proc_ptr = ((int *)node_proc_ptrs)[iproc];
      }

      if (index_type == NC_INT64) {
        num_icm = ((int64_t *)n_var_idx)[iproc + 1] - ((int64_t *)n_var_idx)[iproc];
      }
      else {
        num_icm = ((int *)n_var_idx)[iproc + 1] - ((int *)n_var_idx)[iproc];
      }
      for (icm = 0; icm < num_icm; icm++) {
        size_t cnt;
        if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
          cnt = ((int64_t *)node_cmap_node_cnts)[proc_ptr + icm];
        }
        else {
          cnt = ((int *)node_cmap_node_cnts)[proc_ptr + icm];
        }

        if (index_type == NC_INT64) {
          start[0] = ((int64_t *)n_var_idx)[iproc] + icm;
        }
        else {
          start[0] = ((int *)n_var_idx)[iproc] + icm;
        }
        if (cnt > 0) {
          nmstat = 1;
        }
        else {
          nmstat = 0;
        }

        if ((status = nc_put_var1_int(exoid, n_varid[0], start, &nmstat)) != NC_NOERR) {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to output variable in file ID %d", exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        /* increment to the next starting position */
        nl_ncnt_cmap += cnt;

        /* fill the data index variable */
        status = nc_put_var1_longlong(exoid, n_varid_idx, start, &nl_ncnt_cmap);

        if (status != NC_NOERR) {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH,
                   "ERROR: failed to output int elem map index in file ID %d", exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }
      } /* End "for(icm=0; icm < num_icm; icm++)" */

      if (num_icm > 0) {
        /* Output the nodal comm map IDs */
        if (index_type == NC_INT64) {
          start[0] = ((int64_t *)n_var_idx)[iproc];
        }
        else {
          start[0] = ((int *)n_var_idx)[iproc];
        }
        count[0] = num_icm;
        if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
          status = nc_put_vara_longlong(exoid, n_varid[1], start, count,
                                        &((long long *)node_cmap_ids)[proc_ptr]);
        }
        else {
          status =
              nc_put_vara_int(exoid, n_varid[1], start, count, &((int *)node_cmap_ids)[proc_ptr]);
        }
        if (status != NC_NOERR) {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable in file ID %d", exoid);
          ex_err(func_name, errmsg, exerrval);

          return (EX_FATAL);
        }
      }
    } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */

    /* free up memory for index */
    free(n_var_idx);

  } /* End "if (num_n_comm_maps > 0)" */

  /* Set the status of the elemental communication maps */
  if (num_e_comm_maps > 0) {

    /* need to get the two "e_comm_*" variables" */

    /* Get variable ID for elemental status vector */
    if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &e_varid[0])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_E_COMM_STAT, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* Get the variable ID for the elemental comm map IDs vector */
    if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &e_varid[1])) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
               VAR_E_COMM_IDS, exoid);
      ex_err(func_name, errmsg, exerrval);
      return (EX_FATAL);
    }

    /* reset the index variable */
    nl_ecnt_cmap = 0;

    for (iproc = 0; iproc < num_procs_in_file; iproc++) {
      size_t proc_ptr;
      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
        proc_ptr = ((int64_t *)elem_proc_ptrs)[iproc];
      }
      else {
        proc_ptr = ((int *)elem_proc_ptrs)[iproc];
      }
      if (index_type == NC_INT64) {
        num_icm = ((int64_t *)e_var_idx)[iproc + 1] - ((int64_t *)e_var_idx)[iproc];
      }
      else {
        num_icm = ((int *)e_var_idx)[iproc + 1] - ((int *)e_var_idx)[iproc];
      }
      for (icm = 0; icm < num_icm; icm++) {

        size_t cnt;
        if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
          cnt = ((int64_t *)elem_cmap_elem_cnts)[proc_ptr + icm];
        }
        else {
          cnt = ((int *)elem_cmap_elem_cnts)[proc_ptr + icm];
        }

        if (index_type == NC_INT64) {
          start[0] = ((int64_t *)e_var_idx)[iproc] + icm;
        }
        else {
          start[0] = ((int *)e_var_idx)[iproc] + icm;
        }
        if (cnt > 0) {
          nmstat = 1;
        }
        else {
          nmstat = 0;
        }

        if ((status = nc_put_var1_int(exoid, e_varid[0], start, &nmstat)) != NC_NOERR) {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to output variable in file ID %d", exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }

        /* increment to the next starting position */
        nl_ecnt_cmap += cnt;

        /* fill the data index variable */
        status = nc_put_var1_longlong(exoid, e_varid_idx, start, &nl_ecnt_cmap);

        if (status != NC_NOERR) {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH,
                   "ERROR: failed to output int elem map index in file ID %d", exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }
      } /* End "for(icm=0; icm < num_icm; icm++)" */

      if (num_icm > 0) {
        /* Output the elemental comm map IDs */
        if (index_type == NC_INT64) {
          start[0] = ((int64_t *)e_var_idx)[iproc];
        }
        else {
          start[0] = ((int *)e_var_idx)[iproc];
        }
        count[0] = num_icm;
        if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
          status = nc_put_vara_longlong(exoid, e_varid[1], start, count,
                                        &((long long *)elem_cmap_ids)[proc_ptr]);
        }
        else {
          status =
              nc_put_vara_int(exoid, e_varid[1], start, count, &((int *)elem_cmap_ids)[proc_ptr]);
        }
        if (status != NC_NOERR) {
          exerrval = status;
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable in file ID %d", exoid);
          ex_err(func_name, errmsg, exerrval);
          return (EX_FATAL);
        }
      }
    } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */

    free(e_var_idx);

  } /* End "if (num_e_comm_maps > 0)" */

  return (EX_NOERR);
}
int ex_put_init_ext(int exoid, const ex_init_params *model)
{
  int numdimdim, numnoddim, elblkdim, edblkdim, fablkdim, esetdim, fsetdim, elsetdim, nsetdim,
      ssetdim, dim_str_name, dim[2], temp;
  int nmapdim, edmapdim, famapdim, emapdim, timedim;
  int status;
  int title_len;
#if 0
  /* used for header size calculations which are turned off for now */
  int header_size, fixed_var_size, iows;
#endif
  char errmsg[MAX_ERR_LENGTH];

  EX_FUNC_ENTER();
  int rootid = exoid & EX_FILE_ID_MASK;

  ex_check_valid_file_id(exoid, __func__);

  if (rootid == exoid && nc_inq_dimid(exoid, DIM_NUM_DIM, &temp) == NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: initialization already done for file id %d", exoid);
    ex_err(__func__, errmsg, EX_MSG);
    EX_FUNC_LEAVE(EX_FATAL);
  }

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

  /* define some attributes... */
  title_len = strlen(model->title) < MAX_LINE_LENGTH ? strlen(model->title) : MAX_LINE_LENGTH;
  if ((status = nc_put_att_text(rootid, NC_GLOBAL, (const char *)ATT_TITLE, title_len + 1,
                                model->title)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define model->title attribute to file id %d",
             rootid);
    ex_err(__func__, errmsg, status);
    goto error_ret; /* exit define mode and return */
  }

  /* ...and some dimensions... */

  /* create name string length dimension */
  if (nc_inq_dimid(rootid, DIM_STR_NAME, &dim_str_name) != NC_NOERR) {
    if ((status = nc_def_dim(rootid, DIM_STR_NAME, NC_MAX_NAME, &dim_str_name)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define name string length in file id %d",
               rootid);
      ex_err(__func__, errmsg, status);
      goto error_ret;
    }
  }

  if ((status = nc_def_dim(exoid, DIM_TIME, NC_UNLIMITED, &timedim)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define time dimension in file id %d", exoid);
    ex_err(__func__, errmsg, status);
    goto error_ret;
  }

  dim[0] = timedim;
  if ((status = nc_def_var(exoid, VAR_WHOLE_TIME, nc_flt_code(exoid), 1, dim, &temp)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to define whole time step variable in file id %d", exoid);
    ex_err(__func__, errmsg, status);
    goto error_ret;
  }
  {
    struct ex_file_item *file = ex_find_file_item(exoid);
    file->time_varid          = temp;
  }
  ex_compress_variable(exoid, temp, 2);

  if (model->num_dim > 0) {
    if ((status = nc_def_dim(exoid, DIM_NUM_DIM, model->num_dim, &numdimdim)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of dimensions in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* exit define mode and return */
    }
  }

  /*
   * Need to handle "empty file" that may be the result of a strange
   * load balance or some other strange run.  Note that if num_node
   * == 0, then model->num_elem must be zero since you cannot have elements
   * with no nodes. It *is* permissible to have zero elements with
   * non-zero node count.
   */

  if (model->num_nodes > 0) {
    if ((status = nc_def_dim(exoid, DIM_NUM_NODES, model->num_nodes, &numnoddim)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of nodes in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* exit define mode and return */
    }
  }

  if (model->num_elem > 0) {
    if (model->num_nodes <= 0) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: Cannot have non-zero element count if node count "
               "is zero.in file id %d",
               exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      goto error_ret; /* exit define mode and return */
    }

    if ((status = nc_def_dim(exoid, DIM_NUM_ELEM, model->num_elem, &temp)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of elements in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* exit define mode and return */
    }
  }

  if (model->num_edge > 0) {
    if (model->num_nodes <= 0) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: Cannot have non-zero edge count if node count is "
               "zero.in file id %d",
               exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      goto error_ret; /* exit define mode and return */
    }

    if ((status = nc_def_dim(exoid, DIM_NUM_EDGE, model->num_edge, &temp)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of edges in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* exit define mode and return */
    }
  }

  if (model->num_face > 0) {
    if (model->num_nodes <= 0) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: Cannot have non-zero face count if node count is "
               "zero.in file id %d",
               exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      goto error_ret; /* exit define mode and return */
    }

    if ((status = nc_def_dim(exoid, DIM_NUM_FACE, model->num_face, &temp)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of faces in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* exit define mode and return */
    }
  }

  if (ex_write_object_params(exoid, "element block", DIM_NUM_EL_BLK, VAR_STAT_EL_BLK, VAR_ID_EL_BLK,
                             model->num_elem_blk, &elblkdim)) {
    goto error_ret;
  }
  if (ex_write_object_params(exoid, "edge block", DIM_NUM_ED_BLK, VAR_STAT_ED_BLK, VAR_ID_ED_BLK,
                             model->num_edge_blk, &edblkdim)) {
    goto error_ret;
  }
  if (ex_write_object_params(exoid, "face block", DIM_NUM_FA_BLK, VAR_STAT_FA_BLK, VAR_ID_FA_BLK,
                             model->num_face_blk, &fablkdim)) {
    goto error_ret;
  }

  if (ex_write_object_params(exoid, "node set", DIM_NUM_NS, VAR_NS_STAT, VAR_NS_IDS,
                             model->num_node_sets, &nsetdim)) {
    goto error_ret;
  }
  if (ex_write_object_params(exoid, "edge set", DIM_NUM_ES, VAR_ES_STAT, VAR_ES_IDS,
                             model->num_edge_sets, &esetdim)) {
    goto error_ret;
  }
  if (ex_write_object_params(exoid, "face set", DIM_NUM_FS, VAR_FS_STAT, VAR_FS_IDS,
                             model->num_face_sets, &fsetdim)) {
    goto error_ret;
  }
  if (ex_write_object_params(exoid, "side set", DIM_NUM_SS, VAR_SS_STAT, VAR_SS_IDS,
                             model->num_side_sets, &ssetdim)) {
    goto error_ret;
  }
  if (ex_write_object_params(exoid, "elem set", DIM_NUM_ELS, VAR_ELS_STAT, VAR_ELS_IDS,
                             model->num_elem_sets, &elsetdim)) {
    goto error_ret;
  }

  if (ex_write_map_params(exoid, "node map", DIM_NUM_NM, VAR_NM_PROP(1), model->num_node_maps,
                          &nmapdim) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_map_params(exoid, "edge map", DIM_NUM_EDM, VAR_EDM_PROP(1), model->num_edge_maps,
                          &edmapdim) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_map_params(exoid, "face map", DIM_NUM_FAM, VAR_FAM_PROP(1), model->num_face_maps,
                          &famapdim) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_map_params(exoid, "element map", DIM_NUM_EM, VAR_EM_PROP(1), model->num_elem_maps,
                          &emapdim) != NC_NOERR) {
    goto error_ret;
  }

  if (model->num_nodes > 0) {
    dim[0] = numnoddim;
    if (model->num_dim > 0) {
      if ((status = nc_def_var(exoid, VAR_COORD_X, nc_flt_code(exoid), 1, dim, &temp)) !=
          NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define node x coordinate array in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }
      ex_compress_variable(exoid, temp, 2);
    }

    if (model->num_dim > 1) {
      if ((status = nc_def_var(exoid, VAR_COORD_Y, nc_flt_code(exoid), 1, dim, &temp)) !=
          NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define node y coordinate array in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }
      ex_compress_variable(exoid, temp, 2);
    }

    if (model->num_dim > 2) {
      if ((status = nc_def_var(exoid, VAR_COORD_Z, nc_flt_code(exoid), 1, dim, &temp)) !=
          NC_NOERR) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to define node z coordinate array in file id %d", exoid);
        ex_err(__func__, errmsg, status);
        goto error_ret; /* exit define mode and return */
      }
      ex_compress_variable(exoid, temp, 2);
    }
  }

  if (ex_write_object_names(exoid, "element block", VAR_NAME_EL_BLK, elblkdim, dim_str_name,
                            model->num_elem_blk) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "edge block", VAR_NAME_ED_BLK, edblkdim, dim_str_name,
                            model->num_edge_blk) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "face block", VAR_NAME_FA_BLK, fablkdim, dim_str_name,
                            model->num_face_blk) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "node set", VAR_NAME_NS, nsetdim, dim_str_name,
                            model->num_node_sets) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "edge set", VAR_NAME_ES, esetdim, dim_str_name,
                            model->num_edge_sets) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "face set", VAR_NAME_FS, fsetdim, dim_str_name,
                            model->num_face_sets) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "side set", VAR_NAME_SS, ssetdim, dim_str_name,
                            model->num_side_sets) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "element set", VAR_NAME_ELS, elsetdim, dim_str_name,
                            model->num_elem_sets) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "node map", VAR_NAME_NM, nmapdim, dim_str_name,
                            model->num_node_maps) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "edge map", VAR_NAME_EDM, edmapdim, dim_str_name,
                            model->num_edge_maps) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "face map", VAR_NAME_FAM, famapdim, dim_str_name,
                            model->num_face_maps) != NC_NOERR) {
    goto error_ret;
  }
  if (ex_write_object_names(exoid, "element map", VAR_NAME_EM, emapdim, dim_str_name,
                            model->num_elem_maps) != NC_NOERR) {
    goto error_ret;
  }
  if (model->num_dim > 0) {
    if (ex_write_object_names(exoid, "coordinate", VAR_NAME_COOR, numdimdim, dim_str_name,
                              model->num_dim) != NC_NOERR) {
      goto error_ret;
    }
  }

  /* leave define mode */
  if ((status = nc_enddef(exoid)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete variable definitions in file id %d",
             exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* Fill the id and status arrays with EX_INVALID_ID */
  {
    int *invalid_ids = NULL;
    int  maxset      = model->num_elem_blk;
    if (maxset < model->num_edge_blk) {
      maxset = model->num_edge_blk;
    }
    if (maxset < model->num_face_blk) {
      maxset = model->num_face_blk;
    }
    if (maxset < model->num_node_sets) {
      maxset = model->num_node_sets;
    }
    if (maxset < model->num_edge_sets) {
      maxset = model->num_edge_sets;
    }
    if (maxset < model->num_face_sets) {
      maxset = model->num_face_sets;
    }
    if (maxset < model->num_side_sets) {
      maxset = model->num_side_sets;
    }
    if (maxset < model->num_elem_sets) {
      maxset = model->num_elem_sets;
    }
    if (maxset < model->num_node_maps) {
      maxset = model->num_node_maps;
    }
    if (maxset < model->num_edge_maps) {
      maxset = model->num_edge_maps;
    }
    if (maxset < model->num_face_maps) {
      maxset = model->num_face_maps;
    }
    if (maxset < model->num_elem_maps) {
      maxset = model->num_elem_maps;
    }

    /* allocate space for id/status array */
    if (!(invalid_ids = malloc(maxset * sizeof(int)))) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to allocate memory for id/status array for file id %d", exoid);
      ex_err(__func__, errmsg, EX_MEMFAIL);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    invalidate_id_status(exoid, VAR_STAT_EL_BLK, VAR_ID_EL_BLK, model->num_elem_blk, invalid_ids);
    invalidate_id_status(exoid, VAR_STAT_ED_BLK, VAR_ID_ED_BLK, model->num_edge_blk, invalid_ids);
    invalidate_id_status(exoid, VAR_STAT_FA_BLK, VAR_ID_FA_BLK, model->num_face_blk, invalid_ids);
    invalidate_id_status(exoid, VAR_NS_STAT, VAR_NS_IDS, model->num_node_sets, invalid_ids);
    invalidate_id_status(exoid, VAR_ES_STAT, VAR_ES_IDS, model->num_edge_sets, invalid_ids);
    invalidate_id_status(exoid, VAR_FS_STAT, VAR_FS_IDS, model->num_face_sets, invalid_ids);
    invalidate_id_status(exoid, VAR_SS_STAT, VAR_SS_IDS, model->num_side_sets, invalid_ids);
    invalidate_id_status(exoid, VAR_ELS_STAT, VAR_ELS_IDS, model->num_elem_sets, invalid_ids);

    invalidate_id_status(exoid, 0, VAR_NM_PROP(1), model->num_node_maps, invalid_ids);
    invalidate_id_status(exoid, 0, VAR_EDM_PROP(1), model->num_edge_maps, invalid_ids);
    invalidate_id_status(exoid, 0, VAR_FAM_PROP(1), model->num_face_maps, invalid_ids);
    invalidate_id_status(exoid, 0, VAR_EM_PROP(1), model->num_elem_maps, invalid_ids);

    if (invalid_ids != NULL) {
      free(invalid_ids);
      invalid_ids = NULL;
    }
  }

  /* Write dummy values to the names arrays to avoid corruption issues on some
   * platforms */
  write_dummy_names(exoid, EX_ELEM_BLOCK, model->num_elem_blk);
  write_dummy_names(exoid, EX_EDGE_BLOCK, model->num_edge_blk);
  write_dummy_names(exoid, EX_FACE_BLOCK, model->num_face_blk);
  write_dummy_names(exoid, EX_NODE_SET, model->num_node_sets);
  write_dummy_names(exoid, EX_EDGE_SET, model->num_edge_sets);
  write_dummy_names(exoid, EX_FACE_SET, model->num_face_sets);
  write_dummy_names(exoid, EX_SIDE_SET, model->num_side_sets);
  write_dummy_names(exoid, EX_ELEM_SET, model->num_elem_sets);
  write_dummy_names(exoid, EX_NODE_MAP, model->num_node_maps);
  write_dummy_names(exoid, EX_EDGE_MAP, model->num_edge_maps);
  write_dummy_names(exoid, EX_FACE_MAP, model->num_face_maps);
  write_dummy_names(exoid, EX_ELEM_MAP, model->num_elem_maps);

  EX_FUNC_LEAVE(EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  if ((status = nc_enddef(exoid)) != NC_NOERR) /* exit define mode */
  {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid);
    ex_err(__func__, errmsg, status);
  }
  EX_FUNC_LEAVE(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);
}
/*!
 * writes a map; this is a vector of integers of length number of mesh
 * objects of that type (element, node, face, edge)
 */
int ex_put_partial_num_map (int exoid,
			    ex_entity_type map_type,
			    ex_entity_id map_id,
			    int64_t ent_start,
			    int64_t ent_count, 
			    const void_int *map)
{
  int status;
  int dimid, varid, map_ndx, map_exists;
  size_t start[1]; 
  size_t num_maps, num_mobj, count[1];
  int cur_num_maps;
  char errmsg[MAX_ERR_LENGTH];
  const char* dnumentries;
  const char* dnummaps;
  const char* vmapids;
  const char* vmap;

  exerrval = 0; /* clear error code */

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

  /* Make sure the file contains entries */
  if (nc_inq_dimid (exoid, dnumentries, &dimid) != NC_NOERR ) {
    return (EX_NOERR);
  }

  /* first check if any maps are specified */
  if ((status = nc_inq_dimid (exoid, dnummaps, &dimid)) != NC_NOERR )
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: no %ss specified in file id %d",
	      ex_name_of_object(map_type),exoid);
      ex_err("ex_put_partial_num_map",errmsg,exerrval);
      return (EX_FATAL);
    }
  
  /* Check for duplicate map id entry */
  ex_id_lkup(exoid,map_type,map_id); 
  if (exerrval == EX_LOOKUPFAIL) {   /* did not find the map id */
    map_exists = 0; /* Map is being defined */
  } else {
    map_exists = 1; /* A portion of this map has already been written */
  }
   
  /* Check for duplicate map id entry */
  if (!map_exists) {
    /* Get number of maps initialized for this file */
    if ((status = nc_inq_dimlen(exoid,dimid,&num_maps)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of %ss in file id %d",
	      ex_name_of_object(map_type),exoid);
      ex_err("ex_put_partial_num_map",errmsg,exerrval);
      return (EX_FATAL);
    }

    /* Keep track of the total number of maps defined using a
       counter stored in a linked list keyed by exoid.  NOTE:
       ex_get_file_item is used to find the number of element maps for a
       specific file and returns that value.
    */
    cur_num_maps = ex_get_file_item(exoid, ex_get_counter_list(map_type));
    if (cur_num_maps >= (int)num_maps) {
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: exceeded number of %ss (%"ST_ZU") specified in file id %d",
	      ex_name_of_object(map_type),num_maps,exoid);
      ex_err("ex_put_num_map",errmsg,exerrval);
      return (EX_FATAL);
    }
    
    /*   NOTE: ex_inc_file_item  is used to find the number of element maps
	 for a specific file and returns that value incremented. */
    cur_num_maps = ex_inc_file_item(exoid, ex_get_counter_list(map_type));
  } else {
    map_ndx = ex_id_lkup(exoid,map_type,map_id); 
    cur_num_maps = map_ndx-1;
  }

  /* determine number of elements */
  if ((status = nc_inq_dimid(exoid, dnumentries, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: couldn't determine number of mesh objects in file id %d",
	    exoid);
    ex_err("ex_put_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_dimlen(exoid, dimid, &num_mobj)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get number of mesh objects in file id %d",
	    exoid);
    ex_err("ex_put_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

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

  /* write out information to previously defined variable */

  /* first get id of variable */
  if ((status = nc_inq_varid (exoid, vmapids, &varid)) == -1)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate %s ids in file id %d",
	      ex_name_of_object(map_type),exoid);
      ex_err("ex_put_num_map",errmsg,exerrval);
      return (EX_FATAL);
    }

  /* then, write out map id */
  if (!map_exists) {
    start[0] = cur_num_maps;
    {
      if ((status = nc_put_var1_longlong(exoid, varid, start, (long long*)&map_id)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store %s id %"PRId64" in file id %d",
		ex_name_of_object(map_type),map_id,exoid);
	ex_err("ex_put_num_map",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
  }
  
  switch ( map_type ) {
  case EX_NODE_MAP:
    vmap = VAR_NODE_MAP(cur_num_maps+1);
    break;
  case EX_EDGE_MAP:
    vmap = VAR_EDGE_MAP(cur_num_maps+1);
    break;
  case EX_FACE_MAP:
    vmap = VAR_FACE_MAP(cur_num_maps+1);
    break;
  case EX_ELEM_MAP:
    vmap = VAR_ELEM_MAP(cur_num_maps+1);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized map type in switch: %d in file id %d",
	    map_type,exoid);
    ex_err("ex_putt_n_one_attr",errmsg,EX_MSG);
    return (EX_FATAL);
  }

  /* locate variable array in which to store the map */
  if ((status = nc_inq_varid(exoid,vmap, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate %s %"PRId64" in file id %d",
	    ex_name_of_object(map_type),map_id,exoid);
    ex_err("ex_put_partial_num_map",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* write out the map  */
  start[0] = ent_start-1;
  count[0] = ent_count;

  if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
    status = nc_put_vara_longlong(exoid, varid, start, count, map);
  } else {
    status = nc_put_vara_int(exoid, varid, start, count, map);
  }

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

  return (EX_NOERR);
}
/*!
 * writes the parameters used to describe an element block
 * \param    exoid                   exodus file id
 * \param    elem_blk_id             element block id
 * \param    elem_type               element type string
 * \param    num_elem_this_blk       number of elements in the element blk
 * \param    num_nodes_per_elem      number of nodes per element block
 * \param    num_attr_this_blk       number of attributes
 * \param    define_maps             if != 0, write maps, else don't
 */
int ex_put_concat_elem_block (int    exoid,
                              const void_int*   elem_blk_id,
                              char *elem_type[],
                              const void_int*   num_elem_this_blk,
                              const void_int*   num_nodes_per_elem,
                              const void_int*   num_attr_this_blk,
                              int    define_maps)
{
  int i, varid, dimid, dims[2], strdim, *eb_array;
  int temp;
  int iblk;
  int status;
  int num_elem_blk;
  int map_int_type, conn_int_type;
  size_t length;
  int cur_num_elem_blk, nelnoddim, numelbdim, numattrdim, connid, numelemdim, numnodedim;
  char errmsg[MAX_ERR_LENGTH];

  exerrval  = 0; /* clear error code */

  /* first check if any element blocks are specified
   * OK if zero...
   */
  if (nc_inq_dimid(exoid, DIM_NUM_EL_BLK, &dimid) != NC_NOERR) {
    return (EX_NOERR);
  }

  /* Get number of element blocks defined for this file */
  if ((status = nc_inq_dimlen(exoid,dimid,&length)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get number of element blocks in file id %d",
	    exoid);
    ex_err("ex_put_concat_elem_block",errmsg,exerrval);
    return (EX_FATAL);
  }
  num_elem_blk = length;
  
  /* Fill out the element block status array */
  if (!(eb_array = malloc(num_elem_blk*sizeof(int)))) {
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
	    "Error: failed to allocate space for element block status array in file id %d",
	    exoid);
    ex_err("ex_put_concat_elem_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    for (i=0;i<num_elem_blk;i++) {
      eb_array[i] = (((int64_t*)num_elem_this_blk)[i] == 0) ? 0 : 1;
    }
  } else {
    for (i=0;i<num_elem_blk;i++) {
      eb_array[i] = (((int*)num_elem_this_blk)[i] == 0) ? 0 : 1;
    }
  }

  /* Next, get variable id of status array */
  if ((status = nc_inq_varid(exoid, VAR_STAT_EL_BLK, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate element block status in file id %d",
	    exoid);
    ex_err("ex_put_concat_elem_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  status = nc_put_var_int(exoid, varid, eb_array);

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store element block status array to file id %d",
            exoid);
    ex_err("ex_put_concat_elem_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Next, fill out ids array */
  /* first get id of ids array variable */
  if ((status = nc_inq_varid(exoid, VAR_ID_EL_BLK, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate element block ids array in file id %d",
            exoid);
    ex_err("ex_put_concat_elem_block",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* then, write out id list */
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    status = nc_put_var_longlong(exoid, varid, elem_blk_id);
  } else {
    status = nc_put_var_int(exoid, varid, elem_blk_id);
  }

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

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

  conn_int_type = NC_INT;
  if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
    conn_int_type = NC_INT64;
  }
  
  map_int_type = NC_INT;
  if (ex_int64_status(exoid) & EX_MAPS_INT64_DB) {
    map_int_type = NC_INT64;
  }
  
  /* Iterate over element blocks ... */
  for (iblk = 0; iblk < num_elem_blk; iblk++) {
    ex_entity_id eb_id;
    size_t num_elem;
    size_t num_npe;
    size_t num_attr;
    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      eb_id    = ((int64_t*)elem_blk_id)[iblk];
      num_elem = ((int64_t*)num_elem_this_blk)[iblk];
      num_npe  = ((int64_t*)num_nodes_per_elem)[iblk];
      num_attr = ((int64_t*)num_attr_this_blk)[iblk];
    } else {
      eb_id    = ((int*)elem_blk_id)[iblk];
      num_elem = ((int*)num_elem_this_blk)[iblk];
      num_npe  = ((int*)num_nodes_per_elem)[iblk];
      num_attr = ((int*)num_attr_this_blk)[iblk];
    }

    cur_num_elem_blk=ex_get_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));
    if (cur_num_elem_blk >= num_elem_blk) {
      exerrval = EX_FATAL;
      sprintf(errmsg,
	      "Error: exceeded number of element blocks (%d) defined in file id %d",
              num_elem_blk,exoid);
      ex_err("ex_put_concat_elem_block",errmsg,exerrval);
      goto error_ret;
    }

    /* NOTE: ex_inc_file_item  is used to find the number of element blocks
       for a specific file and returns that value incremented. */
    cur_num_elem_blk=ex_inc_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK));

    if (eb_array[iblk] == 0) /* Is this a NULL element block? */
      continue;

    /* define some dimensions and variables*/
    if ((status = nc_def_dim(exoid,
			     DIM_NUM_EL_IN_BLK(cur_num_elem_blk+1),
			     num_elem, &numelbdim)) != NC_NOERR) {
      exerrval = status;
      if (status == NC_ENAMEINUSE) {     /* duplicate entry */
	sprintf(errmsg,
		"Error: element block %"PRId64" already defined in file id %d",
		eb_id,exoid);
      } else {
	sprintf(errmsg,
		"Error: failed to define number of elements/block for block %"PRId64" file id %d",
		eb_id,exoid);
      }
      ex_err("ex_put_concat_elem_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    if ((status = nc_def_dim(exoid,
			     DIM_NUM_NOD_PER_EL(cur_num_elem_blk+1),
			     num_npe, &nelnoddim)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to define number of nodes/element for block %"PRId64" in file id %d",
	      eb_id,exoid);
      ex_err("ex_put_concat_elem_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    /* element connectivity array */
    dims[0] = numelbdim;
    dims[1] = nelnoddim;

    if ((status = nc_def_var (exoid, VAR_CONN(cur_num_elem_blk+1),
			      conn_int_type, 2, dims, &connid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to create connectivity array for block %"PRId64" in file id %d",
	      eb_id,exoid);
      ex_err("ex_put_concat_elem_block",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(elem_type[iblk])+1, 
				  (void*)elem_type[iblk])) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store element type name %s in file id %d",
	      elem_type[iblk],exoid);
      ex_err("ex_put_concat_elem_block",errmsg,exerrval);
      goto error_ret;         /* exit define mode and return */
    }

    /* element attribute array */
    if (num_attr > 0) {
      if ((status = nc_def_dim (exoid, 
				DIM_NUM_ATT_IN_BLK(cur_num_elem_blk+1),
				num_attr, &numattrdim)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of attributes in block %"PRId64" in file id %d",
		eb_id,exoid);
	ex_err("ex_put_concat_elem_block",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      
      /* Attribute names... */
      dims[0] = numattrdim;
      dims[1] = strdim;
      
      if ((status = nc_def_var(exoid, VAR_NAME_ATTRIB(cur_num_elem_blk+1),
			       NC_CHAR, 2, dims, &temp)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define element attribute name array in file id %d",exoid);
	ex_err("ex_put_concat_elem_block",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }
      eb_array[iblk] = temp;

      dims[0] = numelbdim;
      dims[1] = numattrdim;
      
      if ((status = nc_def_var(exoid, VAR_ATTRIB(cur_num_elem_blk+1),
			       nc_flt_code(exoid), 2, dims, &temp)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error:  failed to define attributes for element block %"PRId64" in file id %d",
		eb_id,exoid);
	ex_err("ex_put_concat_elem_block",errmsg,exerrval);
	goto error_ret;         /* exit define mode and return */
      }

    }
    
  }

  /* Define the element map here to avoid a later redefine call */
  if (define_maps != 0) {
    if (nc_inq_varid(exoid, VAR_ELEM_NUM_MAP, &temp) != NC_NOERR) {
      /* Map does not exist */
      /* Possible to have zero elements but >0 element blocks.
       * Only define map if there are nonzero elements
       */
      if (nc_inq_dimid(exoid, DIM_NUM_ELEM, &numelemdim) == NC_NOERR) {
	dims[0] = numelemdim;
	
	if ((status = nc_def_var(exoid, VAR_ELEM_NUM_MAP, map_int_type, 1, dims, &temp)) != NC_NOERR) {
	  exerrval = status;
	  if (status == NC_ENAMEINUSE) {
	    sprintf(errmsg,
		    "Error: element numbering map already exists in file id %d",
		    exoid);
	  } else {
	    sprintf(errmsg,
		    "Error: failed to create element numbering map in file id %d",
		    exoid);
	  }
	  ex_err("ex_put_concat_elem_block",errmsg,exerrval);
	  goto error_ret;         /* exit define mode and return */
	}
	ex_compress_variable(exoid, temp, 1);
      }
    }

    /* Do the same for the node numbering map */
    if (nc_inq_varid(exoid, VAR_NODE_NUM_MAP, &temp) != NC_NOERR) {
      /* Map does not exist */
      if ((nc_inq_dimid(exoid, DIM_NUM_NODES, &numnodedim)) == NC_NOERR) {
	dims[0] = numnodedim;
	if ((status = nc_def_var(exoid, VAR_NODE_NUM_MAP, map_int_type, 1, dims, &temp)) != NC_NOERR) {
	  exerrval = status;
	  if (status == NC_ENAMEINUSE) {
	    sprintf(errmsg,
		    "Error: node numbering map already exists in file id %d",
		    exoid);
	  } else {
	    sprintf(errmsg,
		    "Error: failed to create node numbering map array in file id %d",
		    exoid);
	  }
	  ex_err("ex_put_concat_elem_block",errmsg,exerrval);
	  goto error_ret;         /* exit define mode and return */
	}
	ex_compress_variable(exoid, temp, 1);
      }
    }
  }

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

  {
  /* Write dummy attribute name. Without this we get corruption in the
   * attribute name.
   */
    size_t  start[2], count[2];
    char *text = "";
    count[0] = 1;
    start[1] = 0;
    count[1] = strlen(text)+1;
    
    for (iblk = 0; iblk < num_elem_blk; iblk++) {
      size_t num_attr;
      if (eb_array[iblk] == 0) /* Is this a NULL element block? */
	continue;
      if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
	num_attr = ((int64_t*)num_attr_this_blk)[iblk];
      } else {
	num_attr = ((int*)num_attr_this_blk)[iblk];
      }
      for (i = 0; i < num_attr; i++) {
	start[0] = i;
	nc_put_vara_text(exoid, eb_array[iblk], start, count, text);
      }
    }
  }
  free(eb_array);
  
  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_concat_elem_block",errmsg,exerrval);
  }
  return (EX_FATAL);
}
예제 #16
0
int ex_get_partial_num_map(int exoid, ex_entity_type map_type, ex_entity_id map_id,
                           int64_t ent_start, int64_t ent_count, void_int *map)
{
  int         dimid, var_id, id_ndx, status;
  size_t      num_mobj, start[1], count[1];
  char        errmsg[MAX_ERR_LENGTH];
  const char *dim_map_size;
  const char *dim_num_maps;

  switch (map_type) {
  case EX_NODE_MAP:
    dim_map_size = DIM_NUM_NODES;
    dim_num_maps = DIM_NUM_NM;
    break;
  case EX_EDGE_MAP:
    dim_map_size = DIM_NUM_EDGE;
    dim_num_maps = DIM_NUM_EDM;
    break;
  case EX_FACE_MAP:
    dim_map_size = DIM_NUM_FACE;
    dim_num_maps = DIM_NUM_FAM;
    break;
  case EX_ELEM_MAP:
    dim_map_size = DIM_NUM_ELEM;
    dim_num_maps = DIM_NUM_EM;
    break;
  default:
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH, "Bad map type (%d) specified", map_type);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

  /* See if file contains any elements...*/
  if (nc_inq_dimid(exoid, dim_map_size, &dimid) != NC_NOERR) {
    return (EX_NOERR);
  }

  if ((status = nc_inq_dimlen(exoid, dimid, &num_mobj)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of mesh objects in file id %d",
             exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* Check input parameters for a valid range of numbers */
  if (ent_start <= 0 || ent_start > num_mobj) {
    exerrval = EX_FATAL;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: start count is invalid in file id %d", exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ent_count < 0) {
    exerrval = EX_FATAL;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid count value in file id %d", exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ent_start + ent_count - 1 > num_mobj) {
    exerrval = EX_FATAL;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: start+count-1 is larger than element count in file id %d", exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* first check if any maps have been defined */
  if ((status = nc_inq_dimid(exoid, dim_num_maps, &dimid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no %ss defined in file id %d",
             ex_name_of_object(map_type), exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_WARN);
  }

  /* Lookup index of element map id property array */
  id_ndx = ex_id_lkup(exoid, map_type, map_id);
  if (exerrval != 0) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate %s id %" PRId64 " in id variable in file id %d",
             ex_name_of_object(map_type), map_id, exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* inquire id's of previously defined dimensions and variables */
  if ((status = nc_inq_varid(exoid, ex_name_of_map(map_type, id_ndx), &var_id)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s %" PRId64 " in file id %d",
             ex_name_of_object(map_type), map_id, exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* read in the map */
  start[0] = ent_start - 1;
  count[0] = ent_count;

  if (ex_int64_status(exoid) & EX_MAPS_INT64_API) {
    status = nc_get_vara_longlong(exoid, var_id, start, count, map);
  }
  else {
    status = nc_get_vara_int(exoid, var_id, start, count, map);
  }

  if (status == -1) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s in file id %d",
             ex_name_of_object(map_type), exoid);
    ex_err("ex_get_partial_num_map", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
예제 #17
0
int ex_put_attr_param (int   exoid,
		       ex_entity_type obj_type,
		       int   obj_id,
		       int   num_attrs)
{
  int status;
  int dims[2];
  int strdim, varid;
  
  char errmsg[MAX_ERR_LENGTH];
  const char *dnumobjent;
  const char *dnumobjatt;
  const char *vobjatt;
  const char *vattnam;
  int numobjentdim;
  int obj_id_ndx;
  int numattrdim;
  
  /* Determine index of obj_id in obj_type id array */
  if (obj_type == EX_NODAL)
    obj_id_ndx = 0;
  else {
    obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id);
    
    if (exerrval != 0) {
      if (exerrval == EX_NULLENTITY) {
	sprintf(errmsg,
		"Warning: no attributes found for NULL %s %d in file id %d",
		ex_name_of_object(obj_type),obj_id,exoid);
	ex_err("ex_put_attr_param",errmsg,EX_MSG);
	return (EX_WARN);              /* no attributes for this object */
      } else {
	sprintf(errmsg,
		"Warning: failed to locate %s id %d in id array in file id %d",
		ex_name_of_object(obj_type),obj_id, exoid);
	ex_err("ex_put_attr_param",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);
    vobjatt = VAR_SSATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_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);
    vobjatt = VAR_NSATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_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);
    vobjatt = VAR_ESATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_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);
    vobjatt = VAR_FSATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_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);
    vobjatt = VAR_ELSATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_ELSATTRIB(obj_id_ndx);
    break;
  case EX_NODAL:
    dnumobjent = DIM_NUM_NODES;
    dnumobjatt = DIM_NUM_ATT_IN_NBLK;
    vobjatt = VAR_NATTRIB;
    vattnam = VAR_NAME_NATTRIB;
    break;
  case EX_EDGE_BLOCK:
    dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx);
    dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
    vobjatt = VAR_EATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_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);
    vobjatt = VAR_FATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_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);
    vobjatt = VAR_ATTRIB(obj_id_ndx);
    vattnam = VAR_NAME_ATTRIB(obj_id_ndx);
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Bad block type (%d) specified for file id %d",
	    obj_type, exoid );
    ex_err("ex_put_attr_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

  if ((status = nc_inq_dimid(exoid, dnumobjent, &numobjentdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate number of entries for %s %d in file id %d",
	    ex_name_of_object(obj_type), obj_id, exoid);
    ex_err("ex_put_attr_param",errmsg,exerrval);
    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_attr_param",errmsg,exerrval);
    return (EX_FATAL);
  }
  
  if ((status = nc_def_dim(exoid, dnumobjatt, num_attrs, &numattrdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define number of attributes in %s %d in file id %d",
	    ex_name_of_object(obj_type), obj_id,exoid);
    ex_err("ex_put_attr_param",errmsg,exerrval);
    goto error_ret;         /* exit define mode and return */
  }

  dims[0] = numobjentdim;
  dims[1] = numattrdim;
  
  if ((status = nc_def_var(exoid, vobjatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error:  failed to define attributes for %s %d in file id %d",
	    ex_name_of_object(obj_type), obj_id,exoid);
    ex_err("ex_put_attr_param",errmsg,exerrval);
    goto error_ret;         /* exit define mode and return */
  }
  
  /* 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_attr_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Attribute names... */
  dims[0] = numattrdim;
  dims[1] = strdim;

  if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define %s attribute name array in file id %d",
	    ex_name_of_object(obj_type), exoid);
    ex_err("ex_put_attr_param",errmsg,exerrval);
    goto error_ret;         /* exit define mode and return */
  }

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

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR) {     /* exit define mode */       
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_attr_param",errmsg,exerrval);
  }
  return (EX_FATAL);
}
int ex_get_partial_side_set_df (int   exoid,
                          ex_entity_id   side_set_id,
                          int64_t   start_num,
                          int64_t   num_df_to_get,
                          void *side_set_dist_fact)
{

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

  exerrval = 0; /* clear error code */

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

  if ((status = nc_inq_dimid (exoid, DIM_NUM_SS, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no side sets stored in file id %d",
            exoid);
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_WARN);
  }

  /* Lookup index of side set id in VAR_SS_IDS array */
  if ((side_set_id_ndx = ex_id_lkup(exoid,EX_SIDE_SET,side_set_id)) < 0) {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
	      "Warning: side set %"PRId64" is NULL in file id %d",
              side_set_id, exoid);
      ex_err("ex_get_partial_side_set_df",errmsg,EX_NULLENTITY);
      return (EX_WARN);
    } 
      sprintf(errmsg,
	      "Error: failed to locate side set %"PRId64" in %s array in file id %d",
              side_set_id, VAR_SS_IDS, exoid);
      ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
      return (EX_FATAL);
    
  }

  /* inquire id's of previously defined dimensions and variables */
  if ((status = nc_inq_dimid (exoid, DIM_NUM_DF_SS(side_set_id_ndx), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Warning: dist factors not stored for side set %"PRId64" in file id %d",
            side_set_id,exoid);
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_WARN);		/* complain - but not too loud */
  }

  if ((status = nc_inq_dimlen (exoid, dimid, &num_df_in_set)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get number of dist factors in side set %"PRId64" in file id %d",
            side_set_id,exoid);
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Check input parameters for a valid range of numbers */
  if (start_num < 0 || start_num > num_df_in_set) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid input");
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (num_df_to_get < 0) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid number of df's to get!");
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* start_num now starts at 1, not 0 */
  if ((start_num + num_df_to_get - 1) > num_df_in_set) {
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: request larger than number of df's in set!");
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid (exoid, VAR_FACT_SS(side_set_id_ndx), &dist_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate dist factors list for side set %"PRId64" in file id %d",
            side_set_id,exoid);
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* read in the distribution factors array */
  start[0] = --start_num;
  count[0] = num_df_to_get;

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

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get dist factors list for side set %"PRId64" in file id %d",
            side_set_id,exoid);
    ex_err("ex_get_partial_side_set_df",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
예제 #19
0
bool exodus_file_query(const char* filename,
                       size_t* real_size,
                       float* version,
                       int* num_mpi_processes,
                       real_array_t* times)
{
  set_ex_opts();

  if (!file_exists(filename))
    return false;

  bool valid = true;
  bool is_parallel = false;
  int my_real_size = (int)sizeof(real_t);
  int io_real_size = 0;
#if POLYMEC_HAVE_MPI
  MPI_Info info;
  MPI_Info_create(&info);
  int id = ex_open_par(filename, EX_READ, &my_real_size,
                       &io_real_size, version, 
                       MPI_COMM_WORLD, info);

  // Did that work? If not, try the serial opener.
  if (id < 0)
  {
    MPI_Info_free(&info);
    id = ex_open(filename, EX_READ, &my_real_size,
                 &io_real_size, version);
  }
  else
    is_parallel = true;
#else
  int id = ex_open(filename, EX_READ, &my_real_size,
                   &io_real_size, version);
#endif

  if (id < 0)
    valid = false;
  else
  {
    *real_size = (size_t)io_real_size;

    // Make sure that the file has 3D data.
    ex_init_params mesh_info;
    int status = ex_get_init_ext(id, &mesh_info);
    if ((status < 0) || (mesh_info.num_dim != 3))
      valid = false;
    else
    {
      // Make sure that each of the element blocks in this file have 
      // valid 3D element types.
      int num_elem_blocks = (int)mesh_info.num_elem_blk;
      int elem_block_ids[num_elem_blocks];
      ex_get_ids(id, EX_ELEM_BLOCK, elem_block_ids);
      for (int i = 0; i < num_elem_blocks; ++i)
      {
        int elem_block = elem_block_ids[i];
        char elem_type_name[MAX_NAME_LENGTH+1];
        int num_elem, num_nodes_per_elem, num_faces_per_elem;
        ex_get_block(id, EX_ELEM_BLOCK, elem_block, 
                     elem_type_name, &num_elem,
                     &num_nodes_per_elem, NULL,
                     &num_faces_per_elem, NULL);
        fe_mesh_element_t elem_type = get_element_type(elem_type_name);
        if (elem_type == FE_INVALID)
        {
          valid = false;
          break;
        }
      }
      
      if (valid)
      {
        // Query the number of processes for which this file has data.
        // Recently, we've had to add guards to check to see whether 
        // DIM_NUM_PROCS exists in the file. If it doesn't, we assume that 
        // the file corresponds to a serial data set.
        int num_proc_in_file;
        char file_type[2];
        int dim_id, status1 = nc_inq_dimid(id, DIM_NUM_PROCS, &dim_id);
        if (status1 == NC_NOERR)
        {
          ex_get_init_info(id, num_mpi_processes, &num_proc_in_file, file_type);
          if (is_parallel)
          {
            ASSERT(*num_mpi_processes == num_proc_in_file);
          }
        }
        else
        {
          *num_mpi_processes = num_proc_in_file = 1;
        }

        if (times != NULL)
        {
          // Ask for the times within the file.
          int num_times = (int)ex_inquire_int(id, EX_INQ_TIME);
          real_array_resize(times, num_times);
          if (num_times > 0)
          {
            ex_get_all_times(id, times->data);
          }
        }
      }
    }

    ex_close(id);
  }

#if POLYMEC_HAVE_MPI
  if (is_parallel)
    MPI_Info_free(&info);
#endif

  return valid;
}
int ex_put_prop_names (int   exoid,
                       ex_entity_type obj_type,
                       int   num_props,
                       char **prop_names)
{
  int status;
  int oldfill, temp;
  int i, propid, dimid, dims[1];
  size_t name_length, prop_name_len;
  char name[MAX_VAR_NAME_LENGTH+1];
  long long vals[1];
  int max_name_len = 0;
  int int_type = NC_INT;

  char errmsg[MAX_ERR_LENGTH];

  exerrval  = 0; /* clear error code */

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

  /* Get the name string length */
  name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH)+1;

  /* inquire id of previously defined dimension (number of objects) */
  if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(obj_type), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate number of %s in file id %d",
	    ex_name_of_object(obj_type), exoid);
    ex_err("ex_put_prop_names",errmsg, exerrval);
    return(EX_FATAL);
  }

  nc_set_fill(exoid, NC_FILL, &oldfill); /* fill with zeros per routine spec */

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

  /* define num_props variables; we postpend the netcdf variable name with  */
  /* a counter starting at 2 because "xx_prop1" is reserved for the id array*/
  dims[0] = dimid;

  for (i=0; i<num_props; i++) {
    switch (obj_type) {
    case EX_ELEM_BLOCK:
      strcpy (name, VAR_EB_PROP(i+2));
      break;
    case EX_FACE_BLOCK:
      strcpy (name, VAR_FA_PROP(i+2));
      break;
    case EX_EDGE_BLOCK:
      strcpy (name, VAR_ED_PROP(i+2));
      break;
    case EX_NODE_SET:
      strcpy (name, VAR_NS_PROP(i+2));
      break;
    case EX_SIDE_SET:
      strcpy (name, VAR_SS_PROP(i+2));
      break;
    case EX_EDGE_SET:
      strcpy (name, VAR_ES_PROP(i+2));
      break;
    case EX_FACE_SET:
      strcpy (name, VAR_FS_PROP(i+2));
      break;
    case EX_ELEM_SET:
      strcpy (name, VAR_ELS_PROP(i+2));
      break;
    case EX_ELEM_MAP:
      strcpy (name, VAR_EM_PROP(i+2));
      break;
    case EX_FACE_MAP:
      strcpy (name, VAR_FAM_PROP(i+2));
      break;
    case EX_EDGE_MAP:
      strcpy (name, VAR_EDM_PROP(i+2));
      break;
    case EX_NODE_MAP:
      strcpy (name, VAR_NM_PROP(i+2));
      break;
    default:
      exerrval = EX_BADPARAM;
      sprintf(errmsg, "Error: object type %d not supported; file id %d",
	      obj_type, exoid);
      ex_err("ex_put_prop_names",errmsg,exerrval);
      goto error_ret;        /* Exit define mode and return */
    }

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

    vals[0] = 0; /* fill value */

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

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

    if (prop_name_len > max_name_len) {
      max_name_len = prop_name_len;
}

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

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

  /* Update the maximum_name_length attribute on the file. */
  ex_update_max_name_length(exoid, max_name_len-1);

  nc_set_fill(exoid, oldfill, &temp); /* default: turn off fill */
  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_prop_names",errmsg,exerrval);
  }
  return (EX_FATAL);
}
예제 #21
0
int ex_get_ids (int  exoid,
		ex_entity_type obj_type, 
		void_int *ids)
{
  int varid, status;
  char errmsg[MAX_ERR_LENGTH];

  const char* varidobj;

  exerrval = 0; /* clear error code */

  switch (obj_type) {
  case EX_EDGE_BLOCK:
    varidobj = VAR_ID_ED_BLK;
    break;
  case EX_FACE_BLOCK:
    varidobj = VAR_ID_FA_BLK;
    break;
  case EX_ELEM_BLOCK:
    varidobj = VAR_ID_EL_BLK;
    break;
  case EX_NODE_SET:
    varidobj = VAR_NS_IDS;
    break;
  case EX_EDGE_SET:
    varidobj = VAR_ES_IDS;
    break;
  case EX_FACE_SET:
    varidobj = VAR_FS_IDS;
    break;
  case EX_SIDE_SET:
    varidobj = VAR_SS_IDS;
    break;
  case EX_ELEM_SET:
    varidobj = VAR_ELS_IDS;
    break;
  case EX_NODE_MAP:
    varidobj = VAR_NM_PROP(1);
    break;
  case EX_EDGE_MAP:
    varidobj = VAR_EDM_PROP(1);
    break;
  case EX_FACE_MAP:
    varidobj = VAR_FAM_PROP(1);
    break;
  case EX_ELEM_MAP:
    varidobj = VAR_EM_PROP(1);
    break;
  default:/* invalid variable type */
    exerrval = EX_BADPARAM;
    sprintf(errmsg, "Error: Invalid type specified in file id %d", exoid);
    ex_err("ex_get_ids",errmsg,exerrval);
    return(EX_FATAL);
  }

  /* Determine if there are any 'obj-type' objects */
  if ((status = nc_inq_dimid (exoid, ex_dim_num_objects(obj_type), &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no %s defined in file id %d",
	    ex_name_of_object(obj_type), exoid);
    ex_err("ex_get_ids",errmsg,exerrval);
    return (EX_WARN);
  }


  /* inquire id's of previously defined dimensions and variables  */
  if ((status = nc_inq_varid(exoid, varidobj, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate %s ids variable in file id %d",
	    ex_name_of_object(obj_type),exoid);
    ex_err("ex_get_ids",errmsg,exerrval);
    return (EX_FATAL);
  }
  
  /* read in the element block ids  */
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    status = nc_get_var_longlong(exoid, varid, ids);
  } else {
    status = nc_get_var_int(exoid, varid, ids);
  }
  
  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to return %s ids in file id %d",
	    ex_name_of_object(obj_type),exoid);
    ex_err("ex_get_ids",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
예제 #22
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_get_partial_set_dist_fact (int   exoid,
				  ex_entity_type set_type,
				  ex_entity_id   set_id,
				  int64_t   offset,
				  int64_t   num_to_put,
				  void *set_dist_fact)
{

  int dimid, dist_id, set_id_ndx;
  int status;
  size_t start[1], count[1];
  char errmsg[MAX_ERR_LENGTH];
  char* factptr = NULL;
 
  exerrval = 0; /* clear error code */

  /* first check if any sets are specified */
  if ((status = nc_inq_dimid (exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no %s sets stored in file id %d",
	    ex_name_of_object(set_type), exoid);
    ex_err("ex_get_partial_set_dist_fact",errmsg,exerrval);
    return (EX_WARN);
  }

  /* Lookup index of set id in VAR_*S_IDS array */
  set_id_ndx = ex_id_lkup(exoid,set_type,set_id);
  if (exerrval != 0)  {
    if (exerrval == EX_NULLENTITY) {
      sprintf(errmsg,
              "Warning: %s set %"PRId64" is NULL in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_get_partial_set_dist_fact",errmsg,EX_NULLENTITY);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "Error: failed to locate %s set %"PRId64" in VAR_*S_IDS array in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_get_partial_set_dist_fact",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* setup more pointers based on set_type */
  if (set_type == EX_NODE_SET) {
    factptr = VAR_FACT_NS(set_id_ndx);
  }
  else if (set_type == EX_EDGE_SET) {
    factptr = VAR_FACT_ES(set_id_ndx);
  }
  else if (set_type == EX_FACE_SET) {
    factptr = VAR_FACT_FS(set_id_ndx);
  }
  else if (set_type == EX_SIDE_SET) {
    factptr = VAR_FACT_SS(set_id_ndx);
  }
  if (set_type == EX_ELEM_SET) {
    factptr = VAR_FACT_ELS(set_id_ndx);
  }

  /* inquire id's of previously defined dimensions and variables */
  if ((status = nc_inq_varid(exoid, factptr, &dist_id)) != NC_NOERR) {
    exerrval = status;
    /* not an error for node sets because this is how we check that df's exist */
    if (set_type == EX_NODE_SET) {
      sprintf(errmsg,
	      "Warning: dist factors not stored for %s set %"PRId64" in file id %d",
	      ex_name_of_object(set_type), set_id, exoid);
      ex_err("ex_get_partial_set_dist_fact",errmsg,exerrval);
      return (EX_WARN);         /* complain - but not too loud */
    }
    /* is an error for other sets */
    else  {
      sprintf(errmsg,
	      "Error: failed to locate dist factors list for %s set %"PRId64" in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_get_partial_set_dist_fact",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* read in the distribution factors array */
  start[0] = offset-1;
  count[0] = num_to_put;
  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_vara_float(exoid, dist_id, start, count, set_dist_fact);
  } else {
    status = nc_get_vara_double(exoid, dist_id, start, count, set_dist_fact);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get dist factors list for %s set %"PRId64" in file id %d",
	    ex_name_of_object(set_type), set_id,exoid);
    ex_err("ex_get_partial_set_dist_fact",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
예제 #24
0
void get_netcdf(e *E){

  int	ncid;
  int varid;
	int retval;
	size_t attlen = 0;

  double  pos[2];


  int     i,j,t;
	int count;

  // read the target grid - this is the roms curvilinear grid
	// in this function we want to find the indexes that intersect
  // out tc tracks

	/* roms output data required

	double lon_rho(eta_rho, xi_rho) ;
		lon_rho:long_name = "longitude of RHO-points" ;
		lon_rho:units = "degree_east" ;
		lon_rho:standard_name = "longitude" ;
		lon_rho:field = "lon_rho, scalar" ;
	double lat_rho(eta_rho, xi_rho) ;
		lat_rho:long_name = "latitude of RHO-points" ;
		lat_rho:units = "degree_north" ;
		lat_rho:standard_name = "latitude" ;
		lat_rho:field = "lat_rho, scalar" ;
	*/
	// open the roms_input file
	// open the file
    if((retval = nc_open(E->roms_grid, NC_NOWRITE, &ncid)))
        fail("failed to open roms input file: %s error is %d\n", E->roms_grid, retval);

    // get the lat dimension sizes
    if((retval = nc_inq_dimid(ncid, "eta_rho", &varid)))
        fail("failed to get roms lat dimid: error is %d\n",retval);

    if((retval = nc_inq_dimlen(ncid,varid,&E->nEtaRho)))
        fail("failed to get roms lat dimid: error is %d\n",retval);

    //printf("xi_rho = %zu\n", E->nEtaRho);

    // get the lon dimension sizes
    if((retval = nc_inq_dimid(ncid, "xi_rho", &varid)))
        fail("failed to get roms lon_rho dimid: error is %d\n",retval);

    if((retval = nc_inq_dimlen(ncid,varid,&E->nXiRho)))
        fail("failed to read roms lon_rho data: error is %d\n",retval);

    //printf("eta_rho = %zu\n", E->nXiRho);

    // malloc room for the arrays
	E->lat_rho = malloc2d_double( E->nEtaRho, E->nXiRho);
	E->lon_rho = malloc2d_double( E->nEtaRho, E->nXiRho);

  nc_inq_varid(ncid, "lat_rho", &varid);
  if((retval = nc_get_var_double(ncid, varid, &E->lat_rho[0][0])))
	fail("failed to read roms lat_rho data: error is %d\n", retval);

		//printf("lat_rho[0][0] = %f\n", E->lat_rho[0][0]);

    nc_inq_varid(ncid, "lon_rho", &varid);
    if((retval = nc_get_var_double(ncid, varid, &E->lon_rho[0][0])))
		fail("failed to read roms lat_rho data: error is %d\n", retval);

	nc_close(ncid);


  // construct the kdtree for grid searching
  E->kd = kd_create(2);
  E->roms_index = malloc(E->nEtaRho*E->nXiRho*sizeof(grid_index));

  count = 0;
  for(i=0;i<E->nEtaRho;i++){
    for(j=0;j<E->nXiRho;j++){
      E->roms_index[count].i = i;
      E->roms_index[count].j = j;
      pos[0] = E->lon_rho[i][j];
      pos[1] = E->lat_rho[i][j];
      kd_insert(E->kd, pos, &E->roms_index[count]);
      count++;
    }
  }
}
예제 #25
0
static int ex_get_concat_set_len(int exoid, int64_t *set_length, const char *set_name,
				 ex_entity_type set_type, const char *set_num_dim,
				 const char *set_stat_var, const char *set_size_root,
				 int missing_ok)
{
  int i;
  int status;
  char  errmsg[MAX_ERR_LENGTH];
  size_t idum;
  int dimid, varid;
  size_t num_sets;
  int *stat_vals = NULL;

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

  if ((status = nc_inq_dimid (exoid, set_num_dim, &dimid)) == NC_NOERR)
    {
      if ((status = nc_inq_dimlen (exoid, dimid, &num_sets)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to get number of %s sets in file id %d",
		set_name, exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }

      /* Allocate space for stat array */
      if (!(stat_vals = malloc((int)num_sets*sizeof(int)))) {
	exerrval = EX_MEMFAIL;
	sprintf(errmsg,
		"Error: failed to allocate memory for %s set status array for file id %d",
		set_name, exoid);
	ex_err("ex_inquire",errmsg,exerrval);
	return (EX_FATAL);
      }

      /* get variable id of status array */
      if ((status = nc_inq_varid (exoid, set_stat_var, &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);
	  sprintf(errmsg,
		  "Error: failed to get %s set status array from file id %d",
		  set_name, exoid);
	  ex_err("ex_inquire",errmsg,exerrval);
	  return (EX_FATAL);
	}
      } else /* default: status is true */
	for(i=0;i<num_sets;i++)
	  stat_vals[i]=1;

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


	if ((status = nc_inq_dimid (exoid, ex_catstr(set_size_root,i+1), &dimid)) != NC_NOERR) {
	  if ( missing_ok ) {
	    idum = 0;
	  } else {
	    *set_length = 0;
	    free(stat_vals);
	    return (EX_FATAL);
	  }
	} else {
	  if ((status = nc_inq_dimlen (exoid, dimid, &idum)) != NC_NOERR) {
	    *set_length = 0;
	    free(stat_vals);
	    return (EX_FATAL);
	  }
	}

	*set_length += idum;
      }

      free(stat_vals);
    }
  return (EX_NOERR);
}
예제 #26
0
파일: ex_put_conn.c 프로젝트: certik/exodus
int ex_put_conn (int   exoid,
                 ex_entity_type blk_type,
                 ex_entity_id   blk_id,
                 const void_int  *node_conn,
                 const void_int  *elem_edge_conn,
                 const void_int  *elem_face_conn)
{
   int connid=-1, blk_id_ndx, status;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

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

/* inquire id's of previously defined dimensions  */
   if (node_conn) {
     switch (blk_type) {
     case EX_ELEM_BLOCK:
       status = nc_inq_varid (exoid, VAR_CONN(blk_id_ndx), &connid);
       break;
     case EX_FACE_BLOCK:
       status = nc_inq_varid (exoid, VAR_FBCONN(blk_id_ndx), &connid);
       break;
     case EX_EDGE_BLOCK:
       status = nc_inq_varid (exoid, VAR_EBCONN(blk_id_ndx), &connid);
       break;
     default:
       exerrval = 1005;
       sprintf(errmsg,
	       "Internal Error: unrecognized block type in switch: %d in file id %d",
	       blk_type,exoid);
       ex_err("ex_putt_conn",errmsg,EX_MSG);
       return (EX_FATAL);
     }
     if (status != NC_NOERR) {
       exerrval = status;
       sprintf(errmsg,
	       "Error: failed to locate connectivity array for %s %"PRId64" in file id %d",
	       ex_name_of_object(blk_type),blk_id,exoid);
       ex_err("ex_put_conn",errmsg, exerrval);
       return(EX_FATAL);
     }
     
     EX_WRITE_CONN(ex_name_of_object(blk_type),connid,node_conn);
   }

   /* If there are edge and face connectivity arrays that belong with the element
    * block, write them now. Warn if they are required but not specified or
    * specified but not required.
    */
   if ( blk_type == EX_ELEM_BLOCK ) {
     int nedpereldim, nfapereldim;
     size_t num_ed_per_elem, num_fa_per_elem;

     status = nc_inq_dimid (exoid, DIM_NUM_EDG_PER_EL(blk_id_ndx), &nedpereldim);
     if (status != NC_NOERR && elem_edge_conn != 0)
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: edge connectivity specified but failed to "
         "locate number of edges/element in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     status = nc_inq_dimid (exoid, DIM_NUM_FAC_PER_EL(blk_id_ndx), &nfapereldim);
     if (status != NC_NOERR && elem_face_conn != 0)
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: face connectivity specified but failed to "
         "locate number of faces/element in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     num_ed_per_elem = 0;
     if ((elem_edge_conn != 0) &&
	 (status = nc_inq_dimlen(exoid, nedpereldim, &num_ed_per_elem) != NC_NOERR))
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: failed to get number of edges/elem in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     num_fa_per_elem = 0;
     if ((elem_face_conn != 0) &&
	 (status = nc_inq_dimlen(exoid, nfapereldim, &num_fa_per_elem) != NC_NOERR))
       {
       exerrval = status;
       sprintf(errmsg,
         "Error: failed to get number of faces/elem in block %"PRId64" in file id %d",
         blk_id,exoid);
       ex_err("ex_put_conn",errmsg,exerrval);
       return(EX_FATAL);
       }

     if ( (num_ed_per_elem == 0 && elem_edge_conn != 0) ||
          (num_ed_per_elem != 0 && elem_edge_conn == 0) )
       {
       exerrval = (EX_FATAL);
       sprintf(errmsg,
         "Error: number of edges per element (%ld) doesn't "
         "agree with elem_edge_conn (0x%p)",
	       (long)num_ed_per_elem, (void*)elem_edge_conn );
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }

     if ( (num_fa_per_elem == 0 && elem_face_conn != 0) ||
          (num_fa_per_elem != 0 && elem_face_conn == 0) )
       {
       exerrval = (EX_FATAL);
       sprintf(errmsg,
         "Error: number of faces per element (%ld) doesn't "
         "agree with elem_face_conn (0x%p)",
	       (long)num_fa_per_elem, (void*)elem_face_conn );
       ex_err("ex_put_conn",errmsg,exerrval);
       return (EX_FATAL);
       }

     if ( num_ed_per_elem != 0 ) {
       status = nc_inq_varid(exoid, VAR_ECONN(blk_id_ndx), &connid);
       if (status != NC_NOERR)
         {
         exerrval = status;
         sprintf(errmsg,
           "Error: failed to locate connectivity array for "
           "element edge block %"PRId64" in file id %d",
           blk_id,exoid);
         ex_err("ex_put_conn",errmsg, exerrval);
         return(EX_FATAL);
         }
       EX_WRITE_CONN("element edge",connid,elem_edge_conn);
     }

     if ( num_fa_per_elem != 0 ) {
       status = nc_inq_varid (exoid, VAR_FCONN(blk_id_ndx), &connid);
       if (status != NC_NOERR)
         {
         exerrval = status;
         sprintf(errmsg,
           "Error: failed to locate connectivity array for "
           "element face block %"PRId64" in file id %d",
           blk_id,exoid);
         ex_err("ex_put_conn",errmsg, exerrval);
         return(EX_FATAL);
         }
       EX_WRITE_CONN("element face",connid,elem_face_conn);
     }
   }

   return (EX_NOERR);

}
예제 #27
0
int ex_put_map (int  exoid,
                const int *elem_map)
{
  int numelemdim, dims[1], mapid, status;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

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

  /* determine number of elements. Return if zero... */
  if (nc_inq_dimid(exoid, DIM_NUM_ELEM, &numelemdim) != NC_NOERR)
    {
      return (EX_NOERR);
    }

  /* put netcdf file into define mode  */

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


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

  dims[0] = numelemdim;

  if ((status = nc_def_var(exoid, VAR_MAP, NC_INT, 1, dims, &mapid)) != NC_NOERR)
    {
      if (status == NC_ENAMEINUSE)
	{
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: element map already exists in file id %d",
		  exoid);
	  ex_err("ex_put_map",errmsg,exerrval);
	}
      else
	{
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to create element map array in file id %d",
		  exoid);
	  ex_err("ex_put_map",errmsg,exerrval);
	}
      goto error_ret;         /* exit define mode and return */
    }


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


  /* write out the element order map  */
  status = nc_put_var_int(exoid, mapid, elem_map);

  if (status != NC_NOERR)
    {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store element map in file id %d",
	      exoid);
      ex_err("ex_put_map",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_map",errmsg,exerrval);
    }
  return (EX_FATAL);
}
예제 #28
0
int ex_get_qa (int exoid,
               char *qa_record[][4])
{
  int status;
  int dimid, varid;
  size_t i, j;
  size_t num_qa_records, start[3], count[3];

  char errmsg[MAX_ERR_LENGTH];

  int rootid = exoid & EX_FILE_ID_MASK;

  exerrval = 0; /* clear error code */

  /* inquire previously defined dimensions and variables  */
  if ((status = nc_inq_dimid(rootid, DIM_NUM_QA, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Warning: no qa records stored in file id %d", 
            rootid);
    ex_err("ex_get_qa",errmsg,exerrval);
    return (EX_WARN);
  }

  if ((status = nc_inq_dimlen(rootid, dimid, &num_qa_records)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get number of qa records in file id %d",
	    rootid);
    ex_err("ex_get_qa",errmsg,exerrval);
    return (EX_FATAL);
  }


  /* do this only if there are any QA records */
  if (num_qa_records > 0) {
    if ((status = nc_inq_varid(rootid, VAR_QA_TITLE, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate qa record data in file id %d", rootid);
      ex_err("ex_get_qa",errmsg,exerrval);
      return (EX_FATAL);
    }


    /* read the QA records */
    for (i=0; i<num_qa_records; i++) {
      for (j=0; j<4; j++) {
	start[0] = i; count[0] = 1;
	start[1] = j; count[1] = 1;
	start[2] = 0; count[2] = MAX_STR_LENGTH+1;
	if ((status = nc_get_vara_text(rootid, varid, start, count, qa_record[i][j])) != NC_NOERR) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to get qa record data in file id %d", rootid);
	  ex_err("ex_get_qa",errmsg,exerrval);
	  return (EX_FATAL);
	}
	qa_record[i][j][MAX_STR_LENGTH] = '\0';
	ex_trim_internal(qa_record[i][j]);
      }
    }
  }
  return (EX_NOERR);
}
int ex_put_partial_elem_attr (int   exoid,
                        ex_entity_id   elem_blk_id,
                        int64_t   start_elem_num,
                        int64_t   num_elems,
                        void *attrib)
{
  int status;
  int numelbdim, numattrdim, attrid, elem_blk_id_ndx;
  size_t num_elem_this_blk, num_attr, start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

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

  /* inquire id's of previously defined dimensions  */
  if ((status = nc_inq_dimid (exoid, DIM_NUM_EL_IN_BLK(elem_blk_id_ndx), &numelbdim)) != NC_NOERR) {
    if (status == NC_EBADDIM) {
      exerrval = status;
      sprintf(errmsg,
         "Error: no element block with id %"PRId64" in file id %d",
             elem_blk_id, exoid);
      ex_err("ex_put_partial_elem_attr",errmsg,exerrval);
      return (EX_FATAL);
    } 
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to locate number of elements for block %"PRId64" in file id %d",
             elem_blk_id, exoid);
      ex_err("ex_put_partial_elem_attr",errmsg,exerrval);
      return (EX_FATAL);
    
  }


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

  if ((status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(elem_blk_id_ndx), &numattrdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
           "Error: number of attributes not defined for block %"PRId64" in file id %d",
            elem_blk_id, exoid);
    ex_err("ex_put_partial_elem_attr",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }

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

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

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

  /* write out the attributes  */
  start[0] = --start_elem_num;
  start[1] = 0;

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

  if (count[0] == 0) {
    start[0] = 0;
}
  
  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_vara_float(exoid, attrid, start, count, attrib);
  } else {
    status = nc_put_vara_double(exoid, attrid, start, count, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to put attributes for block %"PRId64" in file id %d",
            elem_blk_id, exoid);
    ex_err("ex_put_partial_elem_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
예제 #30
0
int ex_id_lkup( int exoid,
                ex_entity_type id_type,
                ex_entity_id   num)
{

  char id_table[MAX_VAR_NAME_LENGTH+1];
  char id_dim[MAX_VAR_NAME_LENGTH+1];
  char stat_table[MAX_VAR_NAME_LENGTH+1];
  int varid, dimid;
  size_t dim_len, i;
  int64_t *id_vals=NULL;
  int *stat_vals=NULL;

  static int filled=FALSE;
  struct obj_stats *tmp_stats;
  int status;
  char errmsg[MAX_ERR_LENGTH];

  exerrval  = 0; /* clear error code */

  switch(id_type) {
  case EX_NODAL:
    return 0;
  case EX_GLOBAL:
    return 0;
  case EX_ELEM_BLOCK:
    strcpy(id_table, VAR_ID_EL_BLK);            /* id array name */
    strcpy(id_dim, DIM_NUM_EL_BLK);             /* id array dimension name*/
    strcpy(stat_table, VAR_STAT_EL_BLK);        /* id status array name */
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_eb);
    break;
  case EX_NODE_SET:
    strcpy(id_table, VAR_NS_IDS);
    strcpy(id_dim, DIM_NUM_NS);
    strcpy(stat_table, VAR_NS_STAT);
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_ns);
    break;
  case EX_SIDE_SET:
    strcpy(id_table, VAR_SS_IDS);
    strcpy(id_dim, DIM_NUM_SS);
    strcpy(stat_table, VAR_SS_STAT);
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_ss);
    break;
  case EX_ELEM_MAP:
    strcpy(id_table, VAR_EM_PROP(1));
    strcpy(id_dim, DIM_NUM_EM);
    strcpy(stat_table, "");
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_em);
    break;
  case EX_NODE_MAP:
    strcpy(id_table, VAR_NM_PROP(1));
    strcpy(id_dim, DIM_NUM_NM);
    strcpy(stat_table, "");
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_nm);
    break;
  case EX_EDGE_BLOCK:
    strcpy(id_table, VAR_ID_ED_BLK);
    strcpy(id_dim, DIM_NUM_ED_BLK);
    strcpy(stat_table, VAR_STAT_ED_BLK);
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_ed);
    break;
  case EX_FACE_BLOCK:
    strcpy(id_table, VAR_ID_FA_BLK);
    strcpy(id_dim, DIM_NUM_FA_BLK);
    strcpy(stat_table, VAR_STAT_FA_BLK);
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_fa);
    break;
  case EX_EDGE_SET:
    strcpy(id_table, VAR_ES_IDS);
    strcpy(id_dim, DIM_NUM_ES);
    strcpy(stat_table, VAR_ES_STAT);
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_es);
    break;
  case EX_FACE_SET:
    strcpy(id_table, VAR_FS_IDS);
    strcpy(id_dim, DIM_NUM_FS);
    strcpy(stat_table, VAR_FS_STAT);
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_fs);
    break;
  case EX_ELEM_SET:
    strcpy(id_table, VAR_ELS_IDS);
    strcpy(id_dim, DIM_NUM_ELS);
    strcpy(stat_table, VAR_ELS_STAT);
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_els);
    break;
  case EX_EDGE_MAP:
    strcpy(id_table, VAR_EDM_PROP(1));
    strcpy(id_dim, DIM_NUM_EDM);
    strcpy(stat_table, "");
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_edm);
    break;
  case EX_FACE_MAP:
    strcpy(id_table, VAR_FAM_PROP(1));
    strcpy(id_dim, DIM_NUM_FAM);
    strcpy(stat_table, "");
    tmp_stats = ex_get_stat_ptr (exoid, &exoII_fam);
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
           "Error: unsupported id array type %d for file id %d",
            id_type, exoid);
    ex_err("ex_id_lkup",errmsg,exerrval);
    return (EX_FATAL);
  }

  if ( (tmp_stats->id_vals == NULL) || (!(tmp_stats->valid_ids)) ) {

    /* first time thru or id arrays haven't been completely filled yet */ 

    /* get size of id array */

    /* First get dimension id of id array */
    if ((status = nc_inq_dimid(exoid,id_dim,&dimid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
           "Error: failed to locate id array dimension in file id %d",
            exoid);
      ex_err("ex_id_lkup",errmsg,exerrval);
      return (EX_FATAL);
    }


    /* Next get value of dimension */ 
    if ((status = nc_inq_dimlen(exoid,dimid,&dim_len)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
           "Error: failed to locate %s array length in file id %d",
            id_table,exoid);
      ex_err("ex_id_lkup",errmsg,exerrval);
      return (EX_FATAL);
    }

    /* get variable id of id array */
    if ((status = nc_inq_varid (exoid, id_table, &varid)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
             "Error: failed to locate %s array in file id %d",
              id_table, exoid);
      ex_err("ex_id_lkup",errmsg,exerrval);
      return (EX_FATAL);
    }

    /* allocate space for id array and initialize to zero to ensure
     that the higher bits don't contain garbage while copy from ints */
    if (!(id_vals = calloc(dim_len,sizeof(int64_t)))) {
      exerrval = EX_MEMFAIL;
      sprintf(errmsg,
             "Error: failed to allocate memory for %s array for file id %d",
              id_table,exoid);
      ex_err("ex_id_lkup",errmsg,exerrval);
      return (EX_FATAL);
    }

    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      status = nc_get_var_longlong (exoid, varid, (long long*)id_vals);
    }
    else {
      int *id_vals_int;
      if (!(id_vals_int = malloc(dim_len*sizeof(int)))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                "Error: failed to allocate memory for temporary array id_vals_int for file id %d",
                exoid);
        ex_err("ex_id_lkup",errmsg,exerrval);
        return (EX_FATAL);
      }
      status = nc_get_var_int(exoid, varid, (int *)id_vals_int);
      if (status == NC_NOERR) {
	for (i=0;i<dim_len;i++)
	  id_vals[i] = (int64_t) id_vals_int[i];
      }
      free(id_vals_int);
    }
    
    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
             "Error: failed to get %s array from file id %d",
              id_table,exoid);
      ex_err("ex_id_lkup",errmsg,exerrval);
      free(id_vals);
      return (EX_FATAL);
    }

    /* check if values in stored arrays are filled with non-zeroes */
    filled = TRUE;
    for (i=0;i<dim_len;i++) {
      if (id_vals[i] == EX_INVALID_ID || id_vals[i] == NC_FILL_INT) {
        filled = FALSE;
        break; /* id array hasn't been completely filled with valid ids yet */
      }
    }

    if (filled) {
      tmp_stats->valid_ids = TRUE;
      tmp_stats->num = dim_len;
      tmp_stats->id_vals = id_vals;
    }

  } else {
    id_vals = tmp_stats->id_vals;
    dim_len = tmp_stats->num;
  }

  /* Do a linear search through the id array to find the array value
     corresponding to the passed index number */

  for (i=0;i<dim_len;i++) {
    if (id_vals[i] == num)
      break; /* found the id requested */
  }
  if (i >= dim_len) /* failed to find id number */
  {
    if ( !(tmp_stats->valid_ids) ) {
       free (id_vals);
    }
    exerrval = EX_LOOKUPFAIL;
    return(EX_LOOKUPFAIL); /*if we got here, the id array value doesn't exist */
  }
  
  /* Now check status array to see if object is null */

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

    if ( (tmp_stats->stat_vals == NULL) || (!(tmp_stats->valid_stat)) ) {
      /* first time thru or status arrays haven't been filled yet */ 

      /* allocate space for new status array */

      if (!(stat_vals = malloc(dim_len*sizeof(int)))) {
        exerrval = EX_MEMFAIL;
        sprintf(errmsg,
                 "Error: failed to allocate memory for %s array for file id %d",
                  id_table,exoid);
        ex_err("ex_id_lkup",errmsg,exerrval);
        return (EX_FATAL);
      }

      if ((status = nc_get_var_int (exoid, varid, stat_vals)) != NC_NOERR) {
        exerrval = status;
        free(stat_vals);
        sprintf(errmsg,
               "Error: failed to get %s array from file id %d",
                stat_table,exoid);
        ex_err("ex_id_lkup",errmsg,exerrval);
        return (EX_FATAL);
      }

      if (tmp_stats->valid_ids) {  
        /* status array is valid only if ids are valid */
        tmp_stats->valid_stat = TRUE;
        tmp_stats->stat_vals = stat_vals;
      }

    } else {
      stat_vals = tmp_stats->stat_vals;
    }

    if (stat_vals[i] == 0) /* is this object null? */ {
      exerrval =  EX_NULLENTITY;
      if ( !(tmp_stats->valid_stat) ) {
        free (stat_vals);
      }
      if ( !(tmp_stats->valid_ids) ) {
        if (id_vals) free (id_vals); 
      }
      return(-((int)i+1)); /* return index into id array (1-based) */
    }
  }
  if ( !(tmp_stats->valid_ids) ) {
    if (id_vals) free (id_vals);
    if (stat_vals) free (stat_vals);
  }
  return(i+1); /* return index into id array (1-based) */
}