赞
踩
UBUNTU新版本,一键安装NETCDF,安装netcdf-c netcdf-v_ubuntu安装netcdf-CSDN博客
参考连接傻瓜式安装netcdf-fortran库
1)保存bash代码,文件名为netcdf_install.sh
- #!/bin/sh
- #
- # install_netcdf.sh
- # Copyright (C) 2018 Daniel Santiago <dpelaez@cicese.edu.mx>
- #
- # Distributed under terms of the GNU/GPL license.
- #
- set -e
-
-
- # ============================================================================
- # Installation of NetCDF4 Fortran libraries
- # ----------------------------------------------------------------------------
- #
- # Purpose:
- # This script get the given versions of the NetCD4 libreries and its
- # dependencies and install them in the MAINDIR=/usr/local/netcdf/ directory
- #
- # Usage:
- # [sudo] CC=gcc FC=gfortran MAINDIR=/usr/local/netcdf ./install_netcdf.sh
- #
- # Autor:
- # Daniel Santiago
- # github/dspelaez
- #
- # ============================================================================
-
- ## define compilers
- CC=${CC:-gcc}
- FC=${FC:-gfortran}
- F90=${FC}
- F77=${FC}
-
- # main directory
- MAINDIR=${MAINDIR:-/usr/local/netcdf}
-
- # version of libs
- CLTAG="7.61.0"
- ZLTAG="1.2.10"
- H5TAG="1.10.1"
- NCTAG="4.9.0"
- NFTAG="4.5.4"
-
- ## donwload source code of depencies
- wget -nc -nv --no-check-certificate https://curl.haxx.se/download/curl-$CLTAG.tar.gz
- wget -nc -nv https://zlib.net/fossils/zlib-$ZLTAG.tar.gz
- wget -nc -nv https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-$H5TAG/src/hdf5-$H5TAG.tar.gz
- #wget -nc -nv ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-$NCTAG.tar.gz
- #https://github.com/Unidata/netcdf-c/compare/v4.8.0.tar.gz
- #wget -nc -nv ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-fortran-$NFTAG.tar.gz
-
- ## create config.log
- touch config.log
-
- ## curl
- tar -xf curl-$CLTAG.tar.gz
- cd curl-$CLTAG/
- CLDIR=$MAINDIR
- echo " --->> Compiling curl-$CLTAG"
- ./configure --prefix=${CLDIR} > config.log 2>&1
- make -j4 > config.log 2>&1
- make install > config.log 2>&1
- cd ..
- rm -rf curl-$CLTAG
-
-
- ## zlib
- #tar -xf zlib-$ZLTAG.tar.gz
- cd zlib-$ZLTAG/
- ZDIR=$MAINDIR
- echo " --->> Compiling zlib-$ZLTAG"
- ./configure --prefix=${ZDIR} > config.log 2>&1
- make -j4 > config.log 2>&1
- make install > config.log 2>&1
- cd ..
- rm -rf zlib-$ZLTAG
-
- ## hdf5
- tar -xf hdf5-$H5TAG.tar.gz
- cd hdf5-$H5TAG/
- H5DIR=$MAINDIR
- echo " --->> Compiling hdf5-$H5TAG"
- ./configure --with-zlib=${ZDIR} --prefix=${H5DIR} > config.log 2>&1
- make -j4 > config.log 2>&1
- make install > config.log 2>&1
- cd ..
- rm -rf hdf5-$H5TAG
-
- ## netcdf4-c
- tar -zxvf netcdf-c-$NCTAG.tar.gz
- cd netcdf-c-$NCTAG/
- NCDIR=$MAINDIR
- echo " --->> Compiling netcdf-c-$NCTAG"
- CPPFLAGS=-I${H5DIR}/include LDFLAGS=-L${H5DIR}/lib ./configure --prefix=${NCDIR} --disable-dap > config.log 2>&1
- echo " --->> 3"
- make -j4 > config.log 2>&1
- make install > config.log 2>&1
- cd ..
- rm -rf netcdf-c-$NCTAG
-
- ## netcdf4-fortran
- #tar -xf netcdf-fortran-$NFTAG.tar.gz
- cd netcdf-fortran-$NFTAG/
- echo " --->> Compiling netcdf-fortran-$NFTAG"
- CPPFLAGS=-I${NCDIR}/include LDFLAGS=-L${NCDIR}/lib ./configure --prefix=${NCDIR} > config.log 2>&1
- make -j4 > config.log 2>&1
- make install > config.log 2>&1
- cd ..
- rm -rf netcdf-fortran-$NFTAG
-
- ## show compilation options
- $NCDIR/bin/nf-config --all
-
- echo ""
- echo ===============================================================================
- echo "Finally, you must add this to the .profile (or .bashrc or .zshrc) file"
- echo " Linux --\>" export LD_LIBRARY_PATH=$NCDIR/lib:'$LD_LIBRARY_PATH'
- echo " OSX --\>" export DYLD_LIBRARY_PATH=$NCDIR/lib:'$DYLD_LIBRARY_PATH'
- echo ===============================================================================
- echo ""
2)进入root模式执行前本,可一句一句执行
[sudo] CC=gcc FC=gfortran MAINDIR=/usr/local/netcdf
3)由于脚本中netcdf-c和netcdf-fortran链接不能下载,手动下载,最重要的名字要对应,zlib也要下载解压,因为解压注释掉了
4)执行脚本,ubuntu20以上版本实测成功
./install_netcdf.sh
5) 查看配置选项 /usr/local/netcdf/bin/nf-config --all
6)若netcdf-c文件不能删除,则可以命令行单独运行安装netcdf-c,若提示是m4没有找到
安装m4
sudo apt-get install m4
7).终端中输入 gedit ~/.bashrc
最后加上如下信息
- export NETCDF=/usr/local/netcdf
-
- export PATH=$NETCDF/bin:$PATH
-
- export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH
-
- export CPPFLAGS='-I/usr/local/netcdf/include'
-
- export LDFLAGS='-L/usr/local/netcdf/lib'
8)保存退出
9)使环境变量生效
终端中输入 source ~/.bashrc
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。