2010 Unidata NetCDF Workshop > Introduction to the NetCDF APIs and Example Programs
9.5 The Fortran-90 API
The Fortran-90 library provides current Fortran support for modelers and scientists.
Strengths
- Well-documented: The netCDF Fortran-90 Users Guide is complete and
up-to-date.
- Overloaded functions and optional arguments: The Fortran-90
interface is significantly
simpler than either the C or Fortran-77 interfaces because of its use of
overloaded functions and optional arguments. For example one
nf90_put_var() function
replaces thirty nf_put_var() functions in the Fortran-77 interface and
forty nc_put_var() functions in the C interface.
- Fewer arguments to functions: string lengths need not be passed
for attribute strings, and array lengths need not be passed for
dimension arrays. There are fewer and simpler inquiry functions in
the Fortran-90 interface with the use of optional arguments.
- Improved error checking: use of intent declarations lets
compilers check whether some arguments are used correctly.
- Arbitrary array sections supported: The language allows
arbitrary array sections to be passed to any procedure, which may
simplify programming.
- Full (but not portable) support for netCDF-4 extensions.
Weaknesses
- Order of subscripts in CDL: CDL uses row-major order for
matrices (last dimension varies fastest), but Fortran uses
column-major order (first dimension varies fastest), which can
occasionally lead to confusion.
- No ncgen support: ncgen cannot generate Fortran-90 code (yet),
although the Fortran-77 code ncgen3 generates works from Fortran-90.
- Memory handling: You have to provide memory
space for any netCDF data values and attribute values you read.
- Error handling: The status of every function call must be
checked, which detracts from code clarity.
Other Characteristics
- Implemented in Fortran-90 as a thin layer on top of
the Fortran-77 library, which in turn is a thin layer on top of the C
netCDF-3 library.
Examples
Annotated examples of complete Fortran90 netCDF programs are available from
the program examples page.
2010 Unidata NetCDF Workshop > Introduction to the NetCDF APIs and Example Programs