NEP 1.5.1
NetCDF Extension Pack: compression extensions for NetCDF
Loading...
Searching...
No Matches
Macros | Functions
simple_nc4.c File Reference

Basic NetCDF-4/HDF5 format file creation and format detection. More...

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

Macros

#define FILE_NAME   "simple_nc4.nc"
 
#define NDIMS   2
 
#define NX   6
 
#define NY   12
 
#define ERRCODE   2
 
#define ERR(e)   {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}
 

Functions

int main ()
 

Detailed Description

Basic NetCDF-4/HDF5 format file creation and format detection.

This example introduces the NetCDF-4 format, which uses HDF5 as the underlying storage layer. NetCDF-4 provides enhanced features including compression, chunking, multiple unlimited dimensions, and user-defined types while maintaining backward compatibility with the NetCDF API.

The program creates a simple 2D array using the NC_NETCDF4 flag and demonstrates format detection to verify the file was created in NetCDF-4/HDF5 format rather than classic NetCDF format.

Learning Objectives:

Key Concepts:

NetCDF-4 vs Classic Comparison:

Prerequisites:

Related Examples:

Compilation:

gcc -o simple_nc4 simple_nc4.c -lnetcdf

Usage:

./simple_nc4
ncdump simple_nc4.nc
h5dump simple_nc4.nc # View as HDF5 file

Expected Output: Creates simple_nc4.nc in NetCDF-4/HDF5 format containing:

Author
Edward Hartnett, Intelligent Data Design, Inc.
Date
2026

Macro Definition Documentation

◆ ERR

#define ERR (   e)    {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}

◆ ERRCODE

#define ERRCODE   2

◆ FILE_NAME

#define FILE_NAME   "simple_nc4.nc"

◆ NDIMS

#define NDIMS   2

◆ NX

#define NX   6

◆ NY

#define NY   12

Function Documentation

◆ main()

int main ( )