由于本人安装过多次、多个版本的WRF程序,走了许多弯路,不忍心大家再像我一样浪费时间,所以整理一些可用经验。参考Compiling WRF (ucar.edu)
-
系统环境配置
1、首先确保有没有安装好编译语言gfortran、gcc、g++以及cpp。
2、创建WRF工作文件及其后续可能用得上的子文件。之所以选择在~/目录下直接建立WRF工作站,主要是方便所有人访问,不需要host/sudo权限。
which gfortran
which cpp
which gcc
sudo apt install gfortran gcc cpp g++ make
gcc --version
gfortran --version
cpp --version
mkdir ~/WRF_WorkStation
mkdir ~/WRF_WorkStation/Libraries
mkdir ~/WRF_WorkStation/netcdf
mkdir ~/WRF_WorkStation/grib2
mkdir ~/WRF_WorkStation/mpich
mkdir ~/WRF_WorkStation/test
3、进入~/WRF_WorkStation/test文件中,将下载好的Fortran and C Tests Tar File 解压。具体的测试成功与否请参照Compiling WRF (ucar.edu)
tar -xf Fortran_C_tests.tar
gfortran TEST_1_fortran_only_fixed.f
./a.out
gfortran TEST_2_fortran_only_free.f90
./a.out
gcc TEST_3_c_only.c
./a.out
gcc -c -m64 TEST_4_fortran+c_c.c
gfortran -c -m64 TEST_4_fortran+c_f.f90
gfortran -m64 TEST_4_fortran+c_f.o TEST_4_fortran+c_c.o
./a.out
./TEST_csh.csh
./TEST_perl.pl
./TEST_sh.sh
其他的unix命令可以后续需要的时候下载!命令下载方式是
sudo apt install command
-
创建库
1、进入到WRF工作文件夹下的Libraries目录下。
cd ~/WRF_WorkStation/Libraries
将
mpich-3.0.4
netcdf-4.1.3
Jasper-1.900.1
libpng-1.2.50
zlib-1.2.7
五个压缩包下载到其中,后续可以删掉,也可以保留,随个人喜好。
2、修改~/.bashrc环境配置,这一步必须有!!!注意###后的内容全部都应该在~/.bashrc的尾部加入,然后用source ~/.bashrc生效。
vi ~/.bashrc
###-----------------------WRF installation-----------------###
export DIR=/home/hsy/WRF_WORKSTATION/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include
source ~/.bashrc
3、配置netcdf。
tar xzvf netcdf-4.1.3.tar.gz #or just .tar if no .gz present
cd netcdf-4.1.3
./configure --prefix=$DIR/netcdf --disable-dap --disable-netcdf-4 --disable-shared
make
make install
vi ~/.bashrc
###--->netcdf<---###
export NETCDF=$DIR/netcdf
export PATH=$NETCDF/bin:$PATH
source ~/.bashrc
nc-config
netcdf安装过程可能会有各种各样的问题,请小心操作,一定要谨慎,不能弄错一步!错了也不要害怕,通过make clean消除编译文件后继续重来。直到看见Congratulations! You have successfully installed netCDF!字眼,且Libraries/netcdf/include/netcdf.inc存在,nc-config --help能用!
4、配置mpich
tar xzvf mpich-3.0.4.tar.gz #or just .tar if no .gz present
cd mpich-3.0.4
./configure --prefix=$DIR/mpich
make
make install
make check #可省略此步
vi ~/.bashrc
###--->mpich<---###
export MPICH=$DIR/mpich
export PATH=$MPICH/bin:$PATH
source ~/.bashrc
5、配置zlib、jasper以及libpng
tar xzvf zlib-1.2.7.tar.gz #or just .tar if no .gz present
cd zlib-1.2.7
./configure --prefix=$DIR/grib2
make
make install
tar xzvf libpng-1.2.50.tar.gz #or just .tar if no .gz present
cd libpng-1.2.50
./configure --prefix=$DIR/grib2
make
make install
tar xzvf jasper-1.900.1.tar.gz #or just .tar if no .gz present
cd jasper-1.900.1
./configure --prefix=$DIR/grib2
make
make install
进入各自的解压包下,首先配置路径到grib2文件下,./configure --prefix,再make -> make install->make check(可省略)。
最后的库的编译环境(~/.bashrc)如下:
###-----------------------WRF installation-----------------###
export DIR=/home/hsy/WRF_WORKSTATION/LIBRARIES
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include###--->netcdf<---###
export NETCDF=$DIR/netcdf
export PATH=$NETCDF/bin:$PATH###--->mpich<---###
export MPICH=$DIR/mpich
###--->zlib<---###
export ZLIB=$DIR/grib2
export PATH=$ZLIB/bin:$PATH###--->libpng<---###
export LIBPNG=$DIR/grib2
export PATH=$LIBPNG/bin:$PATH###--->jasper<---###
export JASPER=$DIR/grib2
export PATH=$JASPER/bin:$PATH###--->WPS Compiler<---###
export WRFIO_NCD_LARGE_FILE_SUPPORT=1
export LD_LIBRARY_PATH=$DIR/grib2/lib:$LD_LIBRARY_PATH
zlib、libpng以及jasper的配置环境可以省略,因为前面已存在。
-
库的兼容性测试
首先下载Fortran_C_NETCDF_MPI_tests.tar并解压,然后开始进行两个测试,一个是netcdf的测试,另一个是mpich的测试。
这里注意把设置的NETCDF路径下的netcdf.inc复制到test文件夹下。
tar -xf Fortran_C_NETCDF_MPI_tests.tar
cp ${NETCDF}/include/netcdf.inc .
gfortran -c 01_fortran+c+netcdf_f.f
gcc -c 01_fortran+c+netcdf_c.c
gfortran 01_fortran+c+netcdf_f.o 01_fortran+c+netcdf_c.o \
-L${NETCDF}/lib -lnetcdff -lnetcdf
./a.out
mpif90 -c 02_fortran+c+netcdf+mpi_f.f
mpicc -c 02_fortran+c+netcdf+mpi_c.c
mpif90 02_fortran+c+netcdf+mpi_f.o \
02_fortran+c+netcdf+mpi_c.o \
-L${NETCDF}/lib -lnetcdff -lnetcdf
mpirun ./a.out
-
创建WRF
1、首先进入WRF与WPS下载目录下,将WRFv4.2与WPSv4.2安装包解压到WRF工作文件夹下,注意两者一定要在同一文件目录下,即保证解压后的WPSV4.2/与WRFV4.2/均在WRF_WORKSTATION文件目录下。
unzip WPS-4.2.zip -d ~/WRF_WORKSTATION/WPSV4.2/
unzip WRF-4.2.zip -d ~/WRF_WORKSTATION/WRFV4.2/
2、配置编译WRF(必须先编译WRF,才可以编译WPS),首先进入WRFV4.2文件目录下,输入./configure进行配置,选择34(dmpar GNU组合),再选择1(basic),然后再编译。
注意如果这里WRF ./configure报错:libimf.so无法链接,那么参考下面这篇文章可以解决。
./configure
34
1
./compile em_real >& log.compile
ls -ls main/*.exe
3、等20min左右,直到出现wrf.exe (model executable)
real.exe (real data initialization)
ndown.exe (one-way nesting)
tc.exe (for tc bogusing--serial only)则证明wrf的real case编译成功了。
-
创建WPS
1、首先进入WPSV4.2中, ./clean清除WPS文件目录。
2、配置WRF,选择dmpar gfortran。
3、编译WPS。
cd WPSV4.2
./clean
export WRF_DIR=../WRFV4.2
vi ~/.bashrc
###---------- WRF compile -----------###
export WRFIO_NCD_LARGE_FILE_SUPPORT=1
source ~/.bashrc
./configure
3
./compile
ls -ls *.exe
出现三个.exe文件即为成功!