Fortran Coder

查看: 5872|回复: 1
打印 上一主题 下一主题

[绘图界面库] 读取nc文件进行计算

[复制链接]

25

帖子

8

主题

0

精华

熟手

F 币
164 元
贡献
104 点
跳转到指定楼层
楼主
发表于 2017-6-16 14:53:58 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
nc文件如下:

利用以下程序对该nc文件进行读取,并使用 (此处s即为nc文件里的silt)
[Fortran] 纯文本查看 复制代码
program readsilt
      implicit none
      external read_silt_nc,handle_err


      !integer,parameter::lon_2=43200,lat_2=16800,depth_2=4
      real SILT_2
      character*299 silt_file
      integer status
      real E
      call read_silt_nc(SILT_2,silt_file)
      call handle_err(status)
      E=1.01*SILT_2**(3.0/5.0)
      write(*,*) E
      end program

      !number 1
      subroutine read_silt_nc(SILT_2,silt_file)
      implicit none

      integer ierr,ncid,varid,len_file
      integer,parameter::lon=43200,lat=16800,depth=4
      real lon_2(lon)
      real lat_2(lat)
      real depth_2(depth)
      real SILT_2(depth,lat,lon)
      !real E
      character*299 silt_file
      include 'netcdf.inc'

      silt_file="/home/iga_qtong/fortran_xcao/gae_c/ap-42/SILT1.nc"
      len_file=len_trim(silt_file)
      ierr=nf_open(trim(silt_file),nf_write,ncid)

      ierr=nf_inq_varid(ncid,'lon',varid)
      ierr=nf_get_var_real(ncid,varid,lon_2)

      ierr=nf_inq_varid(ncid,'lat',varid)
      ierr=nf_get_var_real(ncid,varid,lat_2)


      ierr=nf_inq_varid(ncid,'depth',varid)
      ierr=nf_get_var_real(ncid,varid,depth_2)

      ierr=nf_inq_varid(ncid,'SILT',varid)
      ierr=nf_get_var_real(ncid,varid,SILT_2)
      write(*,*) 'ierr'
      write(*,*) SILT_2(1,31.56247,-179.9958)


      end subroutine read_silt_nc

      subroutine handle_err(status)
      integer status
      if (status .NE. nf_noerr) then
           write(*,*) nf_strerror(status)
           stop 'stopped'
      end if
      end subroutine handle_err
      
遇到以下错误:Bus error (core dumped)请问,是不是我对读取nc文件的理解有误?拜托大家。


分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

47

帖子

3

主题

0

精华

大师

F 币
1634 元
贡献
119 点

规矩勋章

沙发
发表于 2017-7-16 10:15:59 | 只看该作者
三个建议,

1,加输出试试,知道在哪儿出问题
2,nf_get_var_real 应该是读取单real 的,应该用 nf_get_vara_real ,多出来的a是数组array的意思
3,主程序和subroutine里数据定义不同诶,尤其SILT_2,真的能传进去?????
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-4-19 15:55

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表