[Fortran] 纯文本查看 复制代码
program test
integer i
real s, a
character(20):: filename='降雨量-1234.dat'
s = 0.0
do i=1900, 1999
!内部文件读写,将filename 第8-11 字符换为相应年份
write(filename(8:11),'(i4)') i
open(11,file=filename)
read(11,*) a
close(11)
s = s + a
end do
end program
[Fortran] 纯文本查看 复制代码
program test
integer i
real s, a
character(512):: filename
!文件1.dat 中存储工作目录下所有txt 文件列表
call system ('dir *.txt /b > 1.dat' )
s = 0.0
open(10,file='1.dat')
do
!读取文件名
read(10,'(a)',iostat=i) filename
if(i/=0) exit
open(11,file=filename)
read(11,*) a
close(11)
s = s + a
end do
close(10,status='delete') !关闭并删除文件1.dat
end program