Module MOD1
   Implicit None
CONTAINS
   Subroutine SUB1 ( array0 , array1 , array2 )
      Real, Dimension(:), Allocatable, Intent(In) :: array0
      Real, Dimension(:), Allocatable, Intent(Out) :: array1
      Real, Dimension(:), Allocatable, Optional, Intent(Out) :: array2
      !
      Integer :: istat
      !
      If ( .NOT.ALLOCATED(array1) ) Then
         ALLOCATE( array1(SIZE(array0)) , Stat=istat )
         If ( istat /= 0 ) STOP " PB-1 "
      End If
      array1 = 2. * array0
      !
      If ( .NOT.PRESENT(array2) ) Return
      !
      If ( .NOT.ALLOCATED(array2) ) Then
         ALLOCATE( array2(SIZE(array0)) , Stat=istat )
         If ( istat /= 0 ) STOP " PB-2 "
      End If
      array2 = - array0
      !
   End Subroutine SUB1
   !
End Module MOD1
!!!!
!!!!
Program MAIN
   USE MOD1
   Implicit None
   Integer, Parameter :: ndim = 4
   Real, Dimension(:), Allocatable :: arr0, arr1, arr2
   Integer :: istat
   !
   Allocate( arr0(ndim) , Stat=istat )
   If ( istat /= 0 ) STOP " PB-0 "
   !
   arr0 = 1.
   Call SUB1 ( arr0 , arr1 )
   Write(*,*) ALLOCATED(arr0), ALLOCATED(arr1), ALLOCATED(arr2)
   Write(*,*) arr0
   Write(*,*) arr1
   !
   arr0 = 10.
   Call SUB1 ( arr0 , arr1 , arr2 )
   Write(*,*) ALLOCATED(arr0), ALLOCATED(arr1), ALLOCATED(arr2)
   Write(*,*) arr0
   Write(*,*) arr1
   Write(*,*) arr2
   !
   STOP " "
   !
End Program MAIN
