一个脚本完成安装netCDF、NCO、Ncview库

顾恺
2023-12-01

1 安装Intel编译器、OpenMPI

Intel编译器安装的是:parallel_studio_xe_2020_update4_cluster_edition
OpenMPI使用Intel 编译器安装 (CC=icc FC=ifort CXX=icpc)
以上自行上网搜索安装教程。

2 一个脚本实现安装所有库

依赖关系为:
netCDF-Fortran -> netCDF-c -> zlib, szip, HDF5
NCO -> netCDF, antlr, udunits
Ncview -> netCDF, libpng, X11, udunits

  1. 脚本中的版本号根据实际情况更改,注意版本依赖问题,如 netCDF-c 与 HDF5 兼容问题
  2. antrl2.7.7的bug
#!/bin/bash
#####################################################
# the tar.gz file should be decompressed in $SPATH
# all packages are installed in $SPATH/intel-software
#####################################################

export CC=mpicc
export CXX=mpic++
export FC=mpifort
export F90=mpifort
export F77=mpifort
export MPIF90=mpifort
export MPIF77=mpifort
export MPICC=mpicc
export MPICXX=mpic++

SPATH=/home/mppadmin/software #software path, the tar.gz file should be decompressed there
cd $SPATH
if [ -f .env ];then
    rm .env
fi
touch .env

# netCDF

## zlib
export ZLIBPATH=$SPATH/intel-software/zlib-1.2.8
cd $SPATH/zlib-1.2.8
./configure --prefix=ZLIBPATH --eprefix=$ZLIBPATH
make clean;make;make install;make check;make clean
CMD="export LD_LIBRARY_PATH=$ZLIBPATH/lib:$LD_LIBRARY_PATH"
$CMD;echo $CMD>>$SPATH/.env

## szip
export SZIPPATH=$SPATH/intel-software/szip-2.1
cd $SPATH/szip-2.1
./configure --prefix=$SZIPPATH --build=x86_64 CFLAGS="-O2 -fPIC" FCFLAGS="-O2 -fPIC" CXXFLAGS="-O2 -fPIC"
make;make install;make check;make clean
CMD="export LD_LIBRARY_PATH=$SZIPPATH/lib:$LD_LIBRARY_PATH"
$CMD;echo $CMD>>$SPATH/.env

## hdf
cd $SPATH/hdf5-hdf5-1_10_6
export HDFPATH=$SPATH/intel-software/hdf5-1.10.6
./configure --prefix=$HDFPATH --enable-fortran --enable-parallel --with-zlib=$ZLIBPATH --with-szlib=$SZIPPATH CFLAGS="-O2 -fPIC" FCFLAGS="-O2 -fPIC" CXXF                                                                                                                                                                                                                      LAGS="-O2 -fPIC"
make clean;make -j16;make install;make clean
CMD="export LD_LIBRARY_PATH=$HDFPATH/lib:$LD_LIBRARY_PATH"
$CMD;echo $CMD>>$SPATH/.env
CMD="export PATH=$HDFPATH/bin:$PATH"
$CMD;echo $CMD>>$SPATH/.env
source $SPATH/.env

## netcdf-c
cd $SPATH/netcdf-c-4.3.3
export NCPATH=$SPATH/intel-software/netcdf-4.3.3
./configure --prefix=$NCPATH --enable-netcdf4 --enable-extra-example-tests --enable-parallel-tests --enable-logging --enable-extra-tests --enable-large-f                                                                                                                                                                                                                      ile-tests --disable-dap-remote-tests --disable-dap LDFLAGS=" -L$HDFPATH/lib -L$SZIPPATH/lib/ -L$ZLIBPATH/lib/" LIBS=" -lhdf5 -lhdf5_hl -lhdf5hl_fortran -                                                                                                                                                                                                                      lhdf5_fortran -lz -lsz -lcurl" CPPFLAGS=" -I$HDFPATH/include -I$ZLIBPATH/include -I$SZIPPATH/include"
make clean;make -j16;make install;make check;make clean
CMD="export LD_LIBRARY_PATH=$NCPATH/lib:$LD_LIBRARY_PATH"
$CMD;echo $CMD>>$SPATH/.env
CMD="export PATH=$NCPATH/bin:$PATH"
$CMD;echo $CMD>>$SPATH/.env

## netcdf-fortran
cd $SPATH/netcdf-fortran-4.4.1
./configure --prefix=$NCPATH LDFLAGS=" -L$HDFPATH/lib -L$SZIPPATH/lib/ -L$ZLIBPATH/lib/ -L$NCPATH/lib" LIBS=" -lhdf5 -lhdf5_hl -lhdf5hl_fortran -lhdf5_fo                                                                                                                                                                                                                      rtran -lz -lsz -lcurl -lnetcdf" CPPFLAGS=" -I$HDFPATH/include -I$SZIPPATH/include -I$ZLIBPATH/include -I$NCPATH/include"
make clean;make -j16;make install;make check;make clean
source $SPATH/.env


