【问题标题】:Whitespaces are not allowed around % sign in namelist input file for derived type% 签入派生类型的名称列表输入文件周围不允许有空格
【发布时间】:2016-11-17 02:11:33
【问题描述】:

这里是测试代码:

program testcase
    implicit none

    integer :: ios, lu
    type derived
        integer :: a
    end type derived
    type (derived) :: d

    namelist /test/ d

    lu = 3
    open (lu, file = 'test.dat', status='old', iostat=ios)
    read (lu, nml = test, iostat=ios)
    if (ios /= 0) then
        write (*, *) 'error!'
    else
        write (*, *) 'good!', d % a
    endif
end program testcase

此程序读取输入文件 test.dat,其中包含 test 的名称列表,其类型是派生类型 derived。

当我尝试 test.dat 的下一个内容时,它工作正常(它打印 good! 7):

&test
    d%a = 7
/

但是,对于下一个内容,我收到一个错误:

&test
    d % a = 7
/

Equal sign must follow namelist object name d

不同之处在于% 符号周围的空格用于派生类型中的组件访问。

我已经使用 GNU Fortran(gfortran) 5.3.0 进行了测试。我还从同事那里听说,最新的英特尔 Fortran 编译器也出现了同样的问题。他还坚持认为旧版本的英特尔 Fortran 编译器在这两种情况下都能正常工作。

这种行为正常吗?也就是说,标准是否禁止namelist输入文件中%周围的空格,而源代码中允许%周围的空格?

或者,这是编译器的错误还是标准库的实现?

【问题讨论】:

  • 如果% 字符周围有空格,我可以确认gfortran v4.4.7 会出错,而intel fortran 编译器(v12.1.3 和v16.0.3)可以正确读取名称列表。
  • 我发现了错误信息,它是代码 5010,信息是“等号必须遵循 namelist object name d”
  • @chw21 谢谢。您的信息帮助我找到了一些说明这种情况的页面。

标签: fortran


【解决方案1】:

最后,我找到了一些提到这个问题的参考资料。

来自http://technion.ac.il/doc/intel/compiler_f/main_for/lref_for/source_files/pghnminp.htm,

&group-name object = value [, object = value] .../

...

对象

是在 NAMELIST 声明的组名。 对象名称不得 包含嵌入的空格,下标的括号内除外 或子字符串说明符。每个对象必须包含在一个单独的 记录。

另一个来自http://docs.cray.com/books/S-3693-51/html-S-3693-51/i5lylchri.html,

2.13.1.1。名称-值对中的名称

...

  • 输入记录中的名称不得包含嵌入的空格。名称-值对中的名称前面或后面可以是一个或多个 空白。

所以,显然,名称中的空格似乎是不允许的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    相关资源
    最近更新 更多