|
| static const char * | type_name_str (int ncid, nc_type xtype, char *buf, size_t buflen) |
| |
| static int | print_att_value (int ncid, int varid, const char *att_name, nc_type xtype, size_t len) |
| |
| static int | print_attributes (int ncid, int varid, int natts, const char *indent) |
| |
| static int | print_user_types (int ncid, const char *indent) |
| |
| static int | print_group (int ncid, const char *group_name, const char *indent) |
| |
| int | main (int argc, char *argv[]) |
| |
Read a NetCDF-4 file and print all metadata including user-defined types.
This example demonstrates how to use the NetCDF-4 inquiry functions to discover and print all metadata in a NetCDF-4 file without prior knowledge of its contents. It reads a filename from the command line, opens the file, and prints:
- User-defined types (compound, enum, vlen, opaque)
- All dimensions (name and length, noting unlimited dimensions)
- All global attributes (name, type, and value)
- All variables (name, type, dimensions, and attributes)
- Groups (recursively)
This extends the classic dump_classic_metadata example with NetCDF-4 features.
Learning Objectives:
- Use nc_inq_typeids() to discover user-defined types
- Use nc_inq_user_type() to determine type class
- Use nc_inq_compound(), nc_inq_enum(), nc_inq_vlen(), nc_inq_opaque()
- Use nc_inq_grps() to discover groups
- Recursively traverse the group hierarchy
Prerequisites: Basic C programming, familiarity with NetCDF-4 concepts
Compilation:
gcc -o dump_nc4_metadata dump_nc4_metadata.c -lnetcdf
Usage:
./dump_nc4_metadata user_types.nc
- Author
- Edward Hartnett, Intelligent Data Design, Inc.
- Date
- 2026