|
NEP 1.5.1
NetCDF Extension Pack: compression extensions for NetCDF
|
Demonstrates NetCDF classic format variants (CDF-1, CDF-2, CDF-5) 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 | create_format_file (const char *filename, int format_flag, const char *format_name) |
| void | verify_format_file (const char *filename, const char *expected_format_name) |
| int | main () |
Demonstrates NetCDF classic format variants (CDF-1, CDF-2, CDF-5)
This example creates identical data structures in three different classic NetCDF formats to illustrate their differences in file size limits, compatibility, and use cases. Understanding format variants is crucial for choosing the right format for your data requirements.
The program creates three 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 | Use Case |
|---|---|---|---|---|
| CDF-1 | 2GB | 2GB | 3.0+ | Maximum compatibility |
| CDF-2 | Unlimited | 4GB | 3.6.0+ | Large files, moderate variables |
| CDF-5 | Unlimited | Unlimited | 4.4.0+ | Very large variables |
Prerequisites:
Related Examples:
Compilation:
Usage:
Expected Output: Creates three 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 |
| void create_format_file | ( | const char * | filename, |
| int | format_flag, | ||
| const char * | format_name | ||
| ) |
| long get_file_size | ( | const char * | filename | ) |
| int main | ( | ) |
| void verify_format_file | ( | const char * | filename, |
| const char * | expected_format_name | ||
| ) |