The netCDF library

From Planets
Revision as of 07:48, 1 June 2023 by Emillour (talk | contribs)

Jump to: navigation, search

the NetCDF library

The model reads and writes input and output files in NetCDF (Network Common Data Form) format (developed and maintained by Unidata: https://www.unidata.ucar.edu/software/netcdf/ ) and therefore a NetCDF library must be at hand when compiling and running the PCM.

As this library is not quite standard, chances are that you might need to install it yourself on your system, hence this page with some indications on how to do so.

Checking if a NetCDF library is already available

It is possible that the library, including its Fortran component, is already available. An easy way to check this is to see if the related utilities like ncdump are available, i.e. that

which ncdump

returns a positive answer.

Note that this does not suffice as the full library, including its Fortran component, and not just the related utilities are required. A neat way to check this is to use the nf-config

nf-config --all

returns something meaningful. If not, you probably need to take some action along the lines of what is indicated in the following sections.

Various ways to install the NetCDF library

Install from the package repository of your Linux distribution

This is the easiest and fastest (and recommended) way. For example, if your distribution is Ubuntu or Linux Mint (and you have admin, i.e. sudo rights), open a terminal and type:

sudo apt install netcdf-bin libnetcdff-dev

If you want to use XIOS with the PCMs then you need the parallel-enabled version of NetCDF. In addition to the previous apt install command, under Ubuntu or Linux Mint, type:

 sudo apt install libnetcdf-mpi-dev libhdf5-mpi-dev

Guidelines for personal installation

Prerequisites

There are not many prerequisites to install the NetCDF library, appart from having C and Fortran compilers at hand. The installation infrastructure also requires some very common shell tools which are usually available (gmake, m4, etc.).

Manually installing the library

One can always download the source code and compile the NetCDF library (see https://docs.unidata.ucar.edu/netcdf-c/current/faq.html#HowdoIgetthenetCDFsoftwarepackage and https://docs.unidata.ucar.edu/nug/current/getting_and_building_netcdf.html). You may try the following home-made "install_netcdf4_hdf5_seq.bash" script to do so (or simply to get some inspiration on the various steps). For this, run the following commands for instance from your home directory:

mkdir netcdf
cd netcdf
wget -nv --no-check-certificate http://www.lmd.jussieu.fr/~lmdz/pub/script_install/install_netcdf4_hdf5_seq.bash
chmod u=rwx install_netcdf4_hdf5_seq.bash
./install_netcdf4_hdf5_seq.bash > netcdf.log 2>&1

Compiling the library and dependencies can take a while (>>15 minutes; be patient). Once this is done, check file netcdf.log to verify that all went well. You may want to also add its "bin" directory to your PATH environment variable by adding in your .bashrc a line of:

export PATH=$PATH:$HOME/netcdf/bin

The assumption here is that you have run the "install_netcdf4_hdf5_seq.bash" script in a "netcdf" subdirectory of your home directory. Adapt accordingly if not.

Check that the installation was successfully installed :-) Again, a neat way to do that is to run and check the output of

nf-config --all

Personal installation of an advanced NetCDF4-HDF5 library with MPI enabled

This specific version is useful especially if running with the XIOS library. A prerequisite is to have an MPI library installed and available. You can use the following home-made "install_netcdf4_hdf5_seq.bash" script to do so. For this, ensure that you are in your home directory and:

mkdir netcdf4hdf5
cd netcdf4hdf5
wget -nv --no-check-certificate http://www.lmd.jussieu.fr/~lmdz/pub/script_install/install_netcdf4_hdf5.bash
chmod u=rwx install_netcdf4_hdf5.bash
./install_netcdf4_hdf5.bash -CC mpicc -FC mpif90 -CXX mpiCC -MPI /path/to/your/MPI/install > netcdf.log 2>&1

You should of course adapt the command line, especially the -MPI /path/to/your/MPI/install part to your settings.

Compiling the library and dependencies can take a while (>>15 minutes; be patient). Once this is done, check file netcdf.log to verify that all went well. You may want to also add its "bin" directory to your PATH environment variable by adding in your .bashrc a line of:

export PATH=$PATH:$HOME/netcdf4hdf5/bin

The assumption here is that you have run the "install_netcdf4_hdf5.bash" script in a "netcdf4hdf5" subdirectory of your home directory. Adapt accordingly if not.

Check that the installation was successfully installed :-) Again, a neat way to do that is to run and check the output of

nf-config --all

24/05/2023