Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WRF 4.1.2 installation with netCDF4, HDF5 in ubuntu 18.04 LTS
#!/bin/bash
## WRF installation with parallel process.
# Download and install required library and data files for WRF.
# License: LGPL
# Jamal Khan <jamal.khan@legos.obs-mip.fr>
# Tested in Ubuntu 18.04 LTS
# basic package managment
sudo apt update
sudo apt upgrade
sudo apt install gcc gfortran g++ libtool automake autoconf make m4 grads default-jre csh
## Directory Listing
export HOME=`cd;pwd`
mkdir $HOME/WRF
cd $HOME/WRF
mkdir Downloads
mkdir Library
## Downloading Libraries
cd Downloads
wget -c https://www.zlib.net/zlib-1.2.11.tar.gz
wget -c https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.5/src/hdf5-1.10.5.tar.gz
wget -c https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.7.1.tar.gz
wget -c https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.5.1.tar.gz
wget -c http://www.mpich.org/static/downloads/3.3.1/mpich-3.3.1.tar.gz
wget -c https://download.sourceforge.net/libpng/libpng-1.6.37.tar.gz
wget -c https://www.ece.uvic.ca/~frodo/jasper/software/jasper-1.900.1.zip
# Compilers
export DIR=$HOME/WRF/Library
export CC=gcc
export CXX=g++
export FC=gfortran
export F77=gfortran
# zlib
cd $HOME/WRF/Downloads
tar -xvzf zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure --prefix=$DIR
make
make install
# hdf5 library for netcdf4 functionality
cd $HOME/WRF/Downloads
tar -xvzf hdf5-1.10.5.tar.gz
cd hdf5-1.10.5
./configure --prefix=$DIR --with-zlib=$DIR --enable-hl --enable-fortran
make check
make install
export HDF5=$DIR
export LD_LIBRARY_PATH=$DIR/lib:$LD_LIBRARY_PATH
## Install NETCDF C Library
cd $HOME/WRF/Downloads
tar -xvzf netcdf-c-4.7.1.tar.gz
cd netcdf-c-4.7.1/
export CPPFLAGS=-I$DIR/include
export LDFLAGS=-L$DIR/lib
./configure --prefix=$DIR --disable-dap
make check
make install
export PATH=$DIR/bin:$PATH
export NETCDF=$DIR
## NetCDF fortran library
cd $HOME/WRF/Downloads
tar -xvzf netcdf-fortran-4.5.1.tar.gz
cd netcdf-fortran-4.5.1/
export LD_LIBRARY_PATH=$DIR/lib:$LD_LIBRARY_PATH
export CPPFLAGS=-I$DIR/include
export LDFLAGS=-L$DIR/lib
export LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lz"
./configure --prefix=$DIR --disable-shared
make check
make install
## MPICH
cd $HOME/WRF/Downloads
tar -xvzf mpich-3.3.1.tar.gz
cd mpich-3.3.1/
./configure --prefix=$DIR
make
make install
export PATH=$DIR/bin:$PATH
# libpng
cd $HOME/WRF/Downloads
export LDFLAGS=-L$DIR/lib
export CPPFLAGS=-I$DIR/include
tar -xvzf libpng-1.6.37.tar.gz
cd libpng-1.6.37/
./configure --prefix=$DIR
make
make install
# JasPer
cd $HOME/WRF/Downloads
unzip jasper-1.900.1.zip
cd jasper-1.900.1/
autoreconf -i
./configure --prefix=$DIR
make
make install
export JASPERLIB=$DIR/lib
export JASPERINC=$DIR/include
############################ WRF 4.1.2 #################################
## WRF v4.1.2
## Downloaded from git tagged releases
########################################################################
cd $HOME/WRF/Downloads
wget -c https://github.com/wrf-model/WRF/archive/v4.1.2.tar.gz
tar -xvzf v4.1.2.tar.gz -C $HOME/WRF
cd $HOME/WRF/WRF-4.1.2
./clean
./configure # 34, 1 for gfortran and distributed memory
./compile em_real
export WRF_DIR=$HOME/WRF/WRF-4.1.2
## WPSV4.1
cd $HOME/WRF/Downloads
wget -c https://github.com/wrf-model/WPS/archive/v4.1.tar.gz
tar -xvzf v4.1.tar.gz -C $HOME/WRF
cd $HOME/WRF/WPS-4.1
./configure #3
./compile
######################## Post-Processing Tools ####################
## ARWpost
cd $HOME/WRF/Downloads
wget -c http://www2.mmm.ucar.edu/wrf/src/ARWpost_V3.tar.gz
tar -xvzf ARWpost_V3.tar.gz -C $HOME/WRF
cd $HOME/WRF/ARWpost
./clean
sed -i -e 's/-lnetcdf/-lnetcdff -lnetcdf/g' $HOME/WRF/ARWpost/src/Makefile
./configure #3
sed -i -e 's/-C -P/-P/g' $HOME/WRF/ARWpost/configure.arwp
./compile
######################## Model Setup Tools ########################
## DomainWizard
cd $HOME/WRF/Downloads
wget -c http://esrl.noaa.gov/gsd/wrfportal/domainwizard/WRFDomainWizard.zip
mkdir $HOME/WRF/WRFDomainWizard
unzip WRFDomainWizard.zip -d $HOME/WRF/WRFDomainWizard
chmod +x $HOME/WRF/WRFDomainWizard/run_DomainWizard
######################## Static Geography Data ####################
# http://www2.mmm.ucar.edu/wrf/users/download/get_sources_wps_geog.html
cd $HOME/WRF/Downloads
wget -c https://www2.mmm.ucar.edu/wrf/src/wps_files/geog_high_res_mandatory.tar.gz
tar -xvzf geog_high_res_mandatory.tar.gz -C $HOME/WRF
## export PATH and LD_LIBRARY_PATH
echo "export PATH=$DIR/bin:$PATH" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$DIR/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
@uwbeint

