WRF/CMAQ 安装教程

WRF/CMAQ 安装教程_第1张图片


介绍

WRF 是集数值天气预报、大气模拟、数据同化于一体的模型系统,主要用于大气环境模拟、 天气研究、 气象预报等, 并为空气质量模型(CMAQ、 CALPUFF、AERMOD、ADMS 等)提供气象场。CMAQ 模型是第三代空气质量模型系统,主要用于环境规划、环境保护标准、环境影响评价、环境监测与预报预警、环境质量变化趋势、总量控制、排污许可、环境功能区划、环境应急预案、来源解析、 “三线一单” 等有关政策的制定和编制。
WRF, CMAQ, SMOKE 之间的关系:
温度,风,云形成和降水率等天气条件是影响大气交通的主要物理驱动力,这些条件在空气质量模型模拟中使用区域尺度数值气象模型如 WRF 的输出表示,为了获取排放物的输入数据,CMAQ 依靠开源模型 SMOKE 来估算污染源的大小和位置。另一个开源系统 FEST-C 用于运行 EPIC 模型,以生成 CMAQ 双向 NH3 建模所需的农业土地氮和土壤信息。

1 环境检查

[pc@localhost ~]$ which gfortran
/usr/bin/gfortran
[pc@localhost ~]$ which cpp
/usr/bin/cpp
[pc@localhost ~]$ which gcc
/usr/bin/gcc

进行上述操作之后会显示库的位置即可

cd TESTS 创建一个测试文件夹

下载fortran 和 c 语言的测试包https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_tests.tar

2 测试环境

Create a new , clean directory called Build_WRF, and another one called TESTS

mkdir Build_WRF TESTS
cd TESTS

将下载好的文件上传至TESTS目录下

执行一下操作

tar -xvf Fortran_C_tests.tar

2.1 Test #1:

测试1

Type the following in the command line:

gfortran TEST_1_fortran_only_fixed.f

Now type:

./a.out

The following should print out to the screen:

SUCCESS test 1 fortran only fixed format

2.2 Test #2:

Free Format Fortran: TEST_2_fortran_only_free.f90

Type the following in the command line:

gfortran TEST_2_fortran_only_free.f90

and then type:

./a.out

The following should print out to the screen:

Assume Fortran 2003: has FLUSH, ALLOCATABLE, derived type, and ISO C Binding
SUCCESS test 2 fortran only free format

2.3 Test #3:

C: TEST_3_c_only.c

测试3

Type the following in the command line:

gcc TEST_3_c_only.c

and then type:

./a.out

The following should print out to the screen:

SUCCESS test 3 c only

2.4 Test #4:

Fortran Calling a C Function (our gcc and gfortran have different defaults, so we force both to always use 64 bit [-m64] when combining them).

TEST_4_fortran+c_c.c, and TEST_4_fortran+x_f.f90

Type the following in the command line:

gcc -c -m64 TEST_4_fortran+c_c.c

and then type:

gfortran -c -m64 TEST_4_fortran+c_f.f90

and then:

gfortran -m64 TEST_4_fortran+c_f.o TEST_4_fortran+c_c.o

and then issue:

./a.out

The following should print out to the screen:

   C function called by Fortran
   Values are xx =  2.00 and ii = 1 
 SUCCESS test 4 fortran calling c

2.5 Test #5、6、7

Test #5:csh In the command line, type:

./TEST_csh.csh

The result should be:

SUCCESS csh test

Test #6:perl In the command line, type:

./TEST_perl.pl

The result should be:

SUCCESS perl test

Test #7:sh In the command line, type:

./TEST_sh.sh

The result should be:

SUCCESS sh test

3 库的安装

这里有请教大佬Alan,WRF用icc编译失败,但是由于CMAQ本身部分代码又是由icc编写,故安装包需要安装两种编译器的版本。后面使用时将环境配置放到.sh里面,然后source使用即可

2022.6.4补充:其实可以只使用一种编译器安装,后面我尝试过,大家从gcc和icc里选择一个就行,我是都使用intel的icc编译安装的,安装方法基本是一样的,大家按部就班的安装就行。
另外gcc10以上版本安装mpich时会出现问题,我暂时未解决,大家可以使用低版本gcc进行编译安装,不会出错。

mpich:信息传递接口,是用于跨节点通讯的基础软件环境,并行构建 WRF 所必需

netcdf:网络通用数据格式,一种面向数组型并适于网络共享的数据描述和编码标准

Jasper:编译具有 GRIB2 功能的 WPS(特别是 Unrib)所必需的压缩库

libpng:编译具有 GRIB2 功能的 WPS(特别是 Unrib)所必需的压缩库

zlib:编译具有 GRIB2 功能的 WPS(特别是 Unrib)所必需的压缩库

我的所有库安装版本如下

WRF/CMAQ 安装教程_第2张图片

在自己windows电脑下载安装包之后上传至虚拟机即可

3.1 gcc编译库的安装

加载gcc模块(统一安装库的gcc版本)

