JULES is most usually run with links to an appropriate NetCDF installation on your system * . Many compilation errors for JULES can be traced back to not having NetCDF set up correctly on your platform (which is why I needed to set up this webpage). Here is my 3-step check of your NetCDF installation, with many thanks to Andrew Everitt at UKCEH for most of this information.
The first thing to say is that NetCDF libraries are different depending on (1) the compiler you are using and (2) whether or not you are running JULES in parallel, i.e. you are using MPI libraries, which requires Intel MPI (if your compiler is ifort) or OpenMPI (if your compiler is gfortran). Why don't server administrators just install all possible types of libraries for you? I suspect there are just too many different kinds of libraries: you have to know which libraries you need and link to them properly. For example, currently (Feb 2021) on JASMIN it's easiest to do non-parallel stuff using gfortran, but parallel stuff using ifort, because of the current availability of these library combinations.
* For JULES, a set of 'dummy' NetCDF libraries are maintained so that you can still run JULES with ASCII input and output and therefore avoid having NetCDF installed - see the option to "Select NetCDF or not" in the platform file as it is in $JULES_ROOT/etc/fcm-make/platform/custom.cfg - but most users prefer to use NetCDF I/O.
* For JASMIN, please note that the steps below do NOT yield the correct paths because of their rather complicated setup. Please see the JASMIN platform files in $JULES_ROOT/etc/fcm-make/platform/ for the correct paths to use on that platform.
(1) Check whether you actually do have NetCDF installed and whether you also have the Fortran and C++ components:
#General information on the NetCDF installation (specifically, check the -fflags and -flibs options):
#Check whether NetCDF C++ components have been installed:
#Check whether NetCDF Fortran components have been installed:
For this check, we just want to make sure these commands don't generate "command not found" errors. Since NetCDFvn4.2, the Fortran and C components of NetCDF must be installed separately (see here): running JULES requires the Fortran components so if the nf-config command fails then you will need to install these.
- If you find that you do need to install your NetCDF libraries yourself, then you will need to follow a tutorial (which one depends on the OS you are running):
- For Ubuntu and Fedora, all the packages you need are in the repository: see Ubuntu instructions here (Fedora/CentOS should be very similar). Because of the way that “apt” and other package managers work, it does not take too much to install the repository version. For Ubuntu 16.04 the following two lines will get the system to install the gcc compilation environment and NetCDF (the “dev” package usually requires all other related packages to be installed first).
- sudo apt-get install gcc gfortran
- sudo apt-get install libnetcdf-dev libnetcdff-dev
(2) Specify paths. In order to complete the compilation step for JULES (see here), you need to specify some paths for your installation. You need to find four paths:
#The NetCDF include path (includedir) is where header (.h) files are located (e.g. netcdf.h) (default /usr/local/include; at CEH I have /usr/include). Get this from:
#The NetCDF module path is where module (.mod) files such as netcdf.mod are located (default /usr/local/include, but on Fedora and other systems it can be a compiler-specific location e.g. at CEH I have /usr/lib64/gfortran/modules ***). Get this from:
find /usr -name "netcdf.mod" 2>/dev/null
#If you don't have NetCDF Fortran components installed then there will not be any .mod files and therefore no module path. *** Footnote for CEH users: on the linux boxes NetCDF libraries are only available for gfortran. If you need to use ifort, go to Cirrus and run that find command from /cm/shared/apps/ccs_netcdf to get the appropriate path.
#The NetCDF C library path (libdir) is where the library file libnetcdf.a or libnetcdf.so can be found (".a" means a static library file, ".so" means a dynamic shared object library file: generally a particular NetCDF installation runs from either static or dynamic shared libraries - see here - so you should only have one of these) (default /usr/local/lib; at CEH I have /usr/lib64). In theory this should always return the right location:
#However for some reason nc-config doesn't always have a "libdir" line (I don't know why), so rather get the correct path from this:
find /usr -name "libnetcdf.*" 2>/dev/null
#Even if you don't have NetCDF C components installed, there will still be a default library path.
#As it says here, when compiled in parallel mode, NetCDF must be statically linked, so if you are wanting to use parallel mode but only have .so libraries then note that you will need to talk to your IT administrators about getting static libraries installed as well.
#On some UNIX systems the environment variable $LD_LIBRARY_PATH is set to contain a colon-separated list of library locations (although not all, and many argue it's a bad idea to have it set actually). If you do have it set, one of these locations may be the location you need here so inspecting echo $LD_LIBRARY_PATH is worth doing.
#The NetCDF Fortran library path is where the library file libnetcdff.a or libnetcdff.so can be found (which may differ from the C library path if a shared installation is not possible on your system, see here) (default /usr/local/lib; at CEH I have /usr/lib64).
find /usr -name "libnetcdff.*" 2>/dev/null
#If you don't have NetCDF Fortran components installed then there will not be any Fortran library path.
#As above, inspecting echo $LD_LIBRARY_PATH might give you the path you need here.
OK so far. However, JULES asks for two paths to be specified in the platform file, not four: $JULES_NETCDF_INC_PATH and $JULES_NETCDF_LIB_PATH so which does it need? You need to put the module path in for _INC_PATH (not the include path if that is different) and you need to put the Fortran library path for _LIB_PATH (not the C library path if that is different).
(3) Check for missing libraries. If you have shared libraries then check the links on whichever of libnetcdf.so and libnetcdff.so exist, e.g.
This lists all dynamically-linked libraries that the library file needs (use "otool -L" for this on Macs). If there are any "=> not found"s then there are some libraries missing and your installation is incomplete. Even if all are found, if there are two versions of NetCDF installed on your platform then it might be picking up the libraries from a mixture of versions (e.g. links to the OS repository usually override links to a user's compiled version of NetCDF even if it has been installed later). This should be checked because it can cause problems if one of the conflicting versions is older than the other.
If (1) you are not missing any components from your installation, (2) you have specified the paths correctly and (3) your libraries are all present and linked correctly, then your NetCDF installation should be fine.