NetCDF-4 compression filters with performance analysis (Fortran)
Fortran equivalent of compression.c, exploring NetCDF-4 compression using the Fortran 90 NetCDF API. Tests various compression configurations and measures performance.
Learning Objectives:
- Configure compression with nf90_def_var_deflate() and nf90_def_var_zstandard() in Fortran
- Measure compression performance in Fortran applications
- Select appropriate compression levels for different data
- Set fill values with nf90_def_var_fill() for chunked/compressed variables
- Verify that unwritten chunks return the fill value on read
Fortran Compression Functions:
- nf90_def_var_deflate(ncid, varid, shuffle, deflate, deflate_level)
- shuffle: 0=off, 1=on; deflate: 0=off, 1=on; deflate_level: 1-9
- nf90_def_var_zstandard(ncid, varid, level)
- level: 1-22 (higher=better compression, slower)
- Zstandard is generally faster than zlib and provides better compression ratios. Prefer Zstandard when it is available; level 3 is the best tradeoff.
- zlib is the fallback when Zstandard is unavailable. For almost all real-world data, zlib level 1 is the preferred deflate value. Higher levels yield diminishing returns at much greater CPU cost.
Fortran Fill Value Functions:
- nf90_def_var_fill(ncid, varid, no_fill,
fill_value): set fill value (no_fill=0)
- nf90_inq_var_fill(ncid, varid, no_fill, fill_value): query fill value
- In chunked/compressed variables, unwritten chunks return the fill value
Prerequisites:
Related Examples:
Compilation:
program f_compression
Definition f_compression.f90:54
- 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