WRITE

Statement: Transfers output data to external sequential, direct-access, or internal records.

Syntax

Sequential

Formatted:

WRITE (eunit, format [, advance] [, iostat] [, err]) [io-list]

Formatted - List-Directed:

WRITE (eunit, * [, iostat] [, err]) [io-list]

Formatted - Namelist:

WRITE (eunit, nml-group [, iostat] [, err])

Unformatted:

WRITE (eunit [, iostat] [, err]) [io-list]

Direct-Access

Formatted:

WRITE (eunit, format, rec [, iostat] [, err]) [io-list]

Unformatted:

WRITE (eunit, rec [, iostat] [, err]) [io-list]

Indexed (VMS only)

Formatted:

WRITE (eunit, format, [, iostat] [, err]) [io-list]

Unformatted:

WRITE (eunit, [, iostat] [, err]) [io-list]

Internal

WRITE (iunit, format [, iostat] [, err]) [io-list]

eunit
Is an external unit specifier, optionally prefaced by UNIT=. UNIT= is required if eunit is not the first specifier in the list.

format
Is a format specifier. It is optionally prefaced by FMT= if format is the second specifier in the list and the first specifier indicates a logical or internal unit specifier without the optional keyword UNIT=.

For internal WRITEs, an asterisk (*) indicates list-directed formatting. For direct-access WRITEs, an asterisk is not permitted.

advance
Is an advance specifier (ADVANCE=c-expr). If the value of c-expr is 'YES', the statement uses advancing input; if the value is 'NO', the statement uses nonadvancing input. The default value is 'YES'.

iostat
Is the name of a variable to contain the completion status of the I/O operation. Optionally prefaced by IOSTAT=.

err
Are branch specifiers if an error (ERR=label) condition occurs.

io-list
Is an I/O list: the names of the variables, arrays, array elements, or character substrings from which or to which data will be transferred. Optionally an implied-DO list.

form
Is the nonkeyword form of a format specifier (no FMT=).

*
Is the format specifier indicating list-directed formatting. (It can also be specified as FMT=*.)

nml-group
Is the namelist group specification for namelist I/O. Optionally prefaced by NML=. NML= is required if nml-group is not the second I/O specifier.

rec
Is the cell number of a record to be accessed directly. Optionally prefaced by REC=.

iunit
Is an internal unit specifier, optionally prefaced by UNIT=. UNIT= is required if iunit is not the first specifier in the list.

It must be a character variable. It must not be an array section with a vector subscript.

If a parameter of the WRITE statement is an expression that calls a function, that function must not execute an I/O statement or the EOF intrinsic function, because the results are unpredictable.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: I/O Lists, I/O Control List, Forms for Sequential WRITE Statements, Forms for Direct-Access WRITE Statements, Forms for Indexed WRITE Statements (VMS only), Forms and Rules for Internal WRITE Statements, READ, PRINT, OPEN, I/O Formatting

Example

 ! write to file
 open(1,FILE='test.dat')
 write (1, '(A20)') namedef
 ! write with FORMAT statement
 WRITE (*, 10) (n, SQRT(FLOAT(n)), FLOAT(n)**(1.0/3.0), n = 1, 100)
 10 FORMAT (I5, F8.4, F8.5)
 !
 WRITE(6,'("Expected ",F12.6)') 2.0