mcl616 发表于 2011-8-14 20:08:25

fortran90动态数组传递参数的问题

!程序的目的是在主程序里声明一个一维动态数组,但数组的长度及内容通过子程序来定
module tt
contains
subroutine test(s)
    implicit none
    integer i
    integer,allocatable::s(:)
    allocate(s(5))
    do i=1,5
         s(i)=i
   end do
end subroutine test
end module

program main
    use tt
    integer,allocatable::(s)
    call test(s)
    m=ubound(s,1)
   write(*,*)m
   write(*,*)s
   pause
end program main

但是,问题是m=4,而不是想象中的m=5

mcl616 发表于 2011-8-14 20:09:30

为什么是这样,请高手指点

铁道科学 发表于 2011-8-15 18:45:01

请问楼主用的是什么编译器,windows环境下ivf计算结果为m=5。

wangmianzhi 发表于 2011-10-7 04:02:40

gfortran表示也是5module tt
contains
subroutine test(s)
    implicit none
    integer i
    integer,allocatable::s(:)
    allocate(s(5))
    do i=1,5
         s(i)=i
   end do
end subroutine test
end module

program main
    use tt
    integer,allocatable::s(:)
    call test(s)
    m=ubound(s,1)
   write(*,*)m
   write(*,*)s
end program main
页: [1]
查看完整版本: fortran90动态数组传递参数的问题