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);
  }
}
Ejemplo n.º 2
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);

}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
int ex_get_concat_sets (int   exoid,
                        ex_entity_type set_type,
                        struct ex_set_specs* set_specs)
{
  int status, dimid;
  void_int  *num_entries_per_set = set_specs->num_entries_per_set;
  void_int  *num_dist_per_set = set_specs->num_dist_per_set;
  void_int  *sets_entry_index = set_specs->sets_entry_index;
  void_int  *sets_dist_index = set_specs->sets_dist_index;

  void *sets_dist_fact = set_specs->sets_dist_fact; 

  int num_sets, i;
  float  *flt_dist_fact;
  double *dbl_dist_fact;
  char errmsg[MAX_ERR_LENGTH];
  ex_inquiry ex_inq_val;

  exerrval = 0; /* clear error code */

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

  if (set_type == EX_NODE_SET) {
    ex_inq_val = EX_INQ_NODE_SETS;
  }
  else if (set_type == EX_EDGE_SET) {
    ex_inq_val = EX_INQ_EDGE_SETS;
  }
  else if (set_type == EX_FACE_SET) {
    ex_inq_val = EX_INQ_FACE_SETS;
  }
  else if (set_type == EX_SIDE_SET) {
    ex_inq_val = EX_INQ_SIDE_SETS;
  }
  else if (set_type == EX_ELEM_SET) {
    ex_inq_val = EX_INQ_ELEM_SETS;
  }
  else {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: invalid set type (%d)", set_type);
    ex_err("ex_put_set_param",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* first check if any sets are specified */

  if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
    exerrval = status;
    if (status == NC_EBADDIM) {
      sprintf(errmsg,
	      "Warning: no %ss defined for file id %d",
	      ex_name_of_object(set_type), exoid);
      ex_err("ex_get_concat_sets",errmsg,exerrval);
      return (EX_WARN);
    } else {
      sprintf(errmsg,
	      "Error: failed to locate %ss defined in file id %d", 
	      ex_name_of_object(set_type), exoid);
      ex_err("ex_get_concat_sets",errmsg,exerrval);
      return (EX_FATAL);
    }
  }

  /* inquire how many sets have been stored */

  num_sets = ex_inquire_int(exoid, ex_inq_val);
  if (num_sets < 0) {
    sprintf(errmsg,
            "Error: failed to get number of %ss defined for file id %d",
	    ex_name_of_object(set_type), exoid);
    /* use error val from inquire */
    ex_err("ex_get_concat_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_get_ids (exoid, set_type, set_specs->sets_ids) != NC_NOERR) {
    sprintf(errmsg,
            "Error: failed to get %s ids for file id %d",
	    ex_name_of_object(set_type), exoid);
    /* use error val from inquire */
    ex_err("ex_get_concat_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    ((int64_t*)sets_entry_index)[0] = 0;
    ((int64_t*)sets_dist_index)[0] = 0;
  } else {
    ((int*)sets_entry_index)[0] = 0;
    ((int*)sets_dist_index)[0] = 0;
  }

  for (i=0; i<num_sets; i++) {
    int set_id;
    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      set_id = ((int64_t*)set_specs->sets_ids)[i];
    } else {
      set_id = ((int*)set_specs->sets_ids)[i];
    }

    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      if (ex_get_set_param(exoid, set_type, set_id, 
			   &(((int64_t*)num_entries_per_set)[i]),
			   &(((int64_t*)num_dist_per_set)[i])) != NC_NOERR)
	return(EX_FATAL); /* error will be reported by sub */
      
      if (i < num_sets-1) {
	/* fill in entry and dist factor index arrays */
	((int64_t*)sets_entry_index)[i+1] = ((int64_t*)sets_entry_index)[i]+((int64_t*)num_entries_per_set)[i];
	((int64_t*)sets_dist_index)[i+1] = ((int64_t*)sets_dist_index)[i]+((int64_t*)num_dist_per_set)[i];
      }

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

      {
	/* Now, use ExodusII call to get sets */
	int64_t *sets_entry_list = set_specs->sets_entry_list;
	int64_t *sets_extra_list = set_specs->sets_extra_list;
	int64_t *sets_extra = sets_extra_list ? &((int64_t*)sets_extra_list)[((int64_t*)sets_entry_index)[i]] : NULL;
	status = ex_get_set(exoid, set_type, set_id,
			    &(sets_entry_list[((int64_t*)sets_entry_index)[i]]),
			    sets_extra);
      }
    } else {
      if (ex_get_set_param(exoid, set_type, set_id, 
			   &(((int*)num_entries_per_set)[i]),
			   &(((int*)num_dist_per_set)[i])) != NC_NOERR)
	return(EX_FATAL); /* error will be reported by sub */
      
      if (i < num_sets-1) {
	/* fill in entry and dist factor index arrays */
	((int*)sets_entry_index)[i+1] = ((int*)sets_entry_index)[i]+((int*)num_entries_per_set)[i];
	((int*)sets_dist_index)[i+1] = ((int*)sets_dist_index)[i]+((int*)num_dist_per_set)[i];
      }

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

      {
	/* Now, use ExodusII call to get sets */
	int *sets_entry_list = set_specs->sets_entry_list;
	int *sets_extra_list = set_specs->sets_extra_list;
	int *sets_extra = sets_extra_list ? &((int*)sets_extra_list)[((int*)sets_entry_index)[i]] : NULL;
	status = ex_get_set(exoid, set_type, set_id,
			    &(sets_entry_list[((int*)sets_entry_index)[i]]),
			    sets_extra);
      }
    }

    if (status != NC_NOERR)
      return(EX_FATAL); /* error will be reported by subroutine */
    
    /* get distribution factors for this set */
    if (sets_dist_fact != 0) {
      size_t df_idx;
      size_t num_dist;
      if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
	df_idx = ((int64_t*)sets_dist_index)[i];
	num_dist = ((int64_t*)num_dist_per_set)[i];
      } else {
	df_idx = ((int*)sets_dist_index)[i];
	num_dist = ((int*)num_dist_per_set)[i];
      }
      if (num_dist > 0) {      /* only get df if they exist */
	if (ex_comp_ws(exoid) == sizeof(float)) {
	  flt_dist_fact = sets_dist_fact;
	  status = ex_get_set_dist_fact(exoid, set_type, set_id,
					&(flt_dist_fact[df_idx]));
	} else {
	  dbl_dist_fact = sets_dist_fact;
	  status = ex_get_set_dist_fact(exoid, set_type, set_id,
					&(dbl_dist_fact[df_idx]));
	}
	if (status != NC_NOERR) {
	  return(EX_FATAL); /* error will be reported by subroutine */
	}
      }
    }
  }
  return(EX_NOERR);
}
Ejemplo n.º 6
0
int ex_get_var_time( int   exoid,
                     ex_entity_type var_type,
                     int   var_index,
                     int64_t   id,
                     int   beg_time_step, 
                     int   end_time_step,
                     void* var_vals )
{
  int dimid, varid, numel = 0, offset;
  int status;
  int *stat_vals;
  size_t num_obj, i;
  size_t num_entries_this_obj = 0;
  size_t start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];
  const char* varobjids;
  const char* varobstat;

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

  exerrval = 0; /* clear error code */

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

  /* find what object the entry is in */

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

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

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

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

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

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

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

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

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

  numel = num_entries_this_obj;

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

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

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

  free(stat_vals);

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

  if (end_time_step < 0) {
    /* user is requesting the maximum time step;  we find this out using the
     * database inquire function to get the number of time steps;  the ending
     * time step number is 1 less due to 0 based array indexing in C
     */
    end_time_step = ex_inquire_int (exoid, EX_INQ_TIME);
  }

  end_time_step--;

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

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

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get %s variable values in file id %d",
	    ex_name_of_object(var_type),exoid);
    ex_err("ex_get_var_time",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
int ex_put_prop_names (int   exoid,
                       ex_entity_type obj_type,
                       int   num_props,
                       char **prop_names)
{
  int status;
  int oldfill, temp;
  int i, propid, dimid, dims[1];
  char name[MAX_VAR_NAME_LENGTH+1];
  int vals[1];

  char errmsg[MAX_ERR_LENGTH];

  exerrval  = 0; /* clear error code */

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

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

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

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

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

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

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

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

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

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

  nc_set_fill(exoid, oldfill, &temp); /* default: turn off fill */
  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR) {    /* exit define mode */
    sprintf(errmsg,
	    "Error: failed to complete definition for file id %d",
	    exoid);
    ex_err("ex_put_prop_names",errmsg,exerrval);
  }
  return (EX_FATAL);
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
int ex_get_set_dist_fact (int   exoid,
			  ex_entity_type set_type,
			  ex_entity_id   set_id,
			  void *set_dist_fact)
{

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

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

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

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

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

  /* read in the distribution factors array */
  if (ex_comp_ws(exoid) == 4) {
    status = nc_get_var_float(exoid, dist_id, set_dist_fact);
  } else {
    status = nc_get_var_double(exoid, dist_id, set_dist_fact);
  }

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to get dist factors list for %s set %"PRId64" in file id %d",
	    ex_name_of_object(set_type), set_id,exoid);
    ex_err("ex_get_set_dist_fact",errmsg,exerrval);
    return (EX_FATAL);
  }
  return (EX_NOERR);
}
Ejemplo n.º 10
0
int ex_put_concat_sets (int   exoid,
			ex_entity_type set_type,
			const struct ex_set_specs* set_specs)
{
  int status;
  int temp;
  const void_int  *num_entries_per_set = set_specs->num_entries_per_set;
  const void_int  *num_dist_per_set = set_specs->num_dist_per_set;
  const void_int  *sets_entry_index = set_specs->sets_entry_index;
  const void_int  *sets_dist_index = set_specs->sets_dist_index;
  const void *sets_dist_fact = set_specs->sets_dist_fact;
  size_t i, num_df, num_entry;
  int cur_num_sets, num_sets;
  int dimid, varid, set_id_ndx, dims[1];
  int  *set_stat = NULL;
  int set_int_type, int_size;

  const float *flt_dist_fact = NULL;
  const double *dbl_dist_fact = NULL;
  char errmsg[MAX_ERR_LENGTH];
  char* idsptr = NULL;
  char* statptr = NULL;
  char* numdfptr = NULL;
  char* factptr = NULL;
  char* elemptr = NULL;
  char* extraptr = NULL;
  ex_inquiry ex_inq_val;

  exerrval = 0; /* clear error code */

  int_size = sizeof(int);
  if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
    int_size = sizeof(int64_t);
  }
  
  /* setup pointers based on set_type 
     NOTE: there is another block that sets more stuff later ... */

  if (set_type == EX_NODE_SET) {
    ex_inq_val = EX_INQ_NODE_SETS;
    idsptr = VAR_NS_IDS;
    statptr = VAR_NS_STAT;
  }
  else if (set_type == EX_EDGE_SET) {
    ex_inq_val = EX_INQ_EDGE_SETS;
    idsptr = VAR_ES_IDS;
    statptr = VAR_ES_STAT;
  }
  else if (set_type == EX_FACE_SET) {
    ex_inq_val = EX_INQ_FACE_SETS;
    idsptr = VAR_FS_IDS;
    statptr = VAR_FS_STAT;
  }
  else if (set_type == EX_SIDE_SET) {
    ex_inq_val = EX_INQ_SIDE_SETS;
    idsptr = VAR_SS_IDS;
    statptr = VAR_SS_STAT;
  }
  else if (set_type == EX_ELEM_SET) {
    ex_inq_val = EX_INQ_ELEM_SETS;
    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 sets are specified */
  if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &temp)) != NC_NOERR) {
    if (status == NC_EBADDIM) {
      exerrval = status;
      sprintf(errmsg,
	      "Error: no %ss defined for file id %d", ex_name_of_object(set_type), exoid);
      ex_err("ex_put_concat_sets",errmsg,exerrval);
    } else {
      exerrval = status;
      sprintf(errmsg,
	      "Error: failed to locate %ss defined in file id %d",
	      ex_name_of_object(set_type), exoid);
      ex_err("ex_put_concat_sets",errmsg,exerrval);
    }
    return (EX_FATAL);
  }
   
  /* inquire how many sets are to be stored */
  num_sets = ex_inquire_int(exoid, ex_inq_val);
  if (num_sets < 0) {
    sprintf(errmsg,
	    "Error: failed to get number of %ss defined for file id %d",
	    ex_name_of_object(set_type), exoid);
    /* use error val from inquire */
    ex_err("ex_put_concat_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  /* Fill out set status array */

  /* First, allocate space for the status list */
  if (!(set_stat= malloc(num_sets*sizeof(int)))) {
    exerrval = EX_MEMFAIL;
    sprintf(errmsg,
	    "Error: failed to allocate space for %s status array in file id %d",
	    ex_name_of_object(set_type), exoid);
    ex_err("ex_put_concat_sets",errmsg,exerrval);
    return (EX_FATAL);
  }

  if (int_size == sizeof(int64_t)) {
    for (i=0;i<num_sets;i++)  {
      set_stat[i] = (((int64_t*)num_entries_per_set)[i] == 0) ? 0 : 1;
    }
  } else {
    for (i=0;i<num_sets;i++)  {
      set_stat[i] = (((int*)num_entries_per_set)[i] == 0) ? 0 : 1;
    }
  }

  /* Next, get variable id of status array */
  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_concat_sets",errmsg,exerrval);
    ex_safe_free(set_stat);
    return (EX_FATAL);
  }

  status = nc_put_var_int(exoid, varid, set_stat);

  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to store %s status array to file id %d",
	    ex_name_of_object(set_type), exoid);
    ex_err("ex_put_concat_set",errmsg,exerrval);
    ex_safe_free(set_stat);
    return (EX_FATAL);
  }

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

  /* create set definitions */
  for (i=0; i<num_sets; i++) {
    int64_t set_id;
    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      set_id = ((int64_t*)set_specs->sets_ids)[i];
    } else {
      set_id = ((int*)set_specs->sets_ids)[i];
    }

    /* 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  is used to find the number of sets of type
       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_concat_sets",errmsg,exerrval);
      goto error_ret;
    }

    /*   NOTE: ex_inc_file_item  is used to find the number of sets
	 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) {
      elemptr = 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) {
      elemptr = 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) {
      elemptr = 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) {
      elemptr = 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) {
      elemptr = VAR_ELEM_ELS(set_id_ndx);
      extraptr = NULL;
      numdfptr = DIM_NUM_DF_ELS(set_id_ndx);
      factptr = VAR_FACT_ELS(set_id_ndx);
    }

    /*  define dimension for number of entries per set */
    if (set_stat[i] == 0) /* Is this a NULL set? */
      continue; /* Do not create anything for NULL sets! */

    if (int_size == sizeof(int)) {
      status = nc_def_dim(exoid, ex_dim_num_entries_in_object(set_type, set_id_ndx),
			  ((int*)num_entries_per_set)[i], &dimid);
    } else {
      status = nc_def_dim(exoid, ex_dim_num_entries_in_object(set_type, set_id_ndx),
			  ((int64_t*)num_entries_per_set)[i], &dimid);
    }
    
    if (status != NC_NOERR) {
      if (status == NC_ENAMEINUSE) {
	exerrval = status;
	sprintf(errmsg,
		"Error: %s entry count %"PRId64" already defined in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_put_concat_sets",errmsg,exerrval);
      } else {
	exerrval = status;
	sprintf(errmsg,
		"Error: failed to define number of entries for %s %"PRId64" in file id %d",
		ex_name_of_object(set_type), set_id,exoid);
	ex_err("ex_put_concat_sets",errmsg,exerrval);
      }
      goto error_ret;
    }

    /* create element list variable for set */
    set_int_type = NC_INT;
    if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
      set_int_type = NC_INT64;
    }

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

    /* create extra list variable for set  (only for edge, face and side sets) */
    if (extraptr) {
      if ((status = nc_def_var(exoid,extraptr,set_int_type,1,dims, &temp)) != NC_NOERR) { 
	if (status == NC_ENAMEINUSE) {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: extra list already exists for %s %"PRId64" in file id %d",
		  ex_name_of_object(set_type), set_id,exoid);
	  ex_err("ex_put_concat_sets",errmsg,exerrval);
	} else {
	  exerrval = status;
	  sprintf(errmsg,
		  "Error: failed to create extra list for %s %"PRId64" in file id %d",
		  ex_name_of_object(set_type), set_id,exoid);
	  ex_err("ex_put_concat_sets",errmsg,exerrval);
	}
	goto error_ret;         /* exit define mode and return */
      }
      ex_compress_variable(exoid, temp, 1);
    }

    /*  define dimension for number of dist factors per set */
    /*  NOTE: only define df count if the dist factors exist! */
    if (int_size == sizeof(int64_t)) {
      num_df = ((int64_t*)num_dist_per_set)[i];
      num_entry = ((int64_t*)num_entries_per_set)[i];
    } else {
      num_df = ((int*)num_dist_per_set)[i];
      num_entry = ((int*)num_entries_per_set)[i];
    }

    if (num_df > 0) {
      
      if (set_type == EX_NODE_SET) {
	if (num_df != num_entry) {
	  exerrval = EX_FATAL;
	  sprintf(errmsg,
		  "Error: # dist fact (%"ST_ZU") not equal to # nodes (%"ST_ZU") in node set %"PRId64" file id %d",
		  num_df, num_entry, set_id,exoid);
	  ex_err("ex_put_concat_sets",errmsg,exerrval);
	  goto error_ret;          /* exit define mode and return */
	}

	/* resuse dimid from entry lists */
      } else  {
	if ((status = nc_def_dim(exoid, numdfptr,
				 num_df, &dimid)) != NC_NOERR) {
	  if (status == NC_ENAMEINUSE) {
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: %s df count %"PRId64" already defined in file id %d",
		    ex_name_of_object(set_type), set_id,exoid);
	    ex_err("ex_put_concat_sets",errmsg,exerrval);
	  } else {
	    exerrval = status;
	    sprintf(errmsg,
		    "Error: failed to define %s df count for set %"PRId64" in file id %d",
		    ex_name_of_object(set_type), set_id,exoid);
	    ex_err("ex_put_concat_sets",errmsg,exerrval);
	  }
	  goto error_ret;
	}
      }

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

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

  /* Next, fill out set ids array */

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

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

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

  /* If the sets_entry_index is passed in as a NULL pointer, then
   *  the user only wants us to define the sets and not populate
   *  the data structures.
   */
  if (sets_entry_index == 0) {
    ex_safe_free(set_stat);
    return(EX_NOERR);
  }
  
  /* Now, use ExodusII call to store sets */
  for (i=0; i<num_sets; i++) {
    int64_t set_id;
    size_t df_ndx;
    
    if (set_stat[i] == 0) /* Is this a NULL set? */
      continue; /* Do not create anything for NULL sets! */

    if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
      set_id = ((int64_t*)set_specs->sets_ids)[i];
    } else {
      set_id = ((int*)set_specs->sets_ids)[i];
    }

    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      int64_t* extra_list = NULL;
      /* set extra list */
      if (set_type == EX_EDGE_SET || set_type == EX_FACE_SET || set_type == EX_SIDE_SET)
	extra_list = &(((int64_t*)set_specs->sets_extra_list)[((int64_t*)sets_entry_index)[i]]);
      
      status = ex_put_set(exoid, set_type, set_id, 
			  &(((int64_t*)set_specs->sets_entry_list)[((int64_t*)sets_entry_index)[i]]),
			  extra_list);
    } else {
      int* extra_list = NULL;
      /* set extra list */
      if (set_type == EX_EDGE_SET || set_type == EX_FACE_SET || set_type == EX_SIDE_SET)
	extra_list = &(((int*)set_specs->sets_extra_list)[((int*)sets_entry_index)[i]]);
      
      status = ex_put_set(exoid, set_type, set_id, 
			  &(((int*)set_specs->sets_entry_list)[((int*)sets_entry_index)[i]]),
			  extra_list);
    }
    if (status != NC_NOERR) {
      ex_safe_free(set_stat);
      return(EX_FATAL); /* error will be reported by subroutine */
    }

    if (int_size == sizeof(int)) {
      num_df = ((int*)num_dist_per_set)[i];
      df_ndx = ((int*)sets_dist_index)[i];
    } else {
      num_df = ((int64_t*)num_dist_per_set)[i];
      df_ndx = ((int64_t*)sets_dist_index)[i];
    }

    if (ex_comp_ws(exoid) == sizeof(float)) {
      flt_dist_fact = sets_dist_fact;
      if (num_df > 0) {     /* store dist factors if required */
	if (ex_put_set_dist_fact(exoid, set_type, set_id,
				 &(flt_dist_fact[df_ndx])) == -1) {
	  sprintf(errmsg,
		  "Error: failed to store %s %"PRId64" dist factors for file id %d",
		  ex_name_of_object(set_type), set_id,exoid);
	  /* use error val from exodusII routine */
	  ex_err("ex_put_concat_sets",errmsg,exerrval);
	  ex_safe_free(set_stat);
	  return (EX_FATAL);
	}
      }
    } else if (ex_comp_ws(exoid) == sizeof(double)) {
      dbl_dist_fact = sets_dist_fact;
      if (num_df) {             /* only store if they exist */
	if (ex_put_set_dist_fact(exoid, set_type, set_id,
				 &(dbl_dist_fact[df_ndx])) == -1) {
	  sprintf(errmsg,
		  "Error: failed to store %s %"PRId64" dist factors for file id %d",
		  ex_name_of_object(set_type), set_id,exoid);
	  /* use error val from exodusII routine */
	  ex_err("ex_put_concat_sets",errmsg,exerrval);
	  ex_safe_free(set_stat);
	  return (EX_FATAL);
	}
      }
    } else {
      /* unknown floating point word size */
      exerrval = EX_BADPARAM;
      sprintf(errmsg,
	      "Error: unsupported floating point word size %d for file id %d",
	      ex_comp_ws(exoid), exoid);
      ex_err("ex_put_concat_sets", errmsg, exerrval);
      ex_safe_free(set_stat);
      return (EX_FATAL);
    }
  }
  ex_safe_free(set_stat);
  return(EX_NOERR);


  /* Fatal error: exit definition mode and return */
 error_ret:
  ex_safe_free(set_stat);

  if (nc_enddef (exoid) != NC_NOERR)     /* exit define mode */
    {
      sprintf(errmsg,
	      "Error: failed to complete definition for file id %d",
	      exoid);
      ex_err("ex_put_concat_sets",errmsg,exerrval);
    }
  return (EX_FATAL);
}
Ejemplo n.º 11
0
int ex_get_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, void_int *set_entry_list,
               void_int *set_extra_list) /* NULL if dont want to retrieve data */
{

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

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

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

  /* Lookup index of set id in VAR_*S_IDS array */
  set_id_ndx = ex_id_lkup(exoid, set_type, set_id);
  if (set_id_ndx <= 0) {
    ex_get_err(NULL, NULL, &status);

    if (status != 0) {
      if (status == EX_NULLENTITY) {
        snprintf(errmsg, MAX_ERR_LENGTH, "Warning: %s %" PRId64 " is NULL in file id %d",
                 ex_name_of_object(set_type), set_id, exoid);
        ex_err(__func__, errmsg, EX_NULLENTITY);
        EX_FUNC_LEAVE(EX_WARN);
      }

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

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

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

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

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

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

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

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

    if (status != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to get extra list for %s %" PRId64 " in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }
  EX_FUNC_LEAVE(EX_NOERR);
}
int ex_get_partial_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id,
                                 int64_t offset, int64_t num_to_put, void *set_dist_fact)
{

  int    dimid, dist_id, set_id_ndx;
  int    status;
  size_t start[1], count[1];
  char   errmsg[MAX_ERR_LENGTH];
  char * factptr = NULL;

  EX_FUNC_ENTER();
  ex_check_valid_file_id(exoid, __func__);

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

  /* Lookup index of set id in VAR_*S_IDS array */
  set_id_ndx = ex_id_lkup(exoid, set_type, set_id);
  if (set_id_ndx <= 0) {
    ex_get_err(NULL, NULL, &status);

    if (status != 0) {
      if (status == EX_NULLENTITY) {
        snprintf(errmsg, MAX_ERR_LENGTH, "Warning: %s set %" PRId64 " is NULL in file id %d",
                 ex_name_of_object(set_type), set_id, exoid);
        ex_err(__func__, errmsg, EX_NULLENTITY);
        EX_FUNC_LEAVE(EX_WARN);
      }
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to locate %s set %" PRId64 " in VAR_*S_IDS array in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(EX_FATAL);
    }
  }

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

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

    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate dist factors list for %s set %" PRId64 " in file id %d",
             ex_name_of_object(set_type), set_id, exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

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

  if (status != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to get dist factors list for %s set %" PRId64 " in file id %d",
             ex_name_of_object(set_type), set_id, exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }
  EX_FUNC_LEAVE(EX_NOERR);
}
Ejemplo n.º 13
0
int ex_get_concat_sets (int   exoid,
                        ex_entity_type set_type,
                        struct ex_set_specs* set_specs)
{
    int status, dimid;
    int  *set_ids = set_specs->sets_ids;
    int  *num_entries_per_set = set_specs->num_entries_per_set;
    int  *num_dist_per_set = set_specs->num_dist_per_set;
    int  *sets_entry_index = set_specs->sets_entry_index;
    int  *sets_dist_index = set_specs->sets_dist_index;
    int  *sets_entry_list = set_specs->sets_entry_list;
    int  *sets_extra_list = set_specs->sets_extra_list;
    void *sets_dist_fact = set_specs->sets_dist_fact;
    char *cdum;
    int num_sets, i;
    float fdum;
    float  *flt_dist_fact;
    double *dbl_dist_fact;
    char errmsg[MAX_ERR_LENGTH];
    ex_inquiry ex_inq_val;

    exerrval = 0; /* clear error code */

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

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

    if (set_type == EX_NODE_SET) {
        ex_inq_val = EX_INQ_NODE_SETS;
    }
    else if (set_type == EX_EDGE_SET) {
        ex_inq_val = EX_INQ_EDGE_SETS;
    }
    else if (set_type == EX_FACE_SET) {
        ex_inq_val = EX_INQ_FACE_SETS;
    }
    else if (set_type == EX_SIDE_SET) {
        ex_inq_val = EX_INQ_SIDE_SETS;
    }
    else if (set_type == EX_ELEM_SET) {
        ex_inq_val = EX_INQ_ELEM_SETS;
    }
    else {
        exerrval = EX_FATAL;
        sprintf(errmsg,
                "Error: invalid set type (%d)", set_type);
        ex_err("ex_put_set_param",errmsg,exerrval);
        return (EX_FATAL);
    }

    /* first check if any sets are specified */

    if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
        exerrval = status;
        if (status == NC_EBADDIM) {
            sprintf(errmsg,
                    "Warning: no %ss defined for file id %d",
                    ex_name_of_object(set_type), exoid);
            ex_err("ex_get_concat_sets",errmsg,exerrval);
            return (EX_WARN);
        } else {
            sprintf(errmsg,
                    "Error: failed to locate %ss defined in file id %d",
                    ex_name_of_object(set_type), exoid);
            ex_err("ex_get_concat_sets",errmsg,exerrval);
            return (EX_FATAL);
        }
    }

    /* inquire how many sets have been stored */

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

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

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

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

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

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

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

        if (ex_comp_ws(exoid) == sizeof(float)) {
            int *extra_sets = NULL;
            if (sets_extra_list != NULL)
                extra_sets = &(sets_extra_list[sets_entry_index[i]]);

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

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

            /* get distribution factors for this set */
            if (sets_dist_fact != 0) {
                dbl_dist_fact = sets_dist_fact;
                if (num_dist_per_set[i] > 0) {      /* only get df if they exist */
                    if (ex_get_set_dist_fact(exoid, set_type, set_ids[i],
                                             &(dbl_dist_fact[sets_dist_index[i]])) != NC_NOERR) {
                        sprintf(errmsg,
                                "Error: failed to get %s %d dist factors in file id %d",
                                ex_name_of_object(set_type), set_ids[i], exoid);
                        ex_err("ex_get_concat_sets",errmsg,exerrval);
                        return(EX_FATAL);
                    }
                } else {  /* fill distribution factor array with 1's */
                }
            }
        }
    }
    return(EX_NOERR);
}
int ex_put_partial_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t offset,
                       int64_t num_to_put, 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;
  size_t start[1], count[1];
  char   errmsg[MAX_ERR_LENGTH];
  char * entryptr = NULL;
  char * extraptr = NULL;

  EX_FUNC_ENTER();

  ex_check_valid_file_id(exoid, __func__);

  /* first check if any sets are specified */
  if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) {
    snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %ss defined in file id %d",
             ex_name_of_object(set_type), exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* Lookup index of set id in VAR_*S_IDS array */
  set_id_ndx = ex_id_lkup(exoid, set_type, set_id);
  if (set_id_ndx <= 0) {
    ex_get_err(NULL, NULL, &status);

    if (status != 0) {
      if (status == EX_NULLENTITY) {
        snprintf(errmsg, MAX_ERR_LENGTH,
                 "Warning: no data allowed for NULL %s %" PRId64 " in file id %d",
                 ex_name_of_object(set_type), set_id, exoid);
        ex_err(__func__, errmsg, EX_NULLENTITY);
        EX_FUNC_LEAVE(EX_WARN);
      }
      snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s id %" PRId64 " in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(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) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "ERROR: failed to locate entry list for %s %" PRId64 " in file id %d",
             ex_name_of_object(set_type), set_id, exoid);
    ex_err(__func__, errmsg, status);
    EX_FUNC_LEAVE(EX_FATAL);
  }

  /* write out the entry list and extra list arrays */
  if (set_entry_list != NULL || ex_is_parallel(exoid)) {
    start[0] = offset - 1;
    count[0] = num_to_put;
    if (count[0] == 0) {
      start[0] = 0;
    }

    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_put_vara_longlong(exoid, entry_list_id, start, count, set_entry_list);
    }
    else {
      status = nc_put_vara_int(exoid, entry_list_id, start, count, set_entry_list);
    }

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

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

    start[0] = offset - 1;
    count[0] = num_to_put;
    if (count[0] == 0) {
      start[0] = 0;
    }
    if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
      status = nc_put_vara_longlong(exoid, extra_list_id, start, count, set_extra_list);
    }
    else {
      status = nc_put_vara_int(exoid, extra_list_id, start, count, set_extra_list);
    }

    if (status != NC_NOERR) {
      snprintf(errmsg, MAX_ERR_LENGTH,
               "ERROR: failed to store extra list for %s %" PRId64 " in file id %d",
               ex_name_of_object(set_type), set_id, exoid);
      ex_err(__func__, errmsg, status);
      EX_FUNC_LEAVE(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) {
    snprintf(errmsg, MAX_ERR_LENGTH,
             "Warning: extra list was ignored for %s %" PRId64 " in file id %d",
             ex_name_of_object(set_type), set_id, exoid);
    ex_err(__func__, errmsg, EX_BADPARAM);
    EX_FUNC_LEAVE(EX_WARN);
  }

  EX_FUNC_LEAVE(EX_NOERR);
}
Ejemplo n.º 15
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);
}
int ex_put_names (int   exoid,
		  ex_entity_type obj_type,
		  char* names[])
{
  int status;
  int varid; 
  size_t i, num_entity;
  size_t start[2], count[2];
  char errmsg[MAX_ERR_LENGTH];
  const char *vname = NULL;
   
  const char *routine = "ex_put_names";
   
  exerrval = 0; /* clear error code */

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

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

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

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

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

  /* write EXODUS entitynames */
  for (i=0; i<num_entity; i++) {
    if (names[i] != '\0') {
      start[0] = i;
      start[1] = 0;
       
      count[0] = 1;
      count[1] = strlen(names[i]) + 1;
       
      if ((status = nc_put_vara_text(exoid, varid, start, count, names[i])) != NC_NOERR) {
	exerrval = status;
	sprintf(errmsg,
		"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);
      }
    }
  }
  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);
}
Ejemplo n.º 18
0
int ex_put_truth_table (int  exoid,
			ex_entity_type obj_type,
			int  num_blk,
			int  num_var,
			int *var_tab)
{
  int numelblkdim, numelvardim, timedim, dims[2], varid;
  char *sta_type, *tab_type;
  size_t num_entity = 0;
  size_t num_var_db = 0;
  int *stat_vals;
  int i, j, k;
  int status;
  char errmsg[MAX_ERR_LENGTH];
  const char* routine = "ex_put_truth_table";
  
  /*
   * The ent_type and the var_name are used to build the netcdf
   * variables name.  Normally this is done via a macro defined in
   * exodusII_int.h
   */
  const char* ent_type = NULL;
  const char* var_name = NULL;
  const char* ent_size = NULL;
  exerrval = 0; /* clear error code */
   
  ex_get_dimension(exoid, ex_dim_num_objects(obj_type),
		   ex_name_of_object(obj_type), &num_entity, &numelblkdim, routine);

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

  else {       /* invalid variable type */
    exerrval = EX_BADPARAM;
    sprintf(errmsg,
	    "Error: Invalid variable type %d specified in file id %d",
	    obj_type, exoid);
    ex_err("ex_get_varid",errmsg,exerrval);
    return (EX_WARN);
  }
       
  if ((int)num_entity != num_blk) {
    exerrval = EX_FATAL;
    sprintf(errmsg,
	    "Error: # of %s doesn't match those defined in file id %d",
	    ex_name_of_object(obj_type), exoid);
    ex_err("ex_get_var_tab",errmsg,exerrval);
    return (EX_FATAL);
  }

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

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

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

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

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

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

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

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

      /* check if variables are to be put out for this entity */
      if (var_tab[k] != 0) {
	if (stat_vals[i] != 0) {/* check for NULL entity */
	  /* NOTE: This code used to zero out the var_tab entry
	     if the stat_vals[i] value was zero. However, in some
	     cases it is good to know that a variable was assigned to
	     an entity even if that entity is empty. The code was
	     changed to not modify the truth table.
	  */
	  dims[0] = timedim;
	  
	  /* Determine number of entities in block */
	  if ((status = nc_inq_dimid(exoid, ex_catstr(ent_size, (i+1)), &dims[1])) != NC_NOERR) {
	    exerrval = status;
	    free(stat_vals);
	    sprintf(errmsg,
		    "Error: failed to locate number of entities in %d'th %s in file id %d",
		    i+1, ex_name_of_object(obj_type), exoid);
	    ex_err(routine,errmsg,exerrval);
	    goto error_ret;          /* exit define mode and return */
	    }


	  /* define netCDF variable to store variable values; the j
	   * index cycles from 1 through the number of variables so
	   * that the index of the EXODUS II variable (which is part
	   * of the name of the netCDF variable) will begin at 1
	   * instead of 0
	   */

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

  free (stat_vals);

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

  dims[0] = numelblkdim;
  dims[1] = numelvardim;
  status = nc_def_var (exoid, tab_type, NC_INT, 2, dims, &varid);
  
  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to define %s variable truth table in file id %d",
	    ex_name_of_object(obj_type), exoid);
    ex_err(routine,errmsg,exerrval);
    goto error_ret;          /* exit define mode and return */
  }

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

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

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


  return (EX_NOERR);

  /* Fatal error: exit definition mode and return */
 error_ret:
  if (nc_enddef (exoid) != NC_NOERR)     /* exit define mode */
    {
      sprintf(errmsg,
	      "Error: failed to complete definition for file id %d",
	      exoid);
      ex_err(routine,errmsg,exerrval);
    }
  return (EX_FATAL);
}
Ejemplo n.º 19
0
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);
}
Ejemplo n.º 20
0
int ex_get_ids (int  exoid,
		ex_entity_type obj_type, 
		void_int *ids)
{
  int varid, status;
  char errmsg[MAX_ERR_LENGTH];

  const char* varidobj;

  exerrval = 0; /* clear error code */

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

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


  /* inquire id's of previously defined dimensions and variables  */
  if ((status = nc_inq_varid(exoid, varidobj, &varid)) != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to locate %s ids variable in file id %d",
	    ex_name_of_object(obj_type),exoid);
    ex_err("ex_get_ids",errmsg,exerrval);
    return (EX_FATAL);
  }
  
  /* read in the element block ids  */
  if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
    status = nc_get_var_longlong(exoid, varid, ids);
  } else {
    status = nc_get_var_int(exoid, varid, ids);
  }
  
  if (status != NC_NOERR) {
    exerrval = status;
    sprintf(errmsg,
	    "Error: failed to return %s ids in file id %d",
	    ex_name_of_object(obj_type),exoid);
    ex_err("ex_get_ids",errmsg,exerrval);
    return (EX_FATAL);
  }
  return(EX_NOERR);
}