我在Fortran 90中调用具有假定形状数组的连续子例程时遇到了问题.更具体地说,我调用两个级别的子例程,将假定形状的数组作为参数传递,但最后数组丢失了.为了演示它,可以遵循以下代码.
program main
INTERFACE
subroutine sub1(x)
real, dimension(:):: x
real C
end subroutine sub1
subroutine sub2(x)
real, dimension(:):: x
real C
end subroutine sub2
END INTERFACE
real, dimension(:), allocatable:: x
allocate(x(1:10)) ! First executable command in main
x(1) = 5.
call sub1(x)
write(*,*) 'result = ',x(1)
deallocate(x)
end program main
subroutine sub1(x) ! The first subroutine
real, dimension(:):: x
real C
call sub2(x)
end subroutine sub1
subroutine sub2(x) ! The second subroutine
real, dimension(:):: x
real C
C2=x(1)
end …Run Code Online (Sandbox Code Playgroud)