Warm tip: This article is reproduced from serverfault.com, please click

visual studio-了解Fortran中的不同类型

(visual studio - Understanding different types in Fortran)

发布于 2020-11-30 12:06:29

我正在阅读Fortran代码,遇到以下代码,无法理解它的作用。

m%AllOuts( BAzimuth(k) ) = m%BEMT_u(indx)%psi(k)*R2D

我知道这里的%就像管道指示器一样,​​以类似于Python中的字典的方式访问值。我有一本字典比方说,和第一个关键是AllOuts,但到底是什么东西括号内是什么意思?它像另一本字典吗?

Questioner
thisismihir
Viewed
11
chw21 2020-11-30 20:22:21

百分号不表示字典。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几乎可以肯定是其他类型的数组,你还需要查找该数组。