See also Mox_building_netcdf
Below are steps to compile a fortran program which uses netcdf with the intel compiler ifort.
Load the appropriate netcdf+compiler module
Use module avail to see a list of netcdf+compiler options. Below is one possible choice:
module load netcdf_fortran_4.4.1-icc_15.0
Compiling using a Makefile
If you are using a Makefile then inside your Makefile you should have lines similar to below:
FFLAGS = -O3 -fp-model source -I/sw/netcdf-fortran-4.4.1_icc-15.0/include
LDFLAGS = -L/usr/lib64 -L/sw/netcdf-4.3.2_icc-15.0/lib -lnetcdff -lnetcdf -L/sw/netcdf-fortran-4.4.1_icc-15.0/lib
Now you can run make.
Compiling at command line
If you are compiling your code at the command line then you should issue commands similar to below commands:
export FFLAGS = -O3 -fp-model source -I/sw/netcdf-fortran-4.4.1_icc-15.0/include
export LDFLAGS = -L/usr/lib64 -L/sw/netcdf-4.3.2_icc-15.0/lib -lnetcdff -lnetcdf -L/sw/netcdf-fortran-4.4.1_icc-15.0/lib
Now you can run the ifort compiler.
(1) The "-O3 -fp-model source" and "-L/usr/lib64" can be replaced by your choice of compiler and linker flags.
(2) The underscores and dashes in the module name and corresponding directory on /sw are not at the same place.
(3) Use below command to find location of netcdf:
(4) Use below command to find header information for netcdf file pqr.nc
ncdump -h pqr.nc
(5) Use below command to find the type of the netcdf file pqr.nc
ncdump -k pqr.nc
The above command will return classic, "64-bit offset", etc.
(6) head -1 pqr.nc
CDF 0001 means netcdf classic
CDF 0002 means netcdf 64 bit offset
See section on ""How can I tell which format a netCDF file uses?
Example netcdf files:
Example netcdf programs: