int ex_put_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, const char *name)
{
  int         status;
  int         varid, ent_ndx;
  char        errmsg[MAX_ERR_LENGTH];
  const char *vobj;

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

  switch (obj_type) {
  case EX_EDGE_BLOCK: vobj = VAR_NAME_ED_BLK; break;
  case EX_FACE_BLOCK: vobj = VAR_NAME_FA_BLK; break;
  case EX_ELEM_BLOCK: vobj = VAR_NAME_EL_BLK; break;
  case EX_NODE_SET: vobj = VAR_NAME_NS; break;
  case EX_SIDE_SET: vobj = VAR_NAME_SS; break;
  case EX_EDGE_SET: vobj = VAR_NAME_ES; break;
  case EX_FACE_SET: vobj = VAR_NAME_FS; break;
  case EX_ELEM_SET: vobj = VAR_NAME_ELS; break;
  case EX_NODE_MAP: vobj = VAR_NAME_NM; break;
  case EX_EDGE_MAP: vobj = VAR_NAME_EDM; break;
  case EX_FACE_MAP: vobj = VAR_NAME_FAM; break;
  case EX_ELEM_MAP: vobj = VAR_NAME_EM; break;
  default:
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Invalid type specified in file id %d", exoid);
    ex_err(__func__, errmsg, EX_BADPARAM);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  if ((status = nc_inq_varid(exoid, vobj, &varid)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s names in file id %d",
             ex_name_of_object(obj_type), exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  ent_ndx = ex_id_lkup(exoid, obj_type, entity_id);

  if (ent_ndx == -EX_LOOKUPFAIL) { /* could not find the element block id */
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: %s id %" PRId64 " not found in file id %d",
             ex_name_of_object(obj_type), entity_id, exoid);
    ex_err(__func__, errmsg, EX_LOOKUPFAIL);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* If this is a null entity, then 'ent_ndx' will be negative.
   * We don't care in this __func__, so make it positive and continue...
   */
  if (ent_ndx < 0) {
    ent_ndx = -ent_ndx;
  }

  /* write EXODUS entityname */
  status = ex_put_name_internal(exoid, varid, ent_ndx - 1, name, obj_type, "", __func__);

  EX_FUNC_LEAVE(status);
}
Exemplo n.º 2
0
int ex_put_names_internal(int exoid, int varid, size_t num_entity, char **names,
                          ex_entity_type obj_type, const char *subtype, const char *routine)
{
  size_t i;
  int    status;
  size_t start[2], count[2];
  char   errmsg[MAX_ERR_LENGTH];
  int    max_name_len = 0;
  size_t name_length;

  /* inquire previously defined dimensions  */
  name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH) + 1;

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

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

      if (count[1] > name_length) {
        fprintf(stderr, "Warning: The %s %s name '%s' is too long.\n\tIt will "
                        "be truncated from %d to %d characters\n",
                ex_name_of_object(obj_type), subtype, names[i], (int)strlen(names[i]),
                (int)name_length - 1);
        count[1] = name_length;
        too_long = 1;
      }

      if (count[1] > max_name_len) {
        max_name_len = count[1];
      }

      if ((status = nc_put_vara_text(exoid, varid, start, count, names[i])) != NC_NOERR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store %s names in file id %d",
                 ex_name_of_object(obj_type), exoid);
        ex_err(routine, errmsg, exerrval);
        return (EX_FATAL);
      }

      /* Add the trailing null if the variable name was too long */
      if (too_long) {
        start[1] = name_length - 1;
        nc_put_var1_text(exoid, varid, start, "\0");
      }
    }
  }

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

  return (EX_NOERR);
}
Exemplo n.º 3
0
int ex_put_names_internal(int exoid, int varid, size_t num_entity, char **names,
                          ex_entity_type obj_type, const char *subtype, const char *routine)
{
  size_t i;
  int    status;
  char   errmsg[MAX_ERR_LENGTH];
  int    max_name_len = 0;
  size_t name_length;
  size_t length;
  char * int_names  = NULL;
  size_t idx        = 0;
  int    found_name = 0;

  ex_check_valid_file_id(exoid);
  /* inquire previously defined dimensions  */
  name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH) + 1;

  int_names = calloc(num_entity * name_length, 1);

  for (i = 0; i < num_entity; i++) {
    if (names[i] != '\0') {
      found_name = 1;
      strncpy(&int_names[idx], names[i], name_length - 1);
      int_names[idx + name_length - 1] = '\0';
      length                           = strlen(names[i]) + 1;
      if (length > name_length) {
        fprintf(stderr, "Warning: The %s %s name '%s' is too long.\n\tIt will "
                        "be truncated from %d to %d characters\n",
                ex_name_of_object(obj_type), subtype, names[i], (int)length - 1,
                (int)name_length - 1);
        length = name_length;
      }

      if (length > max_name_len) {
        max_name_len = length;
      }
    }
    idx += name_length;
  }

  if (found_name) {
    if ((status = nc_put_var_text(exoid, varid, int_names)) != NC_NOERR) {
      exerrval = status;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store %s names in file id %d",
               ex_name_of_object(obj_type), exoid);
      ex_err(routine, errmsg, exerrval);
      return (EX_FATAL);
    }

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

  return (EX_NOERR);
}
Exemplo n.º 4
0
int ex_get_name_internal(int exoid, int varid, size_t index, char *name, int name_size,
                         ex_entity_type obj_type, const char *routine)
{
  size_t start[2], count[2];
  int    status;
  char   errmsg[MAX_ERR_LENGTH];
  int    api_name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH);

  /* read the name */
  start[0] = index;
  count[0] = 1;
  start[1] = 0;
  count[1] = name_size + 1;

  status = nc_get_vara_text(exoid, varid, start, count, name);
  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get %s name at index %d from file id %d",
             ex_name_of_object(obj_type), (int)index, exoid);
    ex_err(routine, errmsg, exerrval);
    return (EX_FATAL);
  }

  name[api_name_size] = '\0';

  ex_trim_internal(name);
  return EX_NOERR;
}
Exemplo n.º 5
0
int ex_get_name_internal(int exoid, int varid, size_t index, char *name,
			 ex_entity_type obj_type, const char *routine)
{
  size_t start[2], count[2];
  int status;
  char errmsg[MAX_ERR_LENGTH];

  /* read the name */
  start[0] = index;  count[0] = 1;
  start[1] = 0;      count[1] = ex_max_name_length+1;

  status = nc_get_vara_text(exoid, varid, start, count, name);
  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg, "Error: failed to get %s name at index %d from file id %d",
	    ex_name_of_object(obj_type), (int)index, exoid);
    ex_err(routine,errmsg,exerrval);
    return (EX_FATAL);
  }

  name[ex_max_name_length] = '\0';
  
  ex_trim_internal(name);
  return EX_NOERR;
}
static void write_dummy_names(int exoid, ex_entity_type obj_type)
{
  const char *routine = "write_dummy_names";
  size_t  start[2], count[2];
  char *text = "";
  int varid;
  size_t num_entity;
  size_t i;
  
  ex_get_dimension(exoid, ex_dim_num_objects(obj_type),
		   ex_name_of_object(obj_type),
		   &num_entity, &varid, routine);
  
  for (i = 0; i < num_entity; i++) {
    start[0] = i;
    count[0] = 1;

    start[1] = 0;
    count[1] = strlen(text)+1;

    nc_put_vara_text(exoid, varid, start, count, text);
  }
}
Exemplo n.º 7
0
int ex_get_var(int exoid, int time_step, ex_entity_type var_type, int var_index,
               ex_entity_id obj_id, int64_t num_entry_this_obj, void *var_vals)
{
  int    status;
  int    varid, obj_id_ndx;
  size_t start[2], count[2];
  char   errmsg[MAX_ERR_LENGTH];

  ex_check_valid_file_id(exoid);

  if (var_type == EX_NODAL) {
    /* FIXME: Special case: ignore obj_id, possible large_file complications,
     * etc. */
    return ex_get_nodal_var_int(exoid, time_step, var_index, num_entry_this_obj, var_vals);
  }
  if (var_type == EX_GLOBAL) {
    /* FIXME: Special case: all vars stored in 2-D single array. */
    return ex_get_glob_vars_int(exoid, time_step, num_entry_this_obj, var_vals);
  }

  exerrval = 0; /* clear error code */

  /* Determine index of obj_id in VAR_ID_EL_BLK array */
  obj_id_ndx = ex_id_lkup(exoid, var_type, obj_id);
  if (exerrval != 0) {
    if (exerrval == EX_NULLENTITY) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "Warning: no %s variables for NULL block %" PRId64 " in file id %d",
               ex_name_of_object(var_type), obj_id, exoid);
      ex_err("ex_get_var", errmsg, EX_NULLENTITY);
      return (EX_WARN);
    }
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate %s id %" PRId64 " in id variable in file id %d",
             ex_name_of_object(var_type), obj_id, exoid);
    ex_err("ex_get_var", errmsg, exerrval);
    return (EX_FATAL);
  }

  /* inquire previously defined variable */

  if ((status = nc_inq_varid(exoid, ex_name_var_of_object(var_type, var_index, obj_id_ndx),
                             &varid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s %" PRId64 " var %d in file id %d",
             ex_name_of_object(var_type), obj_id, var_index, exoid);
    ex_err("ex_get_var", errmsg, exerrval);
    return (EX_FATAL);
  }

/* Verify that time_step is within bounds */
#ifndef NDEBUG
  {
    int num_time_steps = ex_inquire_int(exoid, EX_INQ_TIME);
    if (time_step <= 0 || time_step > num_time_steps) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: time_step is out-of-range. Value = %d, valid "
                                       "range is 1 to %d in file id %d",
               time_step, num_time_steps, exoid);
      ex_err("ex_get_var", errmsg, EX_BADPARAM);
      return (EX_FATAL);
    }
  }
