Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gfortran无法识别.h文件中第一列以“c”开头的注释_Fortran_Comments_Gfortran_Freeform_Fixed Format - Fatal编程技术网

gfortran无法识别.h文件中第一列以“c”开头的注释

gfortran无法识别.h文件中第一列以“c”开头的注释,fortran,comments,gfortran,freeform,fixed-format,Fortran,Comments,Gfortran,Freeform,Fixed Format,我正在尝试将文件“a.h”包含到Fortran程序“b.f”中 文件内容如下: a、 h b、 f 当我尝试使用以下命令编译文件“b.f”时 gfortran -ffree-form b.f 编译器给出了错误 Included at b.f:2: c This is a comment 1 Error: Unclassifiable statement at (1) 但是当我将注释行更改为 !c This is a comment gfortran编译成功,程序运行正

我正在尝试将文件“a.h”包含到Fortran程序“b.f”中 文件内容如下:

a、 h

b、 f

当我尝试使用以下命令编译文件“b.f”时

gfortran -ffree-form b.f
编译器给出了错误

    Included at b.f:2:
c     This is a comment
1
Error: Unclassifiable statement at (1)
但是当我将注释行更改为

!c    This is a comment
gfortran编译成功,程序运行正常


有人能告诉我如何让gfortran识别“*.h”文件中以“c”开头的行作为注释吗。我试图在我的自由格式fortran代码中包含一个类似的文件,其中的注释以库中的“c”开头,但我不能在该文件中以“c”开头的所有注释(以“!”开头)

包含文件的格式是固定的!不能在单个文件中混合使用自由格式和固定格式。自

包含行的[效果]就好像在程序处理之前,引用的源文本实际替换了包含行[,]

合并的源文本需要固定或自由形式,但不能两者兼而有之。 [来源:Fortran 2008标准,第3.4.6条]

这给您留下了两个选择:

将主程序转换为固定格式,或 将包含文件转换为自由格式。 对于1,您需要指定-ffixed form和格式b.f以符合固定格式。b、 f看起来像

      program test_include
          include 'a.h'
          write(*,100) k
      end program test_include
对于2,您将把include文件转换为自由格式。然后,include可以写为:

!     This is a comment
      k = 10
100  format( I5 )
如果不能转换所有文件,我建议以固定格式编写包装器模块,包括源代码,然后改用包装器模块。对于您提供的代码段,这需要进一步考虑,但对于仅包含变量/参数/接口的include文件,这可能是这样的

      module wrapper_vars
          include 'vars.h'
      end module
对于子程序和函数,您还可以使用模块:

      module wrapper_subroutines
      contains
          include 'subroutines.h'
      end module

因此,在自由形式中,以“c”开头的行不是注释。知道了。编写包装器模块的想法听起来很适合我的工作。谢谢
      module wrapper_vars
          include 'vars.h'
      end module
      module wrapper_subroutines
      contains
          include 'subroutines.h'
      end module