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

Demonstrates all five NetCDF binary format variants. More...

#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>
#include <sys/stat.h>

Macros

#define NTIME   10
 
#define NLAT   20
 
#define NLON   30
 
#define ERRCODE   2
 
#define ERR(e)   {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}
 

Functions

long get_file_size (const char *filename)
 
void populate_file (int ncid)
 
void verify_format_file (const char *filename, int expected_format, const char *expected_format_name)
 
int main ()
 

Detailed Description

Demonstrates all five NetCDF binary format variants.

This example creates identical data structures in all five NetCDF binary formats to illustrate their differences in file size limits, compatibility, storage backend, and use cases. Understanding format variants is crucial for choosing the right format for your data requirements.

The program creates five files with the same 3D temperature and pressure data (time×lat×lon) in different formats, then compares their characteristics including file size, format detection, and size limitations.

Learning Objectives:

Key Concepts:

Format Comparison:

Format File Limit Variable Limit NetCDF Version Backend Use Case
CDF-1 2GB 2GB 3.0+ CDF Maximum compatibility (default)
CDF-2 Unlimited 4GB 3.6.0+ CDF Large files, moderate variables
CDF-5 Unlimited Unlimited 4.4.0+ CDF Very large variables
NC4 Unlimited Unlimited 4.0+ HDF5 Full NetCDF-4 features
NC4/CM Unlimited Unlimited 4.0+ HDF5 HDF5 storage, classic model

Prerequisites:

Related Examples:

Compilation:

gcc -o format_variants format_variants.c -lnetcdf

Usage:

./format_variants
ls -lh format_*.nc
ncdump -h format_classic.nc

Expected Output: Creates five files:

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

◆ NLAT

#define NLAT   20

◆ NLON

#define NLON   30

◆ NTIME

#define NTIME   10

Function Documentation

◆ get_file_size()

long get_file_size ( const char *  filename)

◆ main()

int main ( )

◆ populate_file()

void populate_file ( int  ncid)

◆ verify_format_file()

void verify_format_file ( const char *  filename,
int  expected_format,
const char *  expected_format_name 
)