#endif

  /* read values of element variable */
  start[0] = --time_step;
  start[1] = 0;

  count[0] = 1;
  count[1] = num_entry_this_obj;

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

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get %s %" PRId64 " variable %d in file id %d",
             ex_name_of_object(var_type), obj_id, var_index, exoid);
    ex_err("ex_get_var", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
int ex_get_set_param (int  exoid,
		      ex_entity_type set_type, 
		      int  set_id,
		      int *num_entry_in_set, 
		      int *num_dist_fact_in_set)
{
  int status;
  int varid, dimid, set_id_ndx;
  size_t lnum_entry_in_set;
  size_t lnum_dist_fact_in_set;
  char errmsg[MAX_ERR_LENGTH];
  char* numentryptr = NULL;
  char* numdfptr = 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 %ss stored in file id %d",
	    ex_name_of_object(set_type), exoid);
    ex_err("ex_get_set_param",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)     /* NULL set? */
      {
	*num_entry_in_set = 0;
	*num_dist_fact_in_set = 0;
	return (EX_NOERR);
      } else {
      sprintf(errmsg,
	      "Error: failed to locate %s id %d in id array in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_get_set_param",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* setup more pointers based on set_type */
  if (set_type == EX_NODE_SET) {
    numentryptr = DIM_NUM_NOD_NS(set_id_ndx);
    /* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
    numdfptr = DIM_NUM_NOD_NS(set_id_ndx);
  }
  else if (set_type == EX_EDGE_SET) {
    numentryptr = DIM_NUM_EDGE_ES(set_id_ndx);
    numdfptr = DIM_NUM_DF_ES(set_id_ndx);
  }
  else if (set_type == EX_FACE_SET) {
    numentryptr = DIM_NUM_FACE_FS(set_id_ndx);
    numdfptr = DIM_NUM_DF_FS(set_id_ndx);
  }
  else if (set_type == EX_SIDE_SET) {
    numentryptr = DIM_NUM_SIDE_SS(set_id_ndx);
    numdfptr = DIM_NUM_DF_SS(set_id_ndx);
  }
  if (set_type == EX_ELEM_SET) {
    numentryptr = DIM_NUM_ELE_ELS(set_id_ndx);
    numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
  }

  /* inquire values of dimension for number of entities in set */
  if (ex_get_dimension(exoid, numentryptr,"entries", &lnum_entry_in_set,
		       &dimid, "ex_get_set_param") != NC_NOERR)
    return EX_FATAL;
  *num_entry_in_set = lnum_entry_in_set;

  /* Inquire value of dimension of number of dist factors for this set. 
     NOTE: For node sets, because DIM_NUM_DF_NS is not used, we check to see
     if the dist factor variable for a node set index exits. If it does not,
     the dist factor count is assumed to be zero, otherwise the dist factor 
     count will be the same as the number of nodes in the set. */

  if (set_type == EX_NODE_SET) {
    if ((status = nc_inq_varid(exoid, VAR_FACT_NS(set_id_ndx), &varid)) != NC_NOERR) {
      *num_dist_fact_in_set = 0;        /* signal dist factor doesn't exist */
      if (status == NC_ENOTVAR)
	return (EX_NOERR);
      else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate the dist factors for %s %d in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_get_set_param",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
    *num_dist_fact_in_set = lnum_entry_in_set;   /* # of df = # of nodes */
  }
  else {/* all other set types */
    if ((status = nc_inq_dimid(exoid, numdfptr, &dimid)) != NC_NOERR) {
      *num_dist_fact_in_set = 0; /* no distribution factors for this set*/
      if (status == NC_EBADDIM)
	return (EX_NOERR);
      else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate number of dist factors in %s %d in file id %d",
		ex_name_of_object(set_type), set_id, exoid);
	ex_err("ex_get_set_param",errmsg,exerrval);
	return (EX_FATAL);
      }
    }

    if ((status = nc_inq_dimlen(exoid, dimid, &lnum_dist_fact_in_set)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of dist factors in %s %d in file id %d",
	      ex_name_of_object(set_type), set_id, exoid);
      ex_err("ex_get_set_param",errmsg,exerrval);
      return (EX_FATAL);
    }
    *num_dist_fact_in_set = lnum_dist_fact_in_set;
  }

  return (EX_NOERR);
}
int ex_put_partial_set_dist_fact (int   exoid,
                                  ex_entity_type set_type,
                                  ex_entity_id   set_id,
                                  int64_t   offset,
                                  int64_t   num_to_put,
                                  const void *set_dist_fact)
{
    int status;
    int dimid, set_id_ndx;
    int dist_id;
    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,
                "Error: no %ss specified in file id %d",
                ex_name_of_object(set_type), exoid);
        ex_err("ex_put_set_dist_fact",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* 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: no data allowed for NULL %s %"PRId64" in file id %d",
                    ex_name_of_object(set_type), set_id,exoid);
            ex_err("ex_put_set_fact",errmsg,EX_NULLENTITY);
            return (EX_WARN);
        } else {
            sprintf(errmsg,
                    "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_put_set_dist_fact",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    /* setup more pointers based on set_type */
    if (set_type == EX_NODE_SET) {
        /* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
        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);
    }

    /* find id of distribution factors variable
     */

    if ((status = nc_inq_varid(exoid, factptr, &dist_id)) != NC_NOERR) {
        /* this test is only needed for node set because we're using
           DIM_NUM_NOD_NS instead of  DIM_NUM_DF_NS*/
        if (status == NC_ENOTVAR) {
            exerrval = EX_BADPARAM;
            sprintf(errmsg,
                    "Warning: no dist factors defined for %s %"PRId64" in file id %d",
                    ex_name_of_object(set_type), set_id, exoid);
            ex_err("ex_put_set_dist_fact",errmsg,exerrval);
            return (EX_WARN);
        } else  {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to locate dist factors list for %s %"PRId64" in file id %d",
                    ex_name_of_object(set_type), set_id,exoid);
            ex_err("ex_put_set_dist_fact",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    start[0] = offset-1;
    count[0] = num_to_put;
    if (num_to_put == 0)
        start[0] = 0;

    /* write out the distribution factors array */
    if (ex_comp_ws(exoid) == 4) {
        status = nc_put_vara_float(exoid, dist_id, start, count, set_dist_fact);
    } else {
        status = nc_put_vara_double(exoid, dist_id, start, count, set_dist_fact);
    }

    if (status != NC_NOERR) {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to store dist factors for %s %"PRId64" in file id %d",
                ex_name_of_object(set_type), set_id,exoid);
        ex_err("ex_put_partial_set_dist_fact",errmsg,exerrval);
        return (EX_FATAL);
    }
    return (EX_NOERR);
}
Exemplo n.º 10
0
int ex_put_name (int   exoid,
		 ex_entity_type obj_type,
		 ex_entity_id   entity_id,
		 const char *name)
{
  int status;
  int varid, ent_ndx; 
  char errmsg[MAX_ERR_LENGTH];
  const char *routine = "ex_put_name";
  const char *vobj;
   
  exerrval = 0; /* clear error code */

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

  ent_ndx = ex_id_lkup(exoid, obj_type, entity_id);

  if (exerrval == EX_LOOKUPFAIL) {   /* could not find the element block id */
    sprintf(errmsg,
            "Error: %s id %"PRId64" not found in file id %d",
	    ex_name_of_object(obj_type), entity_id, exoid);
    ex_err("ex_put_name",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* If this is a null entity, then 'ent_ndx' will be negative.
   * We don't care in this routine, so make it positive and continue...
   */
  if (ent_ndx < 0) ent_ndx = -ent_ndx;
   
  /* write EXODUS entityname */
  status = ex_put_name_internal(exoid, varid, ent_ndx-1, name, obj_type, "", routine);

  return(status);
}
Exemplo n.º 11
0
int ex_put_set_param (int exoid,
                      ex_entity_type set_type,
                      int set_id,
                      int num_entries_in_set,
                      int num_dist_fact_in_set)
{
  int status;
  size_t temp;
  int dimid, varid, set_id_ndx, dims[1]; 
  size_t start[1]; 
  int num_sets;
  int ldum;
  int cur_num_sets, set_stat;
  char *cdum;
  char errmsg[MAX_ERR_LENGTH];
  char* dimptr;
  char* idsptr;
  char* statptr;
  char* numentryptr = NULL;
  char* numdfptr = NULL;
  char* factptr = NULL;
  char* entryptr = NULL;
  char* extraptr = NULL;

  exerrval = 0; /* clear error code */

  cdum = 0;

  /* setup pointers based on set_type 
     NOTE: there is another block that sets more stuff later ... */
  if (set_type == EX_NODE_SET) {
    dimptr = DIM_NUM_NS;
    idsptr = VAR_NS_IDS;
    statptr = VAR_NS_STAT;
  }
  else if (set_type == EX_EDGE_SET) {
    dimptr = DIM_NUM_ES;
    idsptr = VAR_ES_IDS;
    statptr = VAR_ES_STAT;
  }
  else if (set_type == EX_FACE_SET) {
    dimptr = DIM_NUM_FS;
    idsptr = VAR_FS_IDS;
    statptr = VAR_FS_STAT;
  }
  else if (set_type == EX_SIDE_SET) {
    dimptr = DIM_NUM_SS;
    idsptr = VAR_SS_IDS;
    statptr = VAR_SS_STAT;
  }
  else if (set_type == EX_ELEM_SET) {
    dimptr = DIM_NUM_ELS;
    idsptr = VAR_ELS_IDS;
    statptr = VAR_ELS_STAT;
  }
  else {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: invalid set type (%d)", set_type);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* first check if any of that set type is specified */

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

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

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


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

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

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

  /* setup more pointers based on set_type */
  if (set_type == EX_NODE_SET) {
    numentryptr = DIM_NUM_NOD_NS(set_id_ndx);
    entryptr = VAR_NODE_NS(set_id_ndx);
    extraptr = NULL;
    /* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
    numdfptr = DIM_NUM_NOD_NS(set_id_ndx);
    factptr = VAR_FACT_NS(set_id_ndx);
  }
  else if (set_type == EX_EDGE_SET) {
    numentryptr = DIM_NUM_EDGE_ES(set_id_ndx);
    entryptr = VAR_EDGE_ES(set_id_ndx);
    extraptr = VAR_ORNT_ES(set_id_ndx);
    numdfptr = DIM_NUM_DF_ES(set_id_ndx);
    factptr = VAR_FACT_ES(set_id_ndx);
  }
  else if (set_type == EX_FACE_SET) {
    numentryptr = DIM_NUM_FACE_FS(set_id_ndx);
    entryptr = VAR_FACE_FS(set_id_ndx);
    extraptr = VAR_ORNT_FS(set_id_ndx);
    numdfptr = DIM_NUM_DF_FS(set_id_ndx);
    factptr = VAR_FACT_FS(set_id_ndx);
  }
  else if (set_type == EX_SIDE_SET) {
    numentryptr = DIM_NUM_SIDE_SS(set_id_ndx);
    entryptr = VAR_ELEM_SS(set_id_ndx);
    extraptr = VAR_SIDE_SS(set_id_ndx);
    numdfptr = DIM_NUM_DF_SS(set_id_ndx);
    factptr = VAR_FACT_SS(set_id_ndx);
  }
  if (set_type == EX_ELEM_SET) {
    numentryptr = DIM_NUM_ELE_ELS(set_id_ndx);
    entryptr = VAR_ELEM_ELS(set_id_ndx);
    extraptr = NULL;
    numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
    factptr = VAR_FACT_ELS(set_id_ndx);
  }

  /* write out information to previously defined variable */

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

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

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

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

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

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

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

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


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

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

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

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

  /* Create distribution factors variable if required */

  if (num_dist_fact_in_set > 0) {

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

      /* resuse dimid from entry lists */

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

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

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

  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_set_param",errmsg,exerrval);
  }
  return (EX_FATAL);
}
Exemplo n.º 12
0
int ex_get_truth_table (int  exoid,
      ex_entity_type obj_type,
      int  num_blk,
      int  num_var,
      int *var_tab)
{
  int dimid, varid, tabid, i, j, status, status1;
  size_t num_entity = 0;
  size_t num_var_db = 0;
  char errmsg[MAX_ERR_LENGTH];
  const char* routine = "ex_get_truth_table";

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

  exerrval = 0; /* clear error code */

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

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

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

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

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

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

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

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
        "Error: failed to get %s truth table from file id %d",
        ex_name_of_object(obj_type), exoid);
      ex_err(routine,errmsg,exerrval);
      return (EX_FATAL);
    }
  } 
  return (EX_NOERR);
}
Exemplo n.º 13
0
int ex_put_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name,
                      const void_int *values)
{
  int    oldfill = 0;
  int    temp;
  int    num_props, i, propid, dimid, dims[1], status;
  int    found = EX_FALSE;
  int    int_type;
  size_t num_obj;
  char * name;
  char   tmpstr[MAX_STR_LENGTH + 1];

  char errmsg[MAX_ERR_LENGTH];

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

  /* check if property has already been created */

  num_props = ex_get_num_props(exoid, obj_type);

  /* inquire id of previously defined dimension (number of objects) */
  status = ex_get_dimension(exoid, ex_dim_num_objects(obj_type), ex_name_of_object(obj_type),
                            &num_obj, &dimid, __func__);
  if (status != NC_NOERR) {
    EX_FUNC_LEAVE(status);
  }

  for (i = 1; i <= num_props; i++) {
    switch (obj_type) {
    case EX_ELEM_BLOCK: name = VAR_EB_PROP(i); break;
    case EX_FACE_BLOCK: name = VAR_FA_PROP(i); break;
    case EX_EDGE_BLOCK: name = VAR_ED_PROP(i); break;
    case EX_NODE_SET: name = VAR_NS_PROP(i); break;
    case EX_EDGE_SET: name = VAR_ES_PROP(i); break;
    case EX_FACE_SET: name = VAR_FS_PROP(i); break;
    case EX_ELEM_SET: name = VAR_ELS_PROP(i); break;
    case EX_SIDE_SET: name = VAR_SS_PROP(i); break;
    case EX_ELEM_MAP: name = VAR_EM_PROP(i); break;
    case EX_FACE_MAP: name = VAR_FAM_PROP(i); break;
    case EX_EDGE_MAP: name = VAR_EDM_PROP(i); break;
    case EX_NODE_MAP: name = VAR_NM_PROP(i); break;
    default:
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type,
               exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      EX_FUNC_LEAVE(EX_FATAL);
    }

    if ((status = nc_inq_varid(exoid, name, &propid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get property array id in file id %d",
               exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }

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

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

  /* if property array has not been created, create it */
  if (!found) {

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

    /*   create a variable with a name xx_prop#, where # is the new number   */
    /*   of properties                                                       */
    switch (obj_type) {
    case EX_ELEM_BLOCK: name = VAR_EB_PROP(num_props + 1); break;
    case EX_FACE_BLOCK: name = VAR_FA_PROP(num_props + 1); break;
    case EX_EDGE_BLOCK: name = VAR_ED_PROP(num_props + 1); break;
    case EX_NODE_SET: name = VAR_NS_PROP(num_props + 1); break;
    case EX_EDGE_SET: name = VAR_ES_PROP(num_props + 1); break;
    case EX_FACE_SET: name = VAR_FS_PROP(num_props + 1); break;
    case EX_ELEM_SET: name = VAR_ELS_PROP(num_props + 1); break;
    case EX_SIDE_SET: name = VAR_SS_PROP(num_props + 1); break;
    case EX_ELEM_MAP: name = VAR_EM_PROP(num_props + 1); break;
    case EX_FACE_MAP: name = VAR_FAM_PROP(num_props + 1); break;
    case EX_EDGE_MAP: name = VAR_EDM_PROP(num_props + 1); break;
    case EX_NODE_MAP: name = VAR_NM_PROP(num_props + 1); break;
    default:
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type,
               exoid);
      ex_err(__func__, errmsg, EX_BADPARAM);
      goto error_ret; /* Exit define mode and return */
    }

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

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

    if ((status = nc_def_var(exoid, name, int_type, 1, dims, &propid)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to create property array variable in file id %d", exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* Exit define mode and return */
    }
    nc_set_fill(exoid, oldfill, &temp); /* default: nofill */

    /*   store property name as attribute of property array variable */
    if ((status = nc_put_att_text(exoid, propid, ATT_PROP_NAME, strlen(prop_name) + 1,
                                  prop_name)) != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store property name %s in file id %d",
               prop_name, exoid);
      ex_err(__func__, errmsg, status);
      goto error_ret; /* Exit define mode and return */
    }

    /* leave define mode  */

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

  /* put num_obj values in property array */
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    status = nc_put_var_longlong(exoid, propid, values);
  }
  else {
    status = nc_put_var_int(exoid, propid, values);
  }

  if (status != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store property values in file id %d", exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  EX_FUNC_LEAVE(EX_NOERR);

/* Fatal error: exit definition mode and return */
error_ret:
  nc_set_fill(exoid, oldfill, &temp);            /* default: nofill */
  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);
}
Exemplo n.º 14
0
int ex_put_attr (int   exoid,
		 ex_entity_type blk_type,
		 int   blk_id,
		 const void *attrib)
{
  int status;
  int attrid, blk_id_ndx = 0;
  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

  if ( blk_type != EX_NODAL ) {
    /* Determine index of blk_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) {
        sprintf(errmsg,
		"Warning: no attributes allowed for NULL %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_put_attr",errmsg,EX_MSG);
        return (EX_WARN);              /* no attributes for this block */
      } else {
        sprintf(errmsg,
		"Error: no %s id %d in in file id %d",
                ex_name_of_object(blk_type), blk_id, exoid);
        ex_err("ex_put_attr",errmsg,exerrval);
        return (EX_FATAL);
      }
    }
  }

  switch (blk_type) {
  case EX_SIDE_SET:
    status = nc_inq_varid (exoid, VAR_SSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_NODE_SET:
    status = nc_inq_varid (exoid, VAR_NSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_EDGE_SET:
    status = nc_inq_varid (exoid, VAR_ESATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_FACE_SET:
    status = nc_inq_varid (exoid, VAR_FSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_ELEM_SET:
    status = nc_inq_varid (exoid, VAR_ELSATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_NODAL:
    status = nc_inq_varid (exoid, VAR_NATTRIB, &attrid);
    break;
  case EX_EDGE_BLOCK:
    status = nc_inq_varid (exoid, VAR_EATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_FACE_BLOCK:
    status = nc_inq_varid (exoid, VAR_FATTRIB(blk_id_ndx), &attrid);
    break;
  case EX_ELEM_BLOCK:
    status = nc_inq_varid (exoid, VAR_ATTRIB(blk_id_ndx), &attrid);
    break;
  default:
    sprintf(errmsg,
      "Error: Called with invalid blk_type %d", blk_type );
    ex_err("ex_put_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate attribute variable for %s %d in file id %d",
            ex_name_of_object(blk_type),blk_id,exoid);
    ex_err("ex_put_attr",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* write out the attributes  */
  if (ex_comp_ws(exoid) == 4) {
    status = nc_put_var_float(exoid, attrid, attrib);
  } else {
    status = nc_put_var_double(exoid, attrid, attrib);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to put attributes for %s %d in file id %d",
            ex_name_of_object(blk_type),blk_id,exoid);
    ex_err("ex_put_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
int ex_get_variable_name (int   exoid,
			  ex_entity_type obj_type,
			  int   var_num,
			  char *var_name)
{
  int status;
  int varid;
  char errmsg[MAX_ERR_LENGTH];
  const char *vname = NULL;
   
  exerrval = 0; /* clear error code */

  /* inquire previously defined variables  */

  switch (obj_type) {
  case EX_GLOBAL:
    vname = VAR_NAME_GLO_VAR;
    break;
  case EX_NODAL:
    vname = VAR_NAME_NOD_VAR;
    break;
  case EX_EDGE_BLOCK:
    vname = VAR_NAME_EDG_VAR;
    break;
  case EX_FACE_BLOCK:
    vname = VAR_NAME_FAC_VAR;
    break;
  case EX_ELEM_BLOCK:
    vname = VAR_NAME_ELE_VAR;
    break;
  case EX_NODE_SET:
    vname = VAR_NAME_NSET_VAR;
    break;
  case EX_EDGE_SET:
    vname = VAR_NAME_ESET_VAR;
    break;
  case EX_FACE_SET:
    vname = VAR_NAME_FSET_VAR;
    break;
  case EX_SIDE_SET:
    vname = VAR_NAME_SSET_VAR;
    break;
  case EX_ELEM_SET:
    vname = VAR_NAME_ELSET_VAR;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Error: Invalid variable type (%d) given for file id %d", obj_type, exoid );
    ex_err( "ex_get_variable_name", errmsg, exerrval );
    return (EX_FATAL);
  }

  if ((status = nc_inq_varid(exoid, vname, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Warning: no %s variable names stored in file id %d",
	    ex_name_of_object(obj_type), exoid);
    ex_err("ex_get_variable_name",errmsg,exerrval);
    return (EX_WARN);
  }

  /* read the variable name */
  {
    int db_name_size = ex_inquire_int(exoid, EX_INQ_DB_MAX_ALLOWED_NAME_LENGTH);
    int api_name_size = ex_inquire_int(exoid, EX_INQ_MAX_READ_NAME_LENGTH);
    int name_size = db_name_size < api_name_size ? db_name_size : api_name_size;

    status = ex_get_name_internal(exoid, varid, var_num-1, var_name, name_size, obj_type, "ex_get_variable_name");
    if (status != NC_NOERR) {
      return (EX_FATAL);
    }
  }
  return (EX_NOERR);
}
Exemplo n.º 16
0
int ex_get_entity_count_per_polyhedra (int            exoid,
                                       ex_entity_type blk_type,
                                       int            blk_id,
                                       int     *entity_counts)
{
   int npeid=-1, blk_id_ndx, status;
   char errmsg[MAX_ERR_LENGTH];

   exerrval = 0; /* clear error code */

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

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

   status = nc_get_var_int(exoid, npeid, entity_counts); 
   if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
      "Error: failed to read node counts array for %s block %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
      ex_err("ex_get_entity_count_per_polyhedra",errmsg, exerrval);
      return(EX_FATAL);
   }
   return (EX_NOERR);
}
Exemplo n.º 17
0
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);

}
Exemplo n.º 18
0
/*
 * reads the attribute names for an element block
 */
int ex_get_attr_names( int   exoid,
                       ex_entity_type obj_type,
                       ex_entity_id   obj_id,
                       char **names)
{
  int status;
  int varid, numattrdim, obj_id_ndx;
  size_t num_attr, i;
  char errmsg[MAX_ERR_LENGTH];
  const char* dnumobjatt;
  const char* vattrbname;

  exerrval = 0; /* clear error code */

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

  switch (obj_type) {
  case EX_NODE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx);
    vattrbname = VAR_NAME_NSATTRIB(obj_id_ndx);
    break;
  case EX_SIDE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx);
    vattrbname = VAR_NAME_SSATTRIB(obj_id_ndx);
    break;
  case EX_EDGE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx);
    vattrbname = VAR_NAME_ESATTRIB(obj_id_ndx);
    break;
  case EX_FACE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx);
    vattrbname = VAR_NAME_FSATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_SET:
    dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx);
    vattrbname = VAR_NAME_ELSATTRIB(obj_id_ndx);
    break;
  case EX_NODAL:
    dnumobjatt = DIM_NUM_ATT_IN_NBLK;
    vattrbname = VAR_NAME_NATTRIB;
    break;
  case EX_EDGE_BLOCK:
    dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
    vattrbname = VAR_NAME_EATTRIB(obj_id_ndx);
    break;
  case EX_FACE_BLOCK:
    dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
    vattrbname = VAR_NAME_FATTRIB(obj_id_ndx);
    break;
  case EX_ELEM_BLOCK:
    dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx);
    vattrbname = VAR_NAME_ATTRIB(obj_id_ndx);
    break;
  default:
    exerrval = 1005;
    sprintf(errmsg,
	    "Internal Error: unrecognized object type in switch: %d in file id %d",
	    obj_type,exoid);
    ex_err("ex_get_attr_names",errmsg,EX_MSG);
    return (EX_FATAL);              /* number of attributes not defined */
  }
  /* inquire id's of previously defined dimensions  */

  if ((status = nc_inq_dimid(exoid, dnumobjatt, &numattrdim)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Warning: no attributes found for %s %"PRId64" in file id %d",
	    ex_name_of_object(obj_type),obj_id,exoid);
    ex_err("ex_get_attr_names",errmsg,EX_MSG);
    return (EX_WARN);              /* no attributes for this object */
  }

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

  /* It is OK if we don't find the attribute names since they were
     added at version 4.26; earlier databases won't have the names.
  */
  status = nc_inq_varid(exoid, vattrbname, &varid);

  /* read in the attributes */

  if (status == NC_NOERR) {
    /* read the names */
    status = ex_get_names_internal(exoid, varid, num_attr, names, obj_type, "ex_get_attr_names");
    if (status != NC_NOERR) {
      return (EX_FATAL);
    }
  } else {
    /* Names variable does not exist on the database; probably since this is an
     * older version of the database.  Return an empty array...
     */
    for (i=0; i<num_attr; i++) {
      names[i][0] = '\0';
    }
  }
  return(EX_NOERR);
}
Exemplo n.º 19
0
int ex_put_variable_name (int   exoid,
			  ex_entity_type obj_type,
			  int   var_num,
			  const char *var_name)
{
  int status;
  int varid; 
  char errmsg[MAX_ERR_LENGTH];
  const char* vname;

  exerrval = 0; /* clear error code */

 /* inquire previously defined variables  */
  switch (obj_type) {
  case EX_GLOBAL:
    vname = VAR_NAME_GLO_VAR;
    break;
  case EX_NODAL:
    vname = VAR_NAME_NOD_VAR;
    break;
  case EX_EDGE_BLOCK:
    vname = VAR_NAME_EDG_VAR;
    break;
  case EX_FACE_BLOCK:
    vname = VAR_NAME_FAC_VAR;
    break;
  case EX_ELEM_BLOCK:
    vname = VAR_NAME_ELE_VAR;
    break;
  case EX_NODE_SET:
    vname = VAR_NAME_NSET_VAR;
    break;
  case EX_EDGE_SET:
    vname = VAR_NAME_ESET_VAR;
    break;
  case EX_FACE_SET:
    vname = VAR_NAME_FSET_VAR;
    break;
  case EX_SIDE_SET:
    vname = VAR_NAME_SSET_VAR;
    break;
  case EX_ELEM_SET:
    vname = VAR_NAME_ELSET_VAR;
    break;
  default:
    exerrval = EX_BADPARAM;
    sprintf( errmsg, "Error: Invalid variable type (%d) given for file id %d", obj_type, exoid );
    ex_err( "ex_put_variable_name", errmsg, exerrval );
    return (EX_WARN);
  }

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

  /* write EXODUS variable name */
  status = ex_put_name_internal(exoid, varid, var_num-1, var_name, obj_type,
				"variable", "ex_put_variable_name");

  return(status);
}
Exemplo n.º 20
0
int ex_get_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, void_int *values)
{
  int   num_props, i, propid, status;
  int   found = EX_FALSE;
  char *name;
  char  tmpstr[MAX_STR_LENGTH + 1];

  char errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

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

  num_props = ex_get_num_props(exoid, obj_type);

  for (i = 1; i <= num_props; i++) {
    switch (obj_type) {
    case EX_ELEM_BLOCK: name = VAR_EB_PROP(i); break;
    case EX_EDGE_BLOCK: name = VAR_ED_PROP(i); break;
    case EX_FACE_BLOCK: name = VAR_FA_PROP(i); break;
    case EX_NODE_SET: name   = VAR_NS_PROP(i); break;
    case EX_EDGE_SET: name   = VAR_ES_PROP(i); break;
    case EX_FACE_SET: name   = VAR_FS_PROP(i); break;
    case EX_ELEM_SET: name   = VAR_ELS_PROP(i); break;
    case EX_SIDE_SET: name   = VAR_SS_PROP(i); break;
    case EX_ELEM_MAP: name   = VAR_EM_PROP(i); break;
    case EX_FACE_MAP: name   = VAR_FAM_PROP(i); break;
    case EX_EDGE_MAP: name   = VAR_EDM_PROP(i); break;
    case EX_NODE_MAP: name   = VAR_NM_PROP(i); break;
    default:
      exerrval = EX_BADPARAM;
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: object type %d not supported; file id %d", obj_type,
               exoid);
      ex_err("ex_get_prop_array", errmsg, exerrval);
      return (EX_FATAL);
    }

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

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

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

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

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

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

  return (EX_NOERR);
}
Exemplo n.º 21
0
int ex_put_sets (int   exoid,
		 size_t set_count,
		 const struct ex_set *sets)
{
  size_t i;
  int needs_define = 0;
  int set_stat;
  int dimid, varid, status, dims[1];
  int set_id_ndx;
  size_t start[1]; 
  int cur_num_sets;
  char errmsg[MAX_ERR_LENGTH];
  int* sets_to_define = NULL;
  char* numentryptr 	= NULL;
  char* entryptr = NULL;
  char* extraptr = NULL;
  char* idsptr = NULL;
  char* statptr = NULL;
  char* numdfptr = NULL;
  char* factptr = NULL;

  size_t int_size;
  
  exerrval = 0; /* clear error code */

  sets_to_define = malloc(set_count*sizeof(int));
  
  /* Note that this routine can be called:
     1) just define the sets
     2) just output the set data (after a previous call to define)
     3) define and output the set data in one call.
  */
  for (i=0; i < set_count; i++) {
    /* first check if any sets are specified */
    if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(sets[i].type), &dimid)) != NC_NOERR) {
      if (status == NC_EBADDIM) {
	exerrval = status;
	sprintf(errmsg,
		"Error: no %ss defined for file id %d", ex_name_of_object(sets[i].type), exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
      } else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate %ss defined in file id %d",
		ex_name_of_object(sets[i].type), exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
      }
      return (EX_FATAL);
    }

    set_id_ndx = ex_id_lkup(exoid, sets[i].type, sets[i].id);
    if (exerrval != EX_LOOKUPFAIL) {  /* found the side set id, so set is already defined... */
      sets_to_define[i] = 0;
      continue;
    } else {
      needs_define++;
      sets_to_define[i] = 1;
    }
  }
    
  if (needs_define > 0) {
    /* 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_sets",errmsg,exerrval);
      return (EX_FATAL);
    }
    
    for (i=0; i < set_count; i++) {
      if (sets_to_define[i] == 0)
	continue;
      
      /*   NOTE: ex_inc_file_item finds the current number of sets defined
	   for a specific file and returns that value incremented. */
      cur_num_sets=ex_inc_file_item(exoid, ex_get_counter_list(sets[i].type));
      set_id_ndx = cur_num_sets + 1;
      sets_to_define[i] = set_id_ndx;
      
      if (sets[i].num_entry == 0)
	continue;
      
      /* setup pointers based on set_type */
      if (sets[i].type == EX_NODE_SET) {
	numentryptr = DIM_NUM_NOD_NS(set_id_ndx);
	entryptr = VAR_NODE_NS(set_id_ndx);
	extraptr = NULL;
	/* note we are using DIM_NUM_NODE_NS instead of DIM_NUM_DF_NS */
	numdfptr = DIM_NUM_NOD_NS(set_id_ndx);
	factptr = VAR_FACT_NS(set_id_ndx);
      }
      else if (sets[i].type == EX_EDGE_SET) {
	numentryptr = DIM_NUM_EDGE_ES(set_id_ndx);
	entryptr = VAR_EDGE_ES(set_id_ndx);
	extraptr = VAR_ORNT_ES(set_id_ndx);
	numdfptr = DIM_NUM_DF_ES(set_id_ndx);
	factptr = VAR_FACT_ES(set_id_ndx);
      }
      else if (sets[i].type == EX_FACE_SET) {
	numentryptr = DIM_NUM_FACE_FS(set_id_ndx);
	entryptr = VAR_FACE_FS(set_id_ndx);
	extraptr = VAR_ORNT_FS(set_id_ndx);
	numdfptr = DIM_NUM_DF_FS(set_id_ndx);
	factptr = VAR_FACT_FS(set_id_ndx);
      }
      else if (sets[i].type == EX_SIDE_SET) {
	numentryptr = DIM_NUM_SIDE_SS(set_id_ndx);
	entryptr = VAR_ELEM_SS(set_id_ndx);
	extraptr = VAR_SIDE_SS(set_id_ndx);
	numdfptr = DIM_NUM_DF_SS(set_id_ndx);
	factptr = VAR_FACT_SS(set_id_ndx);
      }
      else if (sets[i].type == EX_ELEM_SET) {
	numentryptr = DIM_NUM_ELE_ELS(set_id_ndx);
	entryptr = VAR_ELEM_ELS(set_id_ndx);
	extraptr = NULL;
	numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
	factptr = VAR_FACT_ELS(set_id_ndx);
      }

      /* define dimensions and variables */
      if ((status = nc_def_dim(exoid, numentryptr,
			       sets[i].num_entry, &dimid)) != NC_NOERR) {
	exerrval = status;
	if (status == NC_ENAMEINUSE) {
	  sprintf(errmsg,
		  "Error: %s %"PRId64" -- size already defined in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	}
	else {
	  sprintf(errmsg,
		  "Error: failed to define number of entries in %s %"PRId64" in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	}
	goto error_ret;
      }
      
      int_size = sizeof(int);
      if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
	int_size = sizeof(int64_t);
      }
      
      /* create variable array in which to store the entry lists */
      dims[0] = dimid;
      if ((status = nc_def_var(exoid, entryptr, int_size, 1, dims, &varid)) != NC_NOERR) {
	exerrval = status;
	if (status == NC_ENAMEINUSE) {
	  sprintf(errmsg,
		  "Error: entry list already exists for %s %"PRId64" in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	} else {
	  sprintf(errmsg,
		  "Error: failed to create entry list for %s %"PRId64" in file id %d",
		  ex_name_of_object(sets[i].type), sets[i].id,exoid);
	  ex_err("ex_put_sets",errmsg,exerrval);
	}
	goto error_ret;            /* exit define mode and return */
      }
      ex_compress_variable(exoid, varid, 1);
      
      if (extraptr) {
	if ((status = nc_def_var(exoid, extraptr, int_size, 1, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  if (status == NC_ENAMEINUSE) {
	    sprintf(errmsg,
		    "Error: extra list already exists for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id, exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  } else {
	    sprintf(errmsg,
		    "Error: failed to create extra list for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  }
	  goto error_ret;         /* exit define mode and return */
	}
	ex_compress_variable(exoid, varid, 1);
      }

      /* Create distribution factors variable if required */
      if (sets[i].num_distribution_factor > 0) {
	if (sets[i].type != EX_SIDE_SET) {
	  /* but sets[i].num_distribution_factor must equal number of nodes */
	  if (sets[i].num_distribution_factor != sets[i].num_entry) {
	    exerrval = EX_FATAL;
	    sprintf(errmsg,
		    "Error: # dist fact (%"PRId64") not equal to # nodes (%"PRId64") in node  set %"PRId64" file id %d",
		    sets[i].num_distribution_factor, sets[i].num_entry, sets[i].id, exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	    goto error_ret;    /* exit define mode and return */
	  }
	} else {
	  /* resuse dimid from entry lists */
	  if ((status = nc_def_dim(exoid, numdfptr, 
				   sets[i].num_distribution_factor, &dimid)) != NC_NOERR) {
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to define number of dist factors in %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	    goto error_ret;          /* exit define mode and return */
	  }
	}
	
	/* create variable array in which to store the set distribution factors
	 */
	dims[0] = dimid;
	if ((status = nc_def_var(exoid, factptr, nc_flt_code(exoid), 1, dims, &varid)) != NC_NOERR) {
	  exerrval = status;
	  if (status == NC_ENAMEINUSE) {
	    sprintf(errmsg,
		    "Error: dist factors list already exists for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  } else {
	    sprintf(errmsg,
		    "Error: failed to create dist factors list for %s %"PRId64" in file id %d",
		    ex_name_of_object(sets[i].type), sets[i].id,exoid);
	    ex_err("ex_put_sets",errmsg,exerrval);
	  }
	  goto error_ret;            /* exit define mode and return */
	}
	ex_compress_variable(exoid, varid, 2);
      }
    }

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

    /* Output the set ids and status... */
    for (i=0; i < set_count; i++) {
    /* setup pointers based on sets[i].type */
      if (sets[i].type == EX_NODE_SET) {
	idsptr = VAR_NS_IDS;
	statptr = VAR_NS_STAT;
      }
      else if (sets[i].type == EX_EDGE_SET) {
	idsptr = VAR_ES_IDS;
	statptr = VAR_ES_STAT;
      }
      else if (sets[i].type == EX_FACE_SET) {
	idsptr = VAR_FS_IDS;
	statptr = VAR_FS_STAT;
      }
      else if (sets[i].type == EX_SIDE_SET) {
	idsptr = VAR_SS_IDS;
	statptr = VAR_SS_STAT;
      }
      else if (sets[i].type == EX_ELEM_SET) {
	idsptr = VAR_ELS_IDS;
	statptr = VAR_ELS_STAT;
      }
      
      /* first: get id of set id variable */
      if ((status = nc_inq_varid(exoid, idsptr, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate %s %"PRId64" in file id %d", ex_name_of_object(sets[i].type),
		sets[i].id, exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
      
      /* write out set id */
      start[0] = sets_to_define[i]-1;
      status = nc_put_var1_longlong(exoid, varid, start, (long long*)&sets[i].id);
    
      if (status != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store %s id %"PRId64" in file id %d", ex_name_of_object(sets[i].type),
		sets[i].id, exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
      
      set_stat = (sets[i].num_entry == 0) ? 0 : 1;
      
      if ((status = nc_inq_varid(exoid, statptr, &varid)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to locate %s status in file id %d", ex_name_of_object(sets[i].type),
		exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
      
      if ((status = nc_put_var1_int(exoid, varid, start, &set_stat)) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to store %s %"PRId64" status to file id %d", ex_name_of_object(sets[i].type),
		sets[i].id, exoid);
	ex_err("ex_put_sets",errmsg,exerrval);
	return (EX_FATAL);
      }
    }
    free(sets_to_define);
  }
  
  /* Sets are now all defined; see if any set data needs to be output... */
  status = EX_NOERR;
  for (i=0; i < set_count; i++) {
    int stat;
    if (sets[i].entry_list != NULL || sets[i].extra_list != NULL) {
      /* NOTE: ex_put_set will write the warning/error message... */
      stat = ex_put_set(exoid, sets[i].type, sets[i].id, sets[i].entry_list, sets[i].extra_list);
      if (stat != EX_NOERR) status = EX_FATAL;
    }
    if (sets[i].distribution_factor_list != NULL) {
      /* NOTE: ex_put_set_dist_fact will write the warning/error message... */
      stat = ex_put_set_dist_fact(exoid, sets[i].type, sets[i].id, sets[i].distribution_factor_list);
      if (stat != EX_NOERR) status = EX_FATAL;
    }
  }  
  return (status);

  /* Fatal error: exit definition mode and return */
 error_ret:
  free(sets_to_define);
  
  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_sets",errmsg,exerrval);
  }
  return (EX_FATAL);
}
Exemplo n.º 22
0
int ex_get_block_param( int exoid,
			ex_block *block )
{
  int dimid, connid, blk_id_ndx;
  size_t len, i;
  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;

  struct ex_file_item* file = ex_find_file_item(exoid);
  if (!file ) {
    char errmsg[MAX_ERR_LENGTH];
    exerrval = EX_BADFILEID;
    sprintf(errmsg,"Error: unknown file id %d in ex_get_block_param().",exoid);
    ex_err("ex_get_block_param",errmsg,exerrval);
  }
  
  exerrval = 0;

  /* First, locate index of element block id in VAR_ID_EL_BLK array */
  blk_id_ndx = ex_id_lkup(exoid,block->type,block->id);
  if (exerrval != 0)  {
    strcpy(block->topology, "NULL");     	/* NULL element type name */
    block->num_entry = 0;  /* no elements            */
    block->num_nodes_per_entry = 0;   /* no nodes               */
    block->num_edges_per_entry = 0;
    block->num_faces_per_entry = 0;
    block->num_attribute = 0;    /* no attributes          */
    if (exerrval == EX_NULLENTITY) {    /* NULL element block?    */
      return (EX_NOERR);
    } 
      sprintf(errmsg,
	      "Error: failed to locate %s id  %"PRId64" in id array in file id %d",
	      ex_name_of_object(block->type), block->id,exoid);
      ex_err("ex_get_block_param",errmsg,exerrval);
      return (EX_FATAL);
    
  }

  switch (block->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.",
	     block->type, exoid );
    return (EX_FATAL);
  }

  /* inquire values of some dimensions */
  if ((status = nc_inq_dimid (exoid, dnument, &dimid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate number of entities in %s  %"PRId64" in file id %d",
	    ex_name_of_object(block->type),block->id,exoid);
    ex_err("ex_get_block_param",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  %"PRId64" in file id %d",
	    ex_name_of_object(block->type),block->id, exoid);
    ex_err("ex_get_block_param",errmsg, exerrval);
    return(EX_FATAL);
  }
  block->num_entry = len;

  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  %"PRId64" in file id %d",
	      ex_name_of_object(block->type),block->id, exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
  }
  block->num_nodes_per_entry = len;

  if (!file->has_edges || block->type != EX_ELEM_BLOCK) {
    block->num_edges_per_entry = 0;
  } 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  %"PRId64" in file id %d",
		ex_name_of_object(block->type),block->id, exoid);
	ex_err("ex_get_block_param",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
    block->num_edges_per_entry = len;
  }

  if (!file->has_faces || block->type != EX_ELEM_BLOCK ) {
    block->num_faces_per_entry = 0;
  } 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  %"PRId64" in file id %d",
		ex_name_of_object(block->type),block->id, exoid);
	ex_err("ex_get_block_param",errmsg, exerrval);
	return(EX_FATAL);
      }
    }
    block->num_faces_per_entry = len;
  }

  if ((status = nc_inq_dimid (exoid, dnumatt, &dimid)) != NC_NOERR) {
    /* dimension is undefined */
    block->num_attribute = 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  %"PRId64" in file id %d",
	      ex_name_of_object(block->type),block->id, exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    block->num_attribute = len;
  }

  if (block->num_nodes_per_entry > 0) {
    ; /* Do nothing, vblkcon should be correctly set already */
  } else if (block->num_edges_per_entry > 0) {
    vblkcon = VAR_EBCONN(blk_id_ndx);
  } else if (block->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  %"PRId64" in file id %d",
	      ex_name_of_object(block->type), block->id,exoid);
      ex_err("ex_get_block_param",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  %"PRId64" type in file id %d",
	      ex_name_of_object(block->type), block->id,exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    
    if (len > (MAX_STR_LENGTH+1)) {
      len = MAX_STR_LENGTH;
      sprintf (errmsg,
	       "Warning: %s  %"PRId64" type will be truncated to %ld chars", 
	       ex_name_of_object(block->type), block->id, (long)len);
      ex_err("ex_get_block_param",errmsg,EX_MSG);
    }
    
    for (i=0; i < MAX_STR_LENGTH+1; i++) {
      block->topology[i] = '\0';

    /* get the element type name */
    
}if ((status = nc_get_att_text (exoid, connid, ablknam, block->topology)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,"Error: failed to get %s  %"PRId64" type in file id %d",
	      ex_name_of_object(block->type), block->id, exoid);
      ex_err("ex_get_block_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    
    /* get rid of trailing blanks */
    ex_trim_internal(block->topology);
  }
  return (EX_NOERR);
}
Exemplo n.º 23
0
int ex_get_partial_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int64_t start_num,
                        int64_t num_ent, void *attrib)

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

  ex_check_valid_file_id(exoid);

  exerrval = 0; /* clear error code */

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

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

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

  if (start_num + num_ent - 1 > num_entries_this_obj) {
    exerrval = EX_BADPARAM;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: start index (%" PRId64 ") + count (%" PRId64
             ") is larger than total number of entities (%" ST_ZU ") in file id %d",
             start_num, num_ent, num_entries_this_obj, exoid);
    ex_err("ex_get_partial_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

  if (ex_get_dimension(exoid, dnumobjatt, "attributes", &num_attr, &temp, "ex_get_partial_attr") !=
      NC_NOERR) {
    return EX_FATAL;
  }

  if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate attributes for %s %" PRId64 " in file id %d",
             ex_name_of_object(obj_type), obj_id, exoid);
    ex_err("ex_get_partial_attr", errmsg, exerrval);
    return (EX_FATAL);
  }

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

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

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

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get attributes for %s %" PRId64 " in file id %d",
             ex_name_of_object(obj_type), obj_id, exoid);
    ex_err("ex_get_partial_attr", errmsg, exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Exemplo n.º 24
0
int ex_put_set (int   exoid,
		ex_entity_type set_type,
		ex_entity_id   set_id,
		const void_int  *set_entry_list,
		const void_int  *set_extra_list)
{
  int dimid, status;
  int entry_list_id, extra_list_id, 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;
    sprintf(errmsg,
            "Error: no %ss defined in file id %d",
	    ex_name_of_object(set_type), exoid);
    ex_err("ex_put_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* 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: no data allowed for NULL %s %"PRId64" in file id %d",
	      ex_name_of_object(set_type),set_id,exoid);
      ex_err("ex_put_set",errmsg,EX_NULLENTITY);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "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_put_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);
  }
  else if (set_type == EX_ELEM_SET) {
    entryptr = VAR_ELEM_ELS(set_id_ndx);
    extraptr = NULL;
  }

  /* inquire id's of previously defined variables  */
  if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "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_put_set",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* only do for edge, face and side sets */
  if (extraptr) {
    if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "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_put_set",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* write out the entry list and extra list arrays */
  if (set_entry_list != NULL) {

    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_put_var_longlong(exoid, entry_list_id, set_entry_list);
    } else {
      status = nc_put_var_int(exoid, entry_list_id, set_entry_list);
    }
    
    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store entry list for %s %"PRId64" in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set",errmsg,exerrval);
      return (EX_FATAL);
    }
  }


  /* only do for edge, face and side sets */
  if (extraptr && set_extra_list != NULL ) {
    
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_put_var_longlong(exoid, extra_list_id, set_extra_list);
    } else {
      status = nc_put_var_int(exoid, extra_list_id, set_extra_list);
    }    

    if (status != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to store extra list for %s %"PRId64" in file id %d",
	      ex_name_of_object(set_type), set_id,exoid);
      ex_err("ex_put_set",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* warn if extra data was sent in for node sets and elem sets */
  if ((set_type == EX_NODE_SET || set_type == EX_ELEM_SET) &&
      set_extra_list != NULL) {
    sprintf(errmsg,
	    "Warning: extra list was ignored for %s %"PRId64" in file id %d",
	    ex_name_of_object(set_type), set_id, exoid);
    ex_err("ex_put_set",errmsg,EX_MSG);
    return(EX_WARN); 
  }

  return (EX_NOERR);

}
int ex_get_attr_param (int   exoid,
		       ex_entity_type obj_type,
		       ex_entity_id   obj_id,
		       int*  num_attrs)
{
  int status;
  int dimid;
  
  char errmsg[MAX_ERR_LENGTH];
  const char *dnumobjatt;

  int obj_id_ndx;
  size_t lnum_attr_per_entry;
  
  /* Determine index of obj_id in vobjids array */
  if (obj_type == EX_NODAL) {
    obj_id_ndx = 0;
  } else {
    obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id);
    
    if (exerrval != 0) {
      if (exerrval == EX_NULLENTITY) {
	*num_attrs = 0;
	return (EX_NOERR);
      } 
	sprintf(errmsg,
		"Warning: failed to locate %s id %"PRId64" in id array in file id %d",
		ex_name_of_object(obj_type),obj_id,exoid);
	ex_err("ex_get_attr_param",errmsg,exerrval);
	return (EX_WARN);
      
    }
  }

  switch (obj_type) {
  case EX_SIDE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx);
    break;
  case EX_NODE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx);
    break;
  case EX_EDGE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx);
    break;
  case EX_FACE_SET:
    dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx);
    break;
  case EX_ELEM_SET:
    dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx);
    break;
  case EX_NODAL:
    dnumobjatt = DIM_NUM_ATT_IN_NBLK;
    break;
  case EX_EDGE_BLOCK:
    dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx);
    break;
  case EX_FACE_BLOCK:
    dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx);
    break;
  case EX_ELEM_BLOCK:
    dnumobjatt = DIM_NUM_ATT_IN_BLK(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_get_attr_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  exerrval = 0; /* clear error code */

  if ((status = nc_inq_dimid(exoid, dnumobjatt, &dimid)) != NC_NOERR) {
    /* dimension is undefined */
    *num_attrs = 0;
  } else {
    if ((status = nc_inq_dimlen(exoid, dimid, &lnum_attr_per_entry)) != NC_NOERR) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to get number of attributes in %s %"PRId64" in file id %d",
	      ex_name_of_object(obj_type),obj_id, exoid);
      ex_err("ex_get_attr_param",errmsg, exerrval);
      return(EX_FATAL);
    }
    *num_attrs = lnum_attr_per_entry;
  }
  return (EX_NOERR);
}
Exemplo n.º 26
0
int ex_put_num_map ( int exoid,
                     ex_entity_type map_type,
                     int map_id,
                     const int *map )
{
   int dimid, varid;
   size_t start[1]; 
   int ldum;
   int num_maps;
   size_t num_entries;
   int cur_num_maps;
   char errmsg[MAX_ERR_LENGTH];
   const char* dnumentries;
   const char* dnummaps;
   const char* vmapids;
   const char* vmap;
   int status;
   
   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_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)   /* found the map id */
   {
     sprintf(errmsg,
            "Error: %s %d already defined in file id %d",
             ex_name_of_object(map_type),map_id,exoid);
     ex_err("ex_put_num_map",errmsg,exerrval);
     return(EX_FATAL);
   }

   /* Get number of maps initialized for this file */
   if ((status = nc_inq_dimlen(exoid,dimid,&num_entries)) != 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_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }
   num_maps = num_entries;

   /* Keep track of the total number of maps defined using a counter stored
      in a linked list keyed by exoid.
      NOTE: ex_get_file_item  is used to find the number of maps
      for a specific file and returns that value.
   */
   cur_num_maps = ex_get_file_item(exoid, ex_get_counter_list(map_type));
   if (cur_num_maps >= num_maps) {
     exerrval = EX_FATAL;
     sprintf(errmsg,
          "Error: exceeded number of %ss (%d) 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 maps
	for a specific file and returns that value incremented. */
   cur_num_maps = ex_inc_file_item(exoid, ex_get_counter_list(map_type));

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

   ldum = (int)map_id;
   if ((status = nc_put_var1_int(exoid, varid, start, &ldum)) != NC_NOERR)
   {
     exerrval = status;
     sprintf(errmsg,
            "Error: failed to store %s id %d in file id %d",
             ex_name_of_object(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)
     {
       int dims[2];

       /* determine number of entries */
       if ((status = nc_inq_dimid (exoid, dnumentries, &dimid)) == -1 )
	 {
	   exerrval = status;
	   sprintf(errmsg,
		   "Error: couldn't determine number of %s entries in file id %d",
		   ex_name_of_object(map_type),exoid);
	   ex_err("ex_put_num_map",errmsg,exerrval);
	   return (EX_FATAL);
	 }
       
       status = 0;
       
       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_num_map",errmsg,exerrval);
         return (EX_FATAL);
       }

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

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

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

   /* write out the map  */
   if ((status = nc_put_var_int(exoid, varid, map)) != 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_num_map",errmsg,exerrval);
     return (EX_FATAL);
   }

   return (EX_NOERR);
}
Exemplo n.º 27
0
int ex_get_attr( int   exoid,
                 ex_entity_type obj_type,
                 ex_entity_id   obj_id,
                 void* attrib )

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

  exerrval = 0; /* clear error code */

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

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

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


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

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
            "Error: failed to get attributes for %s %"PRId64" in file id %d",
            ex_name_of_object(obj_type),obj_id,exoid);
    ex_err("ex_get_attr",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}
Exemplo n.º 28
0
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;
  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;
    snprintf(errmsg, MAX_ERR_LENGTH, "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;
    snprintf(errmsg, MAX_ERR_LENGTH, "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: name = VAR_EB_PROP(i + 2); break;
    case EX_FACE_BLOCK: name = VAR_FA_PROP(i + 2); break;
    case EX_EDGE_BLOCK: name = VAR_ED_PROP(i + 2); break;
    case EX_NODE_SET: name   = VAR_NS_PROP(i + 2); break;
    case EX_SIDE_SET: name   = VAR_SS_PROP(i + 2); break;
    case EX_EDGE_SET: name   = VAR_ES_PROP(i + 2); break;
    case EX_FACE_SET: name   = VAR_FS_PROP(i + 2); break;
    case EX_ELEM_SET: name   = VAR_ELS_PROP(i + 2); break;
    case EX_ELEM_MAP: name   = VAR_EM_PROP(i + 2); break;
    case EX_FACE_MAP: name   = VAR_FAM_PROP(i + 2); break;
    case EX_EDGE_MAP: name   = VAR_EDM_PROP(i + 2); break;
    case EX_NODE_MAP: name   = VAR_NM_PROP(i + 2); break;
    default:
      exerrval = EX_BADPARAM;
      snprintf(errmsg, MAX_ERR_LENGTH, "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;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "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;
      snprintf(errmsg, MAX_ERR_LENGTH,
               "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;
      snprintf(errmsg, MAX_ERR_LENGTH, "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;
    snprintf(errmsg, MAX_ERR_LENGTH, "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 */
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid);
    ex_err("ex_put_prop_names", errmsg, exerrval);
  }
  return (EX_FATAL);
}
Exemplo n.º 29
0
int ex_get_conn( int   exoid,
                 ex_entity_type blk_type,
                 int   blk_id,
                 int*  nodeconn,
                 int*  edgeconn,
                 int*  faceconn )
{
    int connid, econnid, fconnid, blk_id_ndx, status;
    int numnodperentdim, numedgperentdim, numfacperentdim;
    int iexit = (EX_NOERR); /* exit status */
    size_t num_nodes_per_entry, num_edges_per_entry, num_faces_per_entry;
    char errmsg[MAX_ERR_LENGTH];

    const char* dnumblkent;
    const char* dnumnodent;
    const char* dnumedgent;
    const char* dnumfacent;
    const char* vnodeconn;
    const char* vedgeconn;
    const char* vfaceconn;

    /* Should we warn if edgeconn or faceconn are non-NULL?
     * No, fail silently so the same code can be used to read any type of block info.
     * However, we will warn if edgeconn or faceconn are NULL but num_edges_per_entry
     * or num_faces_per_entry (respectively) are positive.
     */
    exerrval = 0; /* clear error code */

    /* 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)
        {
            sprintf(errmsg,
                    "Warning: no connectivity array for NULL %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg,EX_MSG);
            return (EX_WARN); /* no connectivity array for this element block */
        }
        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_conn",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    switch (blk_type) {
    case EX_EDGE_BLOCK:
        dnumblkent = DIM_NUM_ED_IN_EBLK(blk_id_ndx);
        dnumnodent = DIM_NUM_NOD_PER_ED(blk_id_ndx);
        dnumedgent = 0;
        dnumfacent = 0;
        vnodeconn = VAR_EBCONN(blk_id_ndx);
        vedgeconn = 0;
        vfaceconn = 0;
        break;
    case EX_FACE_BLOCK:
        dnumblkent = DIM_NUM_FA_IN_FBLK(blk_id_ndx);
        dnumnodent = DIM_NUM_NOD_PER_FA(blk_id_ndx);
        dnumedgent = 0;
        dnumfacent = 0;
        vnodeconn = VAR_FBCONN(blk_id_ndx);
        vedgeconn = 0;
        vfaceconn = 0;
        break;
    case EX_ELEM_BLOCK:
        dnumblkent = DIM_NUM_EL_IN_BLK(blk_id_ndx);
        dnumnodent = DIM_NUM_NOD_PER_EL(blk_id_ndx);
        dnumedgent = DIM_NUM_EDG_PER_EL(blk_id_ndx);
        dnumfacent = DIM_NUM_FAC_PER_EL(blk_id_ndx);
        vnodeconn = VAR_CONN(blk_id_ndx);
        vedgeconn = VAR_ECONN(blk_id_ndx);
        vfaceconn = VAR_FCONN(blk_id_ndx);
        break;
    default:
        sprintf(errmsg,
                "Error: Called with invalid blk_type %d", blk_type );
        ex_err("ex_get_conn",errmsg,exerrval);
        return (EX_FATAL);
        break;
    }
    /* inquire id's of previously defined dimensions  */

    if ((status = nc_inq_dimid (exoid, dnumnodent, &numnodperentdim)) != NC_NOERR)
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to locate number of nodes/entity for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg,exerrval);
        return(EX_FATAL);
    }

    if (nc_inq_dimlen(exoid, numnodperentdim, &num_nodes_per_entry) != NC_NOERR)
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to get number of nodes/entity for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg, exerrval);
        return(EX_FATAL);
    }

    if ( dnumedgent ) {
        num_edges_per_entry = 0;
        if ((status = nc_inq_dimid(exoid, dnumedgent, &numedgperentdim)) != NC_NOERR) {
            numedgperentdim = -1;
        } else {
            if ((status = nc_inq_dimlen(exoid, numedgperentdim, &num_edges_per_entry)) != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to get number of edges/entry for %s %d in file id %d",
                        ex_name_of_object(blk_type),blk_id,exoid);
                ex_err("ex_get_conn",errmsg, exerrval);
                return(EX_FATAL);
            }
        }
    }

    if ( dnumfacent ) {
        num_faces_per_entry = 0;
        if ((status = nc_inq_dimid(exoid, dnumfacent, &numfacperentdim)) != NC_NOERR) {
            numfacperentdim = -1;
        } else {
            if ((status = nc_inq_dimlen(exoid, numfacperentdim, &num_faces_per_entry)) != NC_NOERR) {
                exerrval = status;
                sprintf(errmsg,
                        "Error: failed to get number of faces/entry for %s %d in file id %d",
                        ex_name_of_object(blk_type),blk_id,exoid);
                ex_err("ex_get_conn",errmsg, exerrval);
                return(EX_FATAL);
            }
        }
    }


    if ((status = nc_inq_varid(exoid, vnodeconn, &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_conn",errmsg, exerrval);
        return(EX_FATAL);
    }

    status = 0;
    if (edgeconn && (numedgperentdim > 0) &&
            ((status = nc_inq_varid (exoid, vedgeconn, &econnid)) != NC_NOERR))
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to locate edge connectivity array for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg, exerrval);
        return(EX_FATAL);
    }

    if (faceconn && (numfacperentdim > 0) &&
            ((status = nc_inq_varid (exoid, vfaceconn, &fconnid)) != NC_NOERR))
    {
        exerrval = status;
        sprintf(errmsg,
                "Error: failed to locate face connectivity array for %s %d in file id %d",
                ex_name_of_object(blk_type),blk_id,exoid);
        ex_err("ex_get_conn",errmsg, exerrval);
        return(EX_FATAL);
    }


    /* read in the connectivity array */
    if ( edgeconn && num_edges_per_entry > 0) {
        status = nc_get_var_int(exoid, econnid, edgeconn);

        if (status != NC_NOERR)
        {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to get edge connectivity array for %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg, exerrval);
            return(EX_FATAL);
        }
    }

    if ( faceconn && num_faces_per_entry > 0) {
        status = nc_get_var_int(exoid, fconnid, faceconn);

        if (status != NC_NOERR)
        {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to get face connectivity array for %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg, exerrval);
            return(EX_FATAL);
        }
    }

    if ( nodeconn && num_nodes_per_entry > 0) {
        status = nc_get_var_int(exoid, connid, nodeconn);

        if (status != NC_NOERR)
        {
            exerrval = status;
            sprintf(errmsg,
                    "Error: failed to get connectivity array for %s %d in file id %d",
                    ex_name_of_object(blk_type),blk_id,exoid);
            ex_err("ex_get_conn",errmsg, exerrval);
            return(EX_FATAL);
        }
    }

    return iexit;
}
Exemplo n.º 30
0
int ex_put_partial_var(int exoid, int time_step, ex_entity_type var_type, int var_index,
                       ex_entity_id obj_id, int64_t start_index, int64_t num_entities,
                       const void *var_vals)
{
  int    varid, dimid, time_dim, numobjdim, dims[2], obj_id_ndx;
  size_t num_obj;
  size_t num_obj_var;
  size_t num_entity;
  size_t start[2], count[2];
  int *  obj_var_truth_tab;
  int    status;
  char   errmsg[MAX_ERR_LENGTH];

  exerrval = 0; /* clear error code */

#define EX_LOOK_UP_VAR(VOBJID, VVAR, VOBJTAB, DNUMOBJ, DNUMOBJVAR)                                 \
  /* 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) {                                                               \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "Warning: no variables allowed for NULL block %" PRId64 " in file id %d", obj_id,   \
               exoid);                                                                             \
      ex_err("ex_put_partial_var", errmsg, EX_NULLENTITY);                                         \
      return (EX_WARN);                                                                            \
    }                                                                                              \
    else {                                                                                         \
      snprintf(errmsg, MAX_ERR_LENGTH,                                                             \
               "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_partial_var", errmsg, exerrval);                                              \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
  }                                                                                                \
                                                                                                   \
  if ((status = nc_inq_varid(exoid, VVAR(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_partial_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_partial_var");                                   \
        if (status != NC_NOERR)                                                                    \
          return status;                                                                           \
                                                                                                   \
        if (!(obj_var_truth_tab = malloc(num_obj * num_obj_var * sizeof(int)))) {                  \
          exerrval = EX_MEMFAIL;                                                                   \
          snprintf(errmsg, MAX_ERR_LENGTH, "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_partial_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;                                                                       \
          snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get truth table from file id %d",     \
                   exoid);                                                                         \
          ex_err("ex_put_partial_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;                                                                  \
          snprintf(errmsg, MAX_ERR_LENGTH,                                                         \
                   "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_partial_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;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate time dimension in file id %d",   \
                 exoid);                                                                           \
        ex_err("ex_put_partial_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_partial_var");                                                      \
                                                                                                   \
      /*    variable doesn't exist so put file into define mode  */                                \
      if ((status = nc_redef(exoid)) != NC_NOERR) {                                                \
        exerrval = status;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode",       \
                 exoid);                                                                           \
        ex_err("ex_put_partial_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, VVAR(var_index, obj_id_ndx), nc_flt_code(exoid), 2, dims,    \
                               &varid)) != NC_NOERR) {                                             \
        exerrval = status;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define %s variable %d in file id %d",   \
                 ex_name_of_object(var_type), var_index, exoid);                                   \
        ex_err("ex_put_partial_var", errmsg, exerrval);                                            \
        goto error_ret;                                                                            \
      }                                                                                            \
      ex_compress_variable(exoid, varid, 2);                                                       \
                                                                                                   \
      /*    leave define mode  */                                                                  \
                                                                                                   \
      if ((status = nc_enddef(exoid)) != NC_NOERR) {                                               \
        exerrval = status;                                                                         \
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete %s variable %s definition "    \
                                         "to file id %d",                                          \
                 ex_name_of_object(var_type), VVAR(var_index, obj_id_ndx), exoid);                 \
        ex_err("ex_put_partial_var", errmsg, exerrval);                                            \
        return (EX_FATAL);                                                                         \
      }                                                                                            \
    }                                                                                              \
    else {                                                                                         \
      exerrval = status;                                                                           \
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s variable %s in file id %d",     \
               ex_name_of_object(var_type), VVAR(var_index, obj_id_ndx), exoid);                   \
      ex_err("ex_put_partial_var", errmsg, exerrval);                                              \
      return (EX_FATAL);                                                                           \
    }                                                                                              \
  }

  switch (var_type) {
  case EX_GLOBAL:
    if (num_entities <= 0) {
      exerrval = EX_MSG;
      snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no global variables specified for file id %d",
               exoid);
      ex_err("ex_put_partial_var", errmsg, exerrval);

      return (EX_WARN);
    }
    /* inquire previously defined variable */

    if ((status = nc_inq_varid(exoid, VAR_GLO_VAR, &varid)) != NC_NOERR) {
      if (status == NC_ENOTVAR) {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no global variables defined in file id %d", exoid);
        ex_err("ex_put_partial_var", errmsg, exerrval);
      }
      else {
        exerrval = status;
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "ERROR: failed to get global variables parameters in file id %d", exoid);
        ex_err("ex_put_partial_var", errmsg, exerrval);
      }
      return (EX_FATAL);
    }
    break;
  case EX_NODAL:
    return ex_put_partial_nodal_var_int(exoid, time_step, var_index, start_index, num_entities,
                                        var_vals);
    break;
  case EX_EDGE_BLOCK:
    EX_LOOK_UP_VAR(VAR_ID_ED_BLK, VAR_EDGE_VAR, VAR_EBLK_TAB, DIM_NUM_ED_BLK, DIM_NUM_EDG_VAR);
    break;
  case EX_FACE_BLOCK:
    EX_LOOK_UP_VAR(VAR_ID_FA_BLK, VAR_FACE_VAR, VAR_FBLK_TAB, DIM_NUM_FA_BLK, DIM_NUM_FAC_VAR);
    break;
  case EX_ELEM_BLOCK:
    EX_LOOK_UP_VAR(VAR_ID_EL_BLK, VAR_ELEM_VAR, VAR_ELEM_TAB, DIM_NUM_EL_BLK, DIM_NUM_ELE_VAR);
    break;
  case EX_NODE_SET:
    EX_LOOK_UP_VAR(VAR_NS_IDS, VAR_NS_VAR, VAR_NSET_TAB, DIM_NUM_NS, DIM_NUM_NSET_VAR);
    break;
  case EX_EDGE_SET:
    EX_LOOK_UP_VAR(VAR_ES_IDS, VAR_ES_VAR, VAR_ESET_TAB, DIM_NUM_ES, DIM_NUM_ESET_VAR);
    break;
  case EX_FACE_SET:
    EX_LOOK_UP_VAR(VAR_FS_IDS, VAR_FS_VAR, VAR_FSET_TAB, DIM_NUM_FS, DIM_NUM_FSET_VAR);
    break;
  case EX_SIDE_SET:
    EX_LOOK_UP_VAR(VAR_SS_IDS, VAR_SS_VAR, VAR_SSET_TAB, DIM_NUM_SS, DIM_NUM_SSET_VAR);
    break;
  case EX_ELEM_SET:
    EX_LOOK_UP_VAR(VAR_ELS_IDS, VAR_ELS_VAR, VAR_ELSET_TAB, DIM_NUM_ELS, DIM_NUM_ELSET_VAR);
    break;
  default:
    exerrval = EX_MSG;
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: invalid variable type (%d) specified for file id %d",
             var_type, exoid);
    ex_err("ex_put_partial_var", errmsg, exerrval);
    return (EX_FATAL);
  }
  /* store element variable values */

  start[0] = --time_step;
  start[1] = start_index - 1;
  if (var_type == EX_GLOBAL) {
    /* global variables may be written
     * - all at once (by setting var_index to 1 and num_entries_this_obj to
     * num_glob, or
     * - one at a time (by setting var_index to the desired index and
     * num_entries_this_obj to 1.
     */
    count[0] = var_index;
  }
  else {
    count[0] = 1;
  }
  count[1] = num_entities;
  if (count[1] == 0) {
    start[1] = 0;
  }

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

  if (status != NC_NOERR) {
    exerrval = status;
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to store %s %" PRId64 " variable %d in file id %d",
             ex_name_of_object(var_type), obj_id, var_index, exoid);
    ex_err("ex_put_partial_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 */
  {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", exoid);
    ex_err("ex_put_partial_var", errmsg, exerrval);
  }
  return (EX_FATAL);
}