我正在编写一个文件读取库,需要检查文件是否已打开,以便我可以跳过打开语句并直接进行读取。
在 Fortran 中如何实现这一点?
当人们想了解与外部文件的连接时,可以使用inquire
陈述。有两种形式:按卷查询;按单位查询。
tom's answer shows inquire by unit. This tests whether unit 3 is connected to any file. One could then go on to ask the name of the connected file with the name=
and named=
specifiers.1
按文件查询允许询问:给定文件是否连接到any如果是的话,到哪个单位?
inquire(file=filename, number=unit)
如果文件未连接则unit
将-1
, 否则unit
将对应于连接到文件的单元。
或者,取决于您想用open
的说法,不一定是错误的open
与已连接的文件。
[1] The variable in the name=
specifier will become undefined if the file has no name. Testing this variable against the desired filename when it is undefined is bad. The named=
specifier allows detection of this case.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)