|
NEP 2.7.0
NetCDF Extension Pack
|
Basic example demonstrating 2D array creation and reading in NetCDF. More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <netcdf.h>Macros | |
| #define | FILE_NAME "simple_2D.nc" |
| #define | NDIMS 2 |
| #define | NX 6 |
| #define | NY 12 |
| #define | FILL_VALUE -9999 |
| #define | ERRCODE 2 |
| #define | ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} |
Functions | |
| int | main () |
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), partially writes sequential values (0, 1, 2, ..., 59) for the first NY-1 rows (leaving the last row unwritten), and sets a custom fill value (-9999) so unwritten elements are identifiable. It writes to a NetCDF file with a global attribute ("title") and a variable attribute ("units"), then reopens the file to verify metadata, attributes, fill value, 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:
Usage:
Expected Output: Creates simple_2D.nc containing:
| #define ERR | ( | e | ) | {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} |
| #define ERRCODE 2 |
| #define FILE_NAME "simple_2D.nc" |
| #define FILL_VALUE -9999 |
| #define NDIMS 2 |
| #define NX 6 |
| #define NY 12 |
| int main | ( | void | ) |