关闭多个文件 [英] Close multiple files
本文介绍了关闭多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要关闭并删除一些打开的文件,并将内容存储在某些变量中。为避免重复语法,我可以使用:
OPEN(UNIT = 27,FILE =C:/Abaqus_JOBS/w.txt (UNIT,status ='delete'),
$ p $所以我只需要指定CLOSE(UNIT,status ='delete')
一次?
谢谢 我个人不会使用结束语句,而是我将调用一个关闭正确文件的子例程:
子程序del_file(uFile,stat)
implicit none
integer uFile,stat
c如果单位未打开,stat将为非零
close(unit = uFile,status ='delete',iostat = stat)
结束子程序
你读到的语句就是:
如果(stat .ne。0)调用del_file(curUnit,stat),则
read(unit = curUnit,iostat = stat)
您仍然需要一些逻辑来避免从关闭文件读取。我会推荐一个数组来保存与输入文件相对应的所有单位。
I need to close and delete several files once they are open and the content stored in some variables. To avoid repeating the syntax can I use:
OPEN(UNIT = 27, FILE = "C:/Abaqus_JOBS/w.txt", status = "UNKNOWN") C READ(UNIT,END=1000) w 1000 CLOSE (UNIT, status='delete') ,
So that I only need to specify
CLOSE (UNIT, status='delete')
once?Thanks
解决方案I personally wouldn't use the end statement, instead I would call a subroutine that closes the correct file:
subroutine del_file(uFile, stat) implicit none integer uFile, stat c If the unit is not open, stat will be non-zero close(unit=uFile, status='delete', iostat=stat) end subroutine
You're read statement then would be:
read(unit=curUnit, iostat=stat) w if ( stat .ne. 0 ) call del_file(curUnit, stat)
You still would need some logic in there not to read from close files. I would recommend an array to hold all the units corresponding to the input files.
这篇关于关闭多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文