FORTRAN - allocated array in the subroutine

I am trying to use a allocated array in a routine, 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 is that I have to use the explicit interface that I am doing. Here is the appropriate 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
+4
source share
3 answers

The compiler error message describes the problem. With INTENT(IN)you say that the object will not change, but then you try to execute ALLOCATEit.

Yes, the call will require an explicit interface, but this is not a problem.

The Fortran 2008 standard says in section 5.3.10 that

A nonpointer object with the INTENT (IN) attribute must not appear in the context of the variable context

- : 16.6.7, (11).

+5

locs INTENT (IN) - , , .

INTENT (IN) , ( ) locs. ALLOCATE .

+2

, , locs , INTENT(INOUT), , .

0

Source: https://habr.com/ru/post/1529977/


All Articles