Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FORTRAN - allocatable array in subroutine

I'm trying to use an allocatable array in a subroutine but the compiler complains that

Error: Dummy argument 'locs' with INTENT(IN) in variable definition context (ALLOCATE object) at (1)

The only thing I could find was that I am supposed to use an explicit interface, which I am doing. Here the relevant code for the subroutine:

    RECURSIVE SUBROUTINE together(locs, LL, RL)

    INTEGER, DIMENSION(:,:), ALLOCATABLE, INTENT(IN)            :: locs
    INTEGER, INTENT(IN)                                         :: LL, RL


    ALLOCATE(locs(LL,RL))


END SUBROUTINE together
like image 984
clueless_programmer Avatar asked Mar 21 '23 09:03

clueless_programmer


1 Answers

The compiler's error message is one descriptive of the problem. With INTENT(IN) you are saying that the object will not change, but you then go on to attempt to ALLOCATE it.

Yes, an explicit interface will be required for the calling, but that isn't the problem.

The Fortran 2008 standard says in section 5.3.10 that

A nonpointer object with the INTENT (IN) attribute shall not appear in a variable denition context

Allocation is one such context: section 16.6.7, point (11).

like image 64
francescalus Avatar answered Mar 22 '23 22:03

francescalus