routine call with allocatable argument
Dennis Wassel
dennis.wassel@googlemail.com
Mon Sep 28 12:55:00 GMT 2009
Salut Jean,
comp.lang.fortran usually is a much better place to ask questions
about the standard, but since you are here, well let's see...
> subroutine A(tab)
> real(kind=long),dimension(:),allocatable,intent(inout):: tab
>
> [...]
>
> subroutine B(tab)
> real(kind=long),dimension(:,:),allocatable,INTENT(INOUT)::tab
> integer :: nx, ny, i
> if (allocated(tab)) deallocate(tab)
> allocate(tab(nx,ny))
>
> do i=1,nx
> call A(tab(i,:))
> end do
I am definitely not a standards person, but let's think about the
implications if this were standard-conforming:
You would allow tab to be deallocated by A. In your example, tab is
passed to A by B as 1D-slice of a 2D allocatable array, moreover a
strided one. Allowing you to deallocate or even "reallocate" this to
another size would seriously open a can of worms, therefore any
self-respecting standard should not allow you to do that. What happens
with g95 if you try to reallocate tab in A to a different size?
Side note: Calling A(tab(i, :)) is suboptimal w.r.t to Fortran's
storage sequence - this looks like you came from the C world, where
this is the right thing to do. tab(:, i) is usually preferrable
because access is contiguous like this.
Cheers,
Dennis
More information about the Fortran
mailing list