Deflate+shuffle compression in a local NcZarr dataset (Fortran).
Fortran equivalent of nczarr_compression.c. Creates a 4x5 temperature array with explicit chunking [2, 5] (y, x) and deflate level 1 + shuffle in a local NcZarr store, verifies compression metadata after reopening, and validates data values.
Learning Objectives:
- Apply deflate compression and shuffle filter from Fortran
- Follow the recommended workflow: set chunks first, then compression
- Query compression metadata after reopen
- Verify that decompression is transparent
Key Concepts:
- Set chunk shape before compression (recommended workflow)
- nf90_def_var_deflate(ncid, varid, shuffle, deflate, deflate_level) enables shuffle and deflate filters
- Compression is transparent: nf90_get_var returns original values
- Same API works for NetCDF-4/HDF5 and NcZarr
Related Examples:
Compilation:
program f_nczarr_compression
Definition f_nczarr_compression.f90:54
Usage:
ncdump 'file://f_nczarr_compression.zarr#mode=nczarr'
Expected Output: Creates the directory f_nczarr_compression.zarr containing:
- 2 dimensions: y(4), x(5)
- 1 variable: temperature(y, x) of type NF90_FLOAT, chunked [2, 5], with shuffle + deflate level 1
- Attributes: units="K", long_name="Temperature", _FillValue=-999.0
- A 4x5 temperature data grid stored compressed in 2 chunks
- Note
- Companion code for "The NetCDF Developer's Handbook: The Authoritative Guide to Writing
High-Performance Programs for Scientific Data Management, Second Edition" (https://www.amazon.com/dp/B0H7Q1Z75L)
- Author
- Edward Hartnett, Intelligent Data Design, Inc.
- Date
- 2026-06-26