Next: , Previous: nc_def_var_chunking, Up: Variables


6.7 Learn About Chunking Parameters for a Variable: nc_inq_var_chunking

The function nc_inq_var_chunking returns the chunking settings for a variable in a netCDF-4 file.

Usage

     int nc_inq_var_chunking(int ncid, int varid, int *storagep, size_t *chunksizesp);
ncid
NetCDF ID, from a previous call to nc_open or nc_create.
varid
Variable ID.
storagep
Address of returned storage property, returned as NC_CONTIGUOUS if this variable uses contiguous storage, or NC_CHUNKEDif it uses chunked storage.
*chunksizesp
A pointer to an array list of chunk sizes. The array must have one chunksize for each dimension in the variable.

Errors

nc_inq_var_chunking returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error.

Possible return codes include:

NC_NOERR
No error.
NC_BADID
Bad ncid.
NC_ENOTNC4
Not a netCDF-4 file.
NC_ENOTVAR
Can't find this variable.

Example

This example is from libsrc4/tst_vars2.c in which a variable with contiguous storage is created, and then checked with nc_inq_var_chunking:

        printf("**** testing contiguous storage...");
        {
     #define NDIMS6 1
     #define DIM6_NAME "D5"
     #define VAR_NAME6 "V5"
     #define DIM6_LEN 100
     
           int dimids[NDIMS6], dimids_in[NDIMS6];
           int varid;
           int ndims, nvars, natts, unlimdimid;
           nc_type xtype_in;
           char name_in[NC_MAX_NAME + 1];
           int data[DIM6_LEN], data_in[DIM6_LEN];
           size_t chunksize_in[NDIMS6];
           int storage_in;
           int i, d;
     
           for (i = 0; i < DIM6_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, DIM6_NAME, DIM6_LEN, &dimids[0])) ERR;
           if (dimids[0] != 0) ERR;
           if (nc_def_var(ncid, VAR_NAME6, NC_INT, NDIMS6, dimids, &varid)) ERR;
           if (nc_def_var_chunking(ncid, varid, NC_CONTIGUOUS, NULL)) ERR;
           if (nc_put_var_int(ncid, varid, data)) ERR;
     
           /* Check stuff. */
           if (nc_inq_var_chunking(ncid, 0, &storage_in, chunksize_in)) ERR;
           if (storage_in != NC_CONTIGUOUS) ERR;