分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

CentOS 7系统上添加netcdf库

发布时间:2023-09-06 01:14责任编辑:胡小海关键词:暂无标签

这里提供两种方法来安装 netcdf:

一是 yum 安装,yum 安装时采用的是系统自带的 gfortran 编译器,版本较旧;

二是采用源码来 Makefile 编译安装的方式,它可以下载最新版的源码,并自行指定 Intel 或 PGI 编译器,适合自定义的需求。

O  系统环境

centOS 64位系统:centos-release-7-3.1611.el7.centos.x86_64

PGI 2017:PGI Compilers and Tools 17.4-0 64-bit target on x86-64 Linux -tp sandybridge
 

一 yum 安装 netcdf

在CentOS 下安装比较简单,两句命令即可:

[She@she-centos7 netcdf-cxx4-4.3.0]$ sudo yum install netcdf...========================================================================== Package ???????架构 ??????????版本 ???????????????????源 ???????????大小==========================================================================正在安装: netcdf ????????x86_64 ????????4.3.3.1-5.el7 ??????????epel ????????693 k为依赖而安装: hdf5 ??????????x86_64 ????????1.8.12-8.el7 ???????????epel ????????1.6 M事务概要==========================================================================安装 ?1 软件包 (+1 依赖软件包)...完毕![She@she-centos7 netcdf-cxx4-4.3.0]$ sudo yum install netcdf-devel...依赖关系解决========================================================================== Package ???????????架构 ???????版本 ?????????????????????源 ????????大小==========================================================================正在安装: netcdf-devel ??????x86_64 ?????4.3.3.1-5.el7 ????????????epel ??????67 k为依赖而安装: hdf5-devel ????????x86_64 ?????1.8.12-8.el7 ?????????????epel ?????642 k libcurl-devel ?????x86_64 ?????7.29.0-35.el7.centos ?????base ?????299 k事务概要==========================================================================安装 ?1 软件包 (+2 依赖软件包)...完毕!

以上方法安装的 netcdf 版本为 4.3.3.1,是2015年的版本,比较老。

二 从源码编译安装 netcdf

下面采用编译安装的方式,保证每个模块都使用当前最新的版本。

(1). http://www.zlib.net/zlib-1.2.11.tar.gz

(2). https://www.hdfgroup.org/downloads/hdf5/source-code/

(3). https://curl.haxx.se/download/curl-7.55.1.tar.gz

(4).

(5).

截止netcdf 4.1.3版本,C lib和fortran lib没有分开,从4.2版本开始分开。这就导致了netcdf-fortran-4.2的安装麻烦了一点。

需要依次安装 zlib,hdf5,netcdf,netcdf-c,netcdf-fortran。

1  安装 zlib

(1). 下载地址:http://www.zlib.net/zlib-1.2.11.tar.gz

$ cd zlib-1.2.11$ ./configure --prefix=/usr/local/netcdf4 --sharedlibdir=/opt/pgi/linux86-64/17.4/libChecking for gcc...Checking for shared library support...Building shared library libz.so.1.2.11 with gcc.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

$ make clean

2 安装 hdf5

下载地址:在网页 https://www.hdfgroup.org/downloads/hdf5/source-code/ 中选择版本 1.10.1,下载 gz 格式的文件。

