Fortran文件转化问题,从txt文件中读取数据转化为dat格式。运行提示出错。求大神搭救,眼睛都要爆炸了
代码:programghintegeri,j,k,irec,end_num,numreal,allocatable::ano(:,:)integer,allocatabl...
代码:
program gh
integer i,j,k,irec,end_num,num
real,allocatable::ano(:,:)
integer,allocatable::tim(:,:)
num=0
open (8,file="E:\study\grads\experiment2\air_nh_ano.txt",status='old')
read(8,*)
loop1:do
read(8,*,iostat=end_num)
if(end_num==0) then
num=num+1
else
exit loop1
end if
end do loop1
close(8)
allocate(ano(num,17),tim(num,2))
open (7,file='E:\study\grads\experiment2\air_nh_ano.txt',form='formatted',access='direct',status='old',recl=1)
rewind(7)
read(7,*)
do i=1,num
read(7,*) tim(i,:),ano(i,:)
enddo
close(7)
open (12,file="E:\study\grads\experiment2\air_nh_ano.dat",form='unformatted',access='direct',status='replace',recl=1)
irec=1
do i=1,num
do k=1,17
write(12,rec=irec) ano(i,k)
irec=irec+1
enddo
enddo
close(12)
end
txt文件部分内容:
year month 1000hPa 925hPa 850hPa 700hPa 600hPa 500hPa 400hPa 300hPa 250hPa 200hPa 150hPa 100hPa 70hPa 50hPa 30hPa 20hPa 10hPa
1948 1 -0.233 -0.187 -0.474 -0.667 -0.464 -0.386 -0.544 -0.666 -0.525 -0.729 -0.755 -0.944 -1.232 -0.256 0.586 0.239 1.081
1948 2 -0.096 0.029 -0.146 -0.612 -0.635 -0.684 -0.647 -0.601 -0.282 -0.484
错误提示:
forrtl: severe (59): list-directed I/O syntax error, unit 7, file E:\study\grads
\experiment2\air_nh_ano.txt
Image PC Routine Line Source
gj.exe 00409919 Unknown Unknown Unknown
Press any key to continue 展开
program gh
integer i,j,k,irec,end_num,num
real,allocatable::ano(:,:)
integer,allocatable::tim(:,:)
num=0
open (8,file="E:\study\grads\experiment2\air_nh_ano.txt",status='old')
read(8,*)
loop1:do
read(8,*,iostat=end_num)
if(end_num==0) then
num=num+1
else
exit loop1
end if
end do loop1
close(8)
allocate(ano(num,17),tim(num,2))
open (7,file='E:\study\grads\experiment2\air_nh_ano.txt',form='formatted',access='direct',status='old',recl=1)
rewind(7)
read(7,*)
do i=1,num
read(7,*) tim(i,:),ano(i,:)
enddo
close(7)
open (12,file="E:\study\grads\experiment2\air_nh_ano.dat",form='unformatted',access='direct',status='replace',recl=1)
irec=1
do i=1,num
do k=1,17
write(12,rec=irec) ano(i,k)
irec=irec+1
enddo
enddo
close(12)
end
txt文件部分内容:
year month 1000hPa 925hPa 850hPa 700hPa 600hPa 500hPa 400hPa 300hPa 250hPa 200hPa 150hPa 100hPa 70hPa 50hPa 30hPa 20hPa 10hPa
1948 1 -0.233 -0.187 -0.474 -0.667 -0.464 -0.386 -0.544 -0.666 -0.525 -0.729 -0.755 -0.944 -1.232 -0.256 0.586 0.239 1.081
1948 2 -0.096 0.029 -0.146 -0.612 -0.635 -0.684 -0.647 -0.601 -0.282 -0.484
错误提示:
forrtl: severe (59): list-directed I/O syntax error, unit 7, file E:\study\grads
\experiment2\air_nh_ano.txt
Image PC Routine Line Source
gj.exe 00409919 Unknown Unknown Unknown
Press any key to continue 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
应该是通道7的文件读入出了问题,可能是变量与文件不匹配。你可以仔细检查一下读文件的参数,我觉得那个recl=1怪怪的,为什么这么写?看不出来你的txt是什么样的格式。
追问
好像有点对,recl我把它删了,结果显示
forrtl: severe (37): inconsistent record length, unit 7, file E:\study\grads\exp
eriment2\air_nh_ano.txt
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |