ALLOCATABLE subroutine parameter not accepted

Hi!

I have to read some data into an array, but the number of points is not known on beforehand. Therefore, I made the array ALLOCATABLE. To keep my main routine clean, I deferred the actual reading and allocation to a subroutine. I narrowed down the problem to just a few lines, see below. The compiler refuses to accept the code, telling me:

pgf90 testallo.f90 -o testallo.exe

PGF90-S-0134-Illegal attribute - conflict with intent (testallo.f90: 8)
0 inform, 0 warnings, 1 severes, 0 fatal for allocateandfillarray

The code runs fine with g95. Changing the INTENT to anything else did not make any difference.

Do you have a suggestion?

Regards,


Arjan





MODULE MyModule
IMPLICIT NONE
PRIVATE
PUBLIC :: AllocateAndFillArray
CONTAINS
!
SUBROUTINE AllocateAndFillArray(MyArray)
INTEGER, DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: MyArray
INTEGER :: i,N
N = 7
ALLOCATE(MyArray(7))
DO i = 1,N
MyArray(i) = 3i-10
ENDDO
END SUBROUTINE AllocateAndFillArray
!
END MODULE MyModule



PROGRAM Test
USE MyModule
INTEGER, DIMENSION(:), ALLOCATABLE :: MyArray
INTEGER :: I,N
CALL AllocateAndFillArray(MyArray)
N = SIZE(MyArray)
WRITE(
,) ‘Array has ‘,N,’ elements:’
DO i=1,N
WRITE(
,*) ‘Array[’,I,’] = ',MyArray(i)
ENDDO
DEALLOCATE(MyArray)
END PROGRAM Test

ps. It does work when I hide the allocatable array in a user-defined type…



MODULE MyModule
IMPLICIT NONE
PRIVATE
PUBLIC :: AllocateAndFillArray,WrappedArrayType
TYPE WrappedArrayType
INTEGER, DIMENSION(:), ALLOCATABLE :: Elements
END TYPE WrappedArrayType
CONTAINS
!
SUBROUTINE AllocateAndFillArray(MyArray)
TYPE(WrappedArrayType), INTENT(INOUT) :: MyArray
INTEGER :: i,N
N = 7
ALLOCATE(MyArray%Elements(7))
DO i = 1,N
MyArray%Elements(i) = 3i-10
ENDDO
END SUBROUTINE AllocateAndFillArray
!
END MODULE MyModule



PROGRAM Test
USE MyModule
TYPE(WrappedArrayType) :: MyArray
INTEGER :: I,N
CALL AllocateAndFillArray(MyArray)
N = SIZE(MyArray%Elements)
WRITE(
,) ‘Array has ‘,N,’ elements:’
DO i=1,N
WRITE(
,*) ‘Array[’,I,’] = ',MyArray%Elements(i)
ENDDO
DEALLOCATE(MyArray%Elements)
END PROGRAM Test

Hi Arjan,

Another reason for you to upgrade! We added support for the F95 allocatable array extensions including allocatable components in the 7.0 release. This extension is also part of the F2003 standard.

  • Mat
% pgf90 test.f90 -V7.0-1 -o test.out
% test.out
 Array has             7  elements:
 Array[            1 ] =            -7
 Array[            2 ] =            -4
 Array[            3 ] =            -1
 Array[            4 ] =             2
 Array[            5 ] =             5
 Array[            6 ] =             8
 Array[            7 ] =            11