NAG Fortran Compiler, Release 7.2: Input/output extensions [mostly 5.3]

Navigation: Previous Up Next

## 10.7 Input/output extensions [mostly 5.3]

- The `NEWUNIT=` specifier has been added to the `OPEN` statement; this allocates a new unit number that cannot clash with any other logical unit (the unit number will be a special negative value). For example,

            INTEGER unit
            OPEN(FILE='output.log',FORM='FORMATTED',NEWUNIT=unit)
            WRITE(unit,*) 'Logfile opened.'

  The `NEWUNIT=` specifier can only be used if either the `FILE=` specifier is also used, or if the `STATUS=` specifier is used with the value `'SCRATCH'`.
- Recursive input/output is allowed on separate units. For example, in

         Write (*,Output_Unit) f(100)

  the function `f` is permitted to perform i/o on any unit except `Output_Unit`; for example, if the value 100 is out of range, it would be allowed to produce an error message with

         Write (*,Error_Unit) 'Error in F:',n,'is out of range'

- [6.0] A sub-format can be repeated an indefinite number of times by using an asterisk (`*`) as its repeat count. For example,

         SUBROUTINE s(x)
           LOGICAL x(:)
           PRINT 1,x
      1    FORMAT('x =',*(:,' ',L1))
         END SUBROUTINE

  will display the entire array `x` on a single line, no matter how many elements `x` has. An indefinite repeat count is only allowed at the top level of the format specification, and must be the last format item.
- [6.0] The `G0` and `G0.`d edit descriptors perform generalised editing with all leading and trailing blanks (except those within a character value itself) omitted. For example,

         PRINT 1,1.25,.True.,"Hi !",123456789
      1  FORMAT(*(G0,','))

  produces the output

      1.250000,T,Hi !,123456789,

  [7.2] Note that `G0.`d was not permitted by Fortran 2008 to be used for output of types Integer, Logical, or Character data, but this limitation has been removed by Fortran 2018.