Previous: Per-Variable Compression in NetCDF-4 Next: Per-Variable Compression in NetCDF-4, Results Table of contents Frames 2010 Unidata NetCDF Workshop > Chunking and Deflating Data with NetCDF-4

18.7 Per-Variable Compression in NetCDF-4
This example shows how to set the compression level for variables.

 

From libsrc4/tst_vars.c, the following code demonstrates the use of per variable compression. Use the nc_def_var_deflate function, after a var has been defined, before leaving define mode.

      if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
      if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
      if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR;
      if (nc_def_dim(ncid, DIM3_NAME, DIM3_LEN, &dimids[2])) ERR;
      if (nc_def_var(ncid, VAR_BYTE_NAME, NC_BYTE, 2, dimids, &byte_varid)) ERR;
      if (nc_def_var_deflate(ncid, byte_varid, 0, 1, DEFLATE_LEVEL_4)) ERR;
      if (nc_def_var(ncid, VAR_CHAR_NAME, NC_CHAR, 3, dimids, &char_varid)) ERR;
      if (nc_def_var_deflate(ncid, byte_varid, 0, 1, DEFLATE_LEVEL_4)) ERR;

      if (nc_put_var_schar(ncid, byte_varid, (signed char *)byte_out)) ERR;
      if (nc_put_var_text(ncid, char_varid, (char *)char_out)) ERR;
 ...
      /* Open the file and check data. */
      if (nc_open(FILE_NAME, 0, &ncid)) ERR;
      if (nc_get_var_schar(ncid, byte_varid, (signed char *)byte_in)) ERR;   
      for (i = 0; i < DIM1_LEN; i++)
	 for (j = 0; j < DIM2_LEN; j++)
	    if (byte_in[i][j] != byte_out[i][j]) ERR;

 


Previous: Per-Variable Compression in NetCDF-4 Next: Per-Variable Compression in NetCDF-4, Results Table of contents Frames 2010 Unidata NetCDF Workshop > Chunking and Deflating Data with NetCDF-4