int ex_get_partial_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int64_t start_num, int64_t num_ent, void *attrib) { int status; int attrid, obj_id_ndx; int temp; size_t num_entries_this_obj, num_attr; size_t start[2], count[2]; char errmsg[MAX_ERR_LENGTH]; const char *dnumobjent; const char *dnumobjatt; const char *vattrbname; ex_check_valid_file_id(exoid); exerrval = 0; /* clear error code */ if (num_ent == 0) { return 0; } /* Determine index of obj_id in vobjids array */ if (obj_type != EX_NODAL) { obj_id_ndx = ex_id_lkup(exoid, obj_type, obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no attributes found for NULL %s %" PRId64 " in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_get_partial_attr", errmsg, EX_NULLENTITY); return (EX_WARN); /* no attributes for this object */ } snprintf(errmsg, MAX_ERR_LENGTH, "Warning: failed to locate %s id%" PRId64 " in id array in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_get_partial_attr", errmsg, exerrval); return (EX_WARN); } } switch (obj_type) { case EX_SIDE_SET: dnumobjent = DIM_NUM_SIDE_SS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx); vattrbname = VAR_SSATTRIB(obj_id_ndx); break; case EX_NODE_SET: dnumobjent = DIM_NUM_NOD_NS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx); vattrbname = VAR_NSATTRIB(obj_id_ndx); break; case EX_EDGE_SET: dnumobjent = DIM_NUM_EDGE_ES(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx); vattrbname = VAR_ESATTRIB(obj_id_ndx); break; case EX_FACE_SET: dnumobjent = DIM_NUM_FACE_FS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx); vattrbname = VAR_FSATTRIB(obj_id_ndx); break; case EX_ELEM_SET: dnumobjent = DIM_NUM_ELE_ELS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx); vattrbname = VAR_ELSATTRIB(obj_id_ndx); break; case EX_NODAL: dnumobjent = DIM_NUM_NODES; dnumobjatt = DIM_NUM_ATT_IN_NBLK; vattrbname = VAR_NATTRIB; break; case EX_EDGE_BLOCK: dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx); vattrbname = VAR_EATTRIB(obj_id_ndx); break; case EX_FACE_BLOCK: dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx); vattrbname = VAR_FATTRIB(obj_id_ndx); break; case EX_ELEM_BLOCK: dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx); vattrbname = VAR_ATTRIB(obj_id_ndx); break; default: exerrval = 1005; snprintf(errmsg, MAX_ERR_LENGTH, "Internal ERROR: unrecognized object type in switch: %d in file id %d", obj_type, exoid); ex_err("ex_get_partial_attr", errmsg, EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } /* inquire id's of previously defined dimensions */ if (ex_get_dimension(exoid, dnumobjent, "entries", &num_entries_this_obj, &temp, "ex_get_partial_attr") != NC_NOERR) { return EX_FATAL; } if (start_num + num_ent - 1 > num_entries_this_obj) { exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: start index (%" PRId64 ") + count (%" PRId64 ") is larger than total number of entities (%" ST_ZU ") in file id %d", start_num, num_ent, num_entries_this_obj, exoid); ex_err("ex_get_partial_attr", errmsg, exerrval); return (EX_FATAL); } if (ex_get_dimension(exoid, dnumobjatt, "attributes", &num_attr, &temp, "ex_get_partial_attr") != NC_NOERR) { return EX_FATAL; } if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate attributes for %s %" PRId64 " in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_get_partial_attr", errmsg, exerrval); return (EX_FATAL); } /* read in the attributes */ start[0] = start_num - 1; start[1] = 0; count[0] = num_ent; count[1] = num_attr; if (ex_comp_ws(exoid) == 4) { status = nc_get_vara_float(exoid, attrid, start, count, attrib); } else { status = nc_get_vara_double(exoid, attrid, start, count, attrib); } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get attributes for %s %" PRId64 " in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_get_partial_attr", errmsg, exerrval); return (EX_FATAL); } return (EX_NOERR); }
int ex_get_attr_param (int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int* num_attrs) { int status; int dimid; char errmsg[MAX_ERR_LENGTH]; const char *dnumobjatt; int obj_id_ndx; size_t lnum_attr_per_entry; /* Determine index of obj_id in vobjids array */ if (obj_type == EX_NODAL) { obj_id_ndx = 0; } else { obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { *num_attrs = 0; return (EX_NOERR); } sprintf(errmsg, "Warning: failed to locate %s id %"PRId64" in id array in file id %d", ex_name_of_object(obj_type),obj_id,exoid); ex_err("ex_get_attr_param",errmsg,exerrval); return (EX_WARN); } } switch (obj_type) { case EX_SIDE_SET: dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx); break; case EX_NODE_SET: dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx); break; case EX_EDGE_SET: dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx); break; case EX_FACE_SET: dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx); break; case EX_ELEM_SET: dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx); break; case EX_NODAL: dnumobjatt = DIM_NUM_ATT_IN_NBLK; break; case EX_EDGE_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx); break; case EX_FACE_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx); break; case EX_ELEM_BLOCK: dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx); break; default: exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Bad block type (%d) specified for file id %d", obj_type, exoid ); ex_err("ex_get_attr_param",errmsg,exerrval); return (EX_FATAL); } exerrval = 0; /* clear error code */ if ((status = nc_inq_dimid(exoid, dnumobjatt, &dimid)) != NC_NOERR) { /* dimension is undefined */ *num_attrs = 0; } else { if ((status = nc_inq_dimlen(exoid, dimid, &lnum_attr_per_entry)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of attributes in %s %"PRId64" in file id %d", ex_name_of_object(obj_type),obj_id, exoid); ex_err("ex_get_attr_param",errmsg, exerrval); return(EX_FATAL); } *num_attrs = lnum_attr_per_entry; } return (EX_NOERR); }
int ex_add_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int64_t num_attr_per_entry) { int status; int dims[2]; int strdim, varid, att_name_varid; size_t num_obj; char errmsg[MAX_ERR_LENGTH]; const char *dnumobjent; const char *dnumobjatt; const char *vobjatt; const char *vattnam; int numobjentdim; int obj_id_ndx; int numattrdim; exerrval = 0; /* clear error code */ if (num_attr_per_entry <= 0) { return (EX_NOERR); } /* Determine index of obj_id in obj_type id array */ if (obj_type == EX_NODAL) { obj_id_ndx = 0; } else { obj_id_ndx = ex_id_lkup(exoid, obj_type, obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no attributes found for NULL %s %" PRId64 " in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_add_attr", errmsg, EX_NULLENTITY); return (EX_WARN); /* no attributes for this object */ } snprintf(errmsg, MAX_ERR_LENGTH, "Warning: failed to locate %s id %" PRId64 " in id array in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_add_attr", errmsg, exerrval); return (EX_WARN); } } switch (obj_type) { case EX_SIDE_SET: dnumobjent = DIM_NUM_SIDE_SS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx); vobjatt = VAR_SSATTRIB(obj_id_ndx); vattnam = VAR_NAME_SSATTRIB(obj_id_ndx); break; case EX_NODE_SET: dnumobjent = DIM_NUM_NOD_NS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx); vobjatt = VAR_NSATTRIB(obj_id_ndx); vattnam = VAR_NAME_NSATTRIB(obj_id_ndx); break; case EX_EDGE_SET: dnumobjent = DIM_NUM_EDGE_ES(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx); vobjatt = VAR_ESATTRIB(obj_id_ndx); vattnam = VAR_NAME_ESATTRIB(obj_id_ndx); break; case EX_FACE_SET: dnumobjent = DIM_NUM_FACE_FS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx); vobjatt = VAR_FSATTRIB(obj_id_ndx); vattnam = VAR_NAME_FSATTRIB(obj_id_ndx); break; case EX_ELEM_SET: dnumobjent = DIM_NUM_ELE_ELS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx); vobjatt = VAR_ELSATTRIB(obj_id_ndx); vattnam = VAR_NAME_ELSATTRIB(obj_id_ndx); break; case EX_NODAL: dnumobjent = DIM_NUM_NODES; dnumobjatt = DIM_NUM_ATT_IN_NBLK; vobjatt = VAR_NATTRIB; vattnam = VAR_NAME_NATTRIB; break; case EX_EDGE_BLOCK: dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx); vobjatt = VAR_EATTRIB(obj_id_ndx); vattnam = VAR_NAME_EATTRIB(obj_id_ndx); break; case EX_FACE_BLOCK: dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx); vobjatt = VAR_FATTRIB(obj_id_ndx); vattnam = VAR_NAME_FATTRIB(obj_id_ndx); break; case EX_ELEM_BLOCK: dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx); vobjatt = VAR_ATTRIB(obj_id_ndx); vattnam = VAR_NAME_ATTRIB(obj_id_ndx); break; default: exerrval = EX_BADPARAM; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: Bad block type (%d) specified for file id %d", obj_type, exoid); ex_err("ex_put_attr_param", errmsg, exerrval); return (EX_FATAL); } /* element attribute array */ /* 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_add_attr", errmsg, exerrval); return (EX_FATAL); } if ((status = nc_def_dim(exoid, dnumobjatt, num_attr_per_entry, &numattrdim)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define number of attributes in %s %" PRId64 " in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_add_attr", errmsg, exerrval); goto error_ret; /* exit define mode and return */ } ex_get_dimension(exoid, dnumobjent, ex_name_of_object(obj_type), &num_obj, &numobjentdim, "ex_add_attr"); dims[0] = numobjentdim; dims[1] = numattrdim; if ((status = nc_def_var(exoid, vobjatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define attributes for %s %" PRId64 " in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_add_attr", errmsg, exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(exoid, varid, 2); /* inquire previously defined dimensions */ if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get string length in file id %d", exoid); ex_err("ex_add_attr", errmsg, exerrval); return (EX_FATAL); } /* Attribute names... */ dims[0] = numattrdim; dims[1] = strdim; if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &att_name_varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define %s attribute name array in file id %d", ex_name_of_object(obj_type), exoid); ex_err("ex_add_attr", errmsg, exerrval); goto error_ret; /* exit define mode and return */ } /* leave define mode */ if ((exerrval = nc_enddef(exoid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete %s definition in file id %d", ex_name_of_object(obj_type), exoid); ex_err("ex_add_attr", errmsg, exerrval); return (EX_FATAL); } /* Output a dummy empty attribute name in case client code doesn't write anything; avoids corruption in some cases. */ if (att_name_varid >= 0) { size_t count[2]; size_t start[2]; char * text = ""; size_t i; count[0] = 1; start[1] = 0; count[1] = strlen(text) + 1; for (i = 0; i < num_attr_per_entry; i++) { start[0] = i; nc_put_vara_text(exoid, att_name_varid, start, count, text); } } 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_add_attr", errmsg, exerrval); } return (EX_FATAL); }
/* * 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); }
/*! * writes the attribute names for a block * \param exoid exodus file id * \param blk_type block type (edge, face, elem) * \param blk_id block id * \param names ptr to array of attribute names */ int ex_put_attr_names(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, char *names[]) { int varid, numattrdim, blk_id_ndx; size_t num_attr; int status; char errmsg[MAX_ERR_LENGTH]; exerrval = 0; /* clear error code */ blk_id_ndx = ex_id_lkup(exoid, blk_type, blk_id); /* Determine index of blk_id in blk_id_ndx array */ if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no attributes allowed for NULL %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_attr_names", errmsg, EX_NULLENTITY); return (EX_WARN); /* no attributes for this block */ } snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %s id %" PRId64 " in %s array in file id %d", ex_name_of_object(blk_type), blk_id, VAR_ID_EL_BLK, exoid); ex_err("ex_put_attr_names", errmsg, exerrval); return (EX_FATAL); } /* inquire id's of previously defined dimensions */ switch (blk_type) { case EX_SIDE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_SS(blk_id_ndx), &numattrdim); break; case EX_NODE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NS(blk_id_ndx), &numattrdim); break; case EX_EDGE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ES(blk_id_ndx), &numattrdim); break; case EX_FACE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FS(blk_id_ndx), &numattrdim); break; case EX_ELEM_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ELS(blk_id_ndx), &numattrdim); break; case EX_NODAL: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NBLK, &numattrdim); break; case EX_EDGE_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_EBLK(blk_id_ndx), &numattrdim); break; case EX_FACE_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FBLK(blk_id_ndx), &numattrdim); break; case EX_ELEM_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(blk_id_ndx), &numattrdim); break; default: exerrval = 1005; snprintf(errmsg, MAX_ERR_LENGTH, "Internal ERROR: unrecognized object type in switch: %d in file id %d", blk_type, exoid); ex_err("ex_put_attr_names", errmsg, EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: number of attributes not defined for %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_attr_names", errmsg, EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of attributes for %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_attr_names", errmsg, exerrval); return (EX_FATAL); } switch (blk_type) { case EX_SIDE_SET: status = nc_inq_varid(exoid, VAR_NAME_SSATTRIB(blk_id_ndx), &varid); break; case EX_NODE_SET: status = nc_inq_varid(exoid, VAR_NAME_NSATTRIB(blk_id_ndx), &varid); break; case EX_EDGE_SET: status = nc_inq_varid(exoid, VAR_NAME_ESATTRIB(blk_id_ndx), &varid); break; case EX_FACE_SET: status = nc_inq_varid(exoid, VAR_NAME_FSATTRIB(blk_id_ndx), &varid); break; case EX_ELEM_SET: status = nc_inq_varid(exoid, VAR_NAME_ELSATTRIB(blk_id_ndx), &varid); break; case EX_NODAL: status = nc_inq_varid(exoid, VAR_NAME_NATTRIB, &varid); break; case EX_EDGE_BLOCK: status = nc_inq_varid(exoid, VAR_NAME_EATTRIB(blk_id_ndx), &varid); break; case EX_FACE_BLOCK: status = nc_inq_varid(exoid, VAR_NAME_FATTRIB(blk_id_ndx), &varid); break; case EX_ELEM_BLOCK: status = nc_inq_varid(exoid, VAR_NAME_ATTRIB(blk_id_ndx), &varid); break; default: exerrval = 1005; snprintf(errmsg, MAX_ERR_LENGTH, "Internal ERROR: unrecognized object type in switch: %d in file id %d", blk_type, exoid); ex_err("ex_put_attr_names", errmsg, EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } if (status != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate %s attribute names for %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), ex_name_of_object(blk_type), blk_id, exoid); ex_err("ex_put_attr_names", errmsg, exerrval); return (EX_FATAL); } /* write out the attributes */ status = ex_put_names_internal(exoid, varid, num_attr, names, blk_type, "attribute", "ex_put_attr_names"); return (status); }
int ex_put_partial_attr(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, int64_t start_entity, int64_t num_entity, const void *attrib) { int status; int attrid; int blk_id_ndx = 0; int numattrdim; size_t start[2], count[2]; size_t num_attr; char errmsg[MAX_ERR_LENGTH]; EX_FUNC_ENTER(); ex_check_valid_file_id(exoid, __func__); if (blk_type != EX_NODAL) { /* Determine index of blk_id in VAR_ID_EL_BLK array */ blk_id_ndx = ex_id_lkup(exoid, blk_type, blk_id); if (blk_id_ndx <= 0) { ex_get_err(NULL, NULL, &status); if (status != 0) { if (status == EX_NULLENTITY) { snprintf(errmsg, MAX_ERR_LENGTH, "Warning: no attributes allowed for NULL %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err(__func__, errmsg, EX_NULLENTITY); EX_FUNC_LEAVE(EX_WARN); /* no attributes for this block */ } snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: no %s id %" PRId64 " in in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } } } switch (blk_type) { case EX_SIDE_SET: status = nc_inq_varid(exoid, VAR_SSATTRIB(blk_id_ndx), &attrid); break; case EX_NODE_SET: status = nc_inq_varid(exoid, VAR_NSATTRIB(blk_id_ndx), &attrid); break; case EX_EDGE_SET: status = nc_inq_varid(exoid, VAR_ESATTRIB(blk_id_ndx), &attrid); break; case EX_FACE_SET: status = nc_inq_varid(exoid, VAR_FSATTRIB(blk_id_ndx), &attrid); break; case EX_ELEM_SET: status = nc_inq_varid(exoid, VAR_ELSATTRIB(blk_id_ndx), &attrid); break; case EX_NODAL: status = nc_inq_varid(exoid, VAR_NATTRIB, &attrid); break; case EX_EDGE_BLOCK: status = nc_inq_varid(exoid, VAR_EATTRIB(blk_id_ndx), &attrid); break; case EX_FACE_BLOCK: status = nc_inq_varid(exoid, VAR_FATTRIB(blk_id_ndx), &attrid); break; case EX_ELEM_BLOCK: status = nc_inq_varid(exoid, VAR_ATTRIB(blk_id_ndx), &attrid); break; default: snprintf(errmsg, MAX_ERR_LENGTH, "Internal ERROR: unrecognized object type in switch: %d in file id %d", blk_type, exoid); ex_err(__func__, errmsg, EX_BADPARAM); EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */ } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate attribute variable for %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* Determine number of attributes */ switch (blk_type) { case EX_SIDE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_SS(blk_id_ndx), &numattrdim); break; case EX_NODE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NS(blk_id_ndx), &numattrdim); break; case EX_EDGE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ES(blk_id_ndx), &numattrdim); break; case EX_FACE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FS(blk_id_ndx), &numattrdim); break; case EX_ELEM_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ELS(blk_id_ndx), &numattrdim); break; case EX_NODAL: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NBLK, &numattrdim); break; case EX_EDGE_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_EBLK(blk_id_ndx), &numattrdim); break; case EX_FACE_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FBLK(blk_id_ndx), &numattrdim); break; case EX_ELEM_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(blk_id_ndx), &numattrdim); break; default: /* No need for error message, handled in previous switch; just to quiet * compiler. */ EX_FUNC_LEAVE(EX_FATAL); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: number of attributes not defined for %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); /* number of attributes not defined */ } if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get number of attributes for %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } /* write out the attributes */ start[0] = --start_entity; start[1] = 0; count[0] = num_entity; count[1] = num_attr; if (count[0] == 0) { start[0] = 0; } if (ex_comp_ws(exoid) == 4) { status = nc_put_vara_float(exoid, attrid, start, count, attrib); } else { status = nc_put_vara_double(exoid, attrid, start, count, attrib); } if (status != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put attributes for %s %" PRId64 " in file id %d", ex_name_of_object(blk_type), blk_id, exoid); ex_err(__func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } EX_FUNC_LEAVE(EX_NOERR); }
/* * reads the attributes for an edge, face, or element block */ int ex_get_one_attr( int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int attrib_index, void* attrib ) { int status; int attrid, obj_id_ndx; int temp; size_t num_entries_this_obj, num_attr; size_t start[2], count[2]; ptrdiff_t stride[2]; char errmsg[MAX_ERR_LENGTH]; const char* dnumobjent; const char* dnumobjatt; const char* vattrbname; exerrval = 0; /* clear error code */ /* Determine index of obj_id in vobjids array */ if (obj_type != EX_NODAL) { obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: no attributes found for NULL %s %"PRId64" in file id %d", ex_name_of_object(obj_type),obj_id,exoid); ex_err("ex_get_one_attr",errmsg,EX_NULLENTITY); return (EX_WARN); /* no attributes for this object */ } else { sprintf(errmsg, "Warning: failed to locate %s id %"PRId64" in id array in file id %d", ex_name_of_object(obj_type),obj_id, exoid); ex_err("ex_get_one_attr",errmsg,exerrval); return (EX_WARN); } } } switch (obj_type) { case EX_SIDE_SET: dnumobjent = DIM_NUM_SIDE_SS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx); vattrbname = VAR_SSATTRIB(obj_id_ndx); break; case EX_NODE_SET: dnumobjent = DIM_NUM_NOD_NS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx); vattrbname = VAR_NSATTRIB(obj_id_ndx); break; case EX_EDGE_SET: dnumobjent = DIM_NUM_EDGE_ES(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx); vattrbname = VAR_ESATTRIB(obj_id_ndx); break; case EX_FACE_SET: dnumobjent = DIM_NUM_FACE_FS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx); vattrbname = VAR_FSATTRIB(obj_id_ndx); break; case EX_ELEM_SET: dnumobjent = DIM_NUM_ELE_ELS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx); vattrbname = VAR_ELSATTRIB(obj_id_ndx); break; case EX_NODAL: dnumobjent = DIM_NUM_NODES; dnumobjatt = DIM_NUM_ATT_IN_NBLK; vattrbname = VAR_NATTRIB; break; case EX_EDGE_BLOCK: dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx); vattrbname = VAR_EATTRIB(obj_id_ndx); break; case EX_FACE_BLOCK: dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx); vattrbname = VAR_FATTRIB(obj_id_ndx); break; case EX_ELEM_BLOCK: dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx); vattrbname = VAR_ATTRIB(obj_id_ndx); break; default: exerrval = 1005; sprintf(errmsg, "Internal Error: unrecognized object type in switch: %d in file id %d", obj_type,exoid); ex_err("ex_get_one_attr",errmsg,EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } /* inquire id's of previously defined dimensions */ if (ex_get_dimension(exoid, dnumobjent,"entries", &num_entries_this_obj, &temp, "ex_get_one_attr") != NC_NOERR) return EX_FATAL; if (ex_get_dimension(exoid, dnumobjatt,"attributes", &num_attr, &temp, "ex_get_one_attr") != NC_NOERR) return EX_FATAL; if (attrib_index < 1 || attrib_index > (int)num_attr) { exerrval = EX_FATAL; sprintf(errmsg, "Error: Invalid attribute index specified: %d. Valid range is 1 to %d for %s %"PRId64" in file id %d", attrib_index, (int)num_attr, ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_get_one_attr",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_inq_varid(exoid, vattrbname, &attrid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate attributes for %s %"PRId64" in file id %d", ex_name_of_object(obj_type),obj_id,exoid); ex_err("ex_get_one_attr",errmsg,exerrval); return (EX_FATAL); } /* read in the attributes */ start[0] = 0; start[1] = attrib_index-1; count[0] = num_entries_this_obj; count[1] = 1; stride[0] = 1; stride[1] = num_attr; if (ex_comp_ws(exoid) == 4) { status = nc_get_vars_float(exoid, attrid, start, count, stride, attrib); } else { status = nc_get_vars_double(exoid, attrid, start, count, stride, attrib); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get attribute %d for %s %"PRId64" in file id %d", attrib_index, ex_name_of_object(obj_type), obj_id,exoid); ex_err("ex_get_one_attr",errmsg,exerrval); return (EX_FATAL); } return(EX_NOERR); }
/*! * writes the attribute names for a block * \param exoid exodus file id * \param blk_type block type (edge, face, elem) * \param blk_id block id * \param names ptr to array of attribute names */ int ex_put_attr_names(int exoid, ex_entity_type blk_type, int blk_id, char* names[]) { int status; int varid, numattrdim, blk_id_ndx; size_t num_attr, start[2], count[2]; char errmsg[MAX_ERR_LENGTH]; size_t i; exerrval = 0; /* clear error code */ blk_id_ndx = ex_id_lkup(exoid, blk_type, blk_id); /* Determine index of blk_id in blk_id_ndx array */ if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: no attributes allowed for NULL %s %d in file id %d", ex_name_of_object(blk_type),blk_id,exoid); ex_err("ex_put_attr_names",errmsg,EX_MSG); return (EX_WARN); /* no attributes for this block */ } else { sprintf(errmsg, "Error: no %s id %d in %s array in file id %d", ex_name_of_object(blk_type), blk_id, VAR_ID_EL_BLK, exoid); ex_err("ex_put_attr_names",errmsg,exerrval); return (EX_FATAL); } } /* inquire id's of previously defined dimensions */ switch (blk_type) { case EX_SIDE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_SS(blk_id_ndx), &numattrdim); break; case EX_NODE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NS(blk_id_ndx), &numattrdim); break; case EX_EDGE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ES(blk_id_ndx), &numattrdim); break; case EX_FACE_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FS(blk_id_ndx), &numattrdim); break; case EX_ELEM_SET: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_ELS(blk_id_ndx), &numattrdim); break; case EX_NODAL: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_NBLK, &numattrdim); break; case EX_EDGE_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_EBLK(blk_id_ndx), &numattrdim); break; case EX_FACE_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_FBLK(blk_id_ndx), &numattrdim); break; case EX_ELEM_BLOCK: status = nc_inq_dimid(exoid, DIM_NUM_ATT_IN_BLK(blk_id_ndx), &numattrdim); break; default: exerrval = 1005; sprintf(errmsg, "Internal Error: unrecognized object type in switch: %d in file id %d", blk_type,exoid); ex_err("ex_put_attr_names",errmsg,EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: number of attributes not defined for %s %d in file id %d", ex_name_of_object(blk_type),blk_id,exoid); ex_err("ex_put_attr_names",errmsg,EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } if ((status = nc_inq_dimlen(exoid, numattrdim, &num_attr)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get number of attributes for %s %d in file id %d", ex_name_of_object(blk_type),blk_id,exoid); ex_err("ex_put_attr_names",errmsg,exerrval); return (EX_FATAL); } switch (blk_type) { case EX_SIDE_SET: status = nc_inq_varid (exoid, VAR_NAME_SSATTRIB(blk_id_ndx), &varid); break; case EX_NODE_SET: status = nc_inq_varid (exoid, VAR_NAME_NSATTRIB(blk_id_ndx), &varid); break; case EX_EDGE_SET: status = nc_inq_varid (exoid, VAR_NAME_ESATTRIB(blk_id_ndx), &varid); break; case EX_FACE_SET: status = nc_inq_varid (exoid, VAR_NAME_FSATTRIB(blk_id_ndx), &varid); break; case EX_ELEM_SET: status = nc_inq_varid (exoid, VAR_NAME_ELSATTRIB(blk_id_ndx), &varid); break; case EX_NODAL: status = nc_inq_varid (exoid, VAR_NAME_NATTRIB, &varid); break; case EX_EDGE_BLOCK: status = nc_inq_varid (exoid, VAR_NAME_EATTRIB(blk_id_ndx), &varid); break; case EX_FACE_BLOCK: status = nc_inq_varid (exoid, VAR_NAME_FATTRIB(blk_id_ndx), &varid); break; case EX_ELEM_BLOCK: status = nc_inq_varid (exoid, VAR_NAME_ATTRIB(blk_id_ndx), &varid); break; default: exerrval = 1005; sprintf(errmsg, "Internal Error: unrecognized object type in switch: %d in file id %d", blk_type,exoid); ex_err("ex_put_attr_names",errmsg,EX_MSG); return (EX_FATAL); /* number of attributes not defined */ } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate %s attribute names for %s %d in file id %d", ex_name_of_object(blk_type),ex_name_of_object(blk_type),blk_id, exoid); ex_err("ex_put_attr_names",errmsg,exerrval); return (EX_FATAL); } /* write out the attributes */ for (i = 0; i < num_attr; i++) { 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, (void*) names[i])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to put attribute namess for %s %d in file id %d", ex_name_of_object(blk_type),blk_id,exoid); ex_err("ex_put_attr_names",errmsg,exerrval); return (EX_FATAL); } } return(EX_NOERR); }
int ex_put_attr_param (int exoid, ex_entity_type obj_type, int obj_id, int num_attrs) { int status; int dims[2]; int strdim, varid; char errmsg[MAX_ERR_LENGTH]; const char *dnumobjent; const char *dnumobjatt; const char *vobjatt; const char *vattnam; int numobjentdim; int obj_id_ndx; int numattrdim; /* Determine index of obj_id in obj_type id array */ if (obj_type == EX_NODAL) obj_id_ndx = 0; else { obj_id_ndx = ex_id_lkup(exoid,obj_type,obj_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: no attributes found for NULL %s %d in file id %d", ex_name_of_object(obj_type),obj_id,exoid); ex_err("ex_put_attr_param",errmsg,EX_MSG); return (EX_WARN); /* no attributes for this object */ } else { sprintf(errmsg, "Warning: failed to locate %s id %d in id array in file id %d", ex_name_of_object(obj_type),obj_id, exoid); ex_err("ex_put_attr_param",errmsg,exerrval); return (EX_WARN); } } } switch (obj_type) { case EX_SIDE_SET: dnumobjent = DIM_NUM_SIDE_SS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_SS(obj_id_ndx); vobjatt = VAR_SSATTRIB(obj_id_ndx); vattnam = VAR_NAME_SSATTRIB(obj_id_ndx); break; case EX_NODE_SET: dnumobjent = DIM_NUM_NOD_NS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_NS(obj_id_ndx); vobjatt = VAR_NSATTRIB(obj_id_ndx); vattnam = VAR_NAME_NSATTRIB(obj_id_ndx); break; case EX_EDGE_SET: dnumobjent = DIM_NUM_EDGE_ES(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ES(obj_id_ndx); vobjatt = VAR_ESATTRIB(obj_id_ndx); vattnam = VAR_NAME_ESATTRIB(obj_id_ndx); break; case EX_FACE_SET: dnumobjent = DIM_NUM_FACE_FS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FS(obj_id_ndx); vobjatt = VAR_FSATTRIB(obj_id_ndx); vattnam = VAR_NAME_FSATTRIB(obj_id_ndx); break; case EX_ELEM_SET: dnumobjent = DIM_NUM_ELE_ELS(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_ELS(obj_id_ndx); vobjatt = VAR_ELSATTRIB(obj_id_ndx); vattnam = VAR_NAME_ELSATTRIB(obj_id_ndx); break; case EX_NODAL: dnumobjent = DIM_NUM_NODES; dnumobjatt = DIM_NUM_ATT_IN_NBLK; vobjatt = VAR_NATTRIB; vattnam = VAR_NAME_NATTRIB; break; case EX_EDGE_BLOCK: dnumobjent = DIM_NUM_ED_IN_EBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_EBLK(obj_id_ndx); vobjatt = VAR_EATTRIB(obj_id_ndx); vattnam = VAR_NAME_EATTRIB(obj_id_ndx); break; case EX_FACE_BLOCK: dnumobjent = DIM_NUM_FA_IN_FBLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_FBLK(obj_id_ndx); vobjatt = VAR_FATTRIB(obj_id_ndx); vattnam = VAR_NAME_FATTRIB(obj_id_ndx); break; case EX_ELEM_BLOCK: dnumobjent = DIM_NUM_EL_IN_BLK(obj_id_ndx); dnumobjatt = DIM_NUM_ATT_IN_BLK(obj_id_ndx); vobjatt = VAR_ATTRIB(obj_id_ndx); vattnam = VAR_NAME_ATTRIB(obj_id_ndx); break; default: exerrval = EX_BADPARAM; sprintf(errmsg, "Error: Bad block type (%d) specified for file id %d", obj_type, exoid ); ex_err("ex_put_attr_param",errmsg,exerrval); return (EX_FATAL); } exerrval = 0; /* clear error code */ if ((status = nc_inq_dimid(exoid, dnumobjent, &numobjentdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate number of entries for %s %d in file id %d", ex_name_of_object(obj_type), obj_id, exoid); ex_err("ex_put_attr_param",errmsg,exerrval); return (EX_FATAL); } /* put netcdf file into define mode */ if ((status = nc_redef (exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg,"Error: failed to place file id %d into define mode",exoid); ex_err("ex_put_attr_param",errmsg,exerrval); return (EX_FATAL); } if ((status = nc_def_dim(exoid, dnumobjatt, num_attrs, &numattrdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define number of attributes in %s %d in file id %d", ex_name_of_object(obj_type), obj_id,exoid); ex_err("ex_put_attr_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } dims[0] = numobjentdim; dims[1] = numattrdim; if ((status = nc_def_var(exoid, vobjatt, nc_flt_code(exoid), 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define attributes for %s %d in file id %d", ex_name_of_object(obj_type), obj_id,exoid); ex_err("ex_put_attr_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* inquire previously defined dimensions */ if ((status = nc_inq_dimid(exoid, DIM_STR_NAME, &strdim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get string length in file id %d",exoid); ex_err("ex_put_attr_param",errmsg,exerrval); return (EX_FATAL); } /* Attribute names... */ dims[0] = numattrdim; dims[1] = strdim; if ((status = nc_def_var(exoid, vattnam, NC_CHAR, 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define %s attribute name array in file id %d", ex_name_of_object(obj_type), exoid); ex_err("ex_put_attr_param",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } /* leave define mode */ if ((status = nc_enddef(exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to complete %s attribute parameter definition in file id %d", ex_name_of_object(obj_type), exoid); ex_err("ex_put_attr_param",errmsg,exerrval); return (EX_FATAL); } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (nc_enddef (exoid) != NC_NOERR) { /* exit define mode */ sprintf(errmsg, "Error: failed to complete definition for file id %d", exoid); ex_err("ex_put_attr_param",errmsg,exerrval); } return (EX_FATAL); }