Fortran Coder

查看: 2517|回复: 4
打印 上一主题 下一主题

[子程序] 不能传递子程序名字

[复制链接]

237

帖子

0

主题

0

精华

版主

World Analyser

F 币
638 元
贡献
468 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
楼主
发表于 2021-12-14 08:28:18 | 显示全部楼层
gfortran处理主程序contains下的函数有特殊的方式。
你把 subroutine B 放到 program 外面去就行了,或者放到一个module里。

另外的问题,建议用 Procedure 代替子程序内的 interface

[Fortran] 纯文本查看 复制代码
Module fcnMod
  Interface
    Subroutine IF_fcn()
    End Subroutine IF_fcn
  End Interface
contains
   subroutine B()
     write (*,*) 'fk'
   end subroutine B
End Module fcnMod

program  main
  use fcnMod
  IMPLICIT NONE

  CALL B()
  CALL FKB(B)
  
contains

   subroutine FKB(fcn)
     Procedure(IF_fcn) :: fcn
     write (*,*) '1'
     call B()
     write (*,*) '2'
     call fcn()
     write (*,*) '3'
   end subroutine FKB
   
end

或者
[Fortran] 纯文本查看 复制代码
Subroutine C()
  write (*,*) 'fc'
End Subroutine C

program  main
  IMPLICIT NONE
  Interface
    Subroutine IF_fcn()
    End Subroutine IF_fcn
  End Interface
  Procedure(IF_fcn) :: C
  CALL C()
  CALL FKB(C)
  
contains

   subroutine FKB(fcn)
     Procedure(IF_fcn) :: fcn
     write (*,*) '1'
     call C()
     write (*,*) '2'
     call fcn()
     write (*,*) '3'
   end subroutine FKB
   
end

237

帖子

0

主题

0

精华

版主

World Analyser

F 币
638 元
贡献
468 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
沙发
发表于 2021-12-15 08:26:31 | 显示全部楼层
不需要module里再加module,在module里(而不是program)就行。可以在同一个module,或者另一个module。

Fortran 应该是不允许module里再写module的。但是module允许有SubModule
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-4 11:52

Powered by Tencent X3.4

© 2013-2024 Tencent

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