|
|
|||
|
||||
Next: nc_inq_var_chunking, Previous: nc_def_var, Up: Variables
nc_def_var_chunkingThe function nc_def_var_chunking sets the chunking parameters for a variable in a netCDF-4 file. It can set the chunk sizes to get chunked storage, or it can set the contiguous flag to get contiguous storage.
The total size of a chunk must be less than 4 GiB. That is, the product of all chunksizes and the size of the data (or the size of nc_vlen_t for VLEN types) must be less than 4 GiB.
This function may only be called after the variable is defined, but before nc_enddef is called. Once the chunking parameters are set for a variable, they cannot be changed.
Note that this does not work for scalar variables. Only non-scalar variables can have chunking.
int nc_def_var_chunking(int ncid, int varid, int storage, size_t *chunksizesp);
ncidvaridstorageIf NC_CHUNKED, then chunked storage is used for this variable.
Chunk sizes may be specified with the chunksizes parameter or
default sizes will be used if that parameter is NULL.
*chunksizesnc_def_var_chunking returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error.
Possible return codes include:
NC_NOERRNC_BADIDNC_ENOTNC4NC_ENOTVARNC_ELATEDEFNC_ENOTINDEFINENC_ESTRICTNC3NC_EPERMIn this example from libsrc4/tst_vars2.c, chunksizes are set with nc_var_def_chunking, and checked with nc_var_inq_chunking.
printf("**** testing chunking...");
{
#define NDIMS5 1
#define DIM5_NAME "D5"
#define VAR_NAME5 "V5"
#define DIM5_LEN 1000
int dimids[NDIMS5], dimids_in[NDIMS5];
int varid;
int ndims, nvars, natts, unlimdimid;
nc_type xtype_in;
char name_in[NC_MAX_NAME + 1];
int data[DIM5_LEN], data_in[DIM5_LEN];
size_t chunksize[NDIMS5] = {5};
size_t chunksize_in[NDIMS5];
int storage_in;
int i, d;
for (i = 0; i < DIM5_LEN; i++)
data[i] = i;
/* 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 (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_put_var_int(ncid, varid, data)) ERR;
/* Check stuff. */
if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksize_in)) ERR;
for (d = 0; d < NDIMS5; d++)
if (chunksize[d] != chunksize_in[d]) ERR;
if (storage_in != NC_CHUNKED) ERR;
| Contact Us Site Map Search Terms and Conditions Privacy Policy Participation Policy | |||||
|
|||||