问题描述
我对打开文件中使用'iostat'参数感到困惑.就像说的那样,当打开命令成功时,"iostat"的值为0.
I am confused by the use of the 'iostat' argument in open file. As it's said, when the open command succeeds, the 'iostat' gets a value of 0.
open(unit=99, file='vel_zcor22.txt', status='old', iostat=ierr, err=100)
100 if(ierr .ne. 0) then
print*, 'open file error'
endif
print*, ierr
为什么不使用"iostat"而不是"ierr"来表示状态.据我对赋值运算符的理解,"ierr"将其值传递给"iostat".那么"ierr"在此过程中扮演什么角色?
Why is not the 'iostat' used to tell the state rather than the 'ierr'. As my understanding of assignment operator, the 'ierr' transfers its value to 'iostat'. So what is the role of the 'ierr' playing in this procedure?
推荐答案
在 open
语句中, iostat = ierr
使用的是 iostat =
作为说明符.这不是赋值,它将 ierr
的值传输到变量 iostat
.
In an open
statement, the iostat=ierr
is using iostat=
as a specifier. It is not an assignment, transferring the value of ierr
to the variable iostat
.
就像在子例程或函数引用中使用关键字时(其中 call sub(a = x)
将实际参数 x
与伪参数 a相关联)
),发生的事情更多:
Much like when using keywords in a subroutine or function reference (where call sub(a=x)
associates the actual argument x
with the dummy argument a
), what is happening is more:
所以,当" iostat
的值为0"时,真正发生的是定义了变量 ierr
.
So, when "iostat
gets a value of 0" what really happens is the variable ierr
becomes defined.
您可以改用任何变量名来代替 ierr
,通常通常使用 iostat
:
You could instead use any variable name instead of ierr
, and typically one often uses iostat
:
open(..., iostat=iostat, ...)
同样,您看到的其他部分也不是分配.那就是:
Equally, the other parts you see aren't assignments either. That is:
open(unit=99, file='vel_zcor22.txt', status='old', iostat=ierr, err=100)
可能看起来像是作业,但仍在说:
may look like assignments, but it's still saying:
它没有将变量 unit
设置为99,依此类推.
It isn't setting a variable unit
to 99, etc.
这篇关于"iostat"的含义是什么?公开声明中的论点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!