14 #include <nc4internal.h> 15 #include "nc4dispatch.h" 16 #include "hdf5internal.h" 38 NC4_set_var_chunk_cache(
int ncid,
int varid,
size_t size,
size_t nelems,
48 if (preemption < 0 || preemption > 1)
52 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
54 assert(nc && grp && h5);
57 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
60 assert(var && var->hdr.id == varid);
63 var->chunk_cache_size = size;
64 var->chunk_cache_nelems = nelems;
65 var->chunk_cache_preemption = preemption;
67 if ((retval = nc4_reopen_dataset(grp, var)))
87 nc_set_var_chunk_cache_ints(
int ncid,
int varid,
int size,
int nelems,
90 size_t real_size = H5D_CHUNK_CACHE_NBYTES_DEFAULT;
91 size_t real_nelems = H5D_CHUNK_CACHE_NSLOTS_DEFAULT;
92 float real_preemption = CHUNK_CACHE_PREEMPTION;
95 real_size = ((size_t) size) * MEGABYTE;
101 real_preemption = preemption / 100.;
103 return NC4_set_var_chunk_cache(ncid, varid, real_size, real_nelems,
124 NC4_get_var_chunk_cache(
int ncid,
int varid,
size_t *sizep,
125 size_t *nelemsp,
float *preemptionp)
134 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
136 assert(nc && grp && h5);
139 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
142 assert(var && var->hdr.id == varid);
146 *sizep = var->chunk_cache_size;
148 *nelemsp = var->chunk_cache_nelems;
150 *preemptionp = var->chunk_cache_preemption;
172 nc_get_var_chunk_cache_ints(
int ncid,
int varid,
int *sizep,
173 int *nelemsp,
int *preemptionp)
175 size_t real_size, real_nelems;
176 float real_preemption;
179 if ((ret = NC4_get_var_chunk_cache(ncid, varid, &real_size,
180 &real_nelems, &real_preemption)))
184 *sizep = real_size / MEGABYTE;
186 *nelemsp = (int)real_nelems;
188 *preemptionp = (int)(real_preemption * 100);
231 NC4_inq_var_all(
int ncid,
int varid,
char *name,
nc_type *xtypep,
232 int *ndimsp,
int *dimidsp,
int *nattsp,
233 int *shufflep,
int *deflatep,
int *deflate_levelp,
234 int *fletcher32p,
int *contiguousp,
size_t *chunksizesp,
235 int *no_fill,
void *fill_valuep,
int *endiannessp,
236 unsigned int* idp,
size_t* nparamsp,
unsigned int* params
246 LOG((2,
"%s: ncid 0x%x varid %d", __func__, ncid, varid));
249 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
263 if (grp->atts_not_read)
264 if ((retval = nc4_read_atts(grp, NULL)))
267 *nattsp = ncindexcount(grp->att);
273 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
276 assert(var && var->hdr.id == varid);
280 strcpy(name, var->hdr.name);
282 *xtypep = var->type_info->hdr.id;
284 *ndimsp = var->ndims;
286 for (d = 0; d < var->ndims; d++)
287 dimidsp[d] = var->dimids[d];
290 if (var->atts_not_read)
291 if ((retval = nc4_read_atts(grp, var)))
293 *nattsp = ncindexcount(var->att);
297 if (!var->contiguous && chunksizesp)
298 for (d = 0; d < var->ndims; d++)
300 chunksizesp[d] = var->chunksizes[d];
301 LOG((4,
"chunksizesp[%d]=%d", d, chunksizesp[d]));
309 *deflatep = (int)var->deflate;
311 *deflate_levelp = var->deflate_level;
313 *shufflep = (int)var->shuffle;
315 *fletcher32p = (int)var->fletcher32;
318 *idp = var->filterid;
320 *nparamsp = (var->params == NULL ? 0 : var->nparams);
321 if (params && var->params != NULL)
322 memcpy(params,var->params,var->nparams*
sizeof(
unsigned int));
326 *no_fill = (int)var->no_fill;
330 if (!var->no_fill && fill_valuep)
335 if (var->type_info->nc_type_class ==
NC_STRING)
337 assert(*(
char **)var->fill_value);
339 if (!(*(
char **)fill_valuep = strdup(*(
char **)var->fill_value)))
341 free(*(
char **)fill_valuep);
347 assert(var->type_info->size);
348 memcpy(fill_valuep, var->fill_value, var->type_info->size);
353 if (var->type_info->nc_type_class ==
NC_STRING)
355 if (!(*(
char **)fill_valuep = calloc(1,
sizeof(
char *))))
358 if ((retval = nc4_get_default_fill_value(var->type_info, (
char **)fill_valuep)))
360 free(*(
char **)fill_valuep);
366 if ((retval = nc4_get_default_fill_value(var->type_info, fill_valuep)))
374 *endiannessp = var->type_info->endianness;
396 nc_inq_var_chunking_ints(
int ncid,
int varid,
int *contiguousp,
int *chunksizesp)
403 if ((retval = nc4_find_grp_h5_var(ncid, varid, NULL, NULL, &var)))
409 if (!(cs = malloc(var->ndims *
sizeof(
size_t))))
413 retval = NC4_inq_var_all(ncid, varid, NULL, NULL, NULL, NULL, NULL,
414 NULL, NULL, NULL, NULL, contiguousp, cs, NULL,
415 NULL, NULL, NULL, NULL, NULL);
418 if (!retval && chunksizesp && var->contiguous ==
NC_CHUNKED)
420 for (i = 0; i < var->ndims; i++)
422 chunksizesp[i] = (int)cs[i];
446 NC4_inq_varid(
int ncid,
const char *name,
int *varidp)
459 LOG((2,
"%s: ncid 0x%x name %s", __func__, ncid, name));
462 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, NULL)))
466 if ((retval = nc4_normalize_name(name, norm_name)))
470 var = (NC_VAR_INFO_T*)ncindexlookup(grp->vars,norm_name);
473 *varidp = var->hdr.id;
498 NC4_var_par_access(
int ncid,
int varid,
int par_access)
500 #ifndef USE_PARALLEL4 509 LOG((1,
"%s: ncid 0x%x varid %d par_access %d", __func__, ncid,
516 if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
524 var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
526 assert(var->hdr.id == varid);
#define NC_ENOMEM
Memory allocation (malloc) failure.
#define NC_CHUNKED
In HDF5 files you can set storage for each variable to be either contiguous or chunked, with nc_def_var_chunking().
#define NC_MAX_INT
Max or min values for a type.
#define NC_CONTIGUOUS
In HDF5 files you can set storage for each variable to be either contiguous or chunked, with nc_def_var_chunking().
#define NC_ERANGE
Math result not representable.
#define NC_INDEPENDENT
Use with nc_var_par_access() to set parallel access to independent.
int nc_type
The nc_type type is just an int.
#define NC_COLLECTIVE
Use with nc_var_par_access() to set parallel access to collective.
#define NC_EINVAL
Invalid Argument.
#define NC_MAX_NAME
Maximum for classic library.
#define NC_ENOPAR
Parallel operation on file opened for non-parallel access.
#define NC_ENOTVAR
Variable not found.
#define NC_NOERR
No Error.
#define NC_GLOBAL
Attribute id to put/get a global attribute.