Statement: Transfers output data to external sequential, direct-access, or internal records.
Syntax
Sequential
Formatted:
WRITE (eunit, format [, advance] [, asynchronous] [, id] [, iostat] [, err]) [io-list]
Formatted - List-Directed:
WRITE (eunit, * [, asynchronous] [, id] [, iostat] [, err]) [io-list]
Formatted - Namelist:
WRITE (eunit, nml-group [, asynchronous] [, id] [, iostat] [, err])
Unformatted:
WRITE (eunit [, asynchronous] [, id] [, iostat] [, err]) [io-list]
Direct-Access
Formatted:
WRITE (eunit, format, rec [, asynchronous] [, id] [, iostat] [, err]) [io-list]
Unformatted:
WRITE (eunit, rec [, asynchronous] [, id] [, 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'.
asynchronous
Is an asynchronous specifier (ASYNCHRONOUS=i-expr).
If the value of i-expr is 'YES', the statement uses asynchronous input; if the value is 'NO',
the statement uses synchronous input. The default value is 'NO'.
id
Is an id specifier (ID=id-var) that identifies a pending data transfer operation for the specified unit. If an id is specified, a wait
operation is performed for the operation. If it is omitted, wait operations are
performed for all pending data transfers for the specified unit. This specifier can only be used if the
value of ASYNCHRONOUS=i-expr 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. For more information, see Namelist 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 an item in io-list is an expression that calls a function, that function must not execute an I/O statement or the EOF intrinsic function on the same external unit as eunit.
See Also
I/O Lists, I/O Control List, Forms for Sequential WRITE Statements, Forms for Direct-Access WRITE Statements, Forms and Rules for Internal WRITE Statements, READ, PRINT, OPEN, I/O Formatting
Examples
! 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)
The following shows another example:
WRITE(6,'("Expected ",F12.6)') 2.0