

6.1.30 Extended I/O specifiers

GNU Fortran supports the additional legacy I/O specifiers CARRIAGECONTROL, READONLY, and SHARE with the compile flag -fdec, for compatibility.


The CARRIAGECONTROL specifier allows a user to control line termination settings between output records for an I/O unit. The specifier has no meaning for readonly files. When CARRAIGECONTROL is specified upon opening a unit for formatted writing, the exact CARRIAGECONTROL setting determines what characters to write between output records. The syntax is:


Where cc is a character expression that evaluates to one of the following values:

'LIST'One line feed between records (default)
'FORTRAN'Legacy interpretation of the first character (see below)
'NONE'No separator between records

With CARRIAGECONTROL='FORTRAN', when a record is written, the first character of the input record is not written, and instead determines the output record separator as follows:

Leading characterMeaningOutput separating character(s)
'+'OverprintingCarriage return only
'-'New lineLine feed and carriage return
'0'Skip lineTwo line feeds and carriage return
'1'New pageForm feed and carriage return
'$'PromptingLine feed (no carriage return)
CHAR(0)Overprinting (no advance)None

The READONLY specifier may be given upon opening a unit, and is equivalent to specifying ACTION='READ', except that the file may not be deleted on close (i.e. CLOSE with STATUS="DELETE"). The syntax is:


The SHARE specifier allows system-level locking on a unit upon opening it for controlled access from multiple processes/threads. The SHARE specifier has several forms:

OPEN(..., SHARE=sh)

Where sh in the first form is a character expression that evaluates to a value as seen in the table below. The latter two forms are aliases for particular values of sh:

Explicit formShort formMeaning
SHARE='DENYRW'NOSHAREDExclusive (write) lock
SHARE='DENYNONE'SHAREDShared (read) lock

In general only one process may hold an exclusive (write) lock for a given file at a time, whereas many processes may hold shared (read) locks for the same file.

The behavior of locking may vary with your operating system. On POSIX systems, locking is implemented with fcntl. Consult your corresponding operating system’s manual pages for further details. Locking via SHARE= is not supported on other systems.
