在fortran中获得免费单位号码 [英] getting free unit number in fortran
问题描述
我需要开发一个库来打开一个文件并解析这些内容。
由于fortran IO风格,单位编号必须由我决定,但我无法知道客户端代码中打开了哪些其他单位。是否有像这样的标准函数?give_me_any_unit_number_that_is_free()
?
I need to develop a library that opens a file and parses the stuff.
The unit number, due to fortran IO style, must be decided by me, but I can't know what other units are open in the client code. Is there a standard function like give_me_any_unit_number_that_is_free()
?
推荐答案
2008年,有一个newunit子句打开你可以使用
In fortran 2008, there's a newunit clause to open that you can use
integer :: myunit
..
open(newunit=myunit,file='file.dat')
...
close(myunit)
但这足够新,并不是所有的编译器都支持它。如果你还没有,你可以嘲笑自己;在 fortran wiki 上有一个很好的例子。
but that's new enough that not all compilers support it yet. If yours doesn't yet, you can mock one up yourself; there's a good example on the fortran wiki.
这篇关于在fortran中获得免费单位号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!