爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7642|回复: 2

ncl读取二进制数据做变量替换(2)

[复制链接]
发表于 2015-10-5 09:44:18 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 东风急流 于 2015-10-5 19:18 编辑

针对上一个帖子给我的提示,我对我的fortran文件和ncl文件做出了修改,用加粗标注了,但还是有问题,说数组维数超出,希望大家能再帮我看看啊,谢谢~
想用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: the size impliede by the dimension array and record number is greater than record size of the file
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 17 in file wrf_var_replace.ncl



再附上我写这个二进制文件的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)

我用grads检查过我的ana.dat,写300*400的ctl画图没问题,说明是120000个数据啊,怎么到了ncl里面就不是的呢?求到底改写多少啊。。。。。




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


密码修改失败请联系微信:mofangbao
发表于 2015-10-18 15:51:31 | 显示全部楼层
ncl和fortran不一样,和C一样,数组序号的起点是0。你在rec的位置写1意思就是从第二个300*400开始读,如果你只有1×300×400个数据就超了。
ncl维度是n,序号是从0开始数到n-1,所以nx和ny改成300和400,下方s的括号里i,j改成i-1,j-1,不然序号超出数组大小也会报错。还有,如果你想替换起始时刻的第1笔资料,1要改成0。
还有(/nx,ny/),我不确定你是不是搞错了x和y的维度顺序,y方向应该在x方向的左边。这样读进去虽然不会报错但是位置整个就倒了!
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2015-10-18 18:56:51 | 显示全部楼层
谢谢。这个问题我后面也搞定啦,还发了个帖子,但还有一个问题没有理解,你能帮看看嘛?http://bbs.06climate.com/forum.p ... mp;page=1#pid534385
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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