In the first example, this part
> associate( t => first% second% third )
> ...
> q( -1:, -1:, -1: ) => t % q( 1 )
> ...
> endassociate
seems equivalent to
q( -1:, -1:, -1: ) => first % second % third % q( 1 )
but isn't this illegal because q is an allocatable array component?
--------------
https://stackoverflow.com/questions/27183800/error-the-part-name-to-the-right-of-a-part-ref-with-nonzero-rank-has-the-alloca?noredirect=1&lq=1
From the first answer (by @VladimirF):
> each %weight is stored elsewhere and you don't have any simple formula to
> compute where is each %weight(i).
From the second answer (by @IanH):
> In the allocatable component case some components in some elements might not
> be allocated and where they are allocated the component might have different
> bounds, making a "regular" reference to the data in the component across the
> elements of the array conceptually difficult.
The situation seems the same as "jagged" or "rugged" arrays, so making it
impossible to get a "rectangular" reference to a set of elements. But does this
not apply if the associate construct do something special (?) or is there
any exception if "q" is allocated with equal size?
--------------
Btw, for the first code, PGI fortran 2017.4 gives
original
-1 5
-2 3
2 6
reordered
-1 5
-1 4
-1 3
which is the same as Intel Fortran. But if I print "q" (after assigning some
value for check),
do k = lbound(first%second%third, dim=3), ubound(first%second%third, dim=3)
do j = lbound(first%second%third, dim=2), ubound(first%second%third, dim=2)
do i = lbound(first%second%third, dim=1), ubound(first%second%third, dim=1)
allocate(first%second%third(i,j,k)%q(7))
first%second%third(i,j,k)%q(:) = 100 ! <-- assign dummy values
enddo
enddo
enddo
...
associate( t => first % second % third )
...
q( -1:, -1:, -1: ) => t % q( 1 )
...
print *, "minval( q ) = ", minval( q ) !<-- check (1)
print *, "q = ", q ! <-- check (2)
endassociate
I get:
original
-1 5
-2 3
2 6
reordered
-1 5
-1 4
-1 3
minval( q ) = 0
q = 100 100 0 100 8
1078656 100 0 100 100 0
100 0 100 0 100 0
1079712 100 0 100 100 0
100 0 1080416 100 0 100
....
In the second example, PGI fortran gives
1 2
1 3
1 4
which again agrees with Intel, but if I do some calculation with q, it results
in segmentation fault (not surprisingly):
associate( q => first % second % third % q( 3 ) )
print*, lbound(q, dim=1), ubound(q, dim=1)
print*, lbound(q, dim=2), ubound(q, dim=2)
print*, lbound(q, dim=3), ubound(q, dim=3)
print *, minval( q ) !<--- do some calculation
endassociate
=>
1 2
1 3
1 4
Segmentation fault: 11
-------------
I have no Intel Fortran in hand so cannot try it (my workstation recently crushed!!)
but the above are the results on my Mac with gfortran-7.3 and PGI (at hand).