在Fortran中按名称获取文件单元,反之亦然 [英] Get file unit by name and vice versa in Fortran

查看:62
本文介绍了在Fortran中按名称获取文件单元,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Fortran 90中是否可以通过名称获取文件单元,并通过单位编号获取文件名?我知道这会很昂贵,但是创建完文件后,我希望在子例程中重新访问很多文件名.

Is there a way in Fortran 90 to get a file unit by name and file name by unit number? I know it will be expensive, but I have a lot of file names that I want to be able to re-access in a subroutine after they've been created..

推荐答案

类似

inquire(unit=12, opened=openedq, file=name_of_file)

会将连接到单元12的文件的名称返回给字符变量name_of_file.如果没有文件连接到本机,则opened将返回false,否则返回true.该命令也接受各种其他可选参数.

will return the name of the file connected to unit 12 to the character variable name_of_file. If there is no file connected to the unit opened will return false, otherwise true. The command takes a variety of other optional arguments too.

要获取已附加的文件的单元号,请使用前面的变体,例如

To get the unit number of a file which is already attached use a variation on the preceding, like this

inquire(file='my_favourite_file.nuts', number=unknown_unit_number, opened=openedq)

参考您的编译器文档应解释inquire支持的所有变体.

Reference to your compiler documentation should explain all the variations that inquire supports.

这篇关于在Fortran中按名称获取文件单元,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