急问fortran编程问题
答案:3 悬赏:40
解决时间 2021-01-27 15:18
- 提问者网友:留有余香
- 2021-01-26 16:23
急问fortran编程问题
最佳答案
- 二级知识专家网友:鱼忧
- 2021-01-26 17:46
fortran里不允许虚参是allocatable的吧
你这个程序应该在主程序call sub(a,b)之前allocate a,然后子程序里用假定形状的数组
integer,intent(out),dimension(:) :: a
你这个程序应该在主程序call sub(a,b)之前allocate a,然后子程序里用假定形状的数组
integer,intent(out),dimension(:) :: a
全部回答
- 1楼网友:妄饮晩冬酒
- 2021-01-26 18:32
由于数组a没有定义大小,所以不可出现在虚参里,可将a设置成全局变量,从虚参中删除,我习惯用module,更改程序如下:
module adata
implicit none
integer,allocatable::a(:)
endmodule
program arraytest2
use adata
implicit none
integer::b(2)=(/1,3/)
call sub(b)
print*,a
pause
end program
subroutine sub(b)
use adada
integer::b
allocate(a(size(b)))
a=b+1
end subroutine
module adata
implicit none
integer,allocatable::a(:)
endmodule
program arraytest2
use adata
implicit none
integer::b(2)=(/1,3/)
call sub(b)
print*,a
pause
end program
subroutine sub(b)
use adada
integer::b
allocate(a(size(b)))
a=b+1
end subroutine
- 2楼网友:封刀令
- 2021-01-26 18:01
Fortran2003支持,估计您的编译器有点儿老。
我已在编程爱好者论坛回复了您的问题,不过论坛里的asymptotic兄回复得更完美:)
我已在编程爱好者论坛回复了您的问题,不过论坛里的asymptotic兄回复得更完美:)
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |