int ex_get_coord_names (int exoid, char **coord_names) { int status; int ndimdim, varid; size_t num_dim; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* inquire previously defined dimensions and variables */ if ((status = nc_inq_dimid(exoid, DIM_NUM_DIM, &ndimdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate number of dimensions in file id %d", exoid); ex_err("ex_get_coord_names",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_dimlen(exoid, ndimdim, &num_dim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of dimensions in file id %d", exoid); ex_err("ex_get_coord_names",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_varid(exoid, VAR_NAME_COOR, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Warning: failed to locate coordinate names in file id %d", exoid); ex_err("ex_get_coord_names",errmsg,exerrval); return (EX_WARN); } /* read the coordinate names */ status = ex_get_names_internal(exoid, varid, num_dim, coord_names, EX_COORDINATE, "ex_get_coord_names"); if (status != NC_NOERR) { return (EX_FATAL); } return (EX_NOERR); }
/* * reads the attribute names for an element block */ int ex_get_attr_names( int exoid, ex_entity_type obj_type, ex_entity_id obj_id, char **names) { int status; int varid, numattrdim, obj_id_ndx; size_t num_attr, i; char errmsg[MAX_ERR_LENGTH]; const char* dnumobjatt; const char* vattrbname; exerrval = 0; /* clear error code */ /* Determine index of obj_id in vobjids array */ if (obj_type != EX_NODAL) { obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: no attributes found for NULL %s %"PRId64" in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_get_attr_names",errmsg,EX_NULLENTITY); return (EX_WARN); /* no attributes for this object */ } else { sprintf(errmsg, "Warning: failed to locate %s id %"PRId64" in id array in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_get_attr_names",errmsg,exerrval); return (EX_WARN); } } } switch (obj_type) { case EX_NODE_SET: dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx); vattrbname = VAR_NAME_NSATTRIB(obj_id_ndx); break; case EX_SIDE_SET: dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx); vattrbname = VAR_NAME_SSATTRIB(obj_id_ndx); break; case EX_EDGE_SET: dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx); vattrbname = VAR_NAME_ESATTRIB(obj_id_ndx); break; case EX_FACE_SET: dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx); vattrbname = VAR_NAME_FSATTRIB(obj_id_ndx); break; case EX_ELEM_SET: dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx); vattrbname = VAR_NAME_ELSATTRIB(obj_id_ndx); break; case EX_NODAL: dnumobjatt = DIM_NUM_ATT_IN_NBLK; vattrbname = VAR_NAME_NATTRIB; break; case EX_EDGE_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx); vattrbname = VAR_NAME_EATTRIB(obj_id_ndx); break; case EX_FACE_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx); vattrbname = VAR_NAME_FATTRIB(obj_id_ndx); break; case EX_ELEM_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx); vattrbname = VAR_NAME_ATTRIB(obj_id_ndx); break; default: exerrval = 1005; sprintf(errmsg, "Internal Error: unrecognized object type in switch: %d in file id %d", obj_type,exoid); ex_err("ex_get_attr_names",errmsg,EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } /* inquire id's of previously defined dimensions */ if ((status = nc_inq_dimid(exoid, dnumobjatt, &numattrdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Warning: no attributes found for %s %"PRId64" in file id %d", ex_name_of_object(obj_type),obj_id,exoid); ex_err("ex_get_attr_names",errmsg,EX_MSG); return (EX_WARN); /* no attributes for this object */ } if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of attributes for %s %"PRId64" in file id %d", ex_name_of_object(obj_type),obj_id,exoid); ex_err("ex_get_attr_names",errmsg,exerrval); return (EX_FATAL); } /* It is OK if we don't find the attribute names since they were added at version 4.26; earlier databases won't have the names. */ status = nc_inq_varid(exoid, vattrbname, &varid); /* read in the attributes */ if (status == NC_NOERR) { /* read the names */ status = ex_get_names_internal(exoid, varid, num_attr, names, obj_type, "ex_get_attr_names"); if (status != NC_NOERR) { return (EX_FATAL); } } else { /* Names variable does not exist on the database; probably since this is an * older version of the database. Return an empty array... */ for (i=0; i<num_attr; i++) { names[i][0] = '\0'; } } return(EX_NOERR); }
int ex_get_variable_names (int exoid, ex_entity_type obj_type, int num_vars, char *var_names[]) { int varid, status; char errmsg[MAX_ERR_LENGTH]; const char* vvarname; exerrval = 0; /* clear error code */ switch (obj_type) { case EX_NODAL: vvarname = VAR_NAME_NOD_VAR; break; case EX_EDGE_BLOCK: vvarname = VAR_NAME_EDG_VAR; break; case EX_FACE_BLOCK: vvarname = VAR_NAME_FAC_VAR; break; case EX_ELEM_BLOCK: vvarname = VAR_NAME_ELE_VAR; break; case EX_NODE_SET: vvarname = VAR_NAME_NSET_VAR; break; case EX_EDGE_SET: vvarname = VAR_NAME_ESET_VAR; break; case EX_FACE_SET: vvarname = VAR_NAME_FSET_VAR; break; case EX_SIDE_SET: vvarname = VAR_NAME_SSET_VAR; break; case EX_ELEM_SET: vvarname = VAR_NAME_ELSET_VAR; break; case EX_GLOBAL: vvarname = VAR_NAME_GLO_VAR; break; default: exerrval = EX_BADPARAM; sprintf(errmsg, "Warning: invalid variable type %d requested from file id %d", obj_type, exoid); ex_err("ex_get_variable_names",errmsg,exerrval); return (EX_WARN); } /* inquire previously defined variables */ if ((status = nc_inq_varid(exoid, vvarname, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Warning: no %s variables names stored in file id %d", ex_name_of_object(obj_type),exoid); ex_err("ex_get_variable_names",errmsg,exerrval); return (EX_WARN); } /* read the variable names */ status = ex_get_names_internal(exoid, varid, num_vars, var_names, obj_type, "ex_get_variable_names"); if (status != NC_NOERR) { return (EX_FATAL); } return (EX_NOERR); }
int ex_get_names (int exoid, ex_entity_type obj_type, char **names) { int status; int varid, temp; size_t num_entity, i; char errmsg[MAX_ERR_LENGTH]; const char *routine = "ex_get_names"; exerrval = 0; /* clear error code */ /* inquire previously defined dimensions and variables */ switch (obj_type) { /* ======== BLOCKS ========= */ case EX_EDGE_BLOCK: ex_get_dimension(exoid, DIM_NUM_ED_BLK, "edge block", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_ED_BLK, &varid); break; case EX_FACE_BLOCK: ex_get_dimension(exoid, DIM_NUM_FA_BLK, "face block", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_FA_BLK, &varid); break; case EX_ELEM_BLOCK: ex_get_dimension(exoid, DIM_NUM_EL_BLK, "element block", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_EL_BLK, &varid); break; /* ======== SETS ========= */ case EX_NODE_SET: ex_get_dimension(exoid, DIM_NUM_NS, "nodeset", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_NS, &varid); break; case EX_EDGE_SET: ex_get_dimension(exoid, DIM_NUM_ES, "edgeset", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_ES, &varid); break; case EX_FACE_SET: ex_get_dimension(exoid, DIM_NUM_FS, "faceset", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_FS, &varid); break; case EX_SIDE_SET: ex_get_dimension(exoid, DIM_NUM_SS, "sideset", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_SS, &varid); break; case EX_ELEM_SET: ex_get_dimension(exoid, DIM_NUM_ELS, "elemset", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_ELS, &varid); break; /* ======== MAPS ========= */ case EX_NODE_MAP: ex_get_dimension(exoid, DIM_NUM_NM, "node map", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_NM, &varid); break; case EX_EDGE_MAP: ex_get_dimension(exoid, DIM_NUM_EDM, "edge map", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_EDM, &varid); break; case EX_FACE_MAP: ex_get_dimension(exoid, DIM_NUM_FAM, "face map", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_FAM, &varid); break; case EX_ELEM_MAP: ex_get_dimension(exoid, DIM_NUM_EM, "element map", &num_entity, &temp, routine); status = nc_inq_varid(exoid, VAR_NAME_EM, &varid); break; /* invalid variable type */ default: exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Invalid type specified in file id %d", exoid); ex_err(routine,errmsg,exerrval); return(EX_FATAL); } if (status == NC_NOERR) { if ((status = ex_get_names_internal(exoid, varid, num_entity, names, obj_type, "ex_get_names")) != EX_NOERR) { return status; } } else { /* Names variable does not exist on the database; probably since this is an * older version of the database. Return an empty array... */ for (i=0; i<num_entity; i++) { names[i][0] = '\0'; } } return (EX_NOERR); }