当前位置:   article > 正文

UBUNTU新版本,一键安装NETCDF,安装netcdf-c netcdf-v

UBUNTU新版本,一键安装NETCDF,安装netcdf-c netcdf-v

UBUNTU新版本,一键安装NETCDF,安装netcdf-c netcdf-v_ubuntu安装netcdf-CSDN博客

UBUNTU新版本,一键安装NETCDF,安装netcdf-c netcdf-v

参考连接傻瓜式安装netcdf-fortran库
1)保存bash代码,文件名为netcdf_install.sh

  1. #!/bin/sh
  2. #
  3. # install_netcdf.sh
  4. # Copyright (C) 2018 Daniel Santiago <dpelaez@cicese.edu.mx>
  5. #
  6. # Distributed under terms of the GNU/GPL license.
  7. #
  8. set -e
  9. # ============================================================================
  10. # Installation of NetCDF4 Fortran libraries
  11. # ----------------------------------------------------------------------------
  12. #
  13. # Purpose:
  14. # This script get the given versions of the NetCD4 libreries and its
  15. # dependencies and install them in the MAINDIR=/usr/local/netcdf/ directory
  16. #
  17. # Usage:
  18. # [sudo] CC=gcc FC=gfortran MAINDIR=/usr/local/netcdf ./install_netcdf.sh
  19. #
  20. # Autor:
  21. # Daniel Santiago
  22. # github/dspelaez
  23. #
  24. # ============================================================================
  25. ## define compilers
  26. CC=${CC:-gcc}
  27. FC=${FC:-gfortran}
  28. F90=${FC}
  29. F77=${FC}
  30. # main directory
  31. MAINDIR=${MAINDIR:-/usr/local/netcdf}
  32. # version of libs
  33. CLTAG="7.61.0"
  34. ZLTAG="1.2.10"
  35. H5TAG="1.10.1"
  36. NCTAG="4.9.0"
  37. NFTAG="4.5.4"
  38. ## donwload source code of depencies
  39. wget -nc -nv --no-check-certificate https://curl.haxx.se/download/curl-$CLTAG.tar.gz
  40. wget -nc -nv https://zlib.net/fossils/zlib-$ZLTAG.tar.gz
  41. wget -nc -nv https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-$H5TAG/src/hdf5-$H5TAG.tar.gz
  42. #wget -nc -nv ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-$NCTAG.tar.gz
  43. #https://github.com/Unidata/netcdf-c/compare/v4.8.0.tar.gz
  44. #wget -nc -nv ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-fortran-$NFTAG.tar.gz
  45. ## create config.log
  46. touch config.log
  47. ## curl
  48. tar -xf curl-$CLTAG.tar.gz
  49. cd curl-$CLTAG/
  50. CLDIR=$MAINDIR
  51. echo " --->> Compiling curl-$CLTAG"
  52. ./configure --prefix=${CLDIR} > config.log 2>&1
  53. make -j4 > config.log 2>&1
  54. make install > config.log 2>&1
  55. cd ..
  56. rm -rf curl-$CLTAG
  57. ## zlib
  58. #tar -xf zlib-$ZLTAG.tar.gz
  59. cd zlib-$ZLTAG/
  60. ZDIR=$MAINDIR
  61. echo " --->> Compiling zlib-$ZLTAG"
  62. ./configure --prefix=${ZDIR} > config.log 2>&1
  63. make -j4 > config.log 2>&1
  64. make install > config.log 2>&1
  65. cd ..
  66. rm -rf zlib-$ZLTAG
  67. ## hdf5
  68. tar -xf hdf5-$H5TAG.tar.gz
  69. cd hdf5-$H5TAG/
  70. H5DIR=$MAINDIR
  71. echo " --->> Compiling hdf5-$H5TAG"
  72. ./configure --with-zlib=${ZDIR} --prefix=${H5DIR} > config.log 2>&1
  73. make -j4 > config.log 2>&1
  74. make install > config.log 2>&1
  75. cd ..
  76. rm -rf hdf5-$H5TAG
  77. ## netcdf4-c
  78. tar -zxvf netcdf-c-$NCTAG.tar.gz
  79. cd netcdf-c-$NCTAG/
  80. NCDIR=$MAINDIR
  81. echo " --->> Compiling netcdf-c-$NCTAG"
  82. CPPFLAGS=-I${H5DIR}/include LDFLAGS=-L${H5DIR}/lib ./configure --prefix=${NCDIR} --disable-dap > config.log 2>&1
  83. echo " --->> 3"
  84. make -j4 > config.log 2>&1
  85. make install > config.log 2>&1
  86. cd ..
  87. rm -rf netcdf-c-$NCTAG
  88. ## netcdf4-fortran
  89. #tar -xf netcdf-fortran-$NFTAG.tar.gz
  90. cd netcdf-fortran-$NFTAG/
  91. echo " --->> Compiling netcdf-fortran-$NFTAG"
  92. CPPFLAGS=-I${NCDIR}/include LDFLAGS=-L${NCDIR}/lib ./configure --prefix=${NCDIR} > config.log 2>&1
  93. make -j4 > config.log 2>&1
  94. make install > config.log 2>&1
  95. cd ..
  96. rm -rf netcdf-fortran-$NFTAG
  97. ## show compilation options
  98. $NCDIR/bin/nf-config --all
  99. echo ""
  100. echo ===============================================================================
  101. echo "Finally, you must add this to the .profile (or .bashrc or .zshrc) file"
  102. echo " Linux --\>" export LD_LIBRARY_PATH=$NCDIR/lib:'$LD_LIBRARY_PATH'
  103. echo " OSX --\>" export DYLD_LIBRARY_PATH=$NCDIR/lib:'$DYLD_LIBRARY_PATH'
  104. echo ===============================================================================
  105. 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 最后加上如下信息

  1. export NETCDF=/usr/local/netcdf
  2. export PATH=$NETCDF/bin:$PATH
  3. export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH
  4. export CPPFLAGS='-I/usr/local/netcdf/include'
  5. export LDFLAGS='-L/usr/local/netcdf/lib'

8)保存退出

9)使环境变量生效

终端中输入 source ~/.bashrc

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/465084
推荐阅读
相关标签
  

闽ICP备14008679号