[Install] Netcdf and Netcdf++ with their dependencies on linux

Just a reminder to myself about how to install the different libs (because some pages were simply wrong about that…)

Note that I install in “$HOME/install”.

# Download all
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/hdf5-1.8.13.tar.gz
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/zlib-1.2.8.tar.gz
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.4.1.tar.gz
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/szip-2.1.tar.gz
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-cxx-4.2.tar.gz
wget https://curl.haxx.se/download/curl-7.50.3.tar.gz

# Extract
tar -xvf hdf5-1.8.13.tar.gz
tar -xvf zlib-1.2.8.tar.gz
tar -xvf netcdf-4.4.1.tar.gz
tar -xvf szip-2.1.tar.gz
tar -xvf netcdf-cxx-4.2.tar.gz
tar -xvf curl-7.50.3.tar.gz


# SZIP
cd szip-2.1
export currentslibinstall="$HOME/install"
./configure --prefix=$currentslibinstall
make install

cd ..


# ZLIB
cd zlib-1.2.8
export currentzlibinstall="$HOME/install"
./configure --prefix=$currentzlibinstall
make install

cd ..

# HDF5
cd hdf5-1.8.13
export currenthdfinstall="$HOME/install"
./configure --with-zlib=$currentzlibinstall --prefix=$currenthdfinstall --with-szlib=$currentslibinstall --enable-cxx
# cxx and parallel are not compatible
# so
# ./configure --with-zlib=$currentzlibinstall --prefix=$currenthdfinstall --with-szlib=$currentslibinstall --disable-cxx --disable-fortran --enable-shared --enable-parallel
# will not turn on cxx, just select what you want
make install

cd ..

# Libcurl
cd curl-7.50.3
export currentcurlinstall="$HOME/install"
./configure --without-ssl --prefix=$currentcurlinstall
make install

cd ..


# NETCDF
cd netcdf-4.4.1
export currentnetcdfinstall="$HOME/install"
export CPPFLAGS="-I$currenthdfinstall/include -I$currentzlibinstall/include -I$currentslibinstall/include -I$currentcurlinstall/include"
export LDFLAGS="-L$currenthdfinstall/lib -L$currentzlibinstall/lib -L$currentslibinstall/lib -L$currentcurlinstall/lib"
./configure --enable-netcdf-4 --prefix=$currentnetcdfinstall
make install

cd ..

# NETCDF++
cd netcdf-cxx-4.2
export currentnetcdfxxinstall="$HOME/install"
export CPPFLAGS="-I$currenthdfinstall/include -I$currentzlibinstall/include -I$currentslibinstall/include -I$currentnetcdfinstall/include"
export LDFLAGS="-L$currenthdfinstall/lib -L$currentzlibinstall/lib -L$currentslibinstall/lib -L$currentnetcdfinstall/lib"
autoreconf -if
./configure --prefix=$currentnetcdfxxinstall
make install

# Export
export LD_LIBRARY_PATH="$currenthdfinstall/lib:$currentzlibinstall/lib:$currentslibinstall/lib:$currentnetcdfinstall/lib:${LD_LIBRARY_PATH}"


# If m4 is missing
# https://geeksww.com/tutorials/libraries/m4/installation/installing_m4_macro_processor_ubuntu_linux.php