|
NEP 2.7.0
NetCDF Extension Pack
|
Demonstrates fill value handling performance across classic and NetCDF-4 formats. More...
#include <netcdf.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/time.h>Macros | |
| #define | NZ 500 |
| #define | NY 180 |
| #define | NX 360 |
| #define | NVALS ((size_t)NZ * NY * NX) |
| #define | UNCOMPRESSED_BYTES ((double)NVALS * sizeof(float)) |
| #define | FILL_VALUE (9.9692099683868690e+36f) |
| #define | ERRCODE 2 |
| #define | ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} |
Functions | |
| static double | get_time (void) |
| Return current wall-clock time in seconds. | |
| static void | generate_data (float *data) |
| Generate synthetic temperature data. | |
| static int | run_test (const char *path, int format, int fill_mode, const char *format_name) |
| Run one fill value test and print a CSV row. | |
| int | main (void) |
| Main entry point. | |
Demonstrates fill value handling performance across classic and NetCDF-4 formats.
NetCDF supports fill values — a special value indicating missing or unwritten data. When fill mode is enabled (NC_FILL, the default), NetCDF automatically writes fill values to any data not explicitly written. This benchmark measures the performance impact of fill mode (ON vs OFF) across both classic (netCDF-3) and NetCDF-4/HDF5 formats.
This program creates a 500×180×360 NC_FLOAT temperature dataset (~129 MB) four times with different configurations and reports:
Output: CSV printed to stdout with columns:
Typical workflow:
Learning Objectives:
Key Concepts:
Prerequisites:
Related Examples:
Key API functions:
| #define ERR | ( | e | ) | {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} |
Error handling macro.
| #define ERRCODE 2 |
Error exit code.
| #define FILL_VALUE (9.9692099683868690e+36f) |
NetCDF fill value for floats.
| #define NX 360 |
Longitude dimension: 360 degrees.
| #define NY 180 |
Latitude dimension: 180 degrees.
| #define NZ 500 |
Time dimension: 500 time steps.
| #define UNCOMPRESSED_BYTES ((double)NVALS * sizeof(float)) |
Uncompressed size in bytes.
|
static |
Generate synthetic temperature data.
Fills the buffer with synthetic data: 280.0 + t*0.1 + y*0.01 + x*0.001
| data | Buffer of NVALS floats to fill. |
|
static |
Return current wall-clock time in seconds.
| int main | ( | void | ) |
Main entry point.
Runs four fill value tests:
Prints CSV header followed by one data row per test.
|
static |
Run one fill value test and print a CSV row.
Creates a file with the given format and fill mode, writes a 500×180×360 NC_FLOAT temperature variable, stats the file to obtain the on-disk size, reads the variable back, then removes the file.
| path | Path for temporary file (will be created and removed). |
| format | File format: NC_CLOBBER (classic) or NC_NETCDF4|NC_CLOBBER. |
| fill_mode | 1 for NC_FILL, 0 for NC_NOFILL. |
| format_name | String for CSV output ("classic" or "nc4"). |