|
NEP 1.7.0
NetCDF Extension Pack: compression extensions for NetCDF
|
Demonstrates NetCDF-4 user-defined types (Fortran) More...
Functions/Subroutines | |
| program | f_user_types |
| subroutine | handle_err (status) |
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:
| program f_user_types |
| subroutine f_user_types::handle_err | ( | integer, intent(in) | status | ) |