Why does using command PRINT in Fortran overwrite the input file?

后端 未结 2 1630
清歌不尽
清歌不尽 2021-01-28 22:38

I\'m writing my code and using input and output feature in Fortran. The code looks like this (only for simplification):

PROGRAM TEST

  REAL, DIMENSION(         


        
2条回答
  •  礼貌的吻别
    2021-01-28 22:56

    I've found the answers. Actually the code I've posted above will run well on Gfortran 5.3, since I used OPEN(UNIT=1,...) and OPEN(UNIT=2,...) which is there will be no problem since I am using 1 and 2. I just wrote this simple case to represent my real code without checking it first. But actually in my real code, I used two statements that OPEN(UNIT=5,...) and OPEN(UNIT=6,...) existed, which are not allowed in Fortran, since:

    1. UNIT=5 declares Standard In which is used to read in data from the keyboard.
    2. UNIT=6 declares Standard Out which is used to print general output to the screen.
    3. UNIT=0 declares Standard Error which is used to print error messages to the screen.

    I didn't realize before since I'm working on quite old code, so O need to rewrite it into a newer version one. So, in order to avoid the problems, just don't use UNIT=5, UNIT=6 and UNIT=0.

提交回复
热议问题