Fortran可变范围的困难 [英] Difficulty with fortran variable scope
问题描述
例如:
条目a( )
num_calls = 0
条目b()
num_calls = num_calls + 1
从条目b中,我得到了num_calls作为一些垃圾
COMMON / magic / num_calls
我没有使用过Fortran 90,所以我不知道它有什么额外的功能。它可能会保留为了向后兼容而命名的公共块,但也可能提供更好的一些。
我也欺骗了,并且使用了变量的隐式声明。完整的,我应该写:
INTEGER * 4 num_calls
COMMON / magic / num_calls
code>
I have intialized one variable in one of the fortran functions. I am using it in another function. But the value is not remains same. In other function call I am getting garbage value. How do i maintain the initialized value.
Ex:
entry a() num_calls=0 entry b() num_calls= num_calls + 1
From entry "b" i am getting num_calls as some garbage
In classic Fortran (Fortran 77 or earlier), you'd ensure that num_calls is defined in a common block - probably a named common block.
COMMON /magic/ num_calls
I've not used Fortran 90, so I don't know what extra facilities it has. It likely retains named common blocks for backwards compatibility, but likely provides something better too.
I cheated, too, and used an implicit declaration of the variable. In full, I should write:
INTEGER*4 num_calls
COMMON /magic/ num_calls
这篇关于Fortran可变范围的困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!