|
NEP 2.7.0
NetCDF Extension Pack
|
Compare best-performing settings of all lossless compression filters. More...
#include <netcdf.h>#include <netcdf_filter.h>#include "nep.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/time.h>Data Structures | |
| struct | filter_config_t |
Macros | |
| #define | NZ 500 |
| #define | NY 180 |
| #define | NX 360 |
| #define | TMP_FILE "lossless_tmp.nc" |
| #define | CHUNK_Z 10 |
| #define | CHUNK_Y 45 |
| #define | CHUNK_X 90 |
| #define | NVALS ((size_t)NZ * NY * NX) |
| #define | UNCOMPRESSED_BYTES ((double)NVALS * sizeof(float)) |
| #define | ERRCODE 2 |
| #define | ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} |
| #define | NUM_FILTERS (sizeof(filters) / sizeof(filters[0])) |
Functions | |
| static double | get_time (void) |
| Return current wall-clock time in seconds. | |
| static int | apply_filter (int ncid, int varid, const filter_config_t *filter) |
| Apply the specified filter to the variable. | |
| static int | verify_filter (int ncid, int varid, const filter_config_t *filter) |
| Verify that the filter was applied correctly. | |
| static int | run_one_filter (float *data, const filter_config_t *filter) |
| Run one filter test and print a CSV row. | |
| int | main (void) |
| Main entry point. | |
Variables | |
| static const filter_config_t | filters [] |
Compare best-performing settings of all lossless compression filters.
This program evaluates the optimal settings for each available lossless compression filter (DEFLATE, Zstandard, SZIP, LZ4, BZIP2) with the shuffle filter enabled, providing a unified comparison for scientific floating-point data. Results help users choose the right compression based on their priorities: maximum compression ratio or fastest I/O throughput.
Filters tested (all with shuffle enabled):
The shuffle filter is enabled for all tests via nc_def_var_deflate(ncid, varid, 1, 0, 0) before applying the primary compression filter. This has been empirically determined to significantly improve compression ratios for IEEE 754 floating-point data.
This program iterates over the 5 filters (1 row per filter) over a 500×180×360 NC_FLOAT temperature dataset (~129 MB uncompressed) and reports:
Output: CSV printed to stdout with columns:
Typical workflow:
Learning Objectives:
Key Concepts:
Prerequisites:
Related Examples:
Key API functions:
| #define CHUNK_X 90 |
| #define CHUNK_Y 45 |
| #define CHUNK_Z 10 |
Chunk shape: matches all v1.10.0 performance examples for consistency.
| #define ERR | ( | e | ) | {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} |
| #define ERRCODE 2 |
| #define NX 360 |
Longitude dimension: 360 degrees.
| #define NY 180 |
Latitude dimension: 180 degrees.
| #define NZ 500 |
Time dimension: 500 time steps.
| #define TMP_FILE "lossless_tmp.nc" |
Temporary NetCDF file created and removed for each measurement.
| #define UNCOMPRESSED_BYTES ((double)NVALS * sizeof(float)) |
Uncompressed size in bytes.
|
static |
Apply the specified filter to the variable.
| ncid | NetCDF file ID. |
| varid | Variable ID. |
| filter | Filter configuration. |
|
static |
Return current wall-clock time in seconds.
| int main | ( | void | ) |
Main entry point.
Allocates a 500×180×360 NC_FLOAT buffer with synthetic temperature data, then iterates over the 5 filters at their optimal settings (5 rows total), printing one CSV row per filter.
|
static |
Run one filter test and print a CSV row.
Creates lossless_tmp.nc with the given filter at its optimal setting with shuffle enabled, writes a 500×180×360 NC_FLOAT temperature variable, stats the file to obtain the compressed size, reads the variable back, then removes the file.
| data | Pre-allocated buffer of NVALS floats (synthetic data). |
| filter | Filter configuration to test. |
|
static |
Verify that the filter was applied correctly.
| ncid | NetCDF file ID. |
| varid | Variable ID. |
| filter | Filter configuration. |
|
static |
Optimal filter configurations (determined empirically in prior sprints).