我在读Fortran代码时,遇到了以下代码,无法理解它的作用。
m%AllOuts( BAzimuth(k) ) = m%BEMT_u(indx)%psi(k)*R2D
我知道这里的%就像一个管道指示器,以类似于Python中的字典的方式访问值。我有一本字典m,比方说,第一个关键字是AllOuts,但括号内的任何内容是什么意思?它像另一本字典吗?
百分号并不表示字典。Fortran中没有本机词典。
百分号表示一个类型的组成部分。例如:
! Declare a type
type :: rectangle
integer :: x, y
character(len=8) :: color
end type rectangle
! Declare a variable of this type
type(rectangle) :: my_rect
! Use the type
my_rect % x = 4
my_rect % y = 3
my_rect % color = 'red'
print *, "Area: ", my_rect % x * my_rect % y
括号可以指示数组的索引,也可以指示调用的参数。
例如:
integer, dimension(10) :: a
a(8) = 16 ! write the number 16 to the 8th element of array a
或者,作为一种产品:
print *, my_pow(2, 3)
...
contains
function my_pow(a, b)
integer, intent(in) :: a, b
my_pow = a ** b
end function my_pow
为了弄清楚m
是什么,您需要查看m
的声明,它类似于
type(sometype) :: m
或
class(sometype) :: m
然后你需要找到类型声明,它可能类似于
type :: sometype
! component declarations in here
end type
现在,其中一个组件BEMT_u
几乎可以肯定是一个不同类型的数组,您还需要查找它。