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)))
46 assert(h5 && nc && grp);
53 for (g = grp; g && !found; g = g->parent)
55 for (dim = g->dim; dim; dim = dim->l.next)
59 *unlimdimidp = dim->dimid;
94 NC4_def_dim(
int ncid,
const char *name,
size_t len,
int *idp)
98 NC_HDF5_FILE_INFO_T *h5;
104 LOG((2,
"%s: ncid 0x%x name %s len %d", __func__, ncid, name,
108 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
110 assert(h5 && nc && grp);
121 for (dim = grp->dim; dim; dim = dim->l.next)
126 if (!(h5->flags & NC_INDEF))
131 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))
151 if (!(h5->flags & NC_INDEF))
152 if ((retval = NC4_redef(ncid)))
157 if ((retval = nc4_dim_list_add(&grp->dim, &dim)))
159 dim->dimid = grp->nc4_info->next_dimid++;
162 if (!(dim->name = strdup(norm_name)))
166 dim->unlimited = NC_TRUE;
191 NC4_inq_dimid(
int ncid,
const char *name,
int *idp)
194 NC_GRP_INFO_T *grp, *g;
195 NC_HDF5_FILE_INFO_T *h5;
202 LOG((2,
"%s: ncid 0x%x name %s", __func__, ncid, name));
209 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
211 assert(h5 && nc && grp);
214 if ((retval = nc4_normalize_name(name, norm_name)))
217 shash = hash_fast(norm_name, strlen(norm_name));
220 for (g = grp; g && !finished; g = g->parent)
221 for (dim = g->dim; dim; dim = dim->l.next)
222 if (dim->hash == shash && !strncmp(dim->name, norm_name,
NC_MAX_NAME))
249 NC4_inq_dim(
int ncid,
int dimid,
char *name,
size_t *lenp)
252 NC_HDF5_FILE_INFO_T *h5;
253 NC_GRP_INFO_T *grp, *dim_grp;
257 LOG((2,
"%s: ncid 0x%x dimid %d", __func__, ncid, dimid));
260 if ((ret = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
262 assert(h5 && nc && grp);
265 if ((ret = nc4_find_dim(grp, dimid, &dim, &dim_grp)))
270 if (name && dim->name)
271 strcpy(name, dim->name);
283 if ((ret = nc4_find_dim_len(dim_grp, dimid, &lenp)))
321 NC4_rename_dim(
int ncid,
int dimid,
const char *name)
325 NC_HDF5_FILE_INFO_T *h5;
326 NC_DIM_INFO_T *dim, *tmp_dim;
333 LOG((2,
"%s: ncid 0x%x dimid %d name %s", __func__, ncid,
337 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
339 assert(nc && h5 && grp);
346 if ((retval = nc4_check_name(name, norm_name)))
351 for (dim = grp->dim; dim; dim = dim->l.next)
355 if (dim->dimid == dimid)
363 if (dim->hdf_dimscaleid)
366 assert(!dim->coord_var);
367 LOG((3,
"dim %s is a dim without variable", dim->name));
370 if ((retval = delete_existing_dimscale_dataset(grp, dimid, dim)))
378 if (!(dim->name = malloc((strlen(norm_name) + 1) *
sizeof(
char))))
380 strcpy(dim->name, norm_name);
381 dim->hash = hash_fast(norm_name, strlen(norm_name));
382 LOG((3,
"dim is now named %s", dim->name));
386 if (dim->coord_var && strcmp(dim->name, dim->coord_var->name))
389 if ((retval = nc4_break_coord_var(grp, dim->coord_var, dim)))
400 if ((retval = nc4_find_var(grp, dim->name, &var)))
405 if (var && var->dim[0] == dim)
408 assert(var->dimids[0] == dim->dimid);
411 if ((retval = nc4_reform_coord_var(grp, var, dim)))
435 NC4_inq_unlimdims(
int ncid,
int *nunlimdimsp,
int *unlimdimidsp)
440 NC_HDF5_FILE_INFO_T *h5;
444 LOG((2,
"%s: ncid 0x%x", __func__, ncid));
447 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
449 assert(h5 && nc && grp);
454 for (dim=grp->dim; dim; dim=dim->l.next)
459 unlimdimidsp[num_unlim] = dim->dimid;
467 *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.