主题:新手请教fortran编程问题subroutine
program arraytest2
implicit none
integer,allocatable::a(:)
integer::b(2)=(/1,3/)
call sub(a,b)
print*,a
pause
end program
subroutine sub(a,b)
integer,intent(out),allocatable::a(:)
integer,intent(in)::b
allocate(a(size(b)))
a=b+1
end subroutine
编译integer,intent(out),allocatable::a(:)这一行出现一个错误:
Error: A dummy argument name is invalid in this context. [A]
实际上,我的源程序是要从subroutine输出一个数组,其长度是在subroutine运行过程中确定的。因此我在主程序里声明integer,allocatable::a(:),在subroutine里声明integer,intent(out),allocatable::a(:)。
因源程序较长,不详细贴出了。谢谢您的回答,任何建议都非常感激!
implicit none
integer,allocatable::a(:)
integer::b(2)=(/1,3/)
call sub(a,b)
print*,a
pause
end program
subroutine sub(a,b)
integer,intent(out),allocatable::a(:)
integer,intent(in)::b
allocate(a(size(b)))
a=b+1
end subroutine
编译integer,intent(out),allocatable::a(:)这一行出现一个错误:
Error: A dummy argument name is invalid in this context. [A]
实际上,我的源程序是要从subroutine输出一个数组,其长度是在subroutine运行过程中确定的。因此我在主程序里声明integer,allocatable::a(:),在subroutine里声明integer,intent(out),allocatable::a(:)。
因源程序较长,不详细贴出了。谢谢您的回答,任何建议都非常感激!