NEP 2.7.0
NetCDF Extension Pack
Loading...
Searching...
No Matches
Macros | Functions
nczarr_enhanced.c File Reference

Demonstrate the NetCDF-4 enhanced data model in a local NcZarr dataset. More...

#include <netcdf.h>
#include <stdio.h>
#include <stdlib.h>

Macros

#define FILE_URL   "file://nczarr_enhanced.zarr#mode=nczarr"
 
#define NX   5
 
#define NTIMES   2
 
#define NSTATIONS   3
 
#define ERR(e)
 

Functions

int main (void)
 

Detailed Description

Demonstrate the NetCDF-4 enhanced data model in a local NcZarr dataset.

This example extends nczarr_compression.c by introducing two enhanced-model features that are unavailable in classic NetCDF: hierarchical groups and multiple independent unlimited dimensions. The same nc_def_grp() and NC_UNLIMITED APIs used for NetCDF-4/HDF5 files work identically with NcZarr.

The program creates a NcZarr store with a root group containing a time (unlimited) × x(5) grid of temperature and pressure variables, and a child group obs/ that holds its own independent station (unlimited) dimension with observation value and time-index variables. After writing, the program reopens the store, navigates to the child group by name, verifies that both unlimited dimensions grew independently, and validates all data values.

Learning Objectives:

Key Concepts:

Related Examples:

Compilation:

gcc -o nczarr_enhanced nczarr_enhanced.c -lnetcdf

Usage:

./nczarr_enhanced
ncdump 'file://nczarr_enhanced.zarr#mode=nczarr'

Expected Output: Creates the directory nczarr_enhanced.zarr containing:

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-06-27

Macro Definition Documentation

◆ ERR

#define ERR (   e)
Value:
do { \
if (e) { \
fprintf(stderr, "Error: %s at line %d\n", nc_strerror(e), __LINE__); \
return 1; \
} \
} while(0)

◆ FILE_URL

#define FILE_URL   "file://nczarr_enhanced.zarr#mode=nczarr"

◆ NSTATIONS

#define NSTATIONS   3

◆ NTIMES

#define NTIMES   2

◆ NX

#define NX   5

Function Documentation

◆ main()

int main ( void  )