OPeNDAP client-side subsetting example in Fortran.
This is the Fortran equivalent of opendap_subset.c, demonstrating client-side subsetting using start/count arrays.
What this example does:
- Opens the full remote dataset without constraints
- Demonstrates four different subset access patterns:
- Single time slice: All lat/lon for time step 1 (using 1-based)
- Time series: All time points at lat=46, lon=91
- Regional subset: 3x10x10 cube using fixed-size array
- Multiple scattered reads: Loop showing multiple requests
- Closes the dataset
Key differences from constraint expressions:
- Full dataset metadata is available (original dimension sizes)
- Can make multiple different subset requests without reopening
- More flexible for data exploration and iterative analysis
- Network transfer includes only requested subset data
Fortran-specific notes:
- nf90_get_var uses 1-based start indices: (/1, 1, 1/)
- allocatable arrays handle dynamic sizes based on dimensions
Learning Objectives:
- Open a full remote dataset without constraint expressions from Fortran
- Use start/count arrays (1-based) for multiple targeted data requests
- Implement four different access patterns (time slice, time series, regional, scattered)
- Understand the trade-offs between client-side and server-side subsetting
- Recognize the overhead of many small requests vs fewer large requests
Key Concepts:
- Client-Side Subsetting: Open the full dataset once, then use start/count in nf90_get_var() calls to select different subregions on each read
- Time Slice Access: Read all spatial points for one time step (start=(/1,1,1/), count=(/lon_len,lat_len,1/) in Fortran column-major)
- Time Series Access: Read all time points at one spatial location (start=(/lon,lat,1/), count=(/1,1,time_len/))
- Regional Subset: Read a small 3D cube from the full dataset
- Multiple Requests: One nf90_open() supports unlimited nf90_get_var() calls with different start/count values — no need to reopen for each subset
- 1-Based Indexing: Fortran start arrays begin at 1, unlike C's 0-based indexing
Prerequisites:
Related Examples:
Compilation:
program f_opendap_subset
Definition f_opendap_subset.f90:87
Usage:
Expected Output:
- Opens remote SST dataset and prints full dimension sizes
- Demonstrates four access patterns with data summaries: single time slice, time series at a point, regional 3D cube, and multiple scattered requests
- 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