将MAXLOC与具有ALLOCATABLE属性的数组组件一起使用

时间:2018-02-19 22:04:26

标签: fortran gfortran

代码是:

Type , public :: TS_VAR

  Complex , allocatable :: An_array (:)

End type TS_VAR 

Type ( TS_VAR ) , allocatable :: TS_PU (:)

Allocate ( TS_PU ( 24 ) , Stat = ALLOC_ERR )

If ( ALLOC_ERR .ne. 0 ) Stop ( !!! Memory allocation problem !!! )

Do j = 1 , 24 

   Allocate ( TS_PU(j)%An_array ( 1 : 13 ) , Stat = ALLOC_ERR )

   If ( ALLOC_ERR .ne. 0 ) Stop ( !!! Memory allocation problem !!! )

End do

!!! Calculation 

Do j = 1 , 24 

   Do i = 1 , 13

      TS_PU(j)%An_array ( i ) = cmplx ( ! Some calculation  )

   End do

End do

Logical , dimension ( 1 : 13 , 24 ) :: DM_mask = .false.

Forall( 1 : 5 , j = 1 : 24 ) DM_mask(i,j) = .true.

Write(*,*) maxloc ( abs ( TS_PU(:)%An_array ( : ) ) , mask = DM_mask ) 

编译过程完成后我得到了这条消息: Component to the right of a part reference with nonzero rank must not have the ALLOCATABLE attribute

这个例子有什么问题? 在阵列的特定扇区中是否存在最大值搜索的内在函数?

0 个答案:

没有答案