This comment has been minimized.

Copy link

@uwbeint uwbeint commented Mar 24, 2020

Hi Jamal
I've found this Script and it is very useful.
I have try to install WRF on my Ubuntu 18.04 Server with many Problems. All finde, but at the ./compile em_real the executable files won't be created.

Now, i will try your Script.
Thank you very much, maybe you can help me out if it doesn't work?
EDIT: ./compile em_real doesn't work. (configure.wrf removed, it was a error with netcdf_classic or build netcdf with .-.enable.-netcdf-4).
Then, i stop the script and add export NETCDF_classic=1, configure WRF again and start to compile.
The Compile Process stopped with "---> Problems building executables, look for errors in the build log <---"

I have the Problem in Ubuntu 18.04 LTS and with every WRF Version from 3.8 up to WRF 4.1.2

Best Regards from Switzerland

@jamal919

This comment has been minimized.

Copy link
Owner Author

@jamal919 jamal919 commented Mar 24, 2020

Hi, could you please share the build logs? May be by email?

Thanks.

@uwbeint

This comment has been minimized.

Copy link

@uwbeint uwbeint commented Mar 24, 2020

I have found First #Bug in your Script:
This File was not found:
wget -c https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.7.1.tar.gz
I have replaced with
wget -c -O netcdf-c-4.7.1.tar.gz https://github.com/Unidata/netcdf-c/archive/v4.7.1.tar.gz

@uwbeint

This comment has been minimized.

Copy link

@uwbeint uwbeint commented Mar 24, 2020

Hi, could you please share the build logs? May be by email?

Thanks.

Yes, i will after my 2nd test to install. I use also 'sudo make install' instead of 'make install', because i'm logged in with a normal user in group sudo, but not as root.

@leonardojimenez1990

This comment has been minimized.

Copy link

@leonardojimenez1990 leonardojimenez1990 commented Nov 17, 2020

tar xzvf netcdf-c-4.7.1.tar.gz

  • tar -xzvf netcdf-c-4.7.1.tar.gz
@ankit12422

This comment has been minimized.

Copy link

