Is it allowed to pass an array section of an automatic array to another subroutine? The problem is illustrated by the attached program “Automatic_Array”. In the present case, the program stops with an error message, but I have also seen similar cases, where the program failed because of undefined variables. Can anybody help?
Many thanks,
Klaus Lassmann [code] Winapp
Program Automatic_Array
Implicit None
Real , Dimension ( 3 ) :: x
Integer :: n
x (1) = 1.
x (2) = 2.
x (3) = 3.
n = 3
Call SubA ( x (1:n) , n )
! #########
End Program Automatic_Array
Subroutine SubA ( xData, npoint )
Implicit None
Real , Dimension (npoint) :: xData
Integer :: npoint, mpoint
Real , Dimension (npoint) :: yData ! Automatic object
yData = xData * 2.
Write (*,*) ' xData = ', xData
Write (*,*) ' yData = ', yData
mpoint = 2
! This call leads to an error:
Call SubB ( yData (1:mpoint), mpoint )
! This call gives the correct solution
! Call SubB ( yData , mpoint )
End Subroutine SubA
Subroutine SubB ( x , m)
Real , Dimension (m) :: x
Integer :: m
x = x * 0.5
write (*,*) 'y = ', y
End Subroutine SubB
[/code]