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

Demonstrates multi-dimensional arrays (2D, 3D, 4D) with dimension reuse. More...

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

Macros

#define FILE_NAME   "var4d.nc"
 
#define NTIME   3
 
#define NLEVEL   2
 
#define NLAT   4
 
#define NLON   5
 
#define ERRCODE   2
 
#define ERR(e)   {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}
 

Functions

int main ()
 

Detailed Description

Demonstrates multi-dimensional arrays (2D, 3D, 4D) with dimension reuse.

This example shows how to work with multi-dimensional scientific data by creating variables of different dimensionalities (2D, 3D, 4D) that share common dimensions. This pattern is typical in atmospheric and oceanographic data where variables have different spatial and temporal coverage.

The program creates a file with 4 dimensions (time, level, lat, lon) and three temperature variables: surface temperature (2D), temperature profile (3D), and full 3D atmospheric temperature (4D). This demonstrates dimension reuse and efficient file organization.

Learning Objectives:

Key Concepts:

Dimension Ordering Convention:

Prerequisites:

Related Examples:

Compilation:

gcc -o var4d var4d.c -lnetcdf

Usage:

./var4d
ncdump var4d.nc

Expected Output: Creates var4d.nc 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   "var4d.nc"

◆ NLAT

#define NLAT   4

◆ NLEVEL

#define NLEVEL   2

◆ NLON

#define NLON   5

◆ NTIME

#define NTIME   3

Function Documentation

◆ main()

int main ( )