I have been trying to use allocatable variables as subroutine arguments and I am investigating what happens if the arrays have not previously been allocated.
I am not sure if the Fortran 95 standard allows un-allocated arrays as arguments, but FTN95 Ver 7.00 appears to do this. The following example shows the test code I have written.
! Program to test allocate
!
call test_alloc
end
subroutine test_alloc
!
real*8, allocatable, dimension(:,:) :: aa, bb
!
allocate ( aa(4,7) )
!
if (allocated (aa)) then
write (*,*) 'aa is allocated'
else
write (*,*) 'aa is NOT allocated'
end if
!
if (allocated (bb)) then
write (*,*) 'bb is allocated'
else
write (*,*) 'bb is NOT allocated'
end if
!
write (*,*) 'Size test 1'
write (*,*) size (aa)
write (*,*) size (bb) ! this gives a non-zero result with /debug
! but fails with /check
! should it work and return 0 ?
!
! Call routine with un-allocated array bb
call test_call (aa, bb)
!
write (*,*) 'aa=',aa(1,1)
!
write (*,*) 'Size test 2'
write (*,*) size (aa)
write (*,*) size (bb)
!
end subroutine test_alloc
subroutine test_call (aa, bb)
!
real*8 aa(4,*), bb(6,*) ! what declaration should work for Fortran 95 ?
!
aa(1,1) = 1.0
!
! The following will compile and work with FTN95 /debug
if (allocated (aa)) then
write (*,*) 'aa is allocated'
else
write (*,*) 'aa is NOT allocated'
end if
!
if (allocated (bb)) then
write (*,*) 'bb is allocated'
else
write (*,*) 'bb is NOT allocated'
end if
!
end subroutine test_call
The above program aa.f90: works for ftn95 aa /lgo works for ftn95 aa /debug /lgo fails for ftn95 aa /check /lgo I think that FTN95 may not conform to the Fortran 95 standard ?
I am trying to avoid making the arrays allocated, so that I can utilise the status of .not. allocated (bb) in the subroutine. I think F2003 and F2008 have changed the way these arguments may be declared and handled.
Any comments ?
John