WRITE (Sequential) - Fortran

The sequential WRITE statement transfers data to an external file or an internal file from the items specified by the output list.

The four types of sequential WRITE statements are

  1. formatted
  2. unformatted
  3. list-directed
  4. namelist-directed

Each of these statements is discussed in the following sections.
Execution of a WRITE statement for a file that does not exist creates the file.

Parameter Explanations

  • UNIT=unum is a unit or internal file to be acted on.
  • NML= group-name
  • is a namelist specifier.
    f is a format specifier.
    * is the list-directed output specifier.
  • REC=rn is a direct-access mode. rn is the number of the record to be accessed.
  • IOSTAT=rn is the name of a variable in which I/O completion status is posted.
  • ERR=s is a statement label to which control is transferred after an error.
  • iolist specifies a memory location from which data is written.

Formatted WRITE (Sequential)

WRITE ([UNIT=]unum,f[,IOSTAT=rn][,ERR=s]) [iolist]

Method of Operation
A formatted WRITE statement transfers data from internal storage to an external record using sequential-access mode. The WRITE operation translates the data from binary to character format using the f specifier to edit the data.

Unformatted WRITE (Sequential)

WRITE ([UNIT=]unum[,IOSTAT=rn][,ERR=s]) [iolist]

Method of Operation
An unformatted WRITE statement performs no translation on read-in data.
The data is read in directly to the items in iolist. The type of each data item in the input record must match that declared for the corresponding item in iolist.

When sequential-formatted WRITE is performed on a direct-access file, the next record in the file is assumed and the record is zero-padded to the end as if it were a direct, unformatted WRITE.

List-Directed WRITE

WRITE ([UNIT=]unum,*[,IOSTAT=rn][,ERR=s]) [iolist]

Method of Operation
A list-directed WRITE statement transfers data from internal storage to an external record using sequential-access mode. The WRITE operation translates the data from binary to character format using the data types of the items in iolist to edit the data.

Rules

  1. The item to be transferred to an external record can be a constant with a data type of integer, real, logical, complex, or character.
  2. The rules given in the previous section “Constants and Data Structures”, define the acceptable formats for constants in the external record, except character constant. A character constant does not require delimiting apostrophes; an apostrophe within a character string is represented by one apostrophes instead of two.
  3. Table below shows the data types and the defaults of their output format.

    Table: Default Formats of List-Directed Output

    Default Formats of List-Directed Output

  4. List-directed character output data cannot be read as list-directed input because of the use of apostrophes described above.
  5. A list-directed output statement can write one or more records. Position one of each record must contain a space (blank), which Fortran uses for a carriage-control character. Each value must be contained within a single record with the following exceptions:
    • A character constant longer than a record can be extended to a second record.
    • A complex constant can be split onto a second record after the comma.
  6. The output of a complex value contains no embedded spaces.
  7. Octal values, null values, slash separators, or the output of a constant or null value in the repetitive format n*constant or n*z cannot be generated by a list-directed output statement.

Namelist-Directed WRITE

Syntax

WRITE([UNIT=]unum,NML=group-name[,IOSTAT=rn][,ERR=s][,END=eof])

Method of Operation
A namelist-directed WRITE statement transfers data from internal storage to external records. It translates the data from internal to external format using the data type of the items in the corresponding NAMELIST statement. A namelist-directed READ or ACCEPT statement can read the output of a namelist-directed WRITE statement.

Rules for Use
Namelist items are written in the order that referenced NAMELIST defines them.

Examples for All Forms of Sequential WRITE
The following statement writes the prompt enter a filename to standard output:

write (*,105)
105 format (1x,'enter a filename')

The following statement opens the file %%temp and writes the record pair to the file.

open (unit=10, status='unknown',file="%%temp")
write (10,1910) pair
1910 format (A)

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Fortran Topics