2018-07-19 21:05:55 +08:00
|
|
|
/* Copyright 2003-2006, University Corporation for Atmospheric
|
|
|
|
* Research. See COPYRIGHT file for copying and redistribution
|
|
|
|
* conditions.*/
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
|
|
|
* @file
|
2018-07-19 21:05:55 +08:00
|
|
|
* @internal This file is part of netcdf-4, a netCDF-like interface
|
|
|
|
* for HDF5, or a HDF5 backend for netCDF, depending on your point of
|
|
|
|
* view. This file handles the NetCDF-4 variable functions.
|
|
|
|
*
|
|
|
|
* @author Ed Hartnett, Dennis Heimbigner, Ward Fisher
|
2017-12-01 23:18:49 +08:00
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2018-07-19 21:23:03 +08:00
|
|
|
#include "config.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
#include <nc4internal.h>
|
|
|
|
#include "nc4dispatch.h"
|
2018-07-12 21:05:21 +08:00
|
|
|
#include "hdf5internal.h"
|
2010-06-03 21:24:43 +08:00
|
|
|
#include <math.h>
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
|
|
|
* @internal Set chunk cache size for a variable. This is the internal
|
|
|
|
* function called by nc_set_var_chunk_cache().
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param size Size in bytes to set cache.
|
|
|
|
* @param nelems Number of elements in cache.
|
|
|
|
* @param preemption Controls cache swapping.
|
|
|
|
*
|
|
|
|
* @returns ::NC_NOERR No error.
|
|
|
|
* @returns ::NC_EBADID Bad ncid.
|
|
|
|
* @returns ::NC_ENOTVAR Invalid variable ID.
|
|
|
|
* @returns ::NC_ESTRICTNC3 Attempting netcdf-4 operation on strict nc3 netcdf-4 file.
|
|
|
|
* @returns ::NC_EINVAL Invalid input.
|
2017-12-02 00:08:12 +08:00
|
|
|
* @returns ::NC_EHDFERR HDF5 error.
|
2017-12-01 23:18:49 +08:00
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2016-01-01 02:47:39 +08:00
|
|
|
NC4_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems,
|
2017-12-01 23:18:49 +08:00
|
|
|
float preemption)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc;
|
2016-01-01 02:47:39 +08:00
|
|
|
NC_GRP_INFO_T *grp;
|
2018-06-22 21:08:09 +08:00
|
|
|
NC_FILE_INFO_T *h5;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Check input for validity. */
|
|
|
|
if (preemption < 0 || preemption > 1)
|
|
|
|
return NC_EINVAL;
|
|
|
|
|
|
|
|
/* Find info for this file and group, and set pointer to each. */
|
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
|
|
|
return retval;
|
|
|
|
assert(nc && grp && h5);
|
|
|
|
|
|
|
|
/* Find the var. */
|
2018-03-17 01:46:18 +08:00
|
|
|
var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
|
|
|
|
if(!var)
|
2018-07-19 21:33:48 +08:00
|
|
|
return NC_ENOTVAR;
|
2018-03-17 01:46:18 +08:00
|
|
|
assert(var && var->hdr.id == varid);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Set the values. */
|
|
|
|
var->chunk_cache_size = size;
|
|
|
|
var->chunk_cache_nelems = nelems;
|
|
|
|
var->chunk_cache_preemption = preemption;
|
|
|
|
|
|
|
|
if ((retval = nc4_reopen_dataset(grp, var)))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
|
|
|
* @internal A wrapper for NC4_set_var_chunk_cache(), we need this
|
|
|
|
* version for fortran. Negative values leave settings as they are.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param size Size in bytes to set cache.
|
|
|
|
* @param nelems Number of elements in cache.
|
|
|
|
* @param preemption Controls cache swapping.
|
|
|
|
*
|
|
|
|
* @returns ::NC_NOERR for success
|
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2016-01-01 02:47:39 +08:00
|
|
|
nc_set_var_chunk_cache_ints(int ncid, int varid, int size, int nelems,
|
2017-12-01 23:18:49 +08:00
|
|
|
int preemption)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
size_t real_size = H5D_CHUNK_CACHE_NBYTES_DEFAULT;
|
|
|
|
size_t real_nelems = H5D_CHUNK_CACHE_NSLOTS_DEFAULT;
|
2017-12-02 22:15:19 +08:00
|
|
|
float real_preemption = CHUNK_CACHE_PREEMPTION;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
if (size >= 0)
|
2017-12-01 23:18:49 +08:00
|
|
|
real_size = ((size_t) size) * MEGABYTE;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
if (nelems >= 0)
|
|
|
|
real_nelems = nelems;
|
|
|
|
|
|
|
|
if (preemption >= 0)
|
|
|
|
real_preemption = preemption / 100.;
|
2016-01-01 02:47:39 +08:00
|
|
|
|
|
|
|
return NC4_set_var_chunk_cache(ncid, varid, real_size, real_nelems,
|
2017-12-01 23:18:49 +08:00
|
|
|
real_preemption);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
|
|
|
* @internal This is called by nc_get_var_chunk_cache(). Get chunk
|
|
|
|
* cache size for a variable.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param sizep Gets size in bytes of cache.
|
|
|
|
* @param nelemsp Gets number of element slots in cache.
|
|
|
|
* @param preemptionp Gets cache swapping setting.
|
|
|
|
*
|
|
|
|
* @returns ::NC_NOERR No error.
|
|
|
|
* @returns ::NC_EBADID Bad ncid.
|
|
|
|
* @returns ::NC_ENOTVAR Invalid variable ID.
|
|
|
|
* @returns ::NC_ENOTNC4 Not a netCDF-4 file.
|
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2016-01-01 02:47:39 +08:00
|
|
|
NC4_get_var_chunk_cache(int ncid, int varid, size_t *sizep,
|
2017-12-01 23:18:49 +08:00
|
|
|
size_t *nelemsp, float *preemptionp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc;
|
2016-01-01 02:47:39 +08:00
|
|
|
NC_GRP_INFO_T *grp;
|
2018-06-22 21:08:09 +08:00
|
|
|
NC_FILE_INFO_T *h5;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
/* Find info for this file and group, and set pointer to each. */
|
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
|
|
|
return retval;
|
|
|
|
assert(nc && grp && h5);
|
|
|
|
|
|
|
|
/* Find the var. */
|
2018-03-17 01:46:18 +08:00
|
|
|
var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
|
|
|
|
if(!var)
|
2018-07-19 21:33:48 +08:00
|
|
|
return NC_ENOTVAR;
|
2018-03-17 01:46:18 +08:00
|
|
|
assert(var && var->hdr.id == varid);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Give the user what they want. */
|
|
|
|
if (sizep)
|
|
|
|
*sizep = var->chunk_cache_size;
|
|
|
|
if (nelemsp)
|
|
|
|
*nelemsp = var->chunk_cache_nelems;
|
|
|
|
if (preemptionp)
|
|
|
|
*preemptionp = var->chunk_cache_preemption;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
|
|
|
* @internal A wrapper for NC4_get_var_chunk_cache(), we need this
|
|
|
|
* version for fortran.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param sizep Gets size in bytes of cache.
|
|
|
|
* @param nelemsp Gets number of element slots in cache.
|
|
|
|
* @param preemptionp Gets cache swapping setting.
|
|
|
|
*
|
|
|
|
* @returns ::NC_NOERR No error.
|
|
|
|
* @returns ::NC_EBADID Bad ncid.
|
|
|
|
* @returns ::NC_ENOTVAR Invalid variable ID.
|
|
|
|
* @returns ::NC_ENOTNC4 Not a netCDF-4 file.
|
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2016-01-01 02:47:39 +08:00
|
|
|
nc_get_var_chunk_cache_ints(int ncid, int varid, int *sizep,
|
2017-12-01 23:18:49 +08:00
|
|
|
int *nelemsp, int *preemptionp)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
|
|
|
size_t real_size, real_nelems;
|
|
|
|
float real_preemption;
|
|
|
|
int ret;
|
|
|
|
|
2016-01-01 02:47:39 +08:00
|
|
|
if ((ret = NC4_get_var_chunk_cache(ncid, varid, &real_size,
|
2017-12-01 23:18:49 +08:00
|
|
|
&real_nelems, &real_preemption)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return ret;
|
2016-01-01 02:47:39 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
if (sizep)
|
|
|
|
*sizep = real_size / MEGABYTE;
|
|
|
|
if (nelemsp)
|
|
|
|
*nelemsp = (int)real_nelems;
|
|
|
|
if(preemptionp)
|
|
|
|
*preemptionp = (int)(real_preemption * 100);
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
2018-01-05 21:01:22 +08:00
|
|
|
* @internal Get all the information about a variable. Pass NULL for
|
|
|
|
* whatever you don't care about. This is the internal function called
|
|
|
|
* by nc_inq_var(), nc_inq_var_deflate(), nc_inq_var_fletcher32(),
|
|
|
|
* nc_inq_var_chunking(), nc_inq_var_chunking_ints(),
|
|
|
|
* nc_inq_var_fill(), nc_inq_var_endian(), nc_inq_var_filter(), and
|
|
|
|
* nc_inq_var_szip().
|
2017-12-01 23:18:49 +08:00
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param name Gets name.
|
|
|
|
* @param xtypep Gets type.
|
|
|
|
* @param ndimsp Gets number of dims.
|
|
|
|
* @param dimidsp Gets array of dim IDs.
|
|
|
|
* @param nattsp Gets number of attributes.
|
|
|
|
* @param shufflep Gets shuffle setting.
|
|
|
|
* @param deflatep Gets deflate setting.
|
|
|
|
* @param deflate_levelp Gets deflate level.
|
|
|
|
* @param fletcher32p Gets fletcher32 setting.
|
|
|
|
* @param contiguousp Gets contiguous setting.
|
|
|
|
* @param chunksizesp Gets chunksizes.
|
|
|
|
* @param no_fill Gets fill mode.
|
|
|
|
* @param fill_valuep Gets fill value.
|
|
|
|
* @param endiannessp Gets one of ::NC_ENDIAN_BIG ::NC_ENDIAN_LITTLE
|
|
|
|
* ::NC_ENDIAN_NATIVE
|
|
|
|
* @param idp Pointer to memory to store filter id.
|
|
|
|
* @param nparamsp Pointer to memory to store filter parameter count.
|
|
|
|
* @param params Pointer to vector of unsigned integers into which
|
|
|
|
* to store filter parameters.
|
|
|
|
*
|
|
|
|
* @returns ::NC_NOERR No error.
|
|
|
|
* @returns ::NC_EBADID Bad ncid.
|
|
|
|
* @returns ::NC_ENOTVAR Bad varid.
|
|
|
|
* @returns ::NC_ENOMEM Out of memory.
|
|
|
|
* @returns ::NC_EINVAL Invalid input.
|
|
|
|
* @author Ed Hartnett, Dennis Heimbigner
|
|
|
|
*/
|
2016-01-01 02:47:39 +08:00
|
|
|
int
|
|
|
|
NC4_inq_var_all(int ncid, int varid, char *name, nc_type *xtypep,
|
2017-12-01 23:18:49 +08:00
|
|
|
int *ndimsp, int *dimidsp, int *nattsp,
|
|
|
|
int *shufflep, int *deflatep, int *deflate_levelp,
|
|
|
|
int *fletcher32p, int *contiguousp, size_t *chunksizesp,
|
|
|
|
int *no_fill, void *fill_valuep, int *endiannessp,
|
|
|
|
unsigned int* idp, size_t* nparamsp, unsigned int* params
|
|
|
|
)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc;
|
2016-01-01 02:47:39 +08:00
|
|
|
NC_GRP_INFO_T *grp;
|
2018-06-22 21:08:09 +08:00
|
|
|
NC_FILE_INFO_T *h5;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
int d;
|
|
|
|
int retval;
|
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((2, "%s: ncid 0x%x varid %d", __func__, ncid, varid));
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Find info for this file and group, and set pointer to each. */
|
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
|
|
|
return retval;
|
|
|
|
|
2013-01-15 11:46:46 +08:00
|
|
|
assert(nc);
|
2013-01-18 10:25:12 +08:00
|
|
|
assert(grp && h5);
|
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Walk through the list of vars, and return the info about the one
|
|
|
|
with a matching varid. If the varid is -1, find the global
|
|
|
|
atts and call it a day. */
|
|
|
|
if (varid == NC_GLOBAL)
|
|
|
|
{
|
|
|
|
if (nattsp)
|
|
|
|
{
|
2018-06-19 21:56:54 +08:00
|
|
|
/* Do we need to read the atts? */
|
|
|
|
if (grp->atts_not_read)
|
2018-07-21 21:29:12 +08:00
|
|
|
if ((retval = nc4_read_grp_atts2(grp)))
|
2018-06-19 21:56:54 +08:00
|
|
|
return retval;
|
|
|
|
|
2018-07-19 21:33:48 +08:00
|
|
|
*nattsp = ncindexcount(grp->att);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the var. */
|
2018-03-17 01:46:18 +08:00
|
|
|
var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
|
|
|
|
if(!var)
|
2017-12-01 23:18:49 +08:00
|
|
|
return NC_ENOTVAR;
|
2018-03-17 01:46:18 +08:00
|
|
|
assert(var && var->hdr.id == varid);
|
2016-01-01 02:47:39 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Copy the data to the user's data buffers. */
|
|
|
|
if (name)
|
2018-03-17 01:46:18 +08:00
|
|
|
strcpy(name, var->hdr.name);
|
2010-06-03 21:24:43 +08:00
|
|
|
if (xtypep)
|
2018-03-17 01:46:18 +08:00
|
|
|
*xtypep = var->type_info->hdr.id;
|
2010-06-03 21:24:43 +08:00
|
|
|
if (ndimsp)
|
|
|
|
*ndimsp = var->ndims;
|
|
|
|
if (dimidsp)
|
|
|
|
for (d = 0; d < var->ndims; d++)
|
|
|
|
dimidsp[d] = var->dimids[d];
|
|
|
|
if (nattsp)
|
|
|
|
{
|
2018-06-19 21:56:54 +08:00
|
|
|
if (var->atts_not_read)
|
|
|
|
if ((retval = nc4_read_var_atts(grp, var)))
|
|
|
|
return retval;
|
2018-03-17 01:46:18 +08:00
|
|
|
*nattsp = ncindexcount(var->att);
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
2016-01-01 02:47:39 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Chunking stuff. */
|
2010-07-01 05:05:11 +08:00
|
|
|
if (!var->contiguous && chunksizesp)
|
2010-06-03 21:24:43 +08:00
|
|
|
for (d = 0; d < var->ndims; d++)
|
|
|
|
{
|
|
|
|
chunksizesp[d] = var->chunksizes[d];
|
|
|
|
LOG((4, "chunksizesp[%d]=%d", d, chunksizesp[d]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contiguousp)
|
2010-07-01 19:39:34 +08:00
|
|
|
*contiguousp = var->contiguous ? NC_CONTIGUOUS : NC_CHUNKED;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Filter stuff. */
|
|
|
|
if (deflatep)
|
2014-02-12 07:12:08 +08:00
|
|
|
*deflatep = (int)var->deflate;
|
2010-06-03 21:24:43 +08:00
|
|
|
if (deflate_levelp)
|
|
|
|
*deflate_levelp = var->deflate_level;
|
|
|
|
if (shufflep)
|
2014-02-12 07:12:08 +08:00
|
|
|
*shufflep = (int)var->shuffle;
|
2010-06-03 21:24:43 +08:00
|
|
|
if (fletcher32p)
|
2014-02-12 07:12:08 +08:00
|
|
|
*fletcher32p = (int)var->fletcher32;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2017-04-28 03:01:59 +08:00
|
|
|
if (idp)
|
|
|
|
*idp = var->filterid;
|
|
|
|
if (nparamsp)
|
|
|
|
*nparamsp = (var->params == NULL ? 0 : var->nparams);
|
|
|
|
if (params && var->params != NULL)
|
2017-12-01 23:18:49 +08:00
|
|
|
memcpy(params,var->params,var->nparams*sizeof(unsigned int));
|
2017-04-28 03:01:59 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Fill value stuff. */
|
|
|
|
if (no_fill)
|
2014-02-12 07:12:08 +08:00
|
|
|
*no_fill = (int)var->no_fill;
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
/* Don't do a thing with fill_valuep if no_fill mode is set for
|
|
|
|
* this var, or if fill_valuep is NULL. */
|
|
|
|
if (!var->no_fill && fill_valuep)
|
|
|
|
{
|
|
|
|
/* Do we have a fill value for this var? */
|
2017-12-01 23:18:49 +08:00
|
|
|
if (var->fill_value)
|
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
if (var->type_info->nc_type_class == NC_STRING)
|
2017-12-01 23:18:49 +08:00
|
|
|
{
|
2018-01-31 05:39:47 +08:00
|
|
|
assert(*(char **)var->fill_value);
|
2018-02-14 05:17:15 +08:00
|
|
|
/* This will allocate memeory and copy the string. */
|
2018-01-31 05:39:47 +08:00
|
|
|
if (!(*(char **)fill_valuep = strdup(*(char **)var->fill_value)))
|
|
|
|
{
|
|
|
|
free(*(char **)fill_valuep);
|
|
|
|
return NC_ENOMEM;
|
2017-12-01 23:18:49 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 05:39:47 +08:00
|
|
|
else
|
|
|
|
{
|
2017-12-01 23:18:49 +08:00
|
|
|
assert(var->type_info->size);
|
|
|
|
memcpy(fill_valuep, var->fill_value, var->type_info->size);
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-12 07:12:08 +08:00
|
|
|
if (var->type_info->nc_type_class == NC_STRING)
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
{
|
2018-01-31 05:39:47 +08:00
|
|
|
if (!(*(char **)fill_valuep = calloc(1, sizeof(char *))))
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
return NC_ENOMEM;
|
2016-01-01 02:47:39 +08:00
|
|
|
|
2014-02-12 07:12:08 +08:00
|
|
|
if ((retval = nc4_get_default_fill_value(var->type_info, (char **)fill_valuep)))
|
2014-02-20 22:24:55 +08:00
|
|
|
{
|
2018-01-31 05:39:47 +08:00
|
|
|
free(*(char **)fill_valuep);
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
return retval;
|
2017-12-01 23:18:49 +08:00
|
|
|
}
|
Corrected "BAIL" macros to avoid infinite loop when logging is disabled and an
error occurs after an "exit:" label.
Corrected a dozen Coverity errors (mainly allocation issues, along with a few
other things):
711711, 711802, 711803, 711905, 970825, 996123, 996124, 1025787,
1047274, 1130013, 1130014, 1139538
Refactored internal fill-value code to correctly handle string types, and
especially to allow NULL pointers and null strings (ie. "") to be
distinguished. The code now avoids partially aliasing the two together
(which only happened on the 'write' side of things and wasn't reflected on
the 'read' side, adding to the previous confusion).
Probably still weak on handling fill-values of variable-length and compound
datatypes.
Refactored the recursive metadata reads a bit more, to process HDF5 named
datatypes and datasets immediately, avoiding chewing up memory for those
types of objects, etc.
Finished uncommenting and updating the nc_test4/tst_fills2.c code (as I'm
proceeding alphabetically through the nc_test4 code files).
2013-12-29 15:12:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((retval = nc4_get_default_fill_value(var->type_info, fill_valuep)))
|
|
|
|
return retval;
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Does the user want the endianness of this variable? */
|
|
|
|
if (endiannessp)
|
|
|
|
*endiannessp = var->type_info->endianness;
|
|
|
|
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
|
|
|
* @internal Inquire about chunking settings for a var. This is used
|
|
|
|
* by the fortran API.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param contiguousp Gets contiguous setting.
|
|
|
|
* @param chunksizesp Gets chunksizes.
|
|
|
|
*
|
|
|
|
* @returns ::NC_NOERR No error.
|
|
|
|
* @returns ::NC_EBADID Bad ncid.
|
|
|
|
* @returns ::NC_ENOTVAR Invalid variable ID.
|
|
|
|
* @returns ::NC_EINVAL Invalid input
|
|
|
|
* @returns ::NC_ENOMEM Out of memory.
|
|
|
|
* @author Ed Hartnett
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
|
|
|
nc_inq_var_chunking_ints(int ncid, int varid, int *contiguousp, int *chunksizesp)
|
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc;
|
2016-01-01 02:47:39 +08:00
|
|
|
NC_GRP_INFO_T *grp;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_VAR_INFO_T *var;
|
2018-06-22 21:08:09 +08:00
|
|
|
NC_FILE_INFO_T *h5;
|
2014-06-03 03:04:28 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
size_t *cs = NULL;
|
|
|
|
int i, retval;
|
|
|
|
|
|
|
|
/* Find this ncid's file info. */
|
2014-06-03 03:04:28 +08:00
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return retval;
|
|
|
|
assert(nc);
|
|
|
|
|
|
|
|
/* Find var cause I need the number of dims. */
|
|
|
|
if ((retval = nc4_find_g_var_nc(nc, ncid, varid, &grp, &var)))
|
|
|
|
return retval;
|
2016-01-01 02:47:39 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Allocate space for the size_t copy of the chunksizes array. */
|
|
|
|
if (var->ndims)
|
|
|
|
if (!(cs = malloc(var->ndims * sizeof(size_t))))
|
2017-12-01 23:18:49 +08:00
|
|
|
return NC_ENOMEM;
|
2016-01-01 02:47:39 +08:00
|
|
|
|
|
|
|
retval = NC4_inq_var_all(ncid, varid, NULL, NULL, NULL, NULL, NULL,
|
2017-12-01 23:18:49 +08:00
|
|
|
NULL, NULL, NULL, NULL, contiguousp, cs, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2014-03-28 01:11:06 +08:00
|
|
|
/* Copy from size_t array. */
|
2017-12-03 06:43:40 +08:00
|
|
|
if (chunksizesp && var->contiguous == NC_CHUNKED)
|
2010-09-22 22:25:42 +08:00
|
|
|
for (i = 0; i < var->ndims; i++)
|
|
|
|
{
|
2017-12-01 23:18:49 +08:00
|
|
|
chunksizesp[i] = (int)cs[i];
|
|
|
|
if (cs[i] > NC_MAX_INT)
|
|
|
|
retval = NC_ERANGE;
|
2010-09-22 22:25:42 +08:00
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
|
|
|
|
if (var->ndims)
|
|
|
|
free(cs);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
|
|
|
* @internal Find the ID of a variable, from the name. This function
|
|
|
|
* is called by nc_inq_varid().
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param name Name of the variable.
|
|
|
|
* @param varidp Gets variable ID.
|
|
|
|
|
|
|
|
* @returns ::NC_NOERR No error.
|
|
|
|
* @returns ::NC_EBADID Bad ncid.
|
|
|
|
* @returns ::NC_ENOTVAR Bad variable ID.
|
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
|
|
|
NC4_inq_varid(int ncid, const char *name, int *varidp)
|
|
|
|
{
|
2012-09-07 03:44:03 +08:00
|
|
|
NC *nc;
|
2016-01-01 02:47:39 +08:00
|
|
|
NC_GRP_INFO_T *grp;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
char norm_name[NC_MAX_NAME + 1];
|
|
|
|
int retval;
|
2017-12-01 23:18:49 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
if (!name)
|
|
|
|
return NC_EINVAL;
|
|
|
|
if (!varidp)
|
|
|
|
return NC_NOERR;
|
|
|
|
|
2013-12-01 13:20:28 +08:00
|
|
|
LOG((2, "%s: ncid 0x%x name %s", __func__, ncid, name));
|
2016-01-01 02:47:39 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Find info for this file and group, and set pointer to each. */
|
2012-09-07 03:44:03 +08:00
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, NULL)))
|
2010-06-03 21:24:43 +08:00
|
|
|
return retval;
|
2013-01-15 11:46:46 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Normalize name. */
|
|
|
|
if ((retval = nc4_normalize_name(name, norm_name)))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* Find var of this name. */
|
2018-03-17 01:46:18 +08:00
|
|
|
var = (NC_VAR_INFO_T*)ncindexlookup(grp->vars,norm_name);
|
|
|
|
if(var)
|
2018-07-19 21:33:48 +08:00
|
|
|
{
|
|
|
|
*varidp = var->hdr.id;
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOTVAR;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:18:49 +08:00
|
|
|
/**
|
2017-12-02 01:02:40 +08:00
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
* This function will change the parallel access of a variable from
|
|
|
|
* independent to collective.
|
|
|
|
*
|
|
|
|
* @param ncid File ID.
|
|
|
|
* @param varid Variable ID.
|
|
|
|
* @param par_access NC_COLLECTIVE or NC_INDEPENDENT.
|
|
|
|
*
|
|
|
|
* @returns ::NC_NOERR No error.
|
|
|
|
* @returns ::NC_EBADID Invalid ncid passed.
|
|
|
|
* @returns ::NC_ENOTVAR Invalid varid passed.
|
|
|
|
* @returns ::NC_ENOPAR LFile was not opened with nc_open_par/nc_create_var.
|
|
|
|
* @returns ::NC_EINVAL Invalid par_access specified.
|
2017-12-01 23:18:49 +08:00
|
|
|
* @returns ::NC_NOERR for success
|
2017-12-02 01:02:40 +08:00
|
|
|
* @author Ed Hartnett, Dennis Heimbigner
|
2017-12-01 23:18:49 +08:00
|
|
|
*/
|
2010-06-03 21:24:43 +08:00
|
|
|
int
|
2016-01-01 02:47:39 +08:00
|
|
|
NC4_var_par_access(int ncid, int varid, int par_access)
|
2010-06-03 21:24:43 +08:00
|
|
|
{
|
2015-08-16 06:26:35 +08:00
|
|
|
#ifndef USE_PARALLEL4
|
2010-06-03 21:24:43 +08:00
|
|
|
return NC_ENOPAR;
|
|
|
|
#else
|
2016-01-01 02:47:39 +08:00
|
|
|
NC *nc;
|
|
|
|
NC_GRP_INFO_T *grp;
|
2018-06-22 21:08:09 +08:00
|
|
|
NC_FILE_INFO_T *h5;
|
2010-06-03 21:24:43 +08:00
|
|
|
NC_VAR_INFO_T *var;
|
|
|
|
int retval;
|
|
|
|
|
2016-01-01 02:47:39 +08:00
|
|
|
LOG((1, "%s: ncid 0x%x varid %d par_access %d", __func__, ncid,
|
2010-06-03 21:24:43 +08:00
|
|
|
varid, par_access));
|
|
|
|
|
|
|
|
if (par_access != NC_INDEPENDENT && par_access != NC_COLLECTIVE)
|
|
|
|
return NC_EINVAL;
|
2016-01-01 02:47:39 +08:00
|
|
|
|
2010-06-03 21:24:43 +08:00
|
|
|
/* Find info for this file and group, and set pointer to each. */
|
|
|
|
if ((retval = nc4_find_nc_grp_h5(ncid, &nc, &grp, &h5)))
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
/* This function only for files opened with nc_open_par or nc_create_par. */
|
|
|
|
if (!h5->parallel)
|
|
|
|
return NC_ENOPAR;
|
|
|
|
|
|
|
|
/* Find the var, and set its preference. */
|
2018-03-29 03:41:26 +08:00
|
|
|
var = (NC_VAR_INFO_T*)ncindexith(grp->vars,varid);
|
2016-07-07 22:28:24 +08:00
|
|
|
if (!var) return NC_ENOTVAR;
|
2018-03-17 01:46:18 +08:00
|
|
|
assert(var->hdr.id == varid);
|
2010-06-03 21:24:43 +08:00
|
|
|
|
2016-01-01 02:47:39 +08:00
|
|
|
if (par_access)
|
2010-06-03 21:24:43 +08:00
|
|
|
var->parallel_access = NC_COLLECTIVE;
|
|
|
|
else
|
|
|
|
var->parallel_access = NC_INDEPENDENT;
|
|
|
|
return NC_NOERR;
|
2015-08-16 06:26:35 +08:00
|
|
|
#endif /* USE_PARALLEL4 */
|
2010-06-03 21:24:43 +08:00
|
|
|
}
|