/* * 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_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); }
/*! * 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); }
/*! * 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_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); }