/* Given an NC pointer, add the necessary stuff for a * netcdf-4 file. */ int nc4_nc4f_list_add(NC *nc, const char *path, int mode) { NC_HDF5_FILE_INFO_T *h5; assert(nc && !NC4_DATA(nc) && path); /* We need to malloc and initialize the substructure NC_HDF_FILE_INFO_T. */ if (!(h5 = calloc(1, sizeof(NC_HDF5_FILE_INFO_T)))) return NC_ENOMEM; NC4_DATA_SET(nc,h5); h5->controller = nc; /* Hang on to cmode, and note that we're in define mode. */ h5->cmode = mode | NC_INDEF; /* The next_typeid needs to be set beyond the end of our atomic * types. */ h5->next_typeid = NC_FIRSTUSERTYPEID; /* There's always at least one open group - the root * group. Allocate space for one group's worth of information. Set * its hdf id, name, and a pointer to it's file structure. */ return nc4_grp_list_add(&(h5->root_grp), h5->next_nc_grpid++, NULL, nc, NC_GROUP_NAME, NULL); }
/* Given an NC_FILE_INFO_T pointer, add the necessary stuff for a * netcdf-4 file. */ int nc4_nc4f_list_add(NC_FILE_INFO_T *nc, const char *path, int mode) { NC_HDF5_FILE_INFO_T *h5; NC_GRP_INFO_T *grp; assert(nc && !nc->nc4_info && path); /* The NC_FILE_INFO_T was allocated and inited by ncfunc.c before this function is called. We need to malloc and initialize the substructure NC_HDF_FILE_INFO_T. */ if (!(nc->nc4_info = calloc(1, sizeof(NC_HDF5_FILE_INFO_T)))) return NC_ENOMEM; h5 = nc->nc4_info; /* Hang on to the filename for nc_abort. */ if (!(h5->path = malloc((strlen(path) + 1) * sizeof(char)))) return NC_ENOMEM; strcpy(h5->path, path); /* Hang on to cmode, and note that we're in define mode. */ h5->cmode = mode | NC_INDEF; /* The next_typeid needs to be set beyond the end of our atomic * types. */ h5->next_typeid = NC_FIRSTUSERTYPEID; /* There's always at least one open group - the root * group. Allocate space for one group's worth of information. Set * its hdf id, name, and a pointer to it's file structure. */ return nc4_grp_list_add(&(h5->root_grp), h5->next_nc_grpid++, NULL, nc, NC_GROUP_NAME, &grp); }
/* Create a group. It's ncid is returned in the new_ncid pointer. */ int NC4_def_grp(int parent_ncid, const char *name, int *new_ncid) { NC_GRP_INFO_T *grp, *g; NC_HDF5_FILE_INFO_T *h5; char norm_name[NC_MAX_NAME + 1]; int retval; LOG((2, "%s: parent_ncid 0x%x name %s", __func__, parent_ncid, name)); /* Find info for this file and group, and set pointer to each. */ if ((retval = nc4_find_grp_h5(parent_ncid, &grp, &h5))) return retval; if (!h5) return NC_ENOTNC4; /* Check and normalize the name. */ if ((retval = nc4_check_name(name, norm_name))) return retval; /* Check that this name is not in use as a var, grp, or type. */ if ((retval = nc4_check_dup_name(grp, norm_name))) return retval; /* No groups in netcdf-3! */ if (h5->cmode & NC_CLASSIC_MODEL) return NC_ESTRICTNC3; /* If it's not in define mode, switch to define mode. */ if (!(h5->flags & NC_INDEF)) if ((retval = NC4_redef(parent_ncid))) return retval; /* Update internal lists to reflect new group. The actual HDF5 * group creation will be done when metadata is written by a * sync. */ if ((retval = nc4_grp_list_add(&(grp->children), h5->next_nc_grpid, grp, grp->nc4_info->controller, norm_name, &g))) return retval; if (new_ncid) *new_ncid = grp->nc4_info->controller->ext_ncid | h5->next_nc_grpid; h5->next_nc_grpid++; return NC_NOERR; }