回 帖 发 新 帖 刷新版面

主题:从dat到txt的读取,能输出到屏幕上,但是输出到文件就错了,求大侠指点

我要把jan.tmp.dat文件用fotran转成txt文件,能输出到屏幕上,但是要输出到txt文件老出错。请高手指点,感谢!

 

 dat文件的ctl说明文件

dset d:/lw/dat/tmp/jan-dec/jan.tmp.dat
 title CRU TS 3.10 Mean Temperature
 undef  9.96921e+36
 xdef 720 linear -179.75 0.5
 ydef 360 linear -89.75 0.5
 zdef 1 linear 0 1
 tdef 109 linear 00Z16Jan1901 12mon
 vars 1
 tmp 0 99 tmp mon
 endvars

 

从dat转txt的fotran程序

program tmptxt
implicit none
real,dimension(720,360,109):: tmp
integer:: irec1,i,j,t


open(1,file='d:/lw/dat/jan.tmp.dat',form='binary',access='direct',recl=720*360)
open(2,file='d:/lw/dat/jan.tmp.txt',form='formatted',status='unknown')

irec1=0
do t=1,109
irec1=irec1+1
 read (1,rec=irec1) ((tmp(i,j,t),i=1,720),j=1,360)
 write(2,rec=irec1) ((tmp(i,j,t),i=1,720),j=1,360)
end do

close(1)
close(2)

end

 

编译出错:
forrtl: severe (66): output statement overflows record, unit 2, file d:\lw\dat\jan.tmp.txt
Image              PC        Routine            Line        Source
tmp.exe            00408A69  Unknown               Unknown  Unknown

Incrementally linked image--PC correlation disabled.
Press any key to continue

回复列表 (共6个回复)

沙发

你的 1 号文件是二进制,直接读取。2 号文件是文本文件,顺序读取。

2 号文件是 formatted 格式,文本格式,默认是顺序读取方式。所以不能用
 write(2,rec=irec1) ((tmp(i,j,t),i=1,720),j=1,360)

Rec,只能用于直接读取方式。而且你没有为 2 号文件指定 RecL,没有记录长度,如何指定第几个记录呢?

板凳


先谢谢您~!2号文件是txt,不需要设置recl吧。那要写进去2号文件,是不是
write(2,*)就可以了?

3 楼


先谢谢您~!2号文件是txt,不需要设置recl吧。那要写进去2号文件,是不是 write(2,*)就可以了?

4 楼

[quote]你的 1 号文件是二进制,直接读取。2 号文件是文本文件,顺序读取。

2 号文件是 formatted 格式,文本格式,默认是顺序读取方式。所以不能用
write(2,rec=irec1) ((tmp(i,j,t),i=1,720),j=1,360)

Rec,只能用于直接读取方式。而且你没有为 2 号文件指定 RecL,没有记录长度,如何指定第几个记录呢?

[/quote]
先谢谢您~!2号文件是txt,不需要设置recl吧。那要写进去2号文件,是不是 write(2,*)就可以了?

5 楼

是的

6 楼


十分感谢您!!![em2]

我来回复

您尚未登录,请登录后再回复。点此登录或注册