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

Basic example demonstrating 2D array creation and reading in NetCDF. More...

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

Macros

#define FILE_NAME   "simple_2D.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 example demonstrating 2D array creation and reading in NetCDF.

This example shows the fundamental workflow for working with NetCDF files:

The program creates a 2D integer array (6x12) with sequential values (0, 1, 2, ..., 71), writes it to a NetCDF-4 file, then reopens the file to verify both metadata and data correctness. This demonstrates the complete read-write cycle that forms the foundation of NetCDF programming.

Learning Objectives:

Key Concepts:

Prerequisites: None - this is a beginner example

Related Examples:

Compilation:

gcc -o simple_2D simple_2D.c -lnetcdf

Usage:

./simple_2D
ncdump simple_2D.nc

Expected Output: Creates simple_2D.nc containing:

Author
Edward Hartnett
Date
2026-01-15

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_2D.nc"

◆ NDIMS

#define NDIMS   2

◆ NX

#define NX   6

◆ NY

#define NY   12

Function Documentation

◆ main()

int main ( )