|
NEP 2.7.0
NetCDF Extension Pack
|
Demonstrate creating, writing, and reading a local NcZarr dataset. More...
#include <netcdf.h>#include <stdio.h>#include <stdlib.h>Macros | |
| #define | FILE_URL "file://simple_nczarr.zarr#mode=nczarr" |
| #define | NY 4 |
| #define | NX 5 |
| #define | NDIMS 2 |
| #define | ERR(e) |
Functions | |
| int | main (void) |
Demonstrate creating, writing, and reading a local NcZarr dataset.
This example introduces the NetCDF-Zarr (NcZarr) storage format, which extends the netCDF-4 enhanced data model to Zarr, a cloud-native array storage system. Unlike classic NetCDF or NetCDF-4/HDF5, which store a dataset in a single binary file, NcZarr stores each variable's metadata and chunks as separate objects in a directory tree (for local filesystem storage) or in an object store (for cloud storage). This design is optimized for random access over HTTP and scales naturally to cloud object storage such as Amazon S3, Google Cloud Storage, and Azure Blob Storage.
NcZarr is accessed through the familiar netCDF-C API. The only difference at create/open time is the storage URL: a local NcZarr store is selected with the file:// scheme and the #mode=nczarr fragment, which tells the netCDF-C dispatch layer to use the NcZarr implementation. Once the file is open, nc_def_dim(), nc_def_var(), nc_put_att_xxx(), nc_put_var_xxx(), and nc_get_var_xxx() work exactly as they do for NetCDF-4/HDF5 files.
This program creates a small 2D temperature array on a 4x5 y-x grid, stores it as a local NcZarr directory named simple_nczarr.zarr, attaches units, long_name, and _FillValue attributes, closes the file, reopens it read-only, and verifies that the metadata and data values match what was written.
Learning Objectives:
file://...#mode=nczarr URL to create a local NcZarr datasetKey Concepts:
#mode=nczarr suffix selects the NcZarr dispatcherfile:// scheme uses the local Zarr storeComparison with Other NetCDF Formats:
| Feature | Classic | NetCDF-4/HDF5 | NcZarr |
|---|---|---|---|
| Single file | Yes | Yes | No (directory tree) |
| Cloud object storage | No | No | Yes |
| Compression | No | Yes (HDF5 filters) | Yes (Zarr codecs) |
| Groups/user types | No | Yes | Yes |
| HTTP random access | No | No | Yes |
Prerequisites:
Related Examples:
Compilation:
Usage:
Expected Output: Creates the directory simple_nczarr.zarr containing:
| #define ERR | ( | e | ) |
| #define FILE_URL "file://simple_nczarr.zarr#mode=nczarr" |
| #define NDIMS 2 |
| #define NX 5 |
| #define NY 4 |
| int main | ( | void | ) |