编译和安装
操作步骤
- 使用PuTTY工具,以root用户登录服务器。
- 执行以下命令创建并进入安装规划路径。
mkdir /path/to/ncl cd /path/to/ncl
- 执行以下命令获取NCL源码包。
wget https://github.com/chen-shaoheng/NCL-SOURCE/releases/download/ncl-6.6.2/ncl-6.6.2.tar.gz
- 执行以下命令解压源码包。
tar -xvf ncl-6.6.2.tar.gz
- 执行以下命令进入源码目录。
cd ncl-6.6.2/
- 执行以下命令修改config/LINUX文件。
sed -i '21c #define CCompiler gcc' config/LINUX sed -i '22c #define FCompiler gfortran' config/LINUX sed -i '23c #define CtoFLibraries -lgfortran -lmathlib -ltirpc' config/LINUX sed -i '24c #define CtoFLibrariesUser -lgfortran -lmathlib -ltirpc' config/LINUX sed -i '25c #define CcOptions -ansi -fPIC -fopenmp -std=c99 -fsigned-char -Xlinker -zmuldefs -Wl,--copy-dt-needed-entries' config/LINUX sed -i '26c #define FcOptions -fPIC -fno-second-underscore -fno-range-check -fopenmp -fallow-argument-mismatch -Wl,--copy-dt-needed-entries' config/LINUX
GCC为10及以上的版本时请在第26行添加-fallow-argument-mismatch参数。
- 执行以下命令修改ncarview/src/lib/libncarg_ras/misc.c文件。
- 在第41和第42行添加如下函数声明语句,即添加位置在第一个函数定义的int关键字之前的位置。
sed -i '40a void _swapshort (register char *bp, register unsigned n);' ncarview/src/lib/libncarg_ras/misc.c sed -i '41a void _swaplong (register char *bp, register unsigned n);' ncarview/src/lib/libncarg_ras/misc.c
- 修改结果如下图所示,表示修改完成。
- 执行以下命令修改yMakefile。
sed -i "31a #else\nMORE_LIBS = -lm" ncarview/src/bin/ictrans/yMakefile
查看如下,表示修改完成。
- 执行以下命令进入ncarview/src/bin/ictrans目录修改yMakefile第46行。
cd /path/to/ncl/ncl-6.6.2/ncarview/src/bin/ictrans vim yMakefile
添加#以注释,如下显示表示修改完成。
- 执行以下命令进行编译配置。
首次编译时,如config目录下存在ymake-filter文件,请执行以下命令删除ymake-filter。
rm config/ymake-filter -rf
cd /path/to/ncl/ncl-6.6.2 ./Configure
进入安装引导界面,根据实际需要进行配置。
- Enter Return to continue, or q(quit) 回车
- Build NCL (y)? y
- Parent installation directory /path/to/ncl
- System temp space directory /tmp
- Build NetCDF4 feature support (optional)? (y) y
- Build HDF4 support (optional) into NCL? (y) y
- Also build HDF4 support (optional) into raster library? (y) y
- Did you build HDF4 with szip support? (n) n
- Build Triangle support (optional) into NCL (y) n
- did you enable NetCDF-4 support (y) y
- Did you build NetCDF with OPeNDAP support (y) n
- Build GDAL support (optional) into NCL? (n) y
- Build EEMD support (optional) into NCL? (y) y
- Build Udunits-2 support (optional) into NCL (y) y
- Build Vis5d+ support (optional) into NCL (n) y
- Build HDF-EOS2 support (optional) into NCL (y) y
- Build HDF5 support (optional) into NCL (y) y
- Build HDF-EOS5 support (optional) into NCL (y) y
- Build GRIB2 support (optional) into NCL (y) y
- Enter local library search path(s) /path/to/gcc/lib /path/to/gcc/lib64 /path/to/hmpi/lib /path/to/hdf5/lib /path/to/pnetcdf/lib /path/to/netcdf/lib /path/to/libjpeg/lib /path/to/hdf4/lib /path/to/proj/lib /path/to/libpng/lib /path/to/gdal/lib /path/to/jasper/lib /path/to/g2clib/lib /path/to/udunits/lib /path/to/gsl/lib /path/to/hdf-eos2/lib /path/to/hdf-eos5/lib /path/to/mesa/lib /path/to/vis5d+/lib /path/to/szip/lib /lib64 /usr/lib64 /usr/include/X11
- Enter local include search path(s) /path/to/gcc/include /path/to/gcc/lib64/gcc/aarch64-linux-gnu/10.3.1/include /path/to/gcc/lib64/gcc/aarch64-linux-gnu/10.3.1/plugin/include /path/to/gcc/lib64/gcc/aarch64-linux-gnu/10.3.1/install-tools/include /path/to/hmpi/include /path/to/hdf5/include /path/to/pnetcdf/include /path/to/netcdf/include /path/to/libjpeg/include /path/to/hdf4/include /path/to/proj/include /path/to/libpng/include /path/to/gdal/include /path/to/jasper/include /path/to/jasper/include/jasper /path/to/g2clib/include /path/to/udunits/include /path/to/gsl/include /path/to/gsl/include/gsl /path/to/hdf-eos2/include /path/to/hdf-eos5/include /path/to/mesa/include /path/to/mesa/include/GL /path/to/vis5d+/include /path/to/szip/include /usr/include /usr/include/freetype2 /usr/include/freetype2/freetype /usr/include/X11 /usr/include/tirpc
- Go back and make more changes or review? (n) 回车
- Save current configuration ? (y) 回车
回显如下,表示配置完成。
- 执行以下命令修改主目录Makefile。
cd /path/to/ncl/ncl-6.6.2/ vim Makefile
将第137、138、139行修改如下图所示。
- 执行以下命令编译安装。
make Everything >& make-output &
可以通过执行tail -f make-output命令查看编译详情。
在命令行下执行ll /path/to/ncl/bin 查看文件生成情况,如下图所示,最终编译生成名为ncl的二进制文件即表示编译正常结束。
- 执行以下命令建立软连接。
ln -s /path/to/ncl/share/ncarg/* /path/to/ncl/lib/ncarg
- 执行以下命令设置环境变量。
export NCARG_FONTCAPS=/path/to/ncl/lib/ncarg/fontcaps export NCARG_GRAPHCAPS=/path/to/ncl/lib/ncarg/graphcaps export NCARG_ROOT=/path/to/ncl export NCARG_DATABASE=/path/to/ncl/lib/ncarg/database export NCARG_LIB=/path/to/ncl/lib export NCARG_NCARG=/path/to/ncl/lib/ncarg export PATH=/path/to/ncl:$PATH export LD_LIBRARY_PATH=/path/to/ncl/lib:$LD_LIBRARY_PATH