Demonstrates NetCDF-4 hierarchical groups, nested groups, and dimension visibility (Fortran)
More...
Demonstrates NetCDF-4 hierarchical groups, nested groups, and dimension visibility (Fortran)
Fortran equivalent of groups.c, demonstrating NetCDF-4's hierarchical group feature using the Fortran 90 NetCDF API. Groups enable organizing datasets into logical groupings similar to directories in a filesystem, providing namespace isolation for variables while allowing dimensions to be shared across the hierarchy through dimension visibility rules.
The program creates a three-level group hierarchy (root → SubGroup1, root → SubGroup2 → NestedGroup), demonstrates dimension visibility across group boundaries, and showcases all five new NetCDF-4 integer types (NF90_UBYTE, NF90_USHORT, NF90_UINT, NF90_INT64, NF90_UINT64).
Learning Objectives:
- Understand NetCDF-4 hierarchical group structures in Fortran
- Learn to create and navigate nested groups
- Master dimension visibility rules across group boundaries
- Work with all five new NetCDF-4 integer types
- Recognize when groups provide organizational benefits
Key Concepts:
- Hierarchical Groups: Organize datasets into logical groupings (like directories)
- Dimension Visibility: Parent dimensions visible in all child groups
- Variable Scoping: Variables only visible in their defining group
- Group Navigation: Use nf90_inq_grp_ncid() to navigate by name
- New Integer Types: NF90_UBYTE, NF90_USHORT, NF90_UINT, NF90_INT64, NF90_UINT64
NetCDF-4 Group Architecture:
- Groups implemented via NC_GRP_INFO_T structures (libsrc4/libhdf5)
- Dimensions visible in child groups via parent chain lookup
- Variables NOT inherited (scoped to defining group only)
- Requires NF90_NETCDF4 flag (HDF5 backend)
- Not compatible with NF90_CLASSIC_MODEL
Dimension Visibility Rules:
- Dimensions defined in a group are visible in that group and all descendants
- Root dimensions (x, y) visible in SubGroup1, SubGroup2, and NestedGroup
- Local dimensions (z in NestedGroup) only visible in defining group
- Dimension lookup walks parent chain: child → parent → root
Use Cases for Groups:
- Multi-instrument datasets: Group data by instrument or sensor
- Model ensembles: Separate ensemble members into groups
- Quality levels: Organize raw, calibrated, and derived products
- Temporal organization: Group data by year, month, or campaign
- Namespace management: Avoid variable name conflicts
Prerequisites:
Related Examples:
Compilation:
program f_groups
Definition f_groups.f90:79
Usage:
Expected Output: Creates f_groups.nc in NetCDF-4/HDF5 format containing:
- Root group with dimensions x(3), y(4) and variable ubyte_var(NF90_UBYTE)
- SubGroup1 with variable ushort_var(NF90_USHORT)
- SubGroup2 with variable uint_var(NF90_UINT)
- NestedGroup (under SubGroup2) with dimension z(2) and variables:
- int64_var(NF90_INT64, 2D: x, y)
- uint64_var(NF90_UINT64, 3D: x, y, z)
- Author
- Edward Hartnett, Intelligent Data Design, Inc.
- Date
- 2026