# NCO

## udunits
cd $SPATH/udunits-2.2.28
export UDPATH=$SPATH/intel-software/udunits-2.2.28
export LIBINC=$SPATH/X11
./configure --prefix=$UDPATH CPPFLAGS=-I$LIBINC LDFLAGS=-L$LIBINC LIBS=" -lexpat"
make clean;make -j16;make install;make clean
CMD="export LD_LIBRARY_PATH=$UDPATH/lib:$LD_LIBRARY_PATH"
$CMD;echo $CMD>>$SPATH/.env
source $SPATH/.env


## antlr
cd $SPATH/antlr2-master
export ATPATH=$SPATH/intel-software/antlr-2.7.7
./configure --prefix=$ATPATH --disable-csharp --disable-java --disable-python
make clean;make;make install;make clean
CMD="export LD_LIBRARY_PATH=$ATPATH/lib:$LD_LIBRARY_PATH"
$CMD;echo $CMD>>$SPATH/.env
source $SPATH/.env


## nco
cd $SPATH/nco-5.0.6
export NCOPATH=$SPATH/intel-software/nco-5.0.6
./configure --prefix=$NCOPATH CPPFLAGS=-I$ATPATH/include/ LDFLAGS=-L$ATPATH/lib LIBS=" -lantlr"  NETCDF_INC=$NCPATH/include NETCDF_LIB=$NCPATH/lib NETCDF_ROOT=$NCPATH ALTLR_ROOT=$ATPATH UDUNITS2_PATH=$UDPATH --enable-udunits2
make clean;make;make install;make clean
CMD="export LD_LIBRARY_PATH=$NCOPATH/lib:$LD_LIBRARY_PATH"
$CMD;echo $CMD>>$SPATH/.env
CMD="export PATH=$NCOPATH/bin:$PATH"
$CMD;echo $CMD>>$SPATH/.env
source $SPATH/.env


# NCVIEW
cd $SPATH/ncview-2.1.7
export NCVPATH=$SPATH/intel-software/ncview-2.1.7
./configure --prefix=$NCVPATH --with-nc-config=$NCPATH/bin/nc-config --with-udunits2_incdir=$UDPATH/include --with-udunits2_libdir=$UDPATH/lib --with-png_incdir=$SPATH/libpng-1.6.37/include --with-png_libdir=$SPATH/libpng-1.6.37/lib CPPFLAGS=-I$SPATH LDFLAGS=-L$SPATH/X11 --x-includes=$SPATH --x-libraries=$SPATH --with-x
make clean;make;make install;make clean
CMD="export PATH=$NCVPATH/bin:$PATH"
$CMD;echo $CMD>>$SPATH/.env
source $SPATH/.env

3 环境变量

最终~/.bashrc为:

source /home/mppadmin/software/intel/parallel_studio_xe_2020/compilers_and_libraries_2020/linux/bin/compilervars.sh -arch intel64 -platform linux
export LD_LIBRARY_PATH=/home/mppadmin/software/intel-software/udunits-2.2.28/lib:/home/mppadmin/software/libpng-1.6.37/lib:$LD_LIBRARY_PATH
MPI_HOME=/home/mppadmin/software/intel-software/openmpi-4.0.7
export PATH=${MPI_HOME}/bin:$PATH
export LD_LIBRARY_PATH=${MPI_HOME}/lib:${MPI_HOME}/lib/openmpi:$LD_LIBRARY_PATH
export MANPATH=${MPI_HOME}/share/man:$MANPATH
export LD_LIBRARY_PATH=/home/mppadmin/software/intel-software/szip-2.1/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/mppadmin/software/intel-software/zlib-1.2.8/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/mppadmin/software/intel-software/hdf5-1.10.6/lib:$LD_LIBRARY_PATH
export PATH=/home/mppadmin/software/intel-software/hdf5-1.10.6/bin:$PATH
export LD_LIBRARY_PATH=/home/mppadmin/software/intel-software/netcdf-4.3.3/lib:$LD_LIBRARY_PATH
export PATH=/home/mppadmin/software/intel-software/netcdf-4.3.3/bin:$PATH
export PATH=/home/mppadmin/software/intel-software/nco-5.0.6/bin:$PATH
export LD_LIBRARY_PATH=/home/mppadmin/software/intel-software/parallel-netcdf-1.8.1/lib:$LD_LIBRARY_PATH
export PATH=/home/mppadmin/software/intel-software/parallel-netcdf-1.8.1/bin:$PATH
export LD_LIBRARY_PATH=/home/mppadmin/software/X11:$LD_LIBRARY_PATH
export PATH=/home/mppadmin/software/intel-software/ncview-2.1.7/bin:$PATH

4 归档

上面一个可行的安装方案,保存到了 github 上,可以参考

 类似资料: