Netcdf-fortran compile errors

There are a few discussions involving netcdf installations so I though I’d ask for help here. My CAMx work is waiting on a successful install of netcdf, and I’ve gotten through all but the last step which is the netcdf-fortran-4.4.5 component. I’m following step by step instructions modeled on the docs.unidata.ucar.edu pages, and have successfully done (in sequence) zlib-1.2.11, hdf5-1.10.5, and netcdf-c-4.6.1 and have confirmed that libnetcdf.a has been built.

However, I’ve encountered errors after making netcdf-fortran that I don’t understand, but I’m hoping someone with more experience will recognize them and suggest a solution. I’ve defined gcc and gfortran as compilers, the prefixes as paths in my /home, and pasted the build scripts and error messages further down.

Thank you, I appreciate any assistance as I’m mostly on my own in this. It’s been suggested that./configure options will fix this, but I haven’t found which ones those are.

NETCDF INSTALL SCRIPTS

---- Build the zlib library (used for compression) ----

tar xvzf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure --prefix={BLD_DIR}/zlib-1.2.11
make
make install

---- Build the HDF5 library (used for compression) ----

cd {SRC_DIR}
tar xvzf hdf5-1.10.5.tar.gz
cd hdf5-1.10.5
setenv LDFLAGS -L{BLD_DIR}/zlib-1.2.11
./configure --prefix={BLD_DIR}/hdf5-1.10.5 --enable-fortran
make
make install

---- Build the NetCDF C libraries ----

cd {SRC_DIR}
tar xvzf netcdf-c-4.6.1.tar.gz
cd netcdf-c-4.6.1
setenv CFLAGS -I{BLD_DIR}/hdf5-1.12.0/include
setenv LDFLAGS -L{BLD_DIR}/hdf5-1.12.0/lib
./configure --prefix=$CAMx_PKGS/netcdf-c-4.6.1 --disable-dap
make
make install

---- Build the NetCDF FORTRAN libraries ----

cd {SRC_DIR}
tar xvzf netcdf-fortran-4.4.5.tar.gz
cd netcdf-fortran-4.4.5
setenv CPPFLAGS -I{BLD_DIR}/netcdf-c-4.6.1/include
setenv LDFLAGS -L{BLD_DIR}/netcdf-c-4.6.1/lib
setenv LD_LIBRARY_PATH {BLD_DIR}/netcdf-c-4.6.1/lib
./configure --prefix={BLD_DIR}/netcdf-c-4.6.1
make
make install

NETCDF-FORTRAN MAKEFILE ERROR MESSAGES

Making install in fortran
make[1]: Entering directory ‘/home/enzo/NetCDF_Src/netcdf-fortran-4.4.5/fortran’
gfortran -g -O2 -c -o netcdf4.o netcdf4.f90
netcdf4_func.f90:730:75:

730 | inq_var_fill_FourByteReal = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 1


740 | inq_var_fill_EightByteReal = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (REAL(4)/REAL(8)).
netcdf4_func.f90:720:75:

720 | inq_var_fill_EightByteInt = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 1


740 | inq_var_fill_EightByteReal = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 2
Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(8)/REAL(8)).
netcdf4_func.f90:710:74:

710 | _inq_var_fill_FourByteInt = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 1


740 | _inq_var_fill_EightByteReal = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/REAL(8)).
netcdf4_func.f90:700:73:

700 | 0_inq_var_fill_TwoByteInt = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 1


740 | 0_inq_var_fill_EightByteReal = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(2)/REAL(8)).
netcdf4_func.f90:690:73:

690 | 0_inq_var_fill_OneByteInt = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 1


740 | 0_inq_var_fill_EightByteReal = nf_inq_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(1)/REAL(8)).
netcdf4_func.f90:670:75:

670 | def_var_fill_FourByteReal = nf_def_var_fill(ncid, varid, no_fill, fill)
| 1


680 | def_var_fill_EightByteReal = nf_def_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (REAL(4)/REAL(8)).
netcdf4_func.f90:660:75:
660 | def_var_fill_EightByteInt = nf_def_var_fill(ncid, varid, no_fill, fill)
| 1


680 | def_var_fill_EightByteReal = nf_def_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(8)/REAL(8)).
netcdf4_func.f90:650:74:

650 | _def_var_fill_FourByteInt = nf_def_var_fill(ncid, varid, no_fill, fill)
| 1


680 | _def_var_fill_EightByteReal = nf_def_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(4)/REAL(8)).
netcdf4_func.f90:640:73:
640 | 0_def_var_fill_TwoByteInt = nf_def_var_fill(ncid, varid, no_fill, fill)
| 1

680 | 0_def_var_fill_EightByteReal = nf_def_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(2)/REAL(8)).
netcdf4_func.f90:630:73:

630 | 0_def_var_fill_OneByteInt = nf_def_var_fill(ncid, varid, no_fill, fill)
| 1


680 | 0_def_var_fill_EightByteReal = nf_def_var_fill(ncid, varid, no_fill, fill)
| 2

Error: Type mismatch between actual argument at (1) and actual argument at (2) (INTEGER(1)/REAL(8)).
make[1]: *** [Makefile:626: netcdf4.o] Error 1
make[1]: Leaving directory ‘/home/enzo/NetCDF_Src/netcdf-fortran-4.4.5/fortran’
make: *** [Makefile:544: install-recursive] Error 1

This is a compiler-related issue, documented for the I/O API at https://cjcoats.github.io/ioapi/ERRORS.html#gfort10:

Versions 10 and later of gfortran take a particularly idiosyncratic interpretation of the (latest) Fortran-2018 Standard.
AS of July 12, 2020, the relevant ioapi/Makeinclude.${BIN} files have been modified to add Fortran compile-flag

-std=legacy
so that this interpretation does not cause a compile-error.
However, using this compiler version will cause the generation of a huge number of spurious warning-messages, as the compiler is still trying to enforce its version of the Fortran-2018 (not Fortran-90, not Fortran-95, not Fortran-2008) Standard.

Thanks to Mrs. Indumathi S Iyer, (SO/D), BARC, for pointing out this compiler-problem and help with testing the fix.—CJC

You need to add this flag (as part of FFLAGS, iirc) to the configuration for libnetcdff.

Thanks, I can follow that a bit but where exactly does the FFLAGS go? I tried adding setenv FFLAGS -fallow-argument-mismatch or setenv FFLAGS
-std=legacy to the netcdf-fortran script between the setenv LD_LIBRARY_PATH and ./configure lines, but neither worked and I got the same error messages.

I tried looking for an appropriate place for FFLAGS in the netcdf-fortran makefile but I wasn’t sure where it would work.

That is part of the configure part of the netCDF installation – have a look at the output of configure --help

I’ve read through the configure help text but it’s still unclear, is the usage something like:
./configure FFLAGS=“-fallow-argument-mismatch”
or
./configure FFLAGS=“-std=legacy”

For what it’s worth, I figured out a solution that works:

./configure --prefix={BLD_DIR}/netcdf-c-4.6.1 FFLAGS=“-fallow-argument-mismatch” FCFLAGS=“-fallow-argument-mismatch”

I had to do this again to install MPICH and MPI, so I guess using a GFortran compiler version 10 or newer will trigger the same errors. Caveat emptor.