0

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
kdb
  • 4,098
  • 26
  • 49
  • Hi, is this not working? `print *, all( shape( A5(:,1,:,1,:) ) == shape( A3 ) )` – roygvib Jun 24 '16 at 18:25
  • Also this page may also be interesting (about using function return variables as "l-value") http://stackoverflow.com/questions/31570274/have-a-function-in-fortran-return-a-reference-that-can-be-placed-on-the-left-han – roygvib Jun 24 '16 at 18:42

0 Answers0