由于本人安装过多次、多个版本的WRF程序,走了许多弯路,不忍心大家再像我一样浪费时间,所以整理一些可用经验。参考Compiling WRF (ucar.edu)
系统环境配置
1、首先确保有没有安装好编译语言gfortran、gcc、g++以及cpp。
2、创建WRF工作文件及其后续可能用得上的子文件。之所以选择在~/目录下直接建立WRF工作站,主要是方便所有人访问,不需要host/sudo权限。
which gfortranwhich cppwhich gccsudo apt install gfortran gcc cpp g++ makegcc --versiongfortran --versioncpp --versionmkdir ~/WRF_WorkStationmkdir ~/WRF_WorkStation/Librariesmkdir ~/WRF_WorkStation/netcdfmkdir ~/WRF_WorkStation/grib2mkdir ~/WRF_WorkStation/mpichmkdir ~/WRF_WorkStation/test
3、进入~/WRF_WorkStation/test文件中,将下载好的Fortran and C Tests Tar File 解压。具体的测试成功与否请参照Compiling WRF (ucar.edu)
tar -xf Fortran_C_tests.targfortran TEST_1_fortran_only_fixed.f./a.outgfortran TEST_2_fortran_only_free.f90./a.outgcc TEST_3_c_only.c./a.outgcc -c -m64 TEST_4_fortran+c_c.cgfortran -c -m64 TEST_4_fortran+c_f.f90gfortran -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/LIBRARIESexport CC=gccexport CXX=g++export FC=gfortranexport FCFLAGS=-m64export F77=gfortranexport FFLAGS=-m64export JASPERLIB=$DIR/grib2/libexport JASPERINC=$DIR/grib2/includeexport LDFLAGS=-L$DIR/grib2/libexport CPPFLAGS=-I$DIR/grib2/includesource ~/.bashrc
3、配置netcdf。
tar xzvf netcdf-4.1.3.tar.gz#or just .tar if no .gz presentcd netcdf-4.1.3./configure --prefix=$DIR/netcdf --disable-dap --disable-netcdf-4 --disable-sharedmakemake installvi ~/.bashrc###--->netcdf<---###export NETCDF=$DIR/netcdfexport PATH=$NETCDF/bin:$PATHsource ~/.bashrcnc-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 presentcd mpich-3.0.4./configure --prefix=$DIR/mpichmakemake installmake check #可省略此步vi ~/.bashrc###--->mpich<---###export MPICH=$DIR/mpichexport PATH=$MPICH/bin:$PATHsource ~/.bashrc
5、配置zlib、jasper以及libpng
tar xzvf zlib-1.2.7.tar.gz#or just .tar if no .gz presentcd zlib-1.2.7./configure --prefix=$DIR/grib2makemake installtar xzvf libpng-1.2.50.tar.gz#or just .tar if no .gz presentcd libpng-1.2.50./configure --prefix=$DIR/grib2makemake installtar xzvf jasper-1.900.1.tar.gz#or just .tar if no .gz presentcd jasper-1.900.1./configure --prefix=$DIR/grib2makemake 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.tarcp ${NETCDF}/include/netcdf.inc .gfortran -c 01_fortran+c+netcdf_f.fgcc -c 01_fortran+c+netcdf_c.cgfortran 01_fortran+c+netcdf_f.o 01_fortran+c+netcdf_c.o \-L${NETCDF}/lib -lnetcdff -lnetcdf./a.outmpif90 -c 02_fortran+c+netcdf+mpi_f.fmpicc -c 02_fortran+c+netcdf+mpi_c.cmpif90 02_fortran+c+netcdf+mpi_f.o \02_fortran+c+netcdf+mpi_c.o \-L${NETCDF}/lib -lnetcdff -lnetcdfmpirun ./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无法链接,那么参考下面这篇文章可以解决。
error while loading shared libraries: libimf.so: - Intel CommunitiesHi. I cannot complie my program using the makefile. However, if I type the complie command, it can complie. I donot know why this situation happens./t5/Intel-Fortran-Compiler/error-while-loading-shared-libraries-libimf-so/td-p/740546
./configure341./compile em_real >& pilels -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./cleanexport WRF_DIR=../WRFV4.2vi ~/.bashrc###---------- WRF compile -----------###export WRFIO_NCD_LARGE_FILE_SUPPORT=1source ~/.bashrc./configure3./compilels -ls *.exe
出现三个.exe文件即为成功!
如果觉得《WRF4.2安装过程全记录》对你有帮助,请点赞、收藏,并留下你的观点哦!