|
NEP 1.7.0
NetCDF Extension Pack: compression extensions for NetCDF
|
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 () |
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:
Usage:
Expected Output: Creates five files:
| #define ERR | ( | e | ) | {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} |
| #define ERRCODE 2 |
| #define NLAT 20 |
| #define NLON 30 |
| #define NTIME 10 |
| long get_file_size | ( | const char * | filename | ) |
| int main | ( | ) |
| void populate_file | ( | int | ncid | ) |
| void verify_format_file | ( | const char * | filename, |
| int | expected_format, | ||
| const char * | expected_format_name | ||
| ) |