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

Read a NetCDF file and print all metadata (dimensions, variables, attributes) 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 (nc_type xtype)
 
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)
 
int main (int argc, char *argv[])
 

Detailed Description

Read a NetCDF file and print all metadata (dimensions, variables, attributes)

This example demonstrates how to use the NetCDF inquiry functions to discover and print all metadata in a NetCDF file without prior knowledge of its contents. It reads a filename from the command line, opens the file, and prints:

This is a useful pattern for building tools that inspect arbitrary NetCDF files.

Learning Objectives:

Prerequisites: Basic C programming, familiarity with NetCDF concepts

Compilation:

gcc -o dump_classic_metadata dump_classic_metadata.c -lnetcdf

Usage:

./dump_classic_metadata coord_vars.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

◆ type_name()

static const char * type_name ( nc_type  xtype)
static