设置库的安装路径

[pc@localhost LIBRARIES]$ sudo nano ~/.bashrc
输入下面:

export DIR=/home/pc/LIBRARIES

[pc@localhost LIBRARIES]$ source ~/.bashrc

库的安装依照如下顺序,可以给每个库分别创建文件夹存储

3.1.1 zlib的安装

解压

tar -zxvf zlib-1.2.11.tar.gz

进入解压目录,命令:

[pc@localhost LIBRARIES]$ cd zlib-1.2.11
[pc@localhost zlib-1.2.11]$ ./configure --prefix=$DIR/netcdf
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.1.2 png的安装

解压:

tar -zxvf libpng-1.6.37.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd libpng-1.6.37
./configure --prefix=$DIR/netcdf LDFLAGS=-L$DIR/netcdf/lib CPPFLAGS=-I$DIR/netcdf/include

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.1.3 jasper的安装

解压:

tar -zxvf jasper-1.900.1.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd jasper-1.900.1/
./configure --prefix=$DIR/netcdf

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.1.4 hdf5的安装

解压:

tar -zxvf hdf5-1.10.4.tar.gz

遇到问题:

[pc@localhost LIBRARIES]$ tar -zxvf hdf5-1.10.4.tar.gz
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

问题的原因是因为:
1、压缩时留下的问题,虽然文件看起来像是.gz结尾的,但是打包时没有使用-z参数,是做成tar包之后,用gzip命令单独压缩的。知道原因之后就好解决了。先解压再展开tar包
2、下载的文件不全,大约有二十多兆的压缩包,让我传到linux中后是0兆 我就是这个原因,导致操作没跟上
3、操作问题,如果在win下载了JDK压缩包,拖拽进linux中,就会出现这个问题,但是复制粘贴进去就没事儿。

gunzip hdf5-1.10.4.tar.gz
tar -zxvf hdf5-1.10.4.tar

进入解压目录,配置ruby安装参数,命令:

cd hdf5-1.10.4
./configure --prefix=$DIR/netcdf --with-zlib=$DIR/netcdf

编译,命令:

这里很慢

make

编译检查

这里也很慢

make check

这里更慢

安装,命令:

make install
cd ..

3.1.5 netcdf的安装

先安装c再安装fortran

c

解压:

tar -zxvf netcdf-c-4.7.4.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd netcdf-c-4.7.4
./configure --prefix=$DIR/netcdf LDFLAGS=-L$DIR/netcdf/lib CPPFLAGS=-I$DIR/netcdf/include --disable-dap

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

Fortran

解压:

tar -zxvf netcdf-fortran-4.5.3.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd netcdf-fortran-4.5.3
./configure --prefix=$DIR/netcdf CPPFLAGS=-I$DIR/netcdf/include LD_LIBRARY_PATH=$DIR/netcdf/lib:$LD_LIBRARY_PATH LDFLAGS=-L$DIR/netcdf/lib

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.1.6 Mpich安装

解压:

tar -zxvf mpich-3.3.2.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd mpich-3.3.2
./configure --prefix=$DIR/mpich

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.2 icc编译库的安装

Icc建议使用自己单独的intel编译器(防止版本问题导致错误)
因为之前申请的intel 2019学生许可过期,故重新安装了Intel oneAPI代替之前的 Intel Parallel Studio XE,详细见上期文章:Intel学生许可过期后,安装 Intel® oneAPI Base Toolkit 和 Intel® oneAPI HPC来替代

设置变量:

[pc@localhost LIBRARIES]$ sudo nano ~/.bashrc
加入以下:

#module load icc
source /opt/intel/oneapi/setvars.sh intel64
export CC=icc
export CXX=icpc
export FC=ifort
export CFLAGS=-m64
export F77=ifort
export FFLAGS=-m64
export DIR2=/home/pc/LIBRARIESICC

[pc@localhost LIBRARIES]$ source ~/.bashrc

3.2.1 zlib的安装

解压:

tar -zxvf zlib-1.2.11.tar.gz

进入解压目录,命令:

cd zlib-1.2.11
./configure --prefix=$DIR2/netcdf

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.2.2 png的安装

解压:

tar -zxvf libpng-1.6.37.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd libpng-1.6.37
./configure --prefix=$DIR2/netcdf LDFLAGS=-L$DIR2/netcdf/lib CPPFLAGS=-I$DIR2/netcdf/include

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.2.3 jasper的安装

解压:

tar -zxvf jasper-1.900.1.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd jasper-1.900.1/
./configure --prefix=$DIR2/netcdf

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.2.4 hdf5的安装

解压:

tar -zxvf hdf5-1.10.4.tar

进入解压目录,配置ruby安装参数,命令:

cd hdf5-1.10.4
./configure --prefix=$DIR2/netcdf --with-zlib=$DIR2/netcdf

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.2.5 netcdf的安装

先安装c再安装fortran

c

解压:

