在 fortran 中获取免费单元号 [英] getting free unit number in fortran

查看:15
本文介绍了在 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() ?

推荐答案

在 fortran 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屋!

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