Previous: Setting the Chunksizes in NetCDF-4 Next: The Cache in NetCDF-4 Table of contents Frames 2011 Unidata NetCDF Workshop > Chunking and Deflating Data with NetCDF-4

14.3 Example of Setting Chunksizes in Fortran 90
In this example code (from nf_test/f90tst_varss.f90) the chunksize is set for several 2-dimensional variables in Fortran 90.

 

  ! Create the netCDF file. 
  call check(nf90_create(FILE_NAME, nf90_netcdf4, ncid, cache_nelems = DEFAULT_CACHE_NELEMS, &
       cache_size = DEFAULT_CACHE_SIZE, cache_preemption = DEFAULT_CACHE_PREEMPTION))

  ! Define the dimensions.
  call check(nf90_def_dim(ncid, "x", NX, x_dimid))
  call check(nf90_def_dim(ncid, "y", NY, y_dimid))
  dimids =  (/ y_dimid, x_dimid /)

  ! Define some variables. 
  chunksizes = (/ NY, NX /)
  call check(nf90_def_var(ncid, VAR1_NAME, NF90_INT, dimids, varid1, chunksizes = chunksizes, &
       shuffle = .TRUE., fletcher32 = .TRUE., endianness = nf90_endian_big, deflate_level = DEFLATE_LEVEL))
  call check(nf90_def_var(ncid, VAR2_NAME, NF90_INT, dimids, varid2, contiguous = .TRUE.))
  call check(nf90_def_var(ncid, VAR3_NAME, NF90_INT64, varid3))
  call check(nf90_def_var(ncid, VAR4_NAME, NF90_INT, x_dimid, varid4, contiguous = .TRUE.))
  call check(nf90_def_var(ncid, VAR5_NAME, NF90_INT, dimids, varid5, chunksizes = chunksizes, &
       deflate_level = DEFLATE_LEVEL, cache_size = CACHE_SIZE, cache_nelems = CACHE_NELEMS, &
       cache_preemption = CACHE_PREEMPTION))

  ! Write the pretend data to the file.
  call check(nf90_put_var(ncid, varid1, data_out))
  call check(nf90_put_var(ncid, varid2, data_out))
  call check(nf90_put_var(ncid, varid3, TOE_SAN_VALUE))
  call check(nf90_put_var(ncid, varid4, data_out_1d))
  call check(nf90_put_var(ncid, varid5, data_out))

  ! Close the file. 
  call check(nf90_close(ncid))

 


Previous: Setting the Chunksizes in NetCDF-4 Next: The Cache in NetCDF-4 Table of contents Frames 2011 Unidata NetCDF Workshop > Chunking and Deflating Data with NetCDF-4