External Links:
Unidata NetCDF page
NetCDF-C Tutorial
Here is an example Fortran 90 code that uses the NetCDF library from the Unidata NetCDF example programs page.
To avoid copy/paste errors when using, please copy this from the apps directory:
/usr/local/apps/examples/code/netcdf
To put the NetCDF libraries in the path for Intel, use
module load netcdf/4.6.1-intel2017
-lnetcdf
to include the NetCDF-C library, -lnetcdf -lnetcdff
to link the NetCDF-Fortran libraries, and use -I/usr/local/apps/netcdf-centos7/4.6.1-intel2017/include
to include the header files.
To test linking NetCDF with the Intel compiler, compile the example code above, run it, and check that it creates a properly formatted NetCDF file. (Note that normally code should never be run on a login node; this small test is an exception.)
[unityID@login]$ cp -r /usr/local/apps/examples/code/netcdf . [unityID@login]$ cd netcdf [unityID@login]$ module purge [unityID@login]$ module load netcdf/4.6.1-intel2017 [unityID@login]$ ifort -o test_intel example_h3_cf1_6.f90 -lnetcdf -lnetcdff -I/usr/local/apps/netcdf-centos7/4.6.1-intel2017/include [unityID@login]$ ./test_intel [unityID@login]$ file example_h3_cf1_6.nc example_h3_cf1_6.nc: NetCDF Data Format data
To put the NetCDF libraries in the path for GNU, use
module load netcdf/4.6.3-gcc4.8.5
-lnetcdf
to include the NetCDF-C library, -lnetcdf -lnetcdff
to link the NetCDF-Fortran libraries, and use -I/usr/local/apps/netcdf-centos7/4.6.3-gcc4.8.5/include
to include the header files.
To test linking NetCDF with the GNU compiler, compile the example code above, run it, and check that it creates a properly formatted NetCDF file. (Note that normally code should never be run on a login node; this small test is an exception.)
[unityID@login]$ cp -r /usr/local/apps/examples/code/netcdf . [unityID@login]$ cd netcdf [unityID@login]$ module purge [unityID@login]$ module load netcdf/4.6.3-gcc4.8.5 [unityID@login]$ gfortran -o test_gcc example_h3_cf1_6.f90 -lnetcdf -lnetcdff -I/usr/local/apps/netcdf-centos7/4.6.3-gcc4.8.5/include [unityID@login]$ ./test_gcc [unityID@login]$ file example_h3_cf1_6.nc example_h3_cf1_6.nc: NetCDF Data Format data
NetCDF modules include the MPI libraries (Intel MPI for Intel, and OpenMPI for GNU). After loading the NetCDF module, type module list
for the list of other included modules. To use NetCDF with another code, the MPI libraries must be the same.
NetCDF and prerequisite HDF5 were compiled with the following compiler flags. Intel was compiled similarly but with a different prefix.
HDF5: ./configure --prefix=/usr/local/apps/hdf-centos7/hdf5/v1.10.5-gcc4.8.5 --enable-hl --enable-parallel NetCDF: ./configure --prefix=/usr/local/apps/netcdf-centos7/4.6.3-gcc4.8.5If an application requires the NetCDF libraries/modules to be compiled with different flags, the user must install a custom version under a space for user maintained software.
Last modified: March 23 2022 13:18:05.