使用fortran open语句时处理语法错误

时间:2015-05-06 09:47:17

标签: file fortran

我正在打开一个必须在最后删除的文件。以下命令抱怨使用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)

1 个答案:

答案 0 :(得分:5)

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')