Opening a file on unit 5 or 6

前端 未结 2 736
猫巷女王i
猫巷女王i 2020-12-20 03:03

I have a read/write operation going on in the Fortran code snippet as follows

OPEN(5,FILE=\'WKDAT.dat\', STATUS=\'OLD\')
OPEN(6,FILE=\'WKLST.dat\', STATUS=\'         


        
2条回答
  •  清歌不尽
    2020-12-20 03:55

    Nothing in the standard says units 5 and 6 have any special meaning although in practice standard input and standard output are often pre-connected to 5 and 6.

    Module iso_fortran_env from Fortran 2008 contains constants

    INPUT_UNIT
    OUTPUT_UNIT
    ERROR_UNIT
    

    with the unit numbers where standard input, standard output and standard error are connected. These are allowed to be different than 5 and 6.

    Opening a file in unit that is in use causes the unit to be associated with the new file.

    For example the Cray Fortran manual says:

    Unit numbers 100, 101, and 102 are permanently associated with the standard input, standard output, and standard error files, respectively.

    That means if you open some other file as unit 5 or 6 standard input and standard output still have some other unit where they are pre-connected and they will not be closed.

提交回复
热议问题