1

我在运行时收到此错误:

forrtl: severe (10): Cannot overwrite existing file, unit
27, file C:\Abaqus_JOBS\w.txt

错误发生在分析的开始。开始时,文件w.txt已创建,但最初为空。然后1写入w.txt并在我收到上述错误之后。

我的代码是:

 SUBROUTINE MAIN(....)
C
C UPDATE w counter
C
      flag = 0
      OPEN(2700, action = "READWRITE", FILE = "C:/Abaqus_JOBS/w.txt", status = "UNKNOWN")
C
      READ(2700, *, iostat=stat) w
      CALL del_file(2700, stat, flag)
C
      w = w + 1
      IF (w.GT.nELEM) THEN
        nInc = KINC !Update nInc: to check IF failure occurred
      ELSE
        nInc = 0
      ENDIF
C
      OPEN(2700, FILE = "C:/Abaqus_JOBS/w.txt", 
     1 action = "READWRITE", status = "new")
C If I change ´status = "new"´ to `status = "unknown"´ it works...
      WRITE(2700,*) w
      CLOSE(2700)
C
C computations
C      
     RETURN
     END

  SUBROUTINE WMOD(....)
C Subroutine WMOD is called at the end of subroutine MAIN
C
C UPDATE w
    OPEN(27, FILE = "C:/Abaqus_JOBS/w.txt",
 1  action = "READWRITE", status = "UNKNOWN")
    w1 = 0.D0
    WRITE(27,*) w1
    CLOSE(27)

C      
  RETURN
  END

  SUBROUTINE del_file(uFile, stat, flag)
 C
  IMPLICIT NONE
  INTEGER uFile, stat, flag 

  IF (stat.NE.0 .OR. flag.EQ.1) THEN
 C If the unit is not open, stat will be non-zero
    CLOSE(unit=uFile, status='delete', iostat=stat)
  ELSE
    CLOSE(unit=uFile, iostat=stat)
  ENDIF
 C
  END SUBROUTINE

参考:关闭多个文件

我的问题是为什么我必须更改status = "new"status = "unknown"inMAIN才能完成这项工作?

经过一些运行时,我也得到了severe (9): permission to access file denied,对这些错误感到困惑。感谢任何帮助谢谢

4

1 回答 1

3

您正在告诉代码它已格式化(语句FORM中的隐式定义OPEN),但您正试图通过使用将其读取为未格式化的文本READ(27)

这应该读

OPEN(UNIT = 27, FILE = "C:/Abaqus_JOBS/w.txt", status = "UNKNOWN")
READ(27, *, iostat=stat) w
于 2013-10-21T18:53:44.383 回答