Child pages
  • Mox_building_netcdf
Skip to end of metadata
Go to start of metadata

HDF5 is a pre-req for netCDF. See Mox_building_hdf5 and build hdf5 before building netcdf4.

See also Hyak netcdf

(The Fortran .mod files produced by different compilers are not compatible. Each time you use a different compiler, you should download the source code for HDF5 and netcdf again and keep it in different new directories. Then you can follow the instructions in this page.)


Below are steps to build netcdf4 libraries.Here xyz is your hyak group and abc is your hyak userid.

(1) srun -p build --time=4:00:00 --mem=10G --pty /bin/bash

(2) module load gcc/8.2.1

     (You can load a gcc or icc module of your choice, Above is only an example. "module avail gcc" and "module avail icc" will give you the choices.)

(3) mkdir /gscratch/xyz/abc/netcdfstuff

(4) mkdir /gscratch/xyz/abc/netcdfinstall

(5) cd /gscratch/xyz/abc/netcdfstuff

(6) wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-c-4.7.1.tar.gz

(7) wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-fortran-4.5.1.tar.gz

(8) tar -xvf netcdf-c-4.7.1.tar.gz

(9) tar -xvf netcdf-fortran-4.5.1.tar.gz

(10) export NCDIR=/gscratch/xyz/abc/netcdfinstall

       export H5DIR=/gscratch/xyz/abc/hdf5install

       export LD_LIBRARY_PATH=${H5DIR}/lib:$LD_LIBRARY_PATH

(11) cd netcdf-c-4.7.1

(12) CPPFLAGS=-I${H5DIR}/include LDFLAGS=-L${H5DIR}/lib ./configure --prefix=${NCDIR}

(13) make

(14) make install

(15) cd ..

(16) cd netcdf-fortran-4.5.1

(17) export NFDIR=/gscratch/xyz/abc/netcdfinstall

(18) export LD_LIBRARY_PATH=${NCDIR}/lib:${LD_LIBRARY_PATH}

(19) CPPFLAGS=-I${NCDIR}/include LDFLAGS=-L${NCDIR}/lib ./configure --prefix=${NFDIR}

(20) make

(21) make install

(22) The netcdf libraries are in /gscratch/xyz/abc/netcdfinstall/lib 

       The netcdf commands (like ncdump) are in /gscratch/xyz/abc/netcdfinstall/bin

       The netcdf header files are in /gscratch/xyz/abc/netcdfinstall/include 



How to find the type of some netcdf file before you have installed netcdf:

Suppose your netCDF file is pqr.nc.

Issue below command:

head -1 pqr.nc

From the output of the above command if you can find the type of the netcdf file.

CDF 0001 means netcdf classic

CDF 0002 means netcdf 64 bit offset

and so on


Once you have installed netcdf, you can use netcdf command ncdump. Note that ncdump is in the netcdf install's bin directory.

ncdump -k pqr.nc

From the output of the above command, you will get classic, 64 bit offset etc.


Reference:

https://www.unidata.ucar.edu/software/netcdf/docs/getting_and_building_netcdf.html#building

Notes on the reference:

(1) The section on "Building netCDF-4 and the Remote Data Client from source" has a configure command which uses single quotes.

It should use double quotes instead of single quotes in order to allow bash string interpolation.

In above step 12 configure command we do not have any quotes since we are not using zlib.

(2) The section "Building netCDF with Classic Library Only" has a configure command with --disable-netcdf-4 and --disable-dap options. Do not use these options since the Fortran netcdf library will not work with these options.



  • No labels