/* Find the full path name to the group represented by ncid. Either * pointer argument may be NULL; pass a NULL for the third parameter * to get the length of the full path name. The length will not * include room for a null pointer. */ EXTERNL int nc_inq_grpname_full(int ncid, size_t *lenp, char *full_name) { char *name, grp_name[NC_MAX_NAME + 1]; int g, id = ncid, parent_id, *gid; int i, ret = NC_NOERR; /* How many generations? */ for (g = 0; !nc_inq_grp_parent(id, &parent_id); g++, id = parent_id) ; /* Allocate storage. */ if (!(name = malloc((g + 1) * (NC_MAX_NAME + 1) + 1))) return NC_ENOMEM; if (!(gid = malloc((g + 1) * sizeof(int)))) { free(name); return NC_ENOMEM; } assert(name && gid); /* Always start with a "/" for the root group. */ strcpy(name, "/"); /* Get the ncids for all generations. */ gid[0] = ncid; for (i = 1; i < g && !ret; i++) ret = nc_inq_grp_parent(gid[i - 1], &gid[i]); /* Assemble the full name. */ for (i = g - 1; !ret && i >= 0 && !ret; i--) { if ((ret = nc_inq_grpname(gid[i], grp_name))) break; strcat(name, grp_name); if (i) strcat(name, "/"); } /* Give the user the length of the name, if he wants it. */ if (!ret && lenp) *lenp = strlen(name); /* Give the user the name, if he wants it. */ if (!ret && full_name) strcpy(full_name, name); free(gid); free(name); return ret; }
/* get group id in output corresponding to group igrp in input, * given parent group id (or root group id) parid in output. */ static int get_grpid(int igrp, int parid, int *ogrpp) { int stat = NC_NOERR; int ogid; /* like igrp but in output file */ #ifdef USE_NETCDF4 int inparid; /* if not root group, get corresponding output groupid from group name */ stat = nc_inq_grp_parent(igrp, &inparid); if(stat == NC_NOERR) { /* not root group */ char grpname[NC_MAX_NAME + 1]; NC_CHECK(nc_inq_grpname(igrp, grpname)); NC_CHECK(nc_inq_grp_ncid(parid, grpname, &ogid)); } else if(stat == NC_ENOGRP) { /* root group */ ogid = parid; stat = NC_NOERR; } else { NC_CHECK(stat); } #else ogid = parid; #endif /* USE_NETCDF4 */ *ogrpp = ogid; return stat; }
/*! The function ex_close() updates and then closes an open exodus file. \return In case of an error, ex_close() returns a negative number; a warning will return a positive number. Possible causes of errors include: - data file not properly opened with call to ex_create() or ex_open() \param exoid exodus file ID returned from a previous call to ex_create() or ex_open(). The following code segment closes an open exodus file: \code int error,exoid; error = ex_close (exoid); \endcode */ int ex_close (int exoid) { char errmsg[MAX_ERR_LENGTH]; int status; int parent_id = 0; exerrval = 0; /* clear error code */ /* * NOTE: If using netcdf-4, exoid must refer to the root group. * Need to determine whether there are any groups and if so, * call ex_rm_file_item and ex_rm_stat_ptr on each group. */ #if defined(ENABLE_NETCDF4) /* nc_inq_grp_parent() will return NC_ENOGRP error if exoid * refers to the root group (which is what we want) */ if ((status = nc_inq_grp_parent(exoid, &parent_id)) != NC_ENOGRP) { exerrval = EX_NOTROOTID; sprintf(errmsg,"Error: file id %d does not refer to root group.",exoid); ex_err("ex_close",errmsg,exerrval); return(EX_FATAL); } #endif if ((status = nc_sync(exoid)) != NC_NOERR) { exerrval = status; sprintf(errmsg,"Error: failed to update file id %d",exoid); ex_err("ex_close",errmsg,exerrval); return(EX_FATAL); } if ((status = nc_close (exoid)) == NC_NOERR) { ex_conv_exit(exoid); ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK)); ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK)); ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK)); ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_SIDE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_MAP)); ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_MAP)); ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_MAP)); ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_MAP)); ex_rm_stat_ptr (exoid, &exoII_ed); ex_rm_stat_ptr (exoid, &exoII_fa); ex_rm_stat_ptr (exoid, &exoII_eb); ex_rm_stat_ptr (exoid, &exoII_ns); ex_rm_stat_ptr (exoid, &exoII_es); ex_rm_stat_ptr (exoid, &exoII_fs); ex_rm_stat_ptr (exoid, &exoII_ss); ex_rm_stat_ptr (exoid, &exoII_els); ex_rm_stat_ptr (exoid, &exoII_nm); ex_rm_stat_ptr (exoid, &exoII_edm); ex_rm_stat_ptr (exoid, &exoII_fam); ex_rm_stat_ptr (exoid, &exoII_em); } else { exerrval = status; sprintf(errmsg, "Error: failed to close file id %d",exoid); ex_err("ex_close",errmsg, status); return(EX_FATAL); } return(EX_NOERR); }
/*! The function ex_close() updates and then closes an open exodus file. \return In case of an error, ex_close() returns a negative number; a warning will return a positive number. Possible causes of errors include: - data file not properly opened with call to ex_create() or ex_open() \param exoid exodus file ID returned from a previous call to ex_create() or ex_open(). The following code segment closes an open exodus file: ~~~{.c} int error,exoid; error = ex_close (exoid); ~~~ */ int ex_close(int exoid) { char errmsg[MAX_ERR_LENGTH]; int status; int status1; int status2; #if NC_HAS_HDF5 int parent_id = 0; #endif EX_FUNC_ENTER(); ex_check_valid_file_id(exoid, __func__); /* * NOTE: If using netcdf-4, exoid must refer to the root group. * Need to determine whether there are any groups and if so, * call ex_rm_file_item and ex_rm_stat_ptr on each group. */ #if NC_HAS_HDF5 /* nc_inq_grp_parent() will return NC_ENOGRP error if exoid * refers to the root group (which is what we want) */ if ((status = nc_inq_grp_parent(exoid, &parent_id)) != NC_ENOGRP) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: file id %d does not refer to root group.", exoid); ex_err(__func__, errmsg, EX_NOTROOTID); EX_FUNC_LEAVE(EX_FATAL); } #endif if ((status1 = nc_sync(exoid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to update file id %d", exoid); ex_err(__func__, errmsg, status1); } if ((status2 = nc_close(exoid)) != NC_NOERR) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to close file id %d", exoid); ex_err(__func__, errmsg, status2); } /* Even if we have failures above due to nc_sync() or nc_close(), we still need to clean up our * internal datastructures. */ ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_BLOCK)); ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_BLOCK)); ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_BLOCK)); ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_SIDE_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_SET)); ex_rm_file_item(exoid, ex_get_counter_list(EX_NODE_MAP)); ex_rm_file_item(exoid, ex_get_counter_list(EX_EDGE_MAP)); ex_rm_file_item(exoid, ex_get_counter_list(EX_FACE_MAP)); ex_rm_file_item(exoid, ex_get_counter_list(EX_ELEM_MAP)); ex_rm_stat_ptr(exoid, &exoII_ed); ex_rm_stat_ptr(exoid, &exoII_fa); ex_rm_stat_ptr(exoid, &exoII_eb); ex_rm_stat_ptr(exoid, &exoII_ns); ex_rm_stat_ptr(exoid, &exoII_es); ex_rm_stat_ptr(exoid, &exoII_fs); ex_rm_stat_ptr(exoid, &exoII_ss); ex_rm_stat_ptr(exoid, &exoII_els); ex_rm_stat_ptr(exoid, &exoII_nm); ex_rm_stat_ptr(exoid, &exoII_edm); ex_rm_stat_ptr(exoid, &exoII_fam); ex_rm_stat_ptr(exoid, &exoII_em); ex_conv_exit(exoid); status = EX_NOERR; if (status1 != NC_NOERR || status2 != NC_NOERR) { status = EX_FATAL; } EX_FUNC_LEAVE(status); }