Re: [netcdfgroup] What is the "standard" way to use NetCDF from Fortran 90?

Magnus Hagdorn <Magnus.Hagdorn@xxxxxxxx> writes:

> F90 source code is portable (as long as it is standard conforming and
> you have a decent compiler...)

Howdy Magnus!

As noted, fortran compilers do not produce compatible .mod files. This
can be a pain.

In practice it means you must build netCDF for every fortran compiler
you want to use on the machine. That is, if you want to use ifort and
gfortran on the same machine, you need to build the library twice, and
install them in different places. Then you have to use the correct one
when compiling fortran.

As you have also noted, sometimes a compiler will change (as gfortran
did a few years back), so you would need to recompile your netCDF
library. However, in practice, this seems to be rare. The gfortran case
is the only one I know of.

>> Basically this means I need to include the NetCDF library into my
>> model source. When there is no reliable external source to use, this

Including netCDF in your distribution is probably a bad idea. You don't
want to take this on, believe me.

What happens when we update netCDF in some important way, and you are
still distributing an older version? Not good.

Getting and installing netCDF is a well-solved problem. Just tell your
users to go to the Unidata web site and get the latest stable
release. (Always found here:
ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf.tar.gz)

In any case the idea of shipping netCDF with your code will not
scale. Starting with version 4.0 we (optionally) make use of other
libraries, like the HDF5 library. You don't want to have to distribute
all this too.

>> Now, perhaps that mess with Fortran libraries could be cleaned up when
>> there is a nice package of the Fortran wrapper part (for use with
>> NetCDF C API from some version up) that easily can be integrated in
>> custom build systems (in an automated way).

The mess with the fortran libraries is even worse than you imagine. The
F90 library is based on the F77 library, which is really a C library
pretending to be Fortran 77 for your compiler, and which then calls the
"real" netCDF C library.

This was all necessary because there was (until F2003) no standard
C/Fortran interoperability. 

The conversion of the current system to one based on Fortran 2003 will
clear away much of the confusion, but will not eliminate the requirement
for the netCDF fortran compiler to match the fortran compiler for your
particular application.

To fully implement your idea, you could distribute all the fortran code
from a revised, 2003 compliant, netCDF fortran API. But I would not
recommend this.

Thanks,

Ed

-- 
Ed Hartnett  -- ed@xxxxxxxxxxxxxxxx



  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: