0

Fortran 在公共块中有公共块吗?就像结构中有结构一样。例如

integer int 1, int2
common/Common1/int1, int2
float f1, f2
common/Common2/f1, f2
save/Common2/, /Common1/

上面的代码是不是表示common2,in within common1?

4

1 回答 1

0

不,您编写的代码无效。公共块只是一个命名的内存区域。

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

Note that the percent sign (%) is similar to the dot (.) operator in C. It allows you to access the data contained in a derived type.

于 2011-10-27T00:35:04.603 回答