初学者阅读fortran代码,但无法理解这一点

Ogi*_*car 2 parameters fortran function

我试图了解用于实习的Fortran代码,但我是一名C ++程序员,但我被困在这段代码中。有人可以启发我吗?

real(kind=kind_real), pointer :: c(:,:,:)  (I think this created a pointer to a matrix )

self%c => self%gfld3d(:,:,ioff+1:) (this is in the constructor of the class)

flds%c(ibx,iby,2:flds%nc*flds%nl:2) (this is a function that calls the c variable of the class but I don't understand how the parameters work and what does the colon operator do as a a parameter)

Run Code Online (Sandbox Code Playgroud)

rto*_*ala 6

  • real(kind=kind_real), pointer :: c(:,:,:)

正如您已经写过的,此行声明了一个指针变量,该变量c指向一个类型为3的real数字数组kind_real。这里的冒号表示每个尺寸的大小未知。假设它在一个type块内,c是该类型的成员。注意,在Fortran中,()它既用于数组下标又用于函数调用。

  • self%c => self%gfld3d(:,:,ioff+1:)

在构造函数中,为指针分配了一个目标,该目标是3维数组的一部分,该数组self%gfld3d也是同一类型的成员。Fortran中的指针包含有关它们指向的数组切片的尺寸的信息。在这种情况下,前两个冒号表示数组切片跨越目标数组的整个前两个维度。ioff+1:表示在第三维中,指针目标包括self%gfld3d从给定值开始的所有值ioff+1。这是一般切片符号的简化情况,其中a(start:end:step)表示数组的切片a,从index开始start,以结束end,以的步长step

  • flds%c(ibx,iby,2:flds%nc*flds%nl:2)

基于上述情况,这不是函数调用。它是一个表达式,计算结果为一维非连续数组切片。从flds%cindex 的目标开始,在索引ibxiby前两个维度中,它包含第三个维度的第二个值,从索引2开始,在处停止flds%nc * flds%nl。输出数组中的前两个维被省略,因为这些维中的索引是简单的标量。该表达式不能在语句中单独使用,因此我假设您在问题中遗漏了该行的某些部分。