运行完出现fort.28文件
说明:我是想将年数据,按1-12月提取出来,写入12个txt中。运行结果是:8月的数据和原始年数据一模一样。其他月份看上去正常。接着我将数据写入month8.txt的命令注释掉,运存出来,month8.txt依旧和原始数据文件一样。再接着,我把open()语句中month8.txt的文件通道号改成了33(原先是28),在运行时,month8.txt这次是没有数据的,但是多出来一个fort.28文件,大小和原数据文件一样大。因为原始文件比较大,传不了,我上传一个小一点的版本。program fkk
implicit none
character(len=512)::cRead
! character(len=20)::filename,DYfilename
character(len=20)::wwlln_date,wwlln_time
real::lat,lon
character(len=5)::timingerror
character(len=2)::station
integer::status1=0
integer::month,month1
integer::i,j
open(11,file='2014.txt',status='old',form='formatted')
open(12,file='record.txt',status='replace')
OPEN(21,file='month1.txt',status='replace',form='formatted')
OPEN(22,file='month2.txt',status='replace',form='formatted')
OPEN(23,file='month3.txt',status='replace',form='formatted')
OPEN(24,file='month4.txt',status='replace',form='formatted')
OPEN(25,file='month5.txt',status='replace',form='formatted')
OPEN(26,file='month6.txt',status='replace',form='formatted')
OPEN(27,file='month7.txt',status='replace',form='formatted')
OPEN(33,file='month8.txt',status='replace',form='formatted')
OPEN(29,file='month9.txt',status='replace',form='formatted')
OPEN(30,file='month10.txt',status='replace',form='formatted')
OPEN(31,file='month11.txt',status='replace',form='formatted')
OPEN(32,file='month12.txt',status='replace',form='formatted')
do while(.true.)
READ(11,"(A512)",iostat=status1)cRead
if (status1/=0) exit
CALL parserRead(cRead)
! write(*,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
! READ(wwlln_date(1:4),"(I4)")year
! write(*,*)year
write(*,*) LEN_TRIM(wwlln_date)
if(LEN_TRIM(wwlln_date)/=10) then !这里是因为我的文件中大部分日期格式例如:2014/08/12,但有的月份是2014/8/10或者2014/8/1
CALL specialread(wwlln_date)
write(12,*)month1
else
READ(wwlln_date(6:7),"(I2)")month
write(*,*)wwlln_date,month
end if
if(month==1) write(21,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==2) write(22,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==3) write(23,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==4) write(24,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==5) write(25,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==6) write(26,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==7) write(27,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==8) write(33,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==9) write(29,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==10) write(30,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==11) write(31,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
if(month==12) write(32,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
do i=21,32,1
j=i-20
if(month1==j) write(i,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
end do
end do
CLOSE(11)
CLOSE(12)
contains
!调用子程序
subroutine parserRead(c)
character(len=*)::c
integer::j
do j=1,LEN_TRIM(c)
if (c(j:j)=="/") c(j:j)="|"
end do
READ(c,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
do j=1,LEN_TRIM(wwlln_date)
if (wwlln_date(j:j)=="|") wwlln_date(j:j)="/"
end do
end subroutine parserRead
subroutine specialread(d)
character(LEN=*)::d
READ(d(6:6),"(I1)")month1
end subroutine specialread
end program
另外改完文件号之后(month8.txt的,原先是28号,改成了33),运行结果month8.txt大小为0kb,就是没有数据写入。也就是说if(month==8) write(33,*)wwlln_date,wwlln_time,lat,lon,timingerror,station,这条命令无作用,是个摆设。
在线等,谢谢! 我笨的离谱哈哈哈....fort.28是因为我把文件号改了,但输出的还是28号文件。
另外,我尝试了把下面语句
do i=21,32,1
j=i-20
if(month1==j) write(i,*)wwlln_date,wwlln_time,lat,lon,timingerror,station
end do
这个语句放到else上边,然后将 if(month==1) write(21,*)wwlln_date,wwlln_time,lat,lon,timingerror,station....这些if都放到end if 前面,就没问题了。这个也可以用do 循环来写,一样的。
还有要加close,close也可以用do来写。我本来写了,后来为了测出到底哪里出问题,然后删了....
最后还是想请问下,为什么原先这样写,month8.txt会是原数据文件呢?
页:
[1]