I have something similar to following code:
--- type.f90 --- MODULE MTYPE TYPE NEWTYPE INTEGER, ALLOCATABLE :: N(:) END TYPE END MODULE --- subrt.f90 --- MODULE MSUBS CONTAINS SUBROUTINE SETUP(a) TYPE(NEWTYPE), INTENT(OUT) :: a ALLOCATE(a%n(1000)) a%n = 0 END SUBROUTINE END MODULE --- main.f90 --- PROGRAM TEST USE MTYPE TYPE(NEWTYPE) :: a CALL SETUP(a) END PROGRAM
When I run this program, it works fine until I return from the subroutine. When that happens, the array I allocated in the subroutine contains random values. Does the ALLOCATE command have scope in this case? i.e. Do I have to allocate in the outermost program unit or can I allocate in a subroutine like this?