【问题标题】:When do I have to use CONTAINS in a module?什么时候必须在模块中使用 CONTAINS?
【发布时间】:2021-05-21 12:30:25
【问题描述】:

我定义了以下模块:

module data_model_2

        implicit none

        ! -------------------
        ! TYPE DEFINITION
        ! -------------------
        type :: type1_record
                integer                 :: month
                integer                 :: day
                integer                 :: year
                integer                 :: hour
                integer                 :: minute
                integer                 :: second
                integer                 :: value1
                integer                 :: value2
        end type
        type :: timestamp_record
                integer                 :: year
                integer                 :: month
                integer                 :: day
                integer                 :: hour
                integer                 :: minute
                integer                 :: second
        end type

end module

我看到modules 应该使用子句contains。当模块只包含派生类型定义时,是否需要该子句?

如果是这样,它应该包含在哪里,在implicit none之后还是之前?

如果模块还包括函数或过程,派生类型定义应该在contains 子句之前还是之后?

我很想知道这在 Fortran 95 和 Fortran 03 中是如何工作的。

【问题讨论】:

    标签: fortran


    【解决方案1】:

    contains 语句表示以下是内部子程序模块子程序。只有那些东西可能会出现在模块的containsend 之间。

    在 Fortran 2008 之前,不允许有“空包含”部分:如果您在 Fortran 90、95、2003 中没有模块子程序,那么您可能没有 contains。在 Fortran 2008+ 中,您可能拥有它,尽管它不是必需的,但没有它们。

    contains 本质上是模块中允许的最后一件事:所有不是内部/模块子程序的模块范围定义必须在之前。 implicit 语句必须在模块范围的早期:只有模块语句 useimport(在那些支持的极少数情况下)可以在它之前。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2016-10-22
      • 2020-03-06
      • 1970-01-01
      相关资源
      最近更新 更多