爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11734|回复: 7

[其他] (已解决)求助ncl读取二进制数据做变量替换

[复制链接]

新浪微博达人勋

发表于 2015-9-22 11:05:19 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 东风急流 于 2016-11-24 09:53 编辑

我想用ncl读取一个二进制数组,300*400的实型数组(soilana.dat),然后去替换wrfinput里面的土壤湿度第一个时间第一层的值SMOIS(1,1,i, j)(是300*400的)

我的ncl脚本是这么写的:
;======================================================
; This script is used to read a binary file and write the var to the netCDF file.
;======================================================
begin
    nx=299
    ny=399
    a=addfile("./wrfinput.nc","w")
    soil=new((/nx,ny/),"float")
    soil=fbindirread("/home/lw/soil/soilana.dat",1,(/nx,ny/),"float")
;-----------------------
; change the field
;-----------------------
   s=a->SMOIS
   do i=1,300,1
     do j=1,400,1
      s(1,1,i,j)=soil(i-1,j-1)
     end do
   end do
;-----------------------
;write the field
;-----------------------
   a->SMOIS=s
end

运行ncl时总提示我数组设置的太小,不够读取数据。具体提示如下:
warning:fbinrecread: size specified is less than record size, some data will not be read
fatal:Subscript out of range, error in subscript #0
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 17 in file wrf_var_replace.ncl


求助是什么原因呢?我把大小改成nx=400,ny=300也还是同样的错误的

再附上我写这个二进制文件的fortran程序:program rw
implicit none
character(len=30):: filename10="2012060306-ass_vsm_result.dat"
integer,parameter::m=400,n=300
real:: temp2(m,n),temp3(m,n)
integer:: error,i,j

!big endian表示数据在大型机上生成,现在不在这类机器上使用
open(10,file=filename10,access="direct",form="unformatted",recl=m*n,convert="big_endian",status="old")
open(30,file="soilsim.dat",access="direct",form="unformatted",recl=m*n)
open(40,file="soilana.dat",access="direct",form="unformatted",recl=m*n)

read(10,rec=2,iostat=error) ((temp2(i,j),i=1,m),j=1,n)
read(10,rec=3,iostat=error) ((temp3(i,j),i=1,m),j=1,n)
!用作测试是否正常读完数据
print*,error
write(30,rec=1) ((temp2(i,j),i=1,m),j=1,n)
write(40,rec=1) ((temp3(i,j),i=1,m),j=1,n)

!养成关闭文件的好习惯
close(10)




密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-9-22 14:58:13 | 显示全部楼层
初步猜测是写数据文件的For代码有问题,有两点疑问:1.sequential方式输出好像不应该也不需要用rec来指定record的位置;2.如果是在linux下编译上述程序,可能要注意recl值的设定。仅供参考
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-10-4 10:07:38 | 显示全部楼层
每笑苍穹 发表于 2015-9-22 14:58
初步猜测是写数据文件的For代码有问题,有两点疑问:1.sequential方式输出好像不应该也不需要用rec来指定re ...

不好意思,才看到回复。我修改了fortran程序,还是同样的错误,fortran写的数据没有问题,我用grads画图对比过了。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-10-5 09:35:37 | 显示全部楼层
对ncl 进行了一定的修改,现在的提示是:the size implied by the dimension array and record number is greater than the sizae of the file.可我的数据soilana.dat我用grads 检查过,是300*400的,写ctll画图没有w问题的啊
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-10-10 22:06:40 | 显示全部楼层
东风急流 发表于 2015-10-5 09:35
对ncl 进行了一定的修改,现在的提示是:the size implied by the dimension array and record number is gr ...

程序改好了?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2015-10-12 08:18:28 | 显示全部楼层

改好了,谢谢版主~但是不太理解为什么要让我修改维数名称,提示是:lhs has dimension name and rhs doesn’t,deleting name of lhs dimension number(0),use"(/../)"if this is not desired outcome。我不知道怎么把左边的维数名称删掉,就把右边的维数名称加上了,而且得写成和左边第一、二维数一样的名称才能通过(本来我想写的经纬度)。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-2-24 14:05:25 | 显示全部楼层
我也遇到相同的问题,请问楼主是怎么解决的?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2016-2-26 16:13:45 | 显示全部楼层
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

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