NEP 1.7.0
NetCDF Extension Pack: compression extensions for NetCDF
Loading...
Searching...
No Matches
Functions/Subroutines
f_user_types.f90 File Reference

Demonstrates NetCDF-4 user-defined types (Fortran) More...

Functions/Subroutines

program f_user_types
 
subroutine handle_err (status)
 

Detailed Description

Demonstrates NetCDF-4 user-defined types (Fortran)

Fortran equivalent of user_types.c, demonstrating NetCDF-4 user-defined types using the Fortran 90 NetCDF API. This example focuses on enum and opaque types, which are the user-defined types that work well from Fortran.

Compound types and variable-length types are not demonstrated here because the Fortran language does not provide portable control over derived type memory layout (needed for compounds) or a native equivalent of the C nc_vlen_t struct (needed for vlens). See user_types.c for those types.

Enum types work naturally in Fortran because the underlying data is just integers. The enum type definition and member names are metadata; the actual data written and read is an integer array using nf_put_var_int and nf_get_var_int.

Opaque types store fixed-size binary blobs. In Fortran, a character buffer of the appropriate length serves as the data container.

This example uses the Fortran 77 API (nf_* functions) because the Fortran 90 nf90_def_var wrapper validates the xtype argument against built-in types and rejects user-defined type IDs. The nf_def_var function passes the type ID directly to the C library, which handles user-defined types correctly.

Learning Objectives:

Prerequisites:

Related Examples:

Compilation:

gfortran -o f_user_types f_user_types.f90 -lnetcdff -lnetcdf
program f_user_types
Definition f_user_types.f90:48
Author
Edward Hartnett, Intelligent Data Design, Inc.
Date
2026

Function/Subroutine Documentation

◆ f_user_types()

program f_user_types

◆ handle_err()

subroutine f_user_types::handle_err ( integer, intent(in)  status)