由于项目需要需要用到fortran做一个简单的计算,恶补Fortran后计算部分程序写好了,就等着批量打开文件计算了
但是已经卡在这里两天了,希望有人伸出援助之手,
下面是代码
[Fortran] 纯文本查看 复制代码 program main
implicit none
integer::list,inputn !do 循环计数用的变量
character(len=19):: file(23) !存放文件名的字符型一维数组
character(len=19):: file1
integer::file_state,num
open(101,file = 'filelist.txt',status='old',action='read')
open(102,file = 'check.txt',status='old',action='readwrite')
do list = 1,23 !将filelist.txt中存储的文件名写入一维数组 file 中
read(101,*)file(list)
end do
write(102,*)file !检查filelist.txt中的数据是否读取
do inputn=1,23
file1=file(inputn)
num=1
call input(num,file1) !调用input打开名字为 file(i)的txt文档
num=num+1
end do
write(102,*)num !记录循环进行的次数********结果为2,只循环了一次TT
end program main
subroutine input(numb,filename)
implicit none
character(len=19)::filename
integer::file_state,numb
open(unit=numb,file =filename ,status='old',action='read',iostat=file_state)
open (unit=100,file="result.txt",status='old',action='readwrite')
if(file_state/=0)then !检查文件是否正常打开
write(100,*)"failed to open",filename
else
write(100,*)"successed to open",filename
end if
close(numb,status='keep')
close(100,status='keep')
return
end subroutine input
|