Next: , Previous: nc_inq_var_chunking, Up: Variables


6.8 Set HDF5 Chunk Cache for a Variable: nc_set_var_chunk_cache

This function changes the chunk cache settings for a variable. The change in cache size happens immediately. This is a property of the open file - it does not persist the next time you open the file.

For more information, see the documentation for the H5Pset_cache() function in the HDF5 library at the HDF5 website: http://hdfgroup.org/HDF5/.

Usage

     nc_set_var_chunk_cache(int ncid, int varid, size_t size, size_t nelems,
     		       float preemption);
ncid
NetCDF ID, from a previous call to nc_open or nc_create.
varid
Variable ID.
size
The total size of the raw data chunk cache, in bytes. This should be big enough to hold multiple chunks of data.
nelems
The number of chunk slots in the raw data chunk cache hash table. This should be a prime number larger than the number of chunks that will be in the cache.
preemption
The preemtion value must be between 0 and 1 inclusive and indicates how much chunks that have been fully read are favored for preemption. A value of zero means fully read chunks are treated no differently than other chunks (the preemption is strictly LRU) while a value of one means fully read chunks are always preempted before other chunks.

Return Codes

NC_NOERR
No error.
NC_EINVAL
Preemption must be between zero and one (inclusive).

Example

This example is from libsrc4/tst_vars2.c:

     #include <netcdf.h>
        ...
     #define CACHE_SIZE 32000000
     #define CACHE_NELEMS 1009
     #define CACHE_PREEMPTION .75
        ...
     
           /* Create a netcdf-4 file with one dim and one var. */
           if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
           if (nc_def_dim(ncid, DIM5_NAME, DIM5_LEN, &dimids[0])) ERR;
           if (dimids[0] != 0) ERR;
           if (nc_def_var(ncid, VAR_NAME5, NC_INT, NDIMS5, dimids, &varid)) ERR;
           if (nc_def_var_chunking(ncid, varid, NC_CHUNKED, chunksize)) ERR;
           if (nc_set_var_chunk_cache(ncid, varid, CACHE_SIZE, CACHE_NELEMS, CACHE_PREEMPTION)) ERR;