tar -zxvf netcdf-c-4.7.4.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd netcdf-c-4.7.4
./configure --prefix=$DIR2/netcdf LDFLAGS=-L$DIR2/netcdf/lib CPPFLAGS=-I$DIR2/netcdf/include --disable-dap

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

Fortran

解压:

tar -zxvf netcdf-fortran-4.5.3.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd netcdf-fortran-4.5.3
./configure --prefix=$DIR2/netcdf CPPFLAGS=-I$DIR2/netcdf/include LDFLAGS=-L$DIR2/netcdf/lib  LD_LIBRARY_PATH=$DIR2/netcdf/lib:$LD_LIBRARY_PATH

这里或许会报错:
configure: error: netcdf.h could not be found. Please set CPPFLAGS.
搜到https://www.unidata.ucar.edu/support/help/MailArchives/netcdf/msg12385.html
有如下说辞:
As the instructions referenced above explain, the netCDF-Fortran library can only be built after the netCDF C library is built and installed. The default installation location for netCDF libraries is/usr/local, so the default location where netcdf.h will be installed is /usr/local/include/netcdf.h. If you built the netCDF C library for installing in a different location, for example using the configure option
./configure --prefix=$HOME/xyz …
make check
make install
故重新编译netcdf-c,问题解决

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.2.6 Mpich安装

解压:

tar -zxvf mpich-3.3.2.tar.gz

进入解压目录,配置ruby安装参数,命令:

cd mpich-3.3.2
./configure --prefix=$DIR2/mpich
 # 据说mpich后面一定要加版本号,否则后面编译cctm不成功。我怀疑我就是因为这里没加版本号,导致后面要在后面有一步骤要加-qopenmp才能成功,但是安装完了能跑,不管啦!!

编译,命令:

make

编译检查

make check

安装,命令:

make install
cd ..

3.2.7 ioapi安装

这家伙安装时错误太多了,耗费了不少时间才装好

ioapi3.2安装

参考: I/O API 3.2 安装记录

解压ioapi文件至$DIR/ioapi-3.2 下

git clone https://github.com/cjcoats/ioapi-3.2 #这里别用自己下载的解压了,最好用这个git clone直接从github弄下来
cp Makefile.template Makefile

修改ioapi-3.2目录下的Makefile

原来:

BIN        = Linux2_x86_64
BASEDIR    = ${PWD}
INSTALL    = ${HOME}
LIBINST    = $(INSTALL)/$(BIN)
BININST    = $(INSTALL)/$(BIN)
CPLMODE    = nocpl
IOAPIDEFS  = 
PVMINCL    =
NCFLIBS    = -lnetcdf -lnetcdff

修改后:

BIN        = Linux2_x86_64ifort
BASEDIR    = /home/pc/LIBRARIESICC/ioapi-3.2
INSTALL    = /home/pc/LIBRARIESICC/ioapi #这里记得建立一个ioapi的文件夹,程序自己不会建立,最好与上面的目录不一样,不然后面make install的时候会出错
LIBINST    = $(INSTALL)/$(BIN)
BININST    = $(INSTALL)/$(BIN)
CPLMODE    = nocpl
IOAPIDEFS  = 
PVMINCL    =
NCFLIBS    = -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz

教程I/O API 3.2 安装记录注释:

BIN=Linux2_x86_64ifort     #BIN设置跟机器和使用的编译器有关
BASEDIR=${PWD}             #BASEDIR目录就是ioapi-3.2这个目录,也可以设置成绝对路径
INSTALL=/opt/ioapi         #INSTALL目录就是你要把ioapi安装到的目录
LIBINST=$(INSTALL)/$(BIN)  #保持默认不用修改
BININST=$(INSTALL)/$(BIN)  #保持默认不用修改
CPLMODE=nocpl              #不开PVM,一般新手安装,不开nocpl
IOAPIDEFS=                 #保持默认不用修改
PVMINCL=                   #保持默认不用修改
NCFLIBS=-lnetcdff -lnetcdf #我安装的时候默认这两个顺序是反过来的,
                           #然后make出错,后来官网参考教程,
                           #修改成目前这个顺序就make通过了

在ioapi-3.2/iopai 以及 ioapi-3.2/m3tools 下均复制makefile文件

cd ioapi
cp Makefile.nocpl Makefile
cd ../m3tools
cp Makefile.nocpl Makefile
cd .. #切换到ioapi-3.2目录下
export BIN=Linux2_x86_64ifort
mkdir $BIN #创建Linux2_x86_64ifort,目录位于ioapi-3.2目录内
cd $BIN #进入文件夹
cp $DIR2/netcdf/lib/lib* ./ #将库拷贝至该处
#注意,这里我就是之前为什么将 hdf zlib 都放在 netcdf 同一个目录,所以 lib 也是一起粘贴过来,如果你是分开安装,就必须把其他的也粘过来。
cd .. #切换到ioapi-3.2目录下
make configure
make

在make的时候会遇到error:

option '-openmp' is not supported. Please use the replacement option '-qopenmp'

