我正在阅读Fortran代码,遇到以下代码,无法理解它的作用。
m%AllOuts( BAzimuth(k) ) = m%BEMT_u(indx)%psi(k)*R2D
我知道这里的%就像管道指示器一样,以类似于Python中的字典的方式访问值。我有一本字典米比方说,和第一个关键是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
几乎可以肯定是其他类型的数组,你还需要查找该数组。
可能必须寻找其他类型的事物才能确定是什么
m
。m
可以是隐式类型,也可以是几种构造之一中的选择器。如果它不是本地实体,则可能来自相距较远的主机或模块。这对@ chw21有很大帮助。谢谢你 我寻找了m,
TYPE(AD_MiscVarType), INTENT(IN ) :: m ! misc variables
但遇到了以下内容, 但这是子例程中的内容。现在,当我寻找AD_MiscVarType时,遇到了这个问题,TYPE, PUBLIC :: AD_MiscVarType:: AD_MiscVarType
REAL(ReKi) , DIMENSION(:), ALLOCATABLE :: AllOuts
我不确定哪种类型的AD_MiscVarType被分配了两次。@francescalus @ chw21
m%AllOuts( RtAeroPwr ) = m%BEMT_u(indx)%omega * m%AllOuts( RtAeroMxh )
我怎么能打印的价值m%BEMT_u(indx)%omega
和m%AllOuts( RtAeroMxh )
他们很可能是数组。如何打印?我尝试了这个,print *, m%AllOuts( RtAeroMxh ), m%AllOuts, m%BEMT_u
几乎没有错误。我应该分享错误吗?