Update: The "duplicate" link indeed answers the questions, albeit for strings instead of arrays. Also, the proposed solution there ("add an index argument to the function") isn't applicable to intrinsic functions like SHAPE
. However, the basic conclusion ("no, there is no such syntax") remains unaffected by that difference and shows a limitation of the language.
I have an array A5 of rank 5 and A3 of rank 3. I want to verify that subarrays A5(:,I,:,J,:) have the same shape as A3. Is it possible to do so without using temporary variables?
It would seem natural to write the comparison as
ALL( (SHAPE(A5))([1,3,5]) .EQ. SHAPE(A3) )
but indexing the expression seems to be invalid syntax. Is there some valid syntax for this?
Example program
PROGRAM PS
INTEGER A5(5,3,6,2,3)
INTEGER A3(5,6,3)
INTEGER SA5(5), SA3(3)
SA5 = SHAPE(A5)
SA3 = SHAPE(A3)
WRITE(*,*) ALL(SA5([1,3,5]) .EQ. SA3) ! => T
! WRITE(*,*) ALL( (SHAPE(A5))([1,3,5]) .EQ. SHAPE(A3) ) ! Invalid syntax
END PROGRAM PS