fortran open语句的问题
用下面这段fortran程序读写2010年最高气温时,open语句为open(11,file='D:\fortran\keti\usedata\llht0.txt',fo...
用下面这段fortran程序读写2010年最高气温时,open语句为
open(11,file='D:\fortran\keti\usedata\llht0.txt',form='formatted',status='replace')时,存储的数据结构虽然不是很正确,但至少数据是对的,
用open(12,file='D:\fortran\keti\usedata\llht10.dat',form='unformatted',status='replace')这一语句时,就会出错,是为什么?
program keti01
implicit none
integer,parameter::l=31,m=30,n=28
integer::Jan(l),Feb(n),Mar(l),Apr(m),May(l),June(m),July(l),&
Aug(l),Sept(m),Oct(l),Nov(m),Dec(l)
integer::hightempers(12)
integer::i,j,k
Jan=[165,180,195,210,196,167,195,184,195,184,100,51,42,156,198,161,177,202,218,215,&
224,214,205,209,192,143,169,208,194,199,199]
Feb=[207,217,213,215,208,204,231,225,233,221,227,215,219,223,221,217,177,34,146,205,&
205,250,228,224,218,230,246,240]
Mar=[249,253,243,234,242,233,251,256,105,120,243,263,257,238,227,207,235,259,259,272,&
273,277,263,267,140,209,170,186,185,217,229]
Apr=[200,215,249,271,271,277,274,272,285,280,289,299,276,290,254,256,254,276,278,248,&
272,202,142,213,241,166,223,233,254,265]
May=[232,266,269,302,304,327,312,300,300,272,243,286,295,303,306,306,305,290,309,286,&
297,316,296,282,236,224,268,210,241,267,271]
June=[276,201,162,169,193,235,276,282,262,247,261,283,278,265,270,261,272,286,297,267,&
196,235,253,256,267,270,289,261,216,212]
July=[248,272,285,279,268,265,261,256,258,266,256,283,264,271,277,284,280,242,226,243,&
256,223,247,253,210,253,275,249,215,264,268]
Aug=[255,243,265,273,263,275,239,270,285,286,286,275,280,286,273,241,235,252,256,253,&
259,267,259,256,261,238,198,247,257,264,272]
Sept=[229,199,214,244,278,282,290,246,283,239,227,236,244,247,216,243,270,275,291,291,&
297,228,182,235,256,193,227,236,207,219]
Oct=[234,183,164,187,225,231,190,158,180,251,243,254,250,250,150,211,218,177,166,205,220,&
224,237,211,181,137,126,91,103,199,205]
Nov=[219,155,112,129,187,206,189,183,183,192,162,148,177,174,141,128,188,201,138,193,203,&
170,185,164,117,106,135,124,165,120]
Dec=[185,174,164,197,212,177,114,86,166,199,162,174,191,192,182,100,146,185,193,184,161,&
163,170,172,127,68,145,167,178,124,177]
hightempers=[Jan(31),Feb(28),Mar(31),Apr(30),May(31),June(30),July(31),Aug(31),Sept(30),Oct(31),Nov(30),Dec(31)]
open(12,file='D:\fortran\keti\usedata\llht10.dat',form='unformatted',status='replace')
write(12,*)"2010年最高气温"
do i=1,31
write(12,*)Jan(i),Mar(i),May(i),July(i),Aug(i),Oct(i),Dec(i)
end do
do j=1,30
write(12,*) Apr(j),June(j),Sept(j),Nov(j)
end do
do k=1,28
write(12,*) Feb(k)
end do
close(12)
end 展开
open(11,file='D:\fortran\keti\usedata\llht0.txt',form='formatted',status='replace')时,存储的数据结构虽然不是很正确,但至少数据是对的,
用open(12,file='D:\fortran\keti\usedata\llht10.dat',form='unformatted',status='replace')这一语句时,就会出错,是为什么?
program keti01
implicit none
integer,parameter::l=31,m=30,n=28
integer::Jan(l),Feb(n),Mar(l),Apr(m),May(l),June(m),July(l),&
Aug(l),Sept(m),Oct(l),Nov(m),Dec(l)
integer::hightempers(12)
integer::i,j,k
Jan=[165,180,195,210,196,167,195,184,195,184,100,51,42,156,198,161,177,202,218,215,&
224,214,205,209,192,143,169,208,194,199,199]
Feb=[207,217,213,215,208,204,231,225,233,221,227,215,219,223,221,217,177,34,146,205,&
205,250,228,224,218,230,246,240]
Mar=[249,253,243,234,242,233,251,256,105,120,243,263,257,238,227,207,235,259,259,272,&
273,277,263,267,140,209,170,186,185,217,229]
Apr=[200,215,249,271,271,277,274,272,285,280,289,299,276,290,254,256,254,276,278,248,&
272,202,142,213,241,166,223,233,254,265]
May=[232,266,269,302,304,327,312,300,300,272,243,286,295,303,306,306,305,290,309,286,&
297,316,296,282,236,224,268,210,241,267,271]
June=[276,201,162,169,193,235,276,282,262,247,261,283,278,265,270,261,272,286,297,267,&
196,235,253,256,267,270,289,261,216,212]
July=[248,272,285,279,268,265,261,256,258,266,256,283,264,271,277,284,280,242,226,243,&
256,223,247,253,210,253,275,249,215,264,268]
Aug=[255,243,265,273,263,275,239,270,285,286,286,275,280,286,273,241,235,252,256,253,&
259,267,259,256,261,238,198,247,257,264,272]
Sept=[229,199,214,244,278,282,290,246,283,239,227,236,244,247,216,243,270,275,291,291,&
297,228,182,235,256,193,227,236,207,219]
Oct=[234,183,164,187,225,231,190,158,180,251,243,254,250,250,150,211,218,177,166,205,220,&
224,237,211,181,137,126,91,103,199,205]
Nov=[219,155,112,129,187,206,189,183,183,192,162,148,177,174,141,128,188,201,138,193,203,&
170,185,164,117,106,135,124,165,120]
Dec=[185,174,164,197,212,177,114,86,166,199,162,174,191,192,182,100,146,185,193,184,161,&
163,170,172,127,68,145,167,178,124,177]
hightempers=[Jan(31),Feb(28),Mar(31),Apr(30),May(31),June(30),July(31),Aug(31),Sept(30),Oct(31),Nov(30),Dec(31)]
open(12,file='D:\fortran\keti\usedata\llht10.dat',form='unformatted',status='replace')
write(12,*)"2010年最高气温"
do i=1,31
write(12,*)Jan(i),Mar(i),May(i),July(i),Aug(i),Oct(i),Dec(i)
end do
do j=1,30
write(12,*) Apr(j),June(j),Sept(j),Nov(j)
end do
do k=1,28
write(12,*) Feb(k)
end do
close(12)
end 展开
1个回答
展开全部
① unformatted是无格式化,就是按二进制尘哗写文件,后面的write语句,不应该有格式化字符串,应该写成:
write(12)"2010年最高气温" ! write(12,*)"2010年最高气温" <---是错误的。
② 看你的代码,用formatted的格式派没行,即文本方式就可以,比较直观。否则如上面的字符串,存成二进制,将来出来起来,不见得方便~
③ 记得一起有个求助的问题,是关于若干文件,读取数值就平均的,不察毕知道是否是你发的? 转眼就看不到了,话说百度是作搜索的,结果知道的问题搜索,功能还不如普通论坛来到方便,sigh~
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询