NF_DEF_VAR_CHUNKING
The function NF_DEF_VAR_CHUNKING sets the storage 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.
Variables that make use of one or more unlimited dimensions, compression, or checksums must use chunking. Such variables are created with default chunk sizes of 1 for each unlimited dimension and the dimension length for other dimensions, except that if the resulting chunks are too large, the default chunk sizes for non-record dimensions are reduced.
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. This function can be used to change the default chunking for record, compressed, or checksummed variables before nc_enddef is called.
Note that you cannot set chunking for scalar variables. Only non-scalar variables can have chunking.
NF_DEF_VAR_CHUNKING(INTEGER NCID, INTEGER VARID, INTEGER STORAGE, INTEGER CHUNKSIZES)
ncid
varid
storage
If NF_CHUNKED, then chunked storage is used for this variable. Chunk sizes may be specified with the chunksizes parameter. Default sizes will be used if chunking is required and this function is not called.
By default contiguous storage is used for fix-sized variables when
conpression, chunking, checksums, or endianness control are not used.
chunksizes
NF_DEF_VAR_CHUNKING returns the value NF_NOERR if no errors occurred. Otherwise, the returned status indicates an error.
Possible return codes include:
NF_NOERR
NF_BADID
NF_EINVAL
NF_ENOTNC4
NF_ENOTVAR
NF_ELATEDEF
NF_ENOTINDEFINE
NF_ESTRICTNC3
In this example from nf_test/ftst_vars.F, a file is created, two dimensions and a variable are defined, and the chunksizes of the data are set to the size of the data (that is, data will be written in one chunk).
C Create the netCDF file. retval = nf_create(FILE_NAME, NF_NETCDF4, ncid) if (retval .ne. nf_noerr) call handle_err(retval) C Define the dimensions. retval = nf_def_dim(ncid, "x", NX, x_dimid) if (retval .ne. nf_noerr) call handle_err(retval) retval = nf_def_dim(ncid, "y", NY, y_dimid) if (retval .ne. nf_noerr) call handle_err(retval) C Define the variable. dimids(1) = y_dimid dimids(2) = x_dimid retval = NF_DEF_VAR(ncid, "data", NF_INT, NDIMS, dimids, varid) if (retval .ne. nf_noerr) call handle_err(retval) C Turn on chunking. chunks(1) = NY chunks(2) = NX retval = NF_DEF_VAR_chunking(ncid, varid, NF_CHUNKED, chunks) if (retval .ne. nf_noerr) call handle_err(retval)