15 #include "nc4internal.h" 16 #include "nc4dispatch.h" 33 NC4_inq_unlimdim(
int ncid,
int *unlimdimidp)
36 NC_GRP_INFO_T *grp, *g;
37 NC_HDF5_FILE_INFO_T *h5;
42 LOG((2,
"%s: called", __func__));
44 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
51 for (g = grp; g && !found; g = g->parent)
53 for (dim = g->dim; dim; dim = dim->l.next)
57 *unlimdimidp = dim->dimid;
90 NC4_def_dim(
int ncid,
const char *name,
size_t len,
int *idp)
94 NC_HDF5_FILE_INFO_T *h5;
100 LOG((2,
"%s: ncid 0x%x name %s len %d", __func__, ncid, name,
104 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
106 assert(h5 && nc && grp);
117 for (dim = grp->dim; dim; dim = dim->l.next)
122 if (!(h5->flags & NC_INDEF))
127 if (!(h5->flags & NC_INDEF))
128 if ((retval = NC4_redef(ncid)))
132 if ((retval = nc4_check_name(name, norm_name)))
141 nn_hash = hash_fast(norm_name, strlen(norm_name));
144 for (dim = grp->dim; dim; dim = dim->l.next)
145 if (nn_hash == dim->hash && !strncmp(dim->name, norm_name,
NC_MAX_NAME))
150 nc4_dim_list_add(&grp->dim, &dim);
151 dim->dimid = grp->nc4_info->next_dimid++;
154 if (!(dim->name = strdup(norm_name)))
158 dim->unlimited = NC_TRUE;
182 NC4_inq_dimid(
int ncid,
const char *name,
int *idp)
185 NC_GRP_INFO_T *grp, *g;
186 NC_HDF5_FILE_INFO_T *h5;
193 LOG((2,
"%s: ncid 0x%x name %s", __func__, ncid, name));
196 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
203 if ((retval = nc4_normalize_name(name, norm_name)))
206 shash = hash_fast(norm_name, strlen(norm_name));
209 for (g = grp; g && !finished; g = g->parent)
210 for (dim = g->dim; dim; dim = dim->l.next)
211 if (dim->hash == shash && !strncmp(dim->name, norm_name,
NC_MAX_NAME))
237 NC4_inq_dim(
int ncid,
int dimid,
char *name,
size_t *lenp)
240 NC_HDF5_FILE_INFO_T *h5;
241 NC_GRP_INFO_T *grp, *dim_grp;
245 LOG((2,
"%s: ncid 0x%x dimid %d", __func__, ncid, dimid));
248 if ((ret = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
255 if ((ret = nc4_find_dim(grp, dimid, &dim, &dim_grp)))
260 if (name && dim->name)
261 strcpy(name, dim->name);
273 if ((ret = nc4_find_dim_len(dim_grp, dimid, &lenp)))
311 NC4_rename_dim(
int ncid,
int dimid,
const char *name)
315 NC_HDF5_FILE_INFO_T *h5;
316 NC_DIM_INFO_T *dim, *tmp_dim;
323 LOG((2,
"%s: ncid 0x%x dimid %d name %s", __func__, ncid,
327 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
329 assert(nc && h5 && grp);
336 if ((retval = nc4_check_name(name, norm_name)))
341 for (dim = grp->dim; dim; dim = dim->l.next)
345 if (dim->dimid == dimid)
353 if (dim->hdf_dimscaleid)
356 assert(!dim->coord_var);
357 LOG((3,
"dim %s is a dim without variable", dim->name));
360 if ((retval = delete_existing_dimscale_dataset(grp, dimid, dim)))
368 if (!(dim->name = malloc((strlen(norm_name) + 1) *
sizeof(
char))))
370 strcpy(dim->name, norm_name);
371 dim->hash = hash_fast(norm_name, strlen(norm_name));
372 LOG((3,
"dim is now named %s", dim->name));
376 if (dim->coord_var && strcmp(dim->name, dim->coord_var->name))
379 if ((retval = nc4_break_coord_var(grp, dim->coord_var, dim)))
390 if ((retval = nc4_find_var(grp, dim->name, &var)))
395 if (var && var->dim[0] == dim)
398 assert(var->dimids[0] == dim->dimid);
401 if ((retval = nc4_reform_coord_var(grp, var, dim)))
425 NC4_inq_unlimdims(
int ncid,
int *nunlimdimsp,
int *unlimdimidsp)
430 NC_HDF5_FILE_INFO_T *h5;
434 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
437 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
443 for (dim=grp->dim; dim; dim=dim->l.next)
448 unlimdimidsp[num_unlim] = dim->dimid;
456 *nunlimdimsp = num_unlim;
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_EUNLIMIT
NC_UNLIMITED size already in use.
#define NC_CLASSIC_MODEL
Enforce classic model on netCDF-4.
#define NC_ENOTINDEFINE
Operation not allowed in data mode.
#define NC_EBADDIM
Invalid dimension id or name.
#define NC_EDIMSIZE
Invalid dimension size.
#define NC_ENAMEINUSE
String match to name in use.
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_UNLIMITED
Size argument to nc_def_dim() for an unlimited dimension.
#define NC_MAX_UINT
Max or min values for a type.
#define NC_EPERM
Write to read only.
#define NC_NOERR
No Error.