Building NetCDF fortran90 libraries on Macintosh OS X

Here are directions for building netcdf with all fortran 90 features on Macintosh OS X 10.2 using the NAG f95 compiler. make test runs successfully through all tests.

  1. Define the variables:
    setenv FC /usr/local/bin/f95
    setenv FFLAGS "-O -dusty -w"
    setenv F90 /usr/local/bin/f95
    setenv FPP "/usr/local/bin/f95 -fpp"
    setenv F90FLAGS "-O -w=unused -mismatch_all"
    setenv CPPFLAGS "-DNAGf90Fortran"
  2. Run

    configure <--prefix=installation_directory>
  3. OS X is case insensitive, which causes problems with .F files. To work around, modify the .F.o rule in the rules.make file. It should read like this:

    # Not all FORTRAN compilers support C-preprocessing of *.F files; ergo, a
    # relatively complicated rule ensues.
            @case "$(COMPILE.F)" in \
                '') \
                    set -x; \
                    cp $*.F $*.ff; \
                    $(FPP) $(FPPFLAGS) -c -O -dusty -w $*.ff ;      \
                    ;;      \
                *)  \
                    set -x; \
                    $(COMPILE.F) $<;        \
                    ;;      \
  4. Add this line to the file nf_test.F in the directory nf_test, after the program nf_test statement:
    (this will define iargc and getenv) comment out this line:
       integer         iarg

    (conflicts with f90_unix_env)

  5. Run
    make test
  6. Run
    make install
  7. manually copy src/f90/netcdf.mod src/f90/typesizes.mod to /usr/local/include, or wherever the installation is supposed to go.
Thanks to Massimiliano Fatica, Center for Turbulence Research, Stanford University, for his help in getting this to work.