Next: , Previous: Summary of Fortran 90 Interface, Up: Top


Appendix B Appendix B - FORTRAN 77 to Fortran 90 Transition Guide

The new Fortran 90 interface

The Fortran 90 interface to the netCDF library closely follows the FORTRAN 77 interface. In most cases, function and constant names and argument lists are the same, except that nf90_ replaces nf_ in names. The Fortran 90 interface is much smaller than the FORTRAN 77 interface, however. This has been accomplished by using optional arguments and overloaded functions wherever possible.

Because FORTRAN 77 is a subset of Fortran 90, there is no reason to modify working FORTRAN code to use the Fortran 90 interface. New code, however, can easily be patterned after existing FORTRAN while taking advantage of the simpler interface. Some compilers may provide additional support when using Fortran 90. For example, compilers may issue warnings if arguments with intent( in) are not set before they are passed to a procedure.

The Fortran 90 interface is currently implemented as a set of wrappers around the base FORTRAN subroutines in the netCDF distribution. Future versions may be implemented entirely in Fortran 90, adding additional error checking possibilities.

Changes to Inquiry functions

In the Fortran 90 interface there are two inquiry functions each for dimensions, variables, and attributes, and a single inquiry function for datasets. These functions take optional arguments, allowing users to request only the information they need. These functions replace the many-argument and single-argument inquiry functions in the FORTRAN interface.

As an example, compare the attribute inquiry functions in the Fortran 90 interface

      function nf90_inquire_attribute(ncid, varid, name, xtype, len, attnum)
        integer,             intent( in)           :: ncid, varid
        character (len = *), intent( in)           :: name
        integer,             intent(out), optional :: xtype, len, attnum
        integer                                    :: nf90_inquire_attribute
      function nf90_inq_attname(ncid, varid, attnum, name)
        integer,             intent( in) :: ncid, varid, attnum
        character (len = *), intent(out) :: name
        integer                          :: nf90_inq_attname

with those in the FORTRAN interface

      INTEGER FUNCTION  NF_INQ_ATT        (NCID, VARID, NAME, xtype, len)
      INTEGER FUNCTION  NF_INQ_ATTID      (NCID, VARID, NAME, attnum)
      INTEGER FUNCTION  NF_INQ_ATTTYPE    (NCID, VARID, NAME, xtype)
      INTEGER FUNCTION  NF_INQ_ATTLEN     (NCID, VARID, NAME, len)
      INTEGER FUNCTION  NF_INQ_ATTNAME    (NCID, VARID, ATTNUM, name)

Changes to put and get function

The biggest simplification in the Fortran 90 is in the nf90_put_var and nf90_get_var functions. Both functions are overloaded: the values argument can be a scalar or an array any rank (7 is the maximum rank allowed by Fortran 90), and may be of any numeric type or the default character type. The netCDF library provides transparent conversion between the external representation of the data and the desired internal representation.

The start, count, stride, and map arguments to nf90_put_var and nf90_get_var are optional. By default, data is read from or written to consecutive values of starting at the origin of the netCDF variable; the shape of the argument determines how many values are read from or written to each dimension. Any or all of these arguments may be supplied to override the default behavior.

Note also that Fortran 90 allows arbitrary array sections to be passed to any procedure, which may greatly simplify programming. For examples see NF90_PUT_VAR and NF90_GET_VAR.