Fortran将模块拆分为多个文件 [英] Fortran split module into multiple files

查看:242
本文介绍了Fortran将模块拆分为多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的东西:

Module ModA
    contains
    subroutine FooA()
       ....
    end subroutine
    subroutine FooB()
       ....
    end subroutine
end mofule ModA

我可以将两个子例程拆分为一个单独的文件,但它们仍然属于同一模块.

can I split the two subroutines each in a separate file and still both belongs to the same module.

推荐答案

是.您有两种选择.

首先是在模块子程序部分中将文件与子例程的源一起包含在内.

The first is to simply INCLUDE the file with the source of a subroutine in the module subprogram part.

! Module.f90
MODULE ModA
CONTAINS
  INCLUDE 'FooA.f90'
  INCLUDE 'FooB.f90'
END MODULE ModA

! FooA.f90
SUBROUTINE FooA()
!...
END SUBROUTINE FooA

! FooB.f90
SUBROUTINE FooB()
!...
END SUBROUTINE FooB

第二个选择是将每个子例程移到其自己的子模块中.

The second option is to move each subroutine into its own submodule.

MODULE ModA
  INTERFACE
    MODULE SUBROUTINE FooA()
    END MODULE SUBROUTINE FooA
    MODULE SUBROUTINE FooB()
    END MODULE SUBROUTINE FooB()
  END INTERFACE
END MODULE ModA

! FooA.f90 (or whatever name you prefer)
SUBMODULE (ModA) FooA_submodule
CONTAINS
  MODULE PROCEDURE FooA
  !...
  END PROCEDURE FooA
END SUBMODULE FooA_submodule

! FooB.f90 (or whatever name you prefer).
SUBMODULE (ModA) FooB_submodule
CONTAINS
  MODULE PROCEDURE FooB
  !...
  END MODULE PROCEDURE FooB
END SUBMODULE FooB_submodule

但是您需要为此选项使用支持Fortran 2008子模块功能的Fortran编译器.

But you will need to use a Fortran compiler that supports the Fortran 2008 submodule feature for this option.

这篇关于Fortran将模块拆分为多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