Procedure to build NetCDF for Fortran

  1. Set the location of the the NetCDF C library installation directory as NCDIR, for example:

    export NCDIR=/path/to/netcdf_install

    replacing /path/to/netcdf_install with the path to your NetCDF C installation.

    Note: This should be the directory used for the NetCDF installation completed in the Procedure to build NetCDF section.

  2. Create a build directory for NetCDF Fortran library, for example, called fnetcdf_build. Then set the install location for the NetCDF Fortran library to that of the NetCDF C library directory, using the environment variable NFDIR, for example:

    mkdir fnetcdf_build
    export build_dir=/path/to/fnetcdf_build
    export NFDIR=NCDIR
  3. Download and unpack NetCDF for Fortran:

    cd $build_dir
    tar -zxvf netcdf-fortran-4.4.5.tar.gz
  4. Set the compiler environment variables:

    export CC=armclang
    export CXX=armclang++
    export F77=armflang
    export FC=armflang
    export MPICC=mpicc
    export MPIFC=mpifort
    export MPICXX=mpicxx
  5. Change to the source directory and configure the build by passing the location of the HDF5 and NetCDF C library include and lib directories, using:

    export NFDIR=$NCDIR
    export CFLAGS="-L$hdf5_dir/lib -I$hdf5_dir/include -L$NCDIR/lib -I$NCDIR/include"
    export CXXFLAGS="-L$hdf5_dir/lib -I$hdf5_dir/include -L$NCDIR/lib -I$NCDIR/include"
    export FCFLAGS="-L$hdf5_dir/lib -I$hdf5_dir/include -L$NCDIR/lib -I$NCDIR/include"
    export CPPFLAGS="-I${hdf5_dir}/include -I${NCDIR}/include"
    export LDFLAGS="-L${hdf5_dir}/lib -L${NCDIR}/lib"
    export LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lz -lcurl"
    # Need netcdf and hdf5 libs in library path to allow configure tests to succeed
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$NCDIR/lib:$hdf5_dir/lib
    cd $build_dir/netcdf-fortran-4.4.5
    ./configure  --prefix=${NFDIR} --enable-shared --with-pic --disable-doxygen  
  6. Modify libtool to work with Arm Compiler, using:

    sed -i -e 's#wl=""#wl="-Wl,"#g' libtool
    sed -i -e 's#pic_flag=""#pic_flag=" -fPIC -DPIC"#g' libtool
  7. Build and install NetCDF for Fortran, using:

    make -j
    make check
    make install
Previous Next