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

Read a NetCDF-4 file and print all metadata including user-defined types. More...

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

Macros

#define ERRCODE   2
 
#define ERR(e)   {printf("Error: %s\n", nc_strerror(e)); return ERRCODE;}
 

Functions

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[])
 

Detailed Description

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:

This extends the classic dump_classic_metadata example with NetCDF-4 features.

Learning Objectives:

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

Macro Definition Documentation

◆ ERR

#define ERR (   e)    {printf("Error: %s\n", nc_strerror(e)); return ERRCODE;}

◆ ERRCODE

#define ERRCODE   2

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

◆ print_att_value()

static int print_att_value ( int  ncid,
int  varid,
const char *  att_name,
nc_type  xtype,
size_t  len 
)
static

◆ print_attributes()

static int print_attributes ( int  ncid,
int  varid,
int  natts,
const char *  indent 
)
static

◆ print_group()

static int print_group ( int  ncid,
const char *  group_name,
const char *  indent 
)
static

◆ print_user_types()

static int print_user_types ( int  ncid,
const char *  indent 
)
static

◆ type_name_str()

static const char * type_name_str ( int  ncid,
nc_type  xtype,
char *  buf,
size_t  buflen 
)
static