$ cd hdf5-1.10.1
$ ./configure --with-zlib=/usr/local/netcdf4 --prefix=/usr/local/netcdf4
$ make
$ make check
$ make install...
?CC ??????H5Zdeflate.lo ?CC ??????H5Zfletcher32.lo ?CC ??????H5Znbit.lo ?CC ??????H5Zshuffle.lo ?CC ??????H5Zscaleoffset.lo ?CC ??????H5Zszip.lo ?CC ??????H5Ztrans.lo ?CCLD ????libhdf5.la/bin/ld: /usr/local/netcdf4/lib/libz.a(inflate.o): relocation R_X86_64_32S against `zcfree‘ can not be used when making a shared object; recompile with -fPIC/usr/local/netcdf4/lib/libz.a: error adding symbols: Bad valuecollect2: error: ld returned 1 exit statusmake[2]: *** [libhdf5.la] 错误 1make[2]: 离开目录“/home/She/Downloads/NetCDF/hdf5-1.10.1/src”make[1]: *** [all] 错误 2make[1]: 离开目录“/home/She/Downloads/NetCDF/hdf5-1.10.1/src”make: *** [all-recursive] 错误 1

 如果安装时没有提示上述错误,则跳过步骤“1.new” 和“2.new”,直接转至步骤3。

有关这个错误的原因及解决办法,可参见这里。

这个错误一般是64 位 电脑才会出现。

解决方法为重新安装 zlib 和 hdf5,即步骤“1.new” 和“2.new”:

cd zlib-1.2.11 //进入zlib目录CFLAGS="-O3 -fPIC" ./configure ??//使用64位元的方法进行编译

 1.new 重新安装 zlib

$ CFLAGS="-O3 -fPIC" ./configure --prefix=/usr/local/netcdf4 --sharedlibdir=/opt/pgi/linux86-64/17.4/lib$ make check$ sudo make install[sudo] password for She: $ make clean

2.new 重新安装 hdf5

$ cd hdf5-1.10.1/$ ./configure --with-zlib=/usr/local/netcdf4 --prefix=/usr/local/netcdf4$ sudo make$ sudo make check$ sudo make install$ sudo make clean

3 安装netcdf

$ CPPFLAGS=-I/usr/local/netcdf4/include LDFLAGS=-L/usr/local/netcdf4/lib \
?./configure --prefix=/usr/local/netcdf4 CC=pgcc FC=pgf90... ...# NetCDF C Configuration Summary==============================# General-------NetCDF Version: ???????4.4.1Configured On: ???????Wed Sep 27 13:34:01 CST 2017Host System: ???????x86_64-unknown-linux-gnuBuild Directory: ????/home/She/Downloads/NetCDF/netcdf-4.4.1Install Prefix: ????????/usr/local/netcdf4# Compiling Options-----------------C Compiler: ???????/opt/pgi/linux86-64/17.4/bin/pgccCFLAGS: ???????????CPPFLAGS: ???????-I/usr/local/netcdf4/includeLDFLAGS: ???????-L/usr/local/netcdf4/libAM_CFLAGS: ???????AM_CPPFLAGS: ???????AM_LDFLAGS: ???????Shared Library: ???????yesStatic Library: ???????yesExtra libraries: ???-lhdf5_hl -lhdf5 -ldl -lm -lz -lcurl # Features--------NetCDF-2 API: ???????yesHDF4 Support: ???????noNetCDF-4 API: ???????yesNC-4 Parallel Support: ???noPNetCDF Support: ???noDAP Support: ???????yesDiskless Support: ???yesMMap Support: ???????noJNA Support: ???????no$ make$ make check...make ?check-TESTSmake[2]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/h5_test”make[3]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/h5_test”PASS: tst_h_filesPASS: tst_h_files2PASS: tst_h_files4PASS: tst_h_attsPASS: tst_h_atts3PASS: tst_h_atts4PASS: tst_h_varsPASS: tst_h_vars2PASS: tst_h_vars3PASS: tst_h_grpsPASS: tst_h_compoundsPASS: tst_h_compounds2PASS: tst_h_wrt_cmpPASS: tst_h_rd_cmpPASS: tst_h_vlPASS: tst_h_opaquesPASS: tst_h_stringsPASS: tst_h_strings1PASS: tst_h_strings2PASS: tst_h_intsFAIL: tst_h_dimscalesPASS: tst_h_dimscales1PASS: tst_h_dimscales2PASS: tst_h_dimscales3PASS: tst_h_enumsPASS: tst_h_dimscales4============================================================================Testsuite summary for netCDF 4.4.1============================================================================# TOTAL: 26# PASS: ?25# SKIP: ?0# XFAIL: 0# FAIL: ?1# XPASS: 0# ERROR: 0============================================================================See h5_test/test-suite.logPlease report to support-netcdf@unidata.ucar.edu============================================================================make[3]: *** [test-suite.log] 错误 1make[3]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/h5_test”make[2]: *** [check-TESTS] 错误 2make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/h5_test”make[1]: *** [check-am] 错误 2make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/h5_test”make: *** [check-recursive] 错误 1$ sudo make install...Making install in CDLmake[2]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples/CDL”make[3]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples/CDL”make[3]: 对“install-exec-am”无需做任何事。make[3]: 对“install-data-am”无需做任何事。make[3]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples/CDL”make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples/CDL”make[2]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples”make[3]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples”make[3]: 对“install-exec-am”无需做任何事。make[3]: 对“install-data-am”无需做任何事。make[3]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples”make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples”make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1/examples”make[1]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1”make[2]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1” /usr/bin/mkdir -p ‘/usr/local/netcdf4/bin‘ /usr/bin/install -c nc-config ‘/usr/local/netcdf4/bin‘ /usr/bin/mkdir -p ‘/usr/local/netcdf4/lib/pkgconfig‘ /usr/bin/install -c -m 644 netcdf.pc ‘/usr/local/netcdf4/lib/pkgconfig‘ /usr/bin/mkdir -p ‘/usr/local/netcdf4/lib‘ /usr/bin/install -c -m 644 libnetcdf.settings ‘/usr/local/netcdf4/lib‘make ?install-data-hookmake[3]: 进入目录“/home/She/Downloads/NetCDF/netcdf-4.4.1”+-------------------------------------------------------------+| 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[3]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1”make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1”make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-4.4.1”$ sudo make clean

4 安装 netcdf-c 库

[She@she-centos7 netcdf-cxx4-4.3.0]$ CPPFLAGS=-I/usr/local/netcdf4/include LDFLAGS=-L/usr/local/netcdf4/lib \
./configure --prefix=/usr/local/netcdf4 CC=pgcc FC=pgf90[She@she-centos7 netcdf-cxx4-4.3.0]$ make

[She@she-centos7 netcdf-cxx4-4.3.0]$ make check...============================================================================Testsuite summary for netCDF-cxx4 4.3.0============================================================================# TOTAL: 7# PASS: ?7# SKIP: ?0# XFAIL: 0# FAIL: ?0# XPASS: 0# ERROR: 0============================================================================make[3]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0/examples”make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0/examples”make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0/examples”Making check in docsmake[1]: 进入目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0/docs”make[1]: 对“check”无需做任何事。make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0/docs”make[1]: 进入目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0”make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0”[She@she-centos7 netcdf-cxx4-4.3.0]$ sudo make install ...+-------------------------------------------------------------+| Congratulations! You have successfully installed the ???????|| new netCDF-4 C++ Library ???????????????????????????????????|| ????????????????????????????????????????????????????????????|| 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". ???????????????????????????????????|| ????????????????????????????????????????????????????????????|| 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[3]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0”make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0”make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-cxx4-4.3.0”[She@she-centos7 netcdf-cxx4-4.3.0]$ make clean

5 添加 netcdf 的环境变量

[She@she-centos7 NetCDF]$ vi /home/She/Downloads/NetCDF/env_netcdf_LD.sh#!/bin/bash# setting for netcdf, edit by Sheexport LD_LIBRARY_PATH=/usr/local/netcdf4/lib:${LD_LIBRARY_PATH}[She@she-centos7 NetCDF]$ sudo cp /home/She/Downloads/NetCDF/env_netcdf_LD.sh /etc/profile.d[sudo] password for She: [She@she-centos7 NetCDF]$ source /etc/profile.d/env_netcdf_LD.sh [She@she-centos7 NetCDF]$ echo $LD_LIBRARY_PATH/usr/local/netcdf4/lib:

6 安装netcdf-fortran 库

[She@she-centos7 NetCDF] cd netcdf-fortran-4.4.4
[She@she-centos7 netcdf-fortran-4.4.4]$ CPPFLAGS=-I/usr/local/netcdf4/include \
?LDFLAGS=-L/usr/local/netcdf4/lib ./configure --prefix=/usr/local/netcdf4 CC=pgcc FC=pgf90[She@she-centos7 netcdf-fortran-4.4.4]$ make[She@she-centos7 netcdf-fortran-4.4.4]$ make checkMaking check in fortranmake[1]: 进入目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/fortran”make ?check-ammake[2]: 进入目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/fortran”make[2]: 对“check-am”无需做任何事。make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/fortran”make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/fortran”Making check in nf_testmake[1]: 进入目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/nf_test”make ?nf_test tst_f77_v2 ftst_vars ftst_vars2 ftst_vars3 ftst_vars4 ftst_vars5 ftst_vars6 ftst_types ftst_types2 ftst_types3 ftst_groups ftst_path ftst_rengrps f90tst_vars tst_types tst_types2 f90tst_vars_vlen tst_f90_nc4 f90tst_grps f90tst_fill f90tst_fill2 f90tst_vars3 f90tst_vars4 f90tst_vars2 f90tst_path f90tst_rengrps ftst_v2 ???ftest tst_f90make[2]: 进入目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/nf_test”pgf90 -I../fortran ??-I../fortran -g -c -o f03lib_f_interfaces.o ?f03lib_f_interfaces.f90/opt/pgi/linux86-64/17.4/bin/pgf77 -DHAVE_CONFIG_H -I. -I.. -I../libsrc ??-I/usr/local/netcdf4/include -I../fortran ??-I../fortran -g -c -o test_get.o test_get.F/opt/pgi/linux86-64/17.4/bin/pgf77 -DHAVE_CONFIG_H -I. -I.. -I../libsrc ??-I/usr/local/netcdf4/include -I../fortran ??-I../fortran -g -c -o test_put.o test_put.F/opt/pgi/linux86-64/17.4/bin/pgf77 -DHAVE_CONFIG_H -I. -I.. -I../libsrc ??-I/usr/local/netcdf4/include -I../fortran ??-I../fortran -g -c -o nf_error.o nf_error.F/opt/pgi/linux86-64/17.4/bin/pgf77 -DHAVE_CONFIG_H -I. -I.. -I../libsrc ??-I/usr/local/netcdf4/include -I../fortran ??-I../fortran -g -c -o nf_test.o nf_test.F/opt/pgi/linux86-64/17.4/bin/pgf77 -DHAVE_CONFIG_H -I. -I.. -I../libsrc ??-I/usr/local/netcdf4/include -I../fortran ??-I../fortran -g -c -o test_read.o test_read.F/opt/pgi/linux86-64/17.4/bin/pgf77 -DHAVE_CONFIG_H -I. -I.. -I../libsrc ??-I/usr/local/netcdf4/include -I../fortran ??-I../fortran -g -c -o test_write.o test_write.FPGFTN-S-0034-Syntax error at or near / (test_write.F: 167)PGFTN-S-0034-Syntax error at or near / (test_write.F: 197) ?0 inform, ??0 warnings, ??2 severes, 0 fatal for test_nf_redefmake[2]: *** [test_write.o] 错误 2make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/nf_test”make[1]: *** [check-am] 错误 2make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4/nf_test”make: *** [check-recursive] 错误 1[She@she-centos7 netcdf-fortran-4.4.4]$ sudo make install[sudo] password for She: ...+-------------------------------------------------------------+| 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[3]: 离开目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4”make[2]: 离开目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4”make[1]: 离开目录“/home/She/Downloads/NetCDF/netcdf-fortran-4.4.4”[She@she-centos7 netcdf-fortran-4.4.4]$ make clean

7 再次添加 netcdf 终版的环境变量

[She@she-centos7 NetCDF]$ vi /home/She/Downloads/NetCDF/env_netcdf_final.sh#!/bin/bash# setting for netcdf, edit by Sheexport NETCDF=/usr/local/netcdf4export PATH=$PATH:$NETCDF/bin:$NETCDF/include:$NETCDF/libexport MANPATH=$MANPATH:$NETCDF/share/man[She@she-centos7 NetCDF]$ sudo cp /home/She/Downloads/NetCDF/env_netcdf_final.sh /etc/profile.d[sudo] password for She: [She@she-centos7 NetCDF]$ source /etc/profile.d/env_netcdf_final.sh 

三 参考文献

1. 【CESM】1.2.0环境搭建扩充版

2. HDF5 Source Code

3. zlib download

4. curl release and download

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

8. CentOS 7 编译安装 WRF 3.8

9. 在linux下用fortran读取netcdf文件(以WRF模式输出的数据为例)

10. 延伸阅读:NCL基础讲解(一)——NCL简介

11. 延伸阅读:NCL基础讲解(二)——NCL安装与运行

CentOS 7系统上添加netcdf库

原文地址:http://www.cnblogs.com/snake553/p/7455453.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved