找回密码
 注册
Simdroid-非首页
查看: 79|回复: 3

[3. Fortran] fortran90动态数组传递参数的问题

[复制链接]
发表于 2011-8-14 20:08:25 | 显示全部楼层 |阅读模式 来自 黑龙江佳木斯
!程序的目的是在主程序里声明一个一维动态数组,但数组的长度及内容通过子程序来定
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
 楼主| 发表于 2011-8-14 20:09:30 | 显示全部楼层 来自 黑龙江佳木斯
Simdroid开发平台
为什么是这样,请高手指点
回复 不支持

使用道具 举报

发表于 2011-8-15 18:45:01 | 显示全部楼层 来自 江苏南京
请问楼主用的是什么编译器,windows环境下ivf计算结果为m=5。

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2011-10-7 04:02:40 | 显示全部楼层 来自 美国
gfortran表示也是5
  1. module tt
  2. contains
  3. subroutine test(s)
  4.     implicit none
  5.     integer i
  6.     integer,allocatable::s(:)
  7.     allocate(s(5))
  8.     do i=1,5
  9.          s(i)=i
  10.      end do
  11. end subroutine test
  12. end module

  13. program main
  14.     use tt
  15.     integer,allocatable::s(:)
  16.     call test(s)
  17.     m=ubound(s,1)
  18.    write(*,*)m
  19.    write(*,*)s
  20. end program main
复制代码

评分

1

查看全部评分

回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-4-19 15:51 , Processed in 0.036449 second(s), 16 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表