目录
四、创建库
1. 在Build_WRF目录下创建LIBRARIES,并将如下五个安装包下载至该目录下。
2. 安装这些包之前,先设置环境变量。
3. 配置NetCDF, 这一步很重要!确保要成功。
配置netcdf fortran。
4. 配置mpich。
5. 配置zlib。
6. 配置libpng。
7. 配置jasper。
五、 库的兼容性测试。
1. Test #1: Fortran + C + NetCDF
2. Test #2: Fortran + C + NetCDF + MPI
cd Build_WRF
mkdir LIBRARIES
https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/mpich-3.0.4.tar.gz
https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/netcdf-c-4.7.2.tar.gz
https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/jasper-1.900.1.tar.gzhttps://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/libpng-1.2.50.tar.gzhttps://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/zlib-1.2.11.tar.gz
vim ~/.bashrc
export DIR=/home/user/Build_WRF/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使环境变量生效。
在LIBRARIES目录下解压netcdf安装包。
tar xzvf netcdf-c-4.7.2.tar.gz
cd netcdf-c-4.7.2
./configure --prefix=$DIR/netcdf --disable-dap --disable-netcdf-4 --disable-shared
make
make install
可以通过输入“make check" 或者"nc-config --help"测试是否真的安装成功。如果不成功,可以通过make clean消除编译文件后继续重来。
安装成功后,再次进入环境变量,添加变量后source ~/.bashrc使之生效:
export NETCDF=$DIR/netcdf
export PATH=$NETCDF/bin:$PATH
首先添加环境变量,然后解压编译,再添加环境变量。
Libraries/netcdf/include/netcdf.inc一定一定要存在,否则重新编译安装!!!
vim ~/.bashrc
export LDFLAGS=-L$DIR/netcdf/lib
export CPPFLAGS=-I$DIR/netcdf/include
source ~/.bashrc
tar xzvf netcdf-fortran-4.5.2.tar.gz
cd netcdf-fortran-4.5.2
./configure --prefix=$DIR/netcdf --disable-dap --disable-netcdf-4 --disable-shared
make
make install
vim ~/.bashrc
export LDFLAGS=-L$DIR/netcdf/lib
export CPPFLAGS=-I$DIR/netcdf/include
source ~/.bashrc
在LIBRARIES目录下解压mpich安装包。
tar xzvf mpich-3.0.4.tar.gz
cd mpich-3.0.4
./configure --prefix=$DIR/mpich
make
make install
同样安装成功后,添加环境变量:
vim ~/.bashrc
export MPICH=$DIR/mpich
source ~/.bashrc
tar xzvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure --prefix=$DIR/grib2
make
make install
cd ..
vim ~/.bashrc
export ZLIB=$DIR/grib2
export PATH=$ZLIB/bin:$PATH
source ~/.bashrc
tar xzvf libpng-1.2.50.tar.gz
cd libpng-1.2.50
./configure --prefix=$DIR/grib2
make
make install
cd ..
vim ~/.bashrc
export LIBPNG=$DIR/grib2
export PATH=$LIBPNG/bin:$PATH
source ~/.bashrc
tar xzvf jasper-1.900.1.tar.gz
cd jasper-1.900.1
./configure --prefix=$DIR/grib2
make
make install
cd ..
vim ~/.bashrc
export JASPER=$DIR/grib2
export PATH=$JASPER/bin:$PATH
source ~/.bashrc
全部配置完毕后,环境变量如下:
主要进行两个测试,一个是netcdf的测试,另一个是mpich的测试。
将下面的压缩包下载至TESTS目录下,并解压:tar -xf Fortran_C_NETCDF_MPI_tests.tar1.
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
屏幕上会输出以下内容:
C function called by Fortran
Values are xx = 2.00 and ii = 1
SUCCESS test 1 fortran + c + netcdf
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
屏幕上应该输出为:
C function called by Fortran
Values are xx = 2.00 and ii = 1
status = 2
SUCCESS test 2 fortran + c + netcdf + mpi