Lahey/Fujitsu Fortran

WRITE Statement

Description

The WRITE statement transfers values to an input/output unit from entities specified in an output list or a namelist group.

Syntax

WRITE (io-control-specs) [outputs]
Where:

outputs is a comma-separated list of expr or io-implied-do

expr is a variable.

io-implied-do is (outputs, implied-do-control)

implied-do-control is do-variable=start, end [, increment]

start, end, and increment are scalar INTEGER expressions

do-variable is a scalar variable of type INTEGER

io-control-specs is a comma-separated list of:

[UNIT =] io-unit [FMT =] format [NML =] namelist-group-name REC=record IOSTAT=stat ERR=errlabel END=endlabel EOR=eorlabel ADVANCE=advance SIZE=size

io-unit is an external file unit, or *

format is a format specification (see Input/Output Editing).

namelist-group-name is the name of a namelist group.

record is the number of the direct-access record that is to be written.

stat is a scalar default INTEGER variable that is assigned a positive value if an error condition occurs and zero otherwise.

errlabel is a label that is branched to if an error condition occurs and no end-of-record condition or end-of-file condition occurs during execution of the statement.

endlabel is a label that is branched to if an end-of-file condition occurs and no error condition occurs during execution of the statement.

eorlabel is a label that is branched to if an end-of-record condition occurs and no error condition or end-of-file condition occurs during execution of the statement.

advance is a scalar default CHARACTER expression that evaluates to NO if non-advancing input/output is to occur, and YES if advancing input/output is to occur. The default value is YES.

size is a scalar default INTEGER variable that is assigned the number of characters transferred by data edit descriptors during execution of the current non-advancing input/output statement.

Remarks

If the optional characters UNIT= are omitted before io-unit, io-unit must be the first item in io-control-specs. If the optional characters FMT= are omitted before format, format must be the second item in io-control-specs. If the optional characters NML= are omitted before namelist-group-name, namelist-group-name must be the second item in io-control-specs.

io-control-specs must contain exactly one io-unit, and must not contain both a format and a namelist-group-name.

A namelist-group-name must not appear if outputs is present.

If io-unit is an internal file, io-control-specs must not contain a REC= specifier or a namelist-group-name.

If the file is open for DIRECT, BINARY or TRANSPARENT access, an END= specifier must not appear, a namelist-group-name must not appear, and format must not be an asterisk indicating list-directed I/O.

An ADVANCE= specifier can appear only in formatted sequential I/O with an explicit format specification (format-expr) whose control list does not contain an internal file specifier. If an EOR= or SIZE= specifier is present, an ADVANCE= specifier must also appear with the value NO.

The do-variable of an implied-do-control that is contained within another io-implied-do must not appear as the do-variable of the containing io-implied-do.

If an array appears as an output item, it is treated as if the elements were specified in array-element order.

If a derived type object appears as an output item, it is treated as if all of the components were specified in the same order as in the definition of the derived type.

Example

character(len=30) :: intfile integer :: ios,i=1,j=1,k=1 real :: a=1.,b=1.,c=1. write (*,*) a,b,c ! write values to stdout ! using list directed i/o write(3,"(3i10)") i,j,k ! write to unit 3 using format write(10,*) i,j,k ! write stdout using format 10 format(3i10) write(11) a,b,c ! write unformatted data to unit 11 write(intfile,10) i,j,k ! write internal file write(12, rec=2) a,b,c ! write direct access file write(13,10,err=20) i,j ! write with error branch 20 write(13,10,iostat=ios) a ! write with status return write(13,10,advance='no') i,j ! next write on same line