0
Fortran是否在公共块中具有常用块?就像结构中有结构一样。例如。Fortran中的常见块
integer int 1, int2
common/Common1/int1, int2
float f1, f2
common/Common2/f1, f2
save/Common2/, /Common1/
以上代码是否表示common2,在common1中?
Fortran是否在公共块中具有常用块?就像结构中有结构一样。例如。Fortran中的常见块
integer int 1, int2
common/Common1/int1, int2
float f1, f2
common/Common2/f1, f2
save/Common2/, /Common1/
以上代码是否表示common2,在common1中?
不,你写的代码是无效的。一个常见的块只是一个命名的内存区域。
Fortran具有与C结构非常相似的“派生数据类型”。如果Fortran派生类型声明如下:
type float_struct
real :: f1, f2
end type
现在你可以声明包含此类型的变量另一个派生类型:
type my_struct
integer :: int1, int2
type (float_struct) :: my_float_struct
end type
注意,这些都是一个类型的声明,而不是实例该类型的变量。最好将声明放在一个模块中,允许你在子程序,函数或程序中访问它们。例如,假设上述声明放置在名为“my_structs_mod”的模块中。然后你可以使用它们像这样:
subroutine sub()
use my_structs_mod
type (my_struct) :: ms
ms%int1 = 42
...
end subroutine
注意百分号(%)是相似点运营商C.它允许您访问包含在一个派生类型的数据()。