NEP 2.7.0
NetCDF Extension Pack
Loading...
Searching...
No Matches
Macros | Functions
opendap_subset.c File Reference

OPeNDAP client-side subsetting example. More...

#include <netcdf.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

Macros

#define ERR(e)
 

Functions

int main (void)
 

Detailed Description

OPeNDAP client-side subsetting example.

This example demonstrates client-side subsetting: opening the full remote dataset once, then making multiple targeted data requests using start/count arrays. This approach offers more flexibility than server-side constraints.

What this example does:

  1. Opens the full remote dataset (no constraint expression)
  2. Queries the variable dimensions to understand the full dataset shape
  3. Demonstrates four different data access patterns:
    • Single time slice: Read all lat/lon for one time step
    • Time series: Read all time points at a single lat/lon location
    • Regional subset: Read a small 3D cube (3 time steps, 10x10 spatial)
    • Multiple scattered requests: Show overhead of many small requests
  4. Closes the dataset

Client-side vs Server-side subsetting trade-offs:

Client-side (this example):

Server-side (constraint expressions):

The 3D array layout is [time][lat][lon] with dimensions approximately [time~200][lat=89][lon=180] depending on the dataset version.

Learning Objectives:

Key Concepts:

Prerequisites:

Related Examples:

Compilation:

gcc -o opendap_subset opendap_subset.c -lnetcdf

Usage:

./opendap_subset

Expected Output:

Note
Companion code for "The NetCDF Developer's Handbook: The Authoritative Guide to Writing High-Performance Programs for Scientific Data Management, Second Edition" (https://www.amazon.com/dp/B0H7Q1Z75L)
Author
Edward Hartnett
Date
6/15/26

Macro Definition Documentation

◆ ERR

#define ERR (   e)
Value:
do { \
if (e) { \
fprintf(stderr, "Error: %s at line %d\n", nc_strerror(e), __LINE__); \
return 1; \
} \
} while (0)

Function Documentation

◆ main()

int main ( void  )