【问题标题】:dispose syntax error when using fortran open statement使用 fortran open 语句时处理语法错误
【发布时间】:2015-05-06 09:47:17
【问题描述】:

我正在打开一个必须在最后删除的文件。以下命令抱怨使用dispose

f = "espy.tmp";  h = "formatted";  r = "read" 
Open (newunit=u, file=f, form=h, action=r,  &
  status="old", dispose="delete")

lib/core.f:177:21:

     status="old", dispose="delete")
                 1
Error: Syntax error in OPEN statement at (1)

【问题讨论】:

  • 我想知道您是否使用了 gfortran 的 oder 版本,它还不知道 newunit 选项。例如:我无法重新创建它,因为我还不知道它。
  • 我正在使用 gcc-5.00。这是一个不错的功能。 newunit 不是导致问题的原因。

标签: file fortran


【解决方案1】:

Disposenon-standard compiler extension(并且您的编译器不支持)。如in this answer 所述,执行此操作的标准方法是在关闭时删除文件:

f = "espy.tmp";  h = "formatted";  r = "read" 
Open (newunit=u, file=f, form=h, action=r,  &
  status="old")

close(u, status='delete')

或者,您可以使用临时/临时文件(无文件名):

f = "espy.tmp";  h = "formatted";  r = "read" 
Open (newunit=u, form=h, action=r,  &
  status="old", status='scratch')

【讨论】:

  • 我不能使用内部文件,因为文件已经存在并且需要读取它。您的第一个解决方案按我的需要工作。
猜你喜欢
  • 1970-01-01
  • 2019-07-21
  • 1970-01-01
  • 2017-02-17
  • 2015-05-25
  • 2013-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多