解决办法:参考CMAQ_UG_tutorial_build_library_intel.md和

Build and installation instructions for I/O API Versions 3.0, 3.1, 3.2, and 4.0

在ioapi文件夹里面找到makeinclude.Linux2_x86_64ifort文件

Edit the Makeinclude file, lines 27 and 28 to use -qopenmp instead of -openmp

OMPFLAGS  = -qopenmp
OMPLIBS   = -qopenmp

继续make后,又出现一个error:

make[1]: *** [airs2m3] Error 1
make[1]: Leaving directory `/home/pc/LIBRARIESICC/ioapi-3.2/m3tools'
make: *** [all] Error 2

参考https://forum.cmascenter.org/t/installing-disable-netcdf-4-disable-dap-never-works-and-instructions-in-cmaq-documentation-regarding-this-seem-misleading/946/8解决

Edit your ioapi/Makeinclude.Linux2_x86_64ifort so that ARCHFLAGS is
ARCHFLAGS =
-DIOAPI_NCF4=1
-DAUTO_ARRAYS=1
-DF90=1 -DFLDMN=1
-DFSTR_L=int
-DIOAPI_NO_STDOUT=1
-DAVOID_FLUSH=1 -DBIT32=1

and then make clean; make in your ioapi directory

2022.6.4补充:

再进入m3tools,打开Makefile,

在LIBS = -L${OBJDIR} -lioapi -lnetcdff -lnetcdf后面加入 -lhdf5_hl -lhdf5 -lz

然后make一下无错误。
再回到ioapi-3.2目录下make install:

make instal

install后出现:

[pc@localhost ioapi-3.2]$ make install
Makefile:263: warning: overriding recipe for target `/home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort'
Makefile:260: warning: ignoring old recipe for target `/home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort'
cd /home/pc/LIBRARIESICC/ioapi; mkdir -p /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort
echo "Installing I/O API and M3TOOLS in /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort and /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort"
Installing I/O API and M3TOOLS in /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort and /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort
(cd /home/pc/LIBRARIESICC/ioapi-3.2/ioapi   ; make BIN=Linux2_x86_64ifort INSTDIR=/home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort install)
make[1]: Entering directory `/home/pc/LIBRARIESICC/ioapi-3.2/ioapi'
echo "Installing in /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort" ; cd /home/pc/LIBRARIESICC/ioapi-3.2/Linux2_x86_64ifort; cp libioapi.a m3utilio.mod modgctp.mod modwrfio.mod modmpasfio.mod modatts3.mod modncfio.mod modpdata.mod /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort
Installing in /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort
make[1]: Leaving directory `/home/pc/LIBRARIESICC/ioapi-3.2/ioapi'
(cd /home/pc/LIBRARIESICC/ioapi-3.2/m3tools ; make BIN=Linux2_x86_64ifort INSTDIR=/home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort install)
make[1]: Entering directory `/home/pc/LIBRARIESICC/ioapi-3.2/m3tools'
echo "Installing M3TOOLS in /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort"
Installing M3TOOLS in /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort
cd /home/pc/LIBRARIESICC/ioapi-3.2/Linux2_x86_64ifort; cp airs2m3         bcwndw          camxtom3        datshift        dayagg factor          findwndw        greg2jul        gregdate        gridprobe insertgrid      jul2greg        juldate         juldiff         julshift kfxtract        latlon          m3agmax         m3agmask        m3cple m3combo         m3diff          m3edhdr         m3fake          m3hdr m3interp        m3mask          m3merge         m3pair          m3probe m3stat          m3totxt         m3tproc         m3tshift        m3wndw m3xtract        mtxblend        mtxbuild        mtxcalc         mtxcple mpasdiff        mpasstat        mpastom3        presterp        presz projtool        selmrg2d        timediff        timeshift       vertot vertimeproc     vertintegral    wndwdesc        wrfgriddesc     wrftom3 randomstat /home/pc/LIBRARIESICC/ioapi/Linux2_x86_64ifort
make[1]: Leaving directory `/home/pc/LIBRARIESICC/ioapi-3.2/m3tools'

在Linux2_x86_64ifort目录下检查:

[pc@localhost Linux2_x86_64ifort]$ ls libioapi.a
libioapi.a
[pc@localhost Linux2_x86_64ifort]$ ls *.mod
m3utilio.mod  modgctp.mod     modncfio.mod  modwrfio.mod
modatts3.mod  modmpasfio.mod  modpdata.mod
[pc@localhost Linux2_x86_64ifort]$

想装3.1的可以参考:

ioapi3.1安装

参考I/O API v3.1 的安装(基于GCC/GFORTRAN)

1、下载并解压缩

https://www.cmascenter.org/ioapi/documentation/all_versions/html/AVAIL.html#build

tar -zxvf ioapi-3.1.tar.gz
cd ioapi_3.1

2、修改主目录下的Makefile

修改BASEDIR(源文件目录)、INSTALL(安装主目录),选择nocpl(turn off PVM coupling mode),具体修改内容如下:

BASEDIR    = /home/pc/LIBRARIESICC/ioapi_3.1
INSTALL    = /home/pc/LIBRARIESICC/ioapi
LIBINST    = $(INSTALL)/$(BIN)
BININST    = $(INSTALL)/$(BIN)

CPLMODE    = nocpl
IOAPIDEFS  = 
PVMINCL    = /dev/null

千万注意CPLMODE = nocpl 后面没有空格,PVMINCL = /dev/null后面也没有空格。

3、设置环境变量BIN和建立安装子目录

确定自己所用机器的型号,我用的是x86_64,且编译器为icc, ifort,查找ioapi-3.1/ioapi目录下对应的Makefileinclude文件为Makeinclude.Linux2_x86_64ifort,因此,在源文件目录下建立一个名为Linux2_x86_64ifort的新文件夹,并设置环境变量BIN(安装子目录):

export BIN=Linux2_x86_64ifort
mkdir $BIN #创建Linux2_x86_64ifort,目录位于ioapi-3.1目录内

4、建立netcdf库链接

ln -s /home/pc/LIBRARIESICC/netcdf/lib/libnetcdff.a Linux2_x86_64ifort/
ln -s /home/pc/LIBRARIESICC/netcdf/lib/libnetcdf.a Linux2_x86_64ifort/

注意:如果用的是netcdf4.x以前的版本,则只需要链接libnetcdf.a:

ln -s /home/pc/LIBRARIESICC/netcdf/lib/libnetcdf.a Linux2_x86_64ifort/

且在m3tools/Makefile.nocpl.sed中修改:

***LIBS  = -L${OBJDIR} -lioapi -lnetcdff -lnetcdf $(OMPLIBS) $(ARCHLIB) $(ARCHLIBS)***
# ***LIBS=-L${OBJDIR} -lioapi -lnetcdf $(OMPLIBS) $(ARCHLIB) $(ARCHLIBS)***

5、编译和安装

退回到源主目录,执行:

make configure
make

make若出现错误,需要

make clean

后重新执行

至此 库已全部安装完毕

4 WRF的安装_以3.9.1版本为例

可以将如下命令存储为.sh文件每次调用即可

.sh文件的创建方法:

打开终端 依次输入以下内容即可创建并执行 .sh 文件:

touch setenv-gcc.sh
gedit setenv-gcc.sh

此时会弹出一个可编辑页面,在此可编辑页面中输入:

#!/bin/bash
export DIR=/home/pc/LIBRARIES
export CFLAGS=-m64
export FFLAGS=-m64
export INCLUDE=${DIR}/netcdf/include:${INCLUDE}
export PATH=$DIR/netcdf/bin:$PATH
export LD_LIBRARY_PATH=${DIR}/netcdf/lib:${LD_LIBRARY_PATH}
export NETCDF=$DIR/netcdf
export PATH=$DIR/mpich/bin:$PATH
export LDFLAGS=-L$DIR/netcdf/lib
export CPPFLAGS=-I$DIR/netcdf/include
export JASPERLIB=$DIR/netcdf/lib
export JASPERINC=$DIR/netcdf/include
export WRF_DIR=/home/pc/Build_WRF/WRFV3
export WRFIO_NCD_NO_LARGE_FILE_SUPPORT=1
export WRF_EM_CORE=1

保存上述可编辑页面。这样就成功创建了setenv-gcc.sh文件,放到Build_WRF文件夹下面

调用命令

source setenv-gcc.sh

解压

tar -zxvf WRFV3.9.1.TAR.gz

进入解压文件夹

cd WRFV3

清除之前的安装文件

./clean -a

查看配置文件 configure.wrf

执行配置

./configure

根据自己的配置选择,我是这样选择的:

Please select from among the following Linux x86_64 options:

  1. (serial)   2. (smpar)   3. (dmpar)   4. (dm+sm)   PGI (pgf90/gcc)
  5. (serial)   6. (smpar)   7. (dmpar)   8. (dm+sm)   PGI (pgf90/pgcc): SGI MPT
  9. (serial)  10. (smpar)  11. (dmpar)  12. (dm+sm)   PGI (pgf90/gcc): PGI accelerator
 13. (serial)  14. (smpar)  15. (dmpar)  16. (dm+sm)   INTEL (ifort/icc)
                                         17. (dm+sm)   INTEL (ifort/icc): Xeon Phi (MIC architecture)
 18. (serial)  19. (smpar)  20. (dmpar)  21. (dm+sm)   INTEL (ifort/icc): Xeon (SNB with AVX mods)
 22. (serial)  23. (smpar)  24. (dmpar)  25. (dm+sm)   INTEL (ifort/icc): SGI MPT
 26. (serial)  27. (smpar)  28. (dmpar)  29. (dm+sm)   INTEL (ifort/icc): IBM POE
 30. (serial)               31. (dmpar)                PATHSCALE (pathf90/pathcc)
 32. (serial)  33. (smpar)  34. (dmpar)  35. (dm+sm)   GNU (gfortran/gcc)
 36. (serial)  37. (smpar)  38. (dmpar)  39. (dm+sm)   IBM (xlf90_r/cc_r)
 40. (serial)  41. (smpar)  42. (dmpar)  43. (dm+sm)   PGI (ftn/gcc): Cray XC CLE
 44. (serial)  45. (smpar)  46. (dmpar)  47. (dm+sm)   CRAY CCE (ftn $(NOOMP)/cc): Cray XE and XC
 48. (serial)  49. (smpar)  50. (dmpar)  51. (dm+sm)   INTEL (ftn/icc): Cray XC
 52. (serial)  53. (smpar)  54. (dmpar)  55. (dm+sm)   PGI (pgf90/pgcc)
 56. (serial)  57. (smpar)  58. (dmpar)  59. (dm+sm)   PGI (pgf90/gcc): -f90=pgf90
 60. (serial)  61. (smpar)  62. (dmpar)  63. (dm+sm)   PGI (pgf90/pgcc): -f90=pgf90
 64. (serial)  65. (smpar)  66. (dmpar)  67. (dm+sm)   INTEL (ifort/icc): HSW/BDW
 68. (serial)  69. (smpar)  70. (dmpar)  71. (dm+sm)   INTEL (ifort/icc): KNL MIC
 72. (serial)  73. (smpar)  74. (dmpar)  75. (dm+sm)   FUJITSU (frtpx/fccpx): FX10/FX100 SPARC64 IXfx/Xlfx
Enter selection [1-75] : 32
------------------------------------------------------------------------
Compile for nesting? (0=no nesting, 1=basic, 2=preset moves, 3=vortex following) [default 0]: 1

Configuration successful! 
------------------------------------------------------------------------

配置之后编译即可

./compile em_real >& compile.log &
tail -f compile.log

可以在compile.log中查看编译的错误

在main的目录下可以看到ndown.exe, real.exe, tc.exe, wrf.exe即编译成功

==========================================================================
build started:   Thu Mar 25 19:09:30 CST 2021
build completed: Thu Mar 25 19:17:08 CST 2021
 
--->                  Executables successfully built                  <---
 
-rwxrwxr-x. 1 pc pc 39954784 Mar 25 19:17 main/ndown.exe
-rwxrwxr-x. 1 pc pc 39807232 Mar 25 19:17 main/real.exe
-rwxrwxr-x. 1 pc pc 39348832 Mar 25 19:17 main/tc.exe
-rwxrwxr-x. 1 pc pc 44119080 Mar 25 19:16 main/wrf.exe
 
==========================================================================

运行到这里会卡住,如果成功了,在~/Build_WRF/WRFV3/main文件夹里有wrf.exe文件,看一下关闭终端然后接着做

cd ..

5 WPS的安装_以3.9.1版本为例

同样需要wrf时用到的变量 通过source加载

解压

tar -zxvf WPSV3.9.1.TAR.gz

进入解压文件夹

cd WPS

清除之前的安装文件

./clean -a

查看配置文件 configure.wps 配置如下 具体路径自行修改

./configure
Please select from among the following supported platforms.

   1.  Linux x86_64, gfortran    (serial)
   2.  Linux x86_64, gfortran    (serial_NO_GRIB2)
   3.  Linux x86_64, gfortran    (dmpar)
   4.  Linux x86_64, gfortran    (dmpar_NO_GRIB2)
   5.  Linux x86_64, PGI compiler   (serial)
   6.  Linux x86_64, PGI compiler   (serial_NO_GRIB2)
   7.  Linux x86_64, PGI compiler   (dmpar)
   8.  Linux x86_64, PGI compiler   (dmpar_NO_GRIB2)
   9.  Linux x86_64, PGI compiler, SGI MPT   (serial)
  10.  Linux x86_64, PGI compiler, SGI MPT   (serial_NO_GRIB2)
  11.  Linux x86_64, PGI compiler, SGI MPT   (dmpar)
  12.  Linux x86_64, PGI compiler, SGI MPT   (dmpar_NO_GRIB2)
  13.  Linux x86_64, IA64 and Opteron    (serial)
  14.  Linux x86_64, IA64 and Opteron    (serial_NO_GRIB2)
  15.  Linux x86_64, IA64 and Opteron    (dmpar)
  16.  Linux x86_64, IA64 and Opteron    (dmpar_NO_GRIB2)
  17.  Linux x86_64, Intel compiler    (serial)
  18.  Linux x86_64, Intel compiler    (serial_NO_GRIB2)
  19.  Linux x86_64, Intel compiler    (dmpar)
  20.  Linux x86_64, Intel compiler    (dmpar_NO_GRIB2)
  21.  Linux x86_64, Intel compiler, SGI MPT    (serial)
  22.  Linux x86_64, Intel compiler, SGI MPT    (serial_NO_GRIB2)
  23.  Linux x86_64, Intel compiler, SGI MPT    (dmpar)
  24.  Linux x86_64, Intel compiler, SGI MPT    (dmpar_NO_GRIB2)
  25.  Linux x86_64, Intel compiler, IBM POE    (serial)
  26.  Linux x86_64, Intel compiler, IBM POE    (serial_NO_GRIB2)
  27.  Linux x86_64, Intel compiler, IBM POE    (dmpar)
  28.  Linux x86_64, Intel compiler, IBM POE    (dmpar_NO_GRIB2)
  29.  Linux x86_64 g95 compiler     (serial)
  30.  Linux x86_64 g95 compiler     (serial_NO_GRIB2)
  31.  Linux x86_64 g95 compiler     (dmpar)
  32.  Linux x86_64 g95 compiler     (dmpar_NO_GRIB2)
  33.  Cray XE/XC CLE/Linux x86_64, Cray compiler   (serial)
  34.  Cray XE/XC CLE/Linux x86_64, Cray compiler   (serial_NO_GRIB2)
  35.  Cray XE/XC CLE/Linux x86_64, Cray compiler   (dmpar)
  36.  Cray XE/XC CLE/Linux x86_64, Cray compiler   (dmpar_NO_GRIB2)
  37.  Cray XC CLE/Linux x86_64, Intel compiler   (serial)
  38.  Cray XC CLE/Linux x86_64, Intel compiler   (serial_NO_GRIB2)
  39.  Cray XC CLE/Linux x86_64, Intel compiler   (dmpar)
  40.  Cray XC CLE/Linux x86_64, Intel compiler   (dmpar_NO_GRIB2)
Enter selection [1-40] : 1
------------------------------------------------------------------------
Configuration successful. To build the WPS, type: compile
------------------------------------------------------------------------

Testing for NetCDF, C and Fortran compiler

This installation NetCDF is 64-bit
C compiler is 64-bit
Fortran compiler is 64-bit
./compile >& compile.log &
 tail -f compile.log
ls -las *.exe

如果编译成功,最后会在WPS代码根目录得到以下三个程序链接

[pc@localhost WPS]$ ls -las *.exe
0 lrwxrwxrwx. 1 pc pc 23 Mar 25 19:32 geogrid.exe -> geogrid/src/geogrid.exe
0 lrwxrwxrwx. 1 pc pc 23 Mar 25 19:32 metgrid.exe -> metgrid/src/metgrid.exe
0 lrwxrwxrwx. 1 pc pc 21 Mar 25 19:32 ungrib.exe -> ungrib/src/ungrib.exe

至此wps编译完成

6 CMAQ的安装_以5.2.1版本为例

6.1 配置icc环境

setenv-icc.sh文件里面:
注:一定要在linux用命令创建.sh文件

#!/bin/bash
source /opt/intel/oneapi/setvars.sh intel64
export CC=icc
export CXX=icpc
export FC=ifort
export F90=ifort
export F77=ifort
export DIR2=/home/pc/LIBRARIESICC
export INCLUDE=${DIR2}/netcdf/include:${INCLUDE}
export PATH=$DIR2/netcdf/bin:$PATH
export LD_LIBRARY_PATH=${DIR2}/netcdf/lib:${LD_LIBRARY_PATH}
export NETCDF=$DIR2/netcdf
export JASPERLIB=$DIR2/netcdf/lib
export JASPERINC=$DIR2/netcdf/include
export CMAQ_HOME=/home/pc/Build_CMAQ/CMAQ-5.2.1
export CMAQ_LIB=$CMAQ_HOME/lib
export CMAQ_DATA=$CMAQ_HOME/data
source setenv-icc.sh

6.2 获取 CMAQ 安装包

unzip CMAQ-5.2.1.zip
cd CMAQ-5.2.1

设置 bldit_project.csh 脚本

设置对应的cmaq路径

vim bldit_project.csh

变更CMAQ_HOME的值,明确工作目录:

set CMAQ_HOME = /home/pc/Build_CMAQ/CMAQ-5.2.1
# 初始化  运行该脚本
./bldit_project.csh

# 编辑配置文件  
vim config_cmaq.csh

修改对应ioapi路径
改完:

~~#>  Intel fortran compiler......................................................
    case intel:

        #> I/O API, netCDF, and MPI library locations
        setenv IOAPI_MOD_DIR   /home/pc/LIBRARIESICC/ioapi-3.2/Linux2_x86_64ifort  #> I/O API precompiled modules
        setenv IOAPI_INCL_DIR  /home/pc/LIBRARIESICC/ioapi-3.2/ioapi  #> I/O API include header files
        setenv IOAPI_LIB_DIR   /home/pc/LIBRARIESICC/ioapi-3.2/Linux2_x86_64ifort  #> I/O API libraries
        setenv NETCDF_LIB_DIR  /home/pc/LIBRARIESICC/netcdf/lib  #> netCDF directory path
        setenv NETCDF_INCL_DIR /home/pc/LIBRARIESICC/netcdf/include  #> netCDF directory path
        setenv MPI_LIB_DIR     /home/pc/LIBRARIESICC/mpich    #> MPI directory path

        #> Compiler Aliases and Flags
        setenv myFC mpiifort
        setenv myCC icc
        setenv myFSTD "-O3 -fno-alias -mp1 -fp-model source"
        setenv myDBG  "-O0 -g -check bounds -check uninit -fpe0 -fno-alias -ftrapuv -traceback"
        setenv myLINK_FLAG #"-openmp"
        setenv myFFLAGS "-fixed -132"
        setenv myFRFLAGS "-free"
        setenv myCFLAGS "-O2"
        setenv extra_lib "-lcurl"
        #setenv extra_lib ""
        setenv mpi_lib "-lmpich"    #> No Library specification needed for mpiifort
                             #> -lmpich for mvapich 
                             #> -lmpi for openmpi

        breaksw

为“netcdf_lib”变量添加openmp属性,如:~~

~~setenv netcdf_lib "-lnetcdf -lnetcdff **-lgomp**"  #> -lnetcdff -lnetcdf for netCDF v4.2.0 and later~~
csh #切换 csh 终端 直接输入csh
source config_cmaq.csh intel #选择 intel 编译器

6.3 ICON 编译

cd PREP/icon/scripts
vim bldit_icon.csh

修改CMAQ-5.2/PREP/icon/scripts目录下脚本bldit_icon.csh中的参数

修改ioapi相关库文件路径

设置完执行以下命令编译:

./bldit_icon.csh intel

执行完后生成ICON_v52_profile.exe即为编译成功。

运行之后会报错 同时生成BLD_ICON_v52_profile_intel文件夹

进入该文件夹

cd BLD_ICON_v52_profile_intel
make clean  #将刚才安装的清除掉

修改makefile:

LINKER     = $(FC)
LINK_FLAGS = -qopenmp

保存之后 在该文件夹下

make

即可

执行完后生成ICON_v52_profile.exe即为编译成功
WRF/CMAQ 安装教程_第3张图片

6.4 BCON编译

cd PREP/bcon/scripts
vim bldit_bcon.csh

修改CMAQ-5.2/PREP/bcon/scripts目录下脚本bldit_bcon.csh中的参数

修改ioapi相关库文件路径

设置完执行以下命令编译:

./bldit_bcon.csh intel

执行完后生成BCON_v52_profile.exe即为编译成功。

运行之后会报错 同时生成BLD_ICON_v52_profile_intel文件夹

进入该文件夹

cd BLD_BCON_v52_profile_intel
make clean  #将刚才安装的清除掉

修改makefile:

LINKER     = $(FC)
LINK_FLAGS = -qopenmp

保存之后 在该文件夹下

make

即可
执行完后生成BCON_v52_profile.exe即为编译成功
在这里插入图片描述

6.5 MCIP 编译

修改CMAQ-5.2/PREP/mcip/src目录下脚本Makefile中的参数

设置完执行以下命令编译:

source ../../../config_cmaq.csh intel
make

执行完后生成mcip.exe即为编译成功。

在这里插入图片描述

6.6 CCTM编译

修改CMAQ-5.2/CCTM/scripts目录下脚本bldit_cctm.csh中的参数
设置完执行以下命令编译:

./bldit_cctm.csh intel

执行完后生成CCTM*.exe即为编译成功。

[pc@localhost BLD_CCTM_v521_intel]$ ls CCTM*.exe
CCTM_v521.exe

在这里插入图片描述

6.7 COMBINE 编译

cd ~/5.2.1/POST/combine/scripts

./bldit_combine.csh intel 

#执行成功后会在 BLD_combine_v521_intel 目录下生成combine_v521.exe 应用程序

[pc@localhost BLD_combine_v521_intel]$ ls
combine.F         combine_v521.cfg.old  m3files.mod     module_evaluator.F  module_file.o     spec_def.mod
combine.o         combine_v521.exe      Makefile        module_evaluator.o  module_specdef.F  utils.F
combine_v521.cfg  evaluator.mod         Makefile.intel  module_file.F       module_specdef.o  utils.o

在这里插入图片描述

CMAQ5.2.1 安装完毕

参考

[1] CentOS 7安装WRF,SMOKE,CMAQ
[2] Ubuntu下的WRF配置
[3] 01zzCMAQ
[4] I/O API 3.2 安装记录
[5] I/O API v3.1 的安装(基于GCC/GFORTRAN)
在这里特别感谢知乎Alan的帮助,耐心地解答了我不少问题。

2022.6.4 趁着端午假期,修订了一下这篇博文,主要是在ioapi-3.2安装哪里,另外改了下格式。大家喜欢的话就关注我吧,最好再给我点个赞(厚脸皮.jpg)hhhh。

你可能感兴趣的:(WRF,Linux,CMAQ,linux,WRF,CMAQ,IOAPI)