I have been experimenting with allocate on assigment and the following code uses this to to increment the dimensions of an array:
program p
implicit none
real, allocatable :: a(:)
integer i
do i = 1, 4
call inc_alloc(a,real(i))
print*, size(a), a
end do
contains
subroutine inc_alloc (a,next)
real, allocatable, intent(inout) :: a(:)
real, intent(in) :: next
if (allocated(a)) then
a = [a,next]
else
a = [next]
end if
end subroutine inc_alloc
end program p
With the 64 bit compiler (release and debug) the terminal output is correct:
1 1.00000
2 1.00000 2.00000
3 1.00000 2.00000 3.00000
4 1.00000 2.00000 3.00000 4.00000
With the 32 bit compiler (release and debug) the terminal output is incorrect:
1 1.00000
2 0.00000 0.00000
3 0.00000 0.00000 0.00000
4 0.00000 0.00000 0.00000 0.00000
With both the 64 and 32 bit compilers (using checkmate) a run time error occurs (nonconformant arrays) at the line:
a = [a,next]
while the arrays are nonconformant, I don't think this should be an error in this case.