CentOS 7系统上添加netcdf库
这里提供两种方法来安装 netcdf:
一是 yum 安装,yum 安装时采用的是系统自带的 gfortran 编译器,版本较旧;
二是采用源码来 Makefile 编译安装的方式,它可以下载最新版的源码,并自行指定 Intel 或 PGI 编译器,适合自定义的需求。
O 系统环境
centOS 64位系统:CentOS Linux release 7.6.1810 (Core), 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
PGI 2019:PGI Compilers and Tools 19.4-0 64-bit target on x86-64 Linux -tp sandybridge
一 yum 安装 netcdf
在CentOS 下安装比较简单,两句命令即可:
[She@she-centos7 netcdf-cxx4-4.3.]$ sudo yum install netcdf
...==========================================================================
Package 架构 版本 源 大小
==========================================================================
正在安装:
netcdf x86_64 4.3.3.1-.el7 epel k
为依赖而安装:
hdf5 x86_64 1.8.-.el7 epel 1.6 M 事务概要
==========================================================================
安装 软件包 (+ 依赖软件包)
...
完毕! [She@she-centos7 netcdf-cxx4-4.3.]$ sudo yum install netcdf-devel
...
依赖关系解决 ==========================================================================
Package 架构 版本 源 大小
==========================================================================
正在安装:
netcdf-devel x86_64 4.3.3.1-.el7 epel k
为依赖而安装:
hdf5-devel x86_64 1.8.-.el7 epel k
libcurl-devel x86_64 7.29.-.el7.centos base k 事务概要
==========================================================================
安装 软件包 (+ 依赖软件包)
...
完毕!
以上方法安装的 netcdf 版本为 4.3.3.1,是2015年的版本,比较老。
二 从源码编译安装 netcdf
下面采用编译安装的方式,保证每个模块都使用当前最新的版本。
(1). http://www.zlib.net/zlib-1.2.11.tar.gz
(2). ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/szip-2.1.tar.gz
(3) https://curl.haxx.se/download/curl-7.64.1.tar.gz
(4). https://www.hdfgroup.org/downloads/hdf5/source-code/
(5). ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.6.1.tar.gz。
(6). ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-c-4.7.0.tar.gz
(7). https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.4.5.tar.gz
(8). https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-cxx4-4.3.0.tar.gz
截止netcdf 4.1.3版本,C lib和fortran lib没有分开,从4.2版本开始分开。这就导致了netcdf-fortran-4.2的安装麻烦了一点。
需要依次安装 zlib,hdf5,netcdf,netcdf-c,netcdf-fortran。
1 安装 zlib
$ wget http://www.zlib.net/zlib-1.2.11.tar.gz
$ tar -xvf ./zlib-1.2..tar.gz
$ cd ./zlib-1.2.$ env CC="pgcc -fPIC" CFLAGS="-O3" CXX="pgc++ -fPIC" CXXFLAGS="-O3" ./configure \
--prefix=/usr/local/netcdf4 --sharedlibdir=/opt/pgi/linux86-/19.4/lib
...
...
Checking for shared library support...
Building shared library libz.so.1.2. with pgcc -fPIC.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes. $ make $ make check
$ sudo make install $ echo "/usr/local/netcdf4/lib/" >> /etc/ld.so.conf
$ make clean
2 安装 szip
$ wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/szip-2.1.tar.gz
$ tar -xvf szip-2.1.tar.gz
$ cd ./szip-2.1
$ env CC="pgcc" CFLAGS="-O2 -fPIC" CXX="pgc++" CXXFLAGS="-O2 -fPIC" ./configure 、
--prefix=/usr/local/netcdf4 --libdir=/opt/pgi/linux86-/19.4/lib
$ make
$ make check
$ sudo make install
$ make clean
3 安装 curl
$ wget https://curl.haxx.se/download/curl-7.64.1.tar.gz
$ tar -xvf ./curl-7.64..tar.gz
$ cd ./curl-7.64.1
$ env CC="pgcc" CFLAGS="-O2 -fPIC" CXX="pgc++" CXXFLAGS="-O2 -fPIC" ./configure \
--prefix=/usr/local/netcdf4 --libdir=/opt/pgi/linux86-/19.4/lib
...
SSPI: no (--enable-sspi)
ca cert bundle: no
ca cert path:
ca fallback:
LDAP: no (--enable-ldap / --with-ldap-lib / --with-lber-lib)
LDAPS: no (--enable-ldaps)
RTSP: enabled
RTMP: no (--with-librtmp)
Metalink: no (--with-libmetalink)
PSL: no (libpsl not found)
Alt-svc: no (--enable-alt-svc)
HTTP2: disabled (--with-nghttp2)
Protocols: DICT FILE FTP GOPHER HTTP IMAP POP3 RTSP SMTP TELNET TFTP
Features: IPv6 UnixSockets libz AsynchDNS $ make
$ make check
...
PASS: check-easy
PASS: check-multi
============================================================================
Testsuite summary for curl -
============================================================================
# TOTAL:
# PASS:
# SKIP:
# XFAIL:
# FAIL:
# XPASS:
# ERROR:
============================================================================
make[]: Leaving directory `/home/She/Software/LINUX/NetCDF/curl-7.64./docs/libcurl'
make[]: Leaving directory `/home/She/Software/LINUX/NetCDF/curl-7.64./docs/libcurl'
make[]: Leaving directory `/home/She/Software/LINUX/NetCDF/curl-7.64./docs/libcurl'
make[]: Leaving directory `/home/She/Software/LINUX/NetCDF/curl-7.64./docs/libcurl'
$ sudo make install
$ make clean
4 安装 hdf5
下载地址:在网页 https://www.hdfgroup.org/downloads/hdf5/source-code/ 中选择版本 1.10.5,下载 .tar.gz 格式的文件。
$ tar -xvf ./hdf5-1.10..tar.gz
$ cd ./hdf5-1.10.5 $ env CC="pgcc" CFLAGS="-O3 -fPIC" FC="pgfortran" FCFLAGS="-O3 -fPIC" CXX="pgc++" \
CXXFLAGS="-O3 -fPIC" CPPFLAGS=-I/opt/pgi/linux86-/19.4/include \
LDFLAGS=-L/opt/pgi/linux86-/19.4/lib ./configure \
--with-zlib=/usr/local/netcdf4 --with-szlib=/usr/local/netcdf4 \
--prefix=/usr/local/netcdf4 --libdir=/opt/pgi/linux86-/19.4/lib \
--enable-fortran=yes
$ make$ make check
$ make install
$ make clean
5 安装netcdf
下载地址位于UCAR网站 https://www.unidata.ucar.edu/downloads/netcdf/index.jsp,也可以从UCAR的FTP直接下载 ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4,选择其中的*.tar.gz格式的文件,目前的最新版本如下:
(1) NetCDF-4.6.0: ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.6.1.tar.gz
(2) netcdf-c-4.7.0: ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-c-4.7.0.tar.gz
(3) netcdf-fortran-4.4.5: https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.4.5.tar.gz
(4) netcdf-cxx4-4.3.0: https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-cxx4-4.3.0.tar.gz
$ wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.6.1.tar.gz
$ tar -xvf ./netcdf-4.6..tar.gz
$ cd netcdf-4.6. $ env CC="pgcc" CFLAGS="-O3 -fPIC" FC="pgf90" FCFLAGS="-O3 -fPIC" CXX="pgc++" CXXFLAGS="-O3 -fPIC" \
CPPFLAGS=-I/usr/local/netcdf4/include LDFLAGS=-L/usr/local/netcdf4/lib ./configure \
--disable-dap --with-zlib=/usr/local/netcdf4 --with-szlib=/usr/local/netcdf4 \
--libdir=/opt/pgi/linux86-/19.4/lib --prefix=/usr/local/netcdf4 $ make
$ make check
...
============================================================================
Testsuite summary for netCDF 4.6.
============================================================================
# TOTAL:
# PASS:
# SKIP:
# XFAIL:
# FAIL:
# XPASS:
# ERROR:
============================================================================ $ sudo make install
...
+-------------------------------------------------------------+
| Congratulations! You have successfully installed netCDF! |
| |
| You can use script "nc-config" to find out the relevant |
| compiler options to build your application. Enter |
| |
| nc-config --help |
| |
| for additional information. |
| |
| CAUTION: |
| |
| If you have not already run "make check", then we strongly |
| recommend you do so. It does not take very long. |
| |
| Before using netCDF to store important data, test your |
| build with "make check". |
| |
| NetCDF is tested nightly on many platforms at Unidata |
| but your platform is probably different in some ways. |
| |
| If any tests fail, please see the netCDF web site: |
| http://www.unidata.ucar.edu/software/netcdf/ |
| |
| NetCDF is developed and maintained at the Unidata Program |
| Center. Unidata provides a broad array of data and software |
| tools for use in geoscience education and research. |
| http://www.unidata.ucar.edu |
+-------------------------------------------------------------+ $ make clean
6 安装 netcdf-c 库
$ wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.7.0.tar.gz
$ tar -xvf ./netcdf-c-4.7..tar.gz
$ cd netcdf-c-4.7. $ env CC="pgcc" CFLAGS="-O3 -fPIC" FC="pgf90" FCFLAGS="-O3 -fPIC" CXX="pgc++" CXXFLAGS="-O3 -fPIC" \
CPPFLAGS=-I/usr/local/netcdf4/include LDFLAGS=-L/usr/local/netcdf4/lib ./configure \
--disable-dap --with-zlib=/usr/local/netcdf4 --with-szlib=/usr/local/netcdf4 \
--libdir=/opt/pgi/linux86-/19.4/lib --includedir=/opt/pgi/linux86-/19.4/include \
--prefix=/usr/local/netcdf4
$ make
$ make check
$ sudo make install
$ make clean ...
============================== # General
-------
NetCDF Version: 4.7.
Configured On: Mon May :: CST
Host System: x86_64-pc-linux-gnu
Build Directory: /home/She/Software/LINUX/NetCDF/netcdf-c-4.7.
Install Prefix: /usr/local/netcdf4 # Compiling Options
-----------------
C Compiler: /opt/pgi/linux86-/19.4/bin/pgcc
CFLAGS: -O3 -fPIC
CPPFLAGS: -I/usr/local/netcdf4/include
LDFLAGS: -L/usr/local/netcdf4/lib
AM_CFLAGS:
AM_CPPFLAGS:
AM_LDFLAGS:
Shared Library: yes
Static Library: yes
Extra libraries: -lsz -lhdf5_hl -lhdf5 -lm -ldl -lz # Features
--------
NetCDF- API: yes
HDF4 Support: no
HDF5 Support: yes
NetCDF- API: yes
NC- Parallel Support: no
PnetCDF Support: no
DAP2 Support: no
DAP4 Support: no
Byte-Range Support: no
Diskless Support: yes
MMap Support: no
JNA Support: no
CDF5 Support: yes
ERANGE Fill Support: no
Relaxed Boundary Check: yes $ make check
...
============================================================================
Testsuite summary for netCDF 4.7.
============================================================================
# TOTAL:
# PASS:
# SKIP:
# XFAIL:
# FAIL:
# XPASS:
# ERROR: $ sudo make install
...
+-------------------------------------------------------------+
| Congratulations! You have successfully installed netCDF! |
| |
| You can use script "nc-config" to find out the relevant |
| compiler options to build your application. Enter |
| |
| nc-config --help |
| |
| for additional information. |
| |
| CAUTION: |
| |
| If you have not already run "make check", then we strongly |
| recommend you do so. It does not take very long. |
| |
| Before using netCDF to store important data, test your |
| build with "make check". |
| |
| NetCDF is tested nightly on many platforms at Unidata |
| but your platform is probably different in some ways. |
| |
| If any tests fail, please see the netCDF web site: |
| http://www.unidata.ucar.edu/software/netcdf/ |
| |
| NetCDF is developed and maintained at the Unidata Program |
| Center. Unidata provides a broad array of data and software |
| tools for use in geoscience education and research. |
| http://www.unidata.ucar.edu |
+-------------------------------------------------------------+ $ make clean
7 添加 netcdf 的环境变量
$ vi ~/env_netcdf_LD.sh
#!/bin/bash
# setting for netcdf, edit by She
export LD_LIBRARY_PATH=/usr/local/netcdf4/lib:${LD_LIBRARY_PATH} $ sudo cp ~/env_netcdf_LD.sh /etc/profile.d $ source /etc/profile.d/env_netcdf_LD.sh
$ echo $LD_LIBRARY_PATH
/usr/local/netcdf4/lib:/usr/lib64/openmpi/lib
8 安装netcdf-fortran 库
$ wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.4.5.tar.gz
$ tar -xvf ./netcdf-fortran-4.4..tar.gz
$ cd netcdf-fortran-4.4. $ env CC="pgcc" CFLAGS="-O3 -fPIC" FC="pgf90" FCFLAGS="-O3 -fPIC" CXX="pgc++" CXXFLAGS="-O3 -fPIC" \
F90="pgf90" FCFLAGS="-O3 -fPIC" CPPFLAGS=-I/usr/local/netcdf4/include LDFLAGS=-L/usr/local/netcdf4/lib \
./configure --libdir=/opt/pgi/linux86-/19.4/lib --includedir=/opt/pgi/linux86-/19.4/include \
--prefix=/usr/local/netcdf4
$ make $ make check $ sudo make install
.... ...
+-------------------------------------------------------------+
| Congratulations! You have successfully installed the netCDF |
| Fortran libraries. |
| |
| You can use script "nf-config" to find out the relevant |
| compiler options to build your application. Enter |
| |
| nf-config --help |
| |
| for additional information. |
| |
| CAUTION: |
| |
| If you have not already run "make check", then we strongly |
| recommend you do so. It does not take very long. |
| |
| Before using netCDF to store important data, test your |
| build with "make check". |
| |
| NetCDF is tested nightly on many platforms at Unidata |
| but your platform is probably different in some ways. |
| |
| If any tests fail, please see the netCDF web site: |
| http://www.unidata.ucar.edu/software/netcdf/ |
| |
| NetCDF is developed and maintained at the Unidata Program |
| Center. Unidata provides a broad array of data and software |
| tools for use in geoscience education and research. |
| http://www.unidata.ucar.edu |
+-------------------------------------------------------------+ $ make clean
在 make check 时,可能会提示ftst_rengrps.F文件的一个小错误,错误内容如下:
$ make check
...
...
pgfortran -DHAVE_CONFIG_H -I. -I.. -I../libsrc -I../fortran -I../fortran -I/usr/local/netcdf4/include -I../fortran -g -c -o ftst_rengrps.o ftst_rengrps.F
PGF90-S-0034-Syntax error at or near identifier nclude (ftst_rengrps.F: 13)
PGF90/x86-64 Linux 19.4-0: compilation completed with severe errors
make[2]: *** [ftst_rengrps.o] Error 2
make[2]: Leaving directory `/home/xxx/Software/LINUX/NetCDF/netcdf-fortran-4.4.5/nf_test'
make[1]: *** [check-am] Error 2
make[1]: Leaving directory `/home/xxx/Software/LINUX/NetCDF/netcdf-fortran-4.4.5/nf_test'
make: *** [check-recursive] Error 1
解决办法是,在源路径中找到文件“ftst_rengrps.F”,在第13行的开头增加一个空格,重新编译即可。
$ cat /home/She/Software/LINUX/NetCDF/netcdf-fortran-4.4./nf_test/ftst_rengrps.F | grep nclude
include "netcdf.inc"
include "netcdf.inc"
$ head -n /home/She/Software/LINUX/NetCDF/netcdf-fortran-4.4./nf_test/ftst_rengrps.F
C This is part of the netCDF package.
C Copyright 2006 University Corporation for Atmospheric Research/Unidata.
C See COPYRIGHT file for conditions of use. C This program tests netCDF-4 variable functions from fortran. C $Id: ftst_rengrps.F,v 1.3 2010/02/03 14:35:21 ed Exp $ program ftst_rengrps
C use typeSizes
C use netcdf
C use netcdf4_f03
implicit none
include "netcdf.inc" (修改前:错误的句子,不符合固定格式的写法)
include "netcdf.inc" (修改后:正确)
9 再次添加 netcdf 终版的环境变量
$ vi ~/env_netcdf_final.sh
#!/bin/bash
# setting for netcdf, edit by She
export NETCDF=/usr/local/netcdf4
export PATH=$PATH:$NETCDF/bin:$NETCDF/include:$NETCDF/lib
export MANPATH=$MANPATH:$NETCDF/share/man$ sudo cp ~/env_netcdf_final.sh /etc/profile.d
$ source /etc/profile.d/env_netcdf_final.sh
三 参考文献
5. netcdf-4.4.1 FTP source download
6. netcdf-cxx4-4.3.0.tar.gz FTP source download
7. netcdf-fortran-4.4.4.tar.gz FTP source download
9. 在linux下用fortran读取netcdf文件(以WRF模式输出的数据为例)
10. 延伸阅读:NCL基础讲解(一)——NCL简介
11. 延伸阅读:NCL基础讲解(二)——NCL安装与运行
CentOS 7系统上添加netcdf库的更多相关文章
- 在CentOS Linux系统上,添加新的端口,启用ssh服务
SSH作为Linux远程连接重要的方式,如何配置安装linux系统的SSH服务,如何开启SSH? SSH是什么? SSH 为 Secure Shell 由 IETF 的网络工作小组(Network W ...
- CentOS 7系统上制作Clonezilla(再生龙)启动U盘并克隆双系统
笔记本安装的是双系统:Win7 64位,CentOS 7 64位. 政采就是个巨大的坑,笔记本标配的是5400转的机械硬盘,开机时间常常要一至两分钟,软件运行起来时各种数据的读写也非常慢,忍无可忍,决 ...
- CentOS7系统上的GPSTK示例代码调试 & 运行结果 & 心得
下载的源码程序包中,共有16个例子,这里记录它们的调试及运行结果,尤其是哪些可用,哪些不可用,今后使用时用作参考. 总结: (1)在 18 个示例程序中,example16 和 example17 编 ...
- Spire.Cloud 私有化部署教程(一) - CentOS 7 系统
Spire.Cloud支持的Linux服务器系统包括CentOS和Ubuntu(推荐使用CentOS 7和Ubuntu 18版本),本教程主要介绍如何在CentOS 7系统上实现Spire.Cloud ...
- CentOS 6.5系统上安装SVN服务器端的方法及步骤
VN其实就是Subversion,分为服务器端和客户端.之前在网上搜了很多方法,都有各种问题,经过自己搜集整理以及实际尝试,总算有个比较靠谱的方法.本文主要介绍CentOS 6.5系统上安装SVN服务 ...
- CentOS 6.5系统上安装SVN服务器端的方法及目录访问权限配置(转总结)
SVN其实就是Subversion,分为服务器端和客户端.之前在网上搜了很多方法,都有各种问题,经过自己搜集整理以及实际尝试,总算有个比较靠谱的方法.本文主要介绍CentOS 6.5系统上安装SVN服 ...
- 在windows系统上使用pip命令安装python的第三方库
在windows系统上使用pip命令安装python的第三方库 通过cmd启动命令行后,直接输入pip命令,有时候命令行会提示我们pip不是一个指令,这个时候我们可以通过python的集成开发环境里面 ...
- CentOS 6.4 系统上如何安装 tomcat 8
CentOS 6.4 系统上如何安装 tomcat 8 本文将详细讲解在Linux系统上如何安装tomcat,tomcat是没有32位和64位之分的. 1.下载tomcat 首先我们肯定要先下载tom ...
- CentOS 7系统添加启动项
CentOS 7系统已经把CentOS 6的 runlevel 系统服务管理替换成了systemd.在 /etc/rc[0-6S].d 下添加启动项已经不能在系统启动的时候自动执行,需要通过新的 sy ...
随机推荐
- CCF CSP 201403-1 相反数
题目链接:http://118.190.20.162/view.page?gpid=T10 问题描述 试题编号: 201403-1 试题名称: 相反数 时间限制: 1.0s 内存限制: 256.0MB ...
- 爬坑二 activiti流数据库版本错误引发的问题
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'actModelCont ...
- 原生JS动态添加和删除类
原生JS动态添加和删除类 由于需要, 给按钮组监听点击事件(要求用事件委托),当有一个按钮被点击时,相应的给该按钮添加一个类(激活类),其他没有点击的按钮就要移出该类 添加和和删除类有三种方法 首先等 ...
- spring-mvc(基础)
一.MVC框架的概述 1.作用 ①支持直接一个方法对一请求 ② 支持数据的自动封装 ③ 自动支持上传组件 ④ 自动支持JSON的转成 2.配置流程图 3.基于xml的配置 ...
- log4J日志框架
log4j的配置:log4j是一个日志输出框架,就是用于输出日志的,主流框架大部分都是Log4j输出.Spring框架也可以通过Log4j输出日志 Log4j提供了强大的日志输出的自定义功能(1)通过 ...
- puppeteer实现线上服务器任意区域截图
整个九月份由于业务繁重以及玩心颇重,一直没有机会来写一篇博文.而且笔者于十月一日将会举办人生大事--婚礼,现在家里筹办过程中只能抽出零碎的时间来写这篇文章. 关于服务端截图,这种使用场景非常少见,大多 ...
- 移动namenode、secondarynamenode和jobTracker的节点(使其成为独立节点)
https://blog.csdn.net/zwx19921215/article/details/22528097
- [十二省联考2019]异或粽子 01trie
[十二省联考2019]异或粽子 01trie 链接 luogu 思路 首先求前k大的(xo[i]^xo[j])(i<j). 考场上只想到01trie,不怎么会写可持久,就写了n个01trie,和 ...
- Error creating bean
问题原因 Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: bookinfo is not mapped,sql语句中的表 ...
- 20165306 Exp1 PC平台逆向破解
20165306 Exp1 PC平台逆向破解 一.逆向及Bof基础实践说明 1. 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,fo ...