|
NEP 2.7.0
NetCDF Extension Pack
|
Demonstrate deflate+shuffle compression in a local NcZarr dataset. More...
#include <netcdf.h>#include <stdio.h>#include <stdlib.h>Macros | |
| #define | FILE_URL "file://nczarr_compression.zarr#mode=nczarr" |
| #define | NY 4 |
| #define | NX 5 |
| #define | NDIMS 2 |
| #define | CHUNK_Y 2 |
| #define | CHUNK_X 5 |
| #define | DEFLATE_LEVEL 1 |
| #define | ERR(e) |
Functions | |
| int | main (void) |
Demonstrate deflate+shuffle compression in a local NcZarr dataset.
This example extends nczarr_chunking.c by adding compression filters on top of explicit chunking. The recommended workflow for compressed storage is: (1) set the chunk shape with nc_def_var_chunking(), then (2) enable compression with nc_def_var_deflate(). Both steps must occur in define mode before nc_enddef().
The program creates the same 4x5 temperature grid with 2x5 chunks, then applies the shuffle filter and deflate (zlib) compression at level 1. After writing, it reopens the dataset and verifies the compression metadata via nc_inq_var_deflate(), then reads and validates all data values. Decompression is fully transparent — nc_get_var_float() returns the original data without any extra API calls.
Learning Objectives:
Key Concepts:
Related Examples:
Compilation:
Usage:
Expected Output: Creates the directory nczarr_compression.zarr containing:
| #define CHUNK_X 5 |
| #define CHUNK_Y 2 |
| #define DEFLATE_LEVEL 1 |
| #define ERR | ( | e | ) |
| #define FILE_URL "file://nczarr_compression.zarr#mode=nczarr" |
| #define NDIMS 2 |
| #define NX 5 |
| #define NY 4 |
| int main | ( | void | ) |