shrine 发表于 2017-12-14 10:08:14

请问这种子程序的参数该怎么设计

本帖最后由 shrine 于 2017-12-14 10:30 编辑

主程序里动态分配了几个数组,要向子程序传递这几个数组,每次传的都不一样,这几个数组已经放到一个global-data的模块里,子程序可以直接use

module global_data
implicit none
Integer , parameter :: QP = Selected_real_kind( 18 )
real(kind=QP),allocatable::h(:),u(:)
Integer , parameter :: ne=100
end module

program main
use global_data
implicit none
integer::NERR
ALLOCATE(h(ne),u(ne),STAT=NERR)
IF(NERR>0)THEN
WRITE(6,*)      'ERROR IN ALLOCATE'
         STOP
ENDIF

call tvdd(h)
call tvdd(u)
DEALLOCATE(h,u)
end

subroutine tvdd(t) !这个参数该怎么设置,现在这样写肯定不行,t无法声明,我想把h和u传进来,每次传一个,每次不一样
use global_data
implicit none
t=t+1
endsubroutine



pasuka 发表于 2017-12-14 11:09:21

已经导入global_data模块的情况下,变量h和u对于函数tvdd就是透明公开的,lz为啥画蛇添足?
选择h和u直接select case呗

shrine 发表于 2017-12-14 11:13:00

pasuka 发表于 2017-12-14 11:09
已经导入global_data模块的情况下,变量h和u对于函数tvdd就是透明公开的,lz为啥画蛇添足?
选择h和u直接se ...

没明白,能写成代码吗

fcode 发表于 2017-12-14 12:09:55

module global_data
implicit none
Integer , parameter :: QP = Selected_real_kind( 18 )
real(kind=QP),allocatable::h(:),u(:)
Integer , parameter :: ne=100

contains
subroutine tvdd(t) !//把 tvdd 包含在module里,方便使用
    real(kind=QP) :: t(:)
    t=t+1
endsubroutine
end module

program main
use global_data
implicit none
integer::NERR
ALLOCATE(h(ne),u(ne),STAT=NERR)
IF(NERR>0)THEN
    WRITE(6,*)      'ERROR IN ALLOCATE'
    STOP
ENDIF
call tvdd(h)
call tvdd(u)
DEALLOCATE(h,u)
end

shrine 发表于 2017-12-14 12:54:24

fcode 发表于 2017-12-14 12:09
module global_data
implicit none
Integer , parameter :: QP = Selected_ ...

perfect!!
感谢版大
页: [1]
查看完整版本: 请问这种子程序的参数该怎么设计