@ankit12422 ankit12422 commented Feb 4, 2021

Thanks...
Due to your script, I successfully installed WRF4.1...

@jamal919

This comment has been minimized.

Copy link
Owner Author

@jamal919 jamal919 commented Mar 16, 2021

I have found First #Bug in your Script:
This File was not found:
wget -c https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.7.1.tar.gz
I have replaced with
wget -c -O netcdf-c-4.7.1.tar.gz https://github.com/Unidata/netcdf-c/archive/v4.7.1.tar.gz

Thanks for reporting. It seems to be high time the script is revised.

@jamal919

This comment has been minimized.

Copy link
Owner Author

@jamal919 jamal919 commented Mar 16, 2021

tar xzvf netcdf-c-4.7.1.tar.gz

  • tar -xzvf netcdf-c-4.7.1.tar.gz

Thanks!

@ben029med

This comment has been minimized.

Copy link

@ben029med ben029med commented May 20, 2021

This is the complete installation for WRF ??

@jamal919

This comment has been minimized.

Copy link
Owner Author

@jamal919 jamal919 commented May 23, 2021

This is the complete installation for WRF ??
@ben029med, I think I did not understand your remark.

@dereckvan01

This comment has been minimized.

Copy link

@dereckvan01 dereckvan01 commented Jun 4, 2021

thanks man¡ youre awsome¡

@ChanaChancham

This comment has been minimized.

Copy link

@ChanaChancham ChanaChancham commented Jun 7, 2021

Thank guy !

@tamerthamoqa

This comment has been minimized.

Copy link

@tamerthamoqa tamerthamoqa commented Jul 14, 2021

Thank you very much.

@srikar-iist

This comment has been minimized.

Copy link

@srikar-iist srikar-iist commented Aug 14, 2021

Can we use the Same for Installing WRF 4.3, with all the latest libraries ?

And while installing HDF 5, i am getting the following errors: (4.1.2)

***** 12 FAILURES! *****
Command exited with non-zero status 1
0.87user 0.26system 0:01.30elapsed 87%CPU (0avgtext+0avgdata 4048maxresident)k
0inputs+0outputs (0major+17978minor)pagefaults 0swaps
make[4]: *** [Makefile:3143: dt_arith.chkexe_] Error 1
make[4]: Leaving directory '/home/nitian/WRF/Downloads/hdf5-1.10.5/test'
make[3]: *** [Makefile:3129: build-check-s] Error 2
make[3]: Leaving directory '/home/nitian/WRF/Downloads/hdf5-1.10.5/test'
make[2]: *** [Makefile:3123: test] Error 2
make[2]: Leaving directory '/home/nitian/WRF/Downloads/hdf5-1.10.5/test'
make[1]: *** [Makefile:2906: check-am] Error 2
make[1]: Leaving directory '/home/nitian/WRF/Downloads/hdf5-1.10.5/test'
make: *** [Makefile:654: check-recursive] Error 1

@whatheway

This comment has been minimized.

Copy link

@whatheway whatheway commented Aug 14, 2021

@LujunZz

This comment has been minimized.

Copy link

@LujunZz LujunZz commented Aug 22, 2021

Wonderful! Thanks a lot for sharing this script!

@amirs2a

This comment has been minimized.

Copy link

@amirs2a amirs2a commented Oct 7, 2021

Hi jamal,
I was wondering if there is a way to fix the JASPERINC and JASPERLIB error when configuring wrf? I don't know how to link zlib, jasper and libpng into a grib2 directory using your script.

@ilomilo98

This comment has been minimized.

Copy link

@ilomilo98 ilomilo98 commented Oct 19, 2021

You chose option 3 while installing WPS. What is the difference with option 1 and option 3? Does it change WRF run speed?

  1. Linux x86_64, gfortran (serial) ***
  2. Linux x86_64, gfortran (serial_NO_GRIB2)
  3. Linux x86_64, gfortran (dmpar) ***
@whatheway

This comment has been minimized.

Copy link

@whatheway whatheway commented Oct 19, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment