1: NetCDF编译过程
cd netcdf-4.1.3
./configure --disable-dap --disable-netcdf-4 --prefix=/usr/local/netcdf
但是连这一步都没有通过,
.......................
checking whether ifort accepts -g... no
checking for Fortran flag to compile .f90 files... unknown
configure: error: Fortran could not compile .f90 files
configure: error: ./configure failed for libcf
在 --prefix=/usr/local/netcdf之后加上FC=gfortran之后
./configure --disable-dap --disable-netcdf-4 --prefix=/usr/local/netcdf FC=gfortran
编译通过!
2: make
直接输入
make
出现
.......................
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/home/dinghao/netcdf-4.1.3/examples'
make[2]: Leaving directory `/home/dinghao/netcdf-4.1.3/examples'
make[2]: Entering directory `/home/dinghao/netcdf-4.1.3'
make[2]: Leaving directory `/home/dinghao/netcdf-4.1.3'
make[1]: Leaving directory `/home/dinghao/netcdf-4.1.3'
在/usr/local/netcdf/ 目录下没有出现任何东西!?confused!
3: make check 步骤
键入
make check
出现
.......................
==================
All 7 tests passed
==================
make[3]: Leaving directory `/home/dinghao/netcdf-4.1.3/examples/CXX'
make[2]: Leaving directory `/home/dinghao/netcdf-4.1.3/examples/CXX'
make[2]: Entering directory `/home/dinghao/netcdf-4.1.3/examples'
make[2]: Nothing to be done for `check-am'.
make[2]: Leaving directory `/home/dinghao/netcdf-4.1.3/examples'
make[1]: Leaving directory `/home/dinghao/netcdf-4.1.3/examples'
make[1]: Entering directory `/home/dinghao/netcdf-4.1.3'
make[1]: Leaving directory `/home/dinghao/netcdf-4.1.3'
check 居然通过!
4: make install 步骤
键入
sudo make install
最后显示
...........................
make install-data-hook
make[3]: Entering directory `/home/dinghao/netcdf-4.1.3'
+-------------------------------------------------------------+
| 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]: Leaving directory `/home/dinghao/netcdf-4.1.3'
make[2]: Leaving directory `/home/dinghao/netcdf-4.1.3'
make[1]: Leaving directory `/home/dinghao/netcdf-4.1.3'
说明安装成功!
5: 测试
program simple_xy_wr
use netcdf
implicit none
! 定义数据文件的名称
character (len = *), parameter :: FILE_NAME = "simple_xy.nc"
! 写一个12*6的二维数据
integer, parameter :: NDIMS = 2
integer, parameter :: NX = 6, NY = 12
! 当创建netCDF文件的时候,变量和维数都有一个对应的ID
integer :: ncid, varid, dimids(NDIMS)
integer :: x_dimid, y_dimid
integer :: x, y
! 要保存到文件的数据数组
integer, dimension(:,:), allocatable :: data_out
! 为数据数组分配内存
allocate(data_out(NY, NX))
! 随意往数据数组里写一些数据
do x = 1, NX
do y = 1, NY
data_out(y, x) = (x - 1) * NY + (y - 1)
end do
end do
! 创建netCDF文件,返回文件对应的ID,如果存在则覆盖,check子程序用来检验执行是否成功
call check( nf90_create(FILE_NAME, NF90_CLOBBER, ncid) )
! 定义维数,返回一个对应的ID
call check( nf90_def_dim(ncid, "x", NX, x_dimid) )
call check( nf90_def_dim(ncid, "y", NY, y_dimid) )
! 把上面得到的ID写到一个存放ID的数组里,注意,在fortran中,数组是以列为主存放数据的
dimids = (/ y_dimid, x_dimid /)
! 定义变量,返回一个对应的ID
call check( nf90_def_var(ncid, "data", NF90_INT, dimids, varid) )
! 定义完成,关闭定义模式
call check( nf90_enddef(ncid) )
! 写入数据
call check( nf90_put_var(ncid, varid, data_out) )
! 关闭文件
call check( nf90_close(ncid) )
!提示写文件成功
print *, "*** SUCCESS writing example file simple_xy.nc! "
contains
subroutine check(status)
integer, intent ( in) :: status
if(status /= nf90_noerr) then
print *, trim(nf90_strerror(status))
stop 2
end if
end subroutine check
end program simple_xy_wr
在主目录下键入
gfortran cel-test.f90 -I/usr/local/netcdf/include -L/usr/local/netcdf/lib -lnetcdff -o test
( cel-test.f90为程序名, test为编译后生成的 )
编译通过!
然后运行test,键入
./test
结果无法运行,出现
Attempting netcdf-4 operation on netcdf-3 file
STOP 2
再次郁闷!
打开.zshrc, 即打开所用shell的配置文件
gedit .zshrc
在文件后面加上
export NETCDF=/usr/local/
export DYLD_LIBRARY_PATH=$NETCDF/lib:$DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH
export PATH=$NETCDF/bin:$PATH
重新启动shell,然后再编译,运行test,得到
0 12 24 36
*** SUCCESS writing example file simple_xy.nc!
大功告成!
备注:以下为各个步骤执行命令的解释:
$ ./configure
The configuration script will set up the Makefiles that will be used to build the NetCDF libraries and utilities. It will also set up the installation directory for the default location of /usr/local.
If you would like to install the libraries in another location, use this configure command:
$ ./configure --prefix=/your/desired/install/directory)
$ make----Make the libraries
When the configuration step completes successfully, you can build the libraries using ‘make’.
$ make check-----Testing NetCDF on Linux*
You can test your NetCDF libraries using ‘make check’.
$ make install------Installing NetCDF on Linux*
Install NetCDF libraries using ‘make install’.
This will install the NetCDF libraries, include files, and utilities in the default location of /usr/local or the location specified in the configuration step with the --prefix= option
References:
1: http://bbs.sciencenet.cn/home.php?mod=space&uid=237238&do=blog&id=547593
2: http://blog.sina.com.cn/s/blog_4b1d9e7b0100zg89.html
3: http://blog.sina.com.cn/s/articlelist_1260232315_3_1.html
转载本文请联系原作者获取授权,同时请注明本文来自丁鹏基科学网博客。 链接地址: https://blog.sciencenet.cn/blog-653020-549872.html
上一篇:
NetCDF学习纪要A 下一篇:
TH光谱处理