HP Fortran for OpenVMS
Language Reference Manual


Previous Contents Index

Each output statement writes one or more complete records.

A literal character constant or complex constant can be longer than an entire record. In the case of complex constants, the end of the record can occur between the comma and the imaginary part, if the imaginary part and closing right parenthesis cannot fit in the current record.

Each output record begins with a blank character for carriage control, except for literal character constants that are continued from the previous record.

Slashes, octal values, null values, and repeated forms of values are not output.

If the file is connected for unformatted I/O, list-directed data transfer is prohibited.

Examples

Suppose the following statements are specified:


DIMENSION A(4) 
DATA A/4*3.4/ 
WRITE (1,*) 'ARRAY VALUES FOLLOW' 
WRITE (1,*) A,4 

The following records are then written to external unit 1:


ARRAY VALUES FOLLOW 
   3.400000      3.400000      3.400000      3.400000      4 

For More Information:

10.5.1.3 Rules for Namelist Sequential WRITE Statements

Namelist, sequential WRITE statements translate data from internal to external form by using the data types of the objects in the corresponding NAMELIST statement to determine the form of the data. The translated data is then written to an external file.

In general, values transferred as output have the same forms as values transferred as input.

By default, character constants are not delimited by apostrophes or quotation marks, and each internal apostrophe or quotation mark is represented externally by one apostrophe or quotation mark.

This behavior can be changed by the DELIM specifier (in an OPEN statement) as follows:

Each output statement writes one or more complete records.

A literal character constant or complex constant can be longer than an entire record. In the case of complex constants, the end of the record can occur between the comma and the imaginary part, if the imaginary part and closing right parenthesis cannot fit in the current record.

Each output record begins with a blank character for carriage control, except for literal character constants that are continued from the previous record.

Slashes, octal values, null values, and repeated forms of values are not output.

If the file is connected for unformatted I/O, namelist data transfer is prohibited.

Examples

Consider the following statements:


CHARACTER*19 NAME(2)/2*' '/ 
REAL PITCH, ROLL, YAW, POSITION(3) 
LOGICAL DIAGNOSTICS 
INTEGER ITERATIONS 
NAMELIST /PARAM/ NAME, PITCH, ROLL, YAW, POSITION,        & 
         DIAGNOSTICS, ITERATIONS 
... 
READ (UNIT=1,NML=PARAM) 
WRITE (UNIT=2,NML=PARAM) 

Suppose the following input is read:


&PARAM 
    NAME(2)(10:)='HEISENBERG', 
    PITCH=5.0, YAW=0.0, ROLL=5.0, 
    DIAGNOSTICS=.TRUE. 
    ITERATIONS=10 
/ 

The following is then written to the file connected to unit 2:


&PARAM 
NAME   = '                         ', '        HEISENBERG', 
PITCH  =    5.000000    , 
ROLL   =    5.000000    , 
YAW    =   0.0000000E+00, 
POSITION        = 3*0.0000000E+00, 
DIAGNOSTICS     = T, 
ITERATIONS      =                10 
/ 

Note that character values are not enclosed in apostrophes unless the output file is opened with DELIM= ' APOSTROPHE ' . The value of POSITION is not defined in the namelist input, so the current value of POSITION is written.

For More Information:

10.5.1.4 Rules for Unformatted Sequential WRITE Statements

Unformatted, sequential WRITE statements transfer binary data (without translation) between the entities specified in the I/O list and the current record. Only one record is written.

Objects of intrinsic or derived types can be transferred.

This form of WRITE statement writes exactly one record. If there is no I/O item list, the statement writes one null record.

If the file is connected for formatted, list-directed, or namelist I/O, unformatted data transfer is prohibited.

Examples

The following example shows an unformatted, sequential WRITE statement:


WRITE (UNIT=6, IOSTAT=IO_STATUS) A, B, C 

10.5.2 Forms for Direct-Access WRITE Statements

Direct-access WRITE statements transfer output data to external records with direct access. (The attributes of a direct-access file are established by the OPEN statement.)

A direct-access WRITE statement can be formatted or unformatted, and takes one of the following forms:

Formatted

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

Unformatted

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

eunit

Is an external unit specifier ([UNIT=]io-unit).

format

Is a format specifier ([FMT=]format). It must not be an asterisk (*).

rec

Is a record specifier (REC=r).

iostat

Is a status specifier (IOSTAT=i-var).

err

Is a branch specifier (ERR=label) if an error condition occurs.

io-list

Is an I/O list.

For More Information:

10.5.2.1 Rules for Formatted Direct-Access WRITE Statements

Formatted, direct-access WRITE statements translate data from binary to character form by using format specifications for editing (if any). The translated data is written to an external file that is connected for direct access.

Values can be transferred from objects of intrinsic or derived types. For derived types, values of intrinsic types are transferred from the components of intrinsic types that ultimately make up these structured objects.

If the values specified by the I/O list do not fill a record, blank characters are added to fill the record. If the I/O list specifies too many characters for the record, an error occurs.

If the format specification specifies another record, the record number is increased by 1 as each subsequent record is written by that output statement.

Examples

The following example shows a formatted, direct-access WRITE statement:


WRITE (2, REC=35, FMT=10) (NUM(K), K=1,10) 

10.5.2.2 Rules for Unformatted Direct-Access WRITE Statements

Unformatted, direct-access WRITE statements transfer binary data (without translation) between the entities specified in the I/O list and the current record. Only one record is written.

Objects of intrinsic or derived types can be transferred.

If the values specified by the I/O list do not fill a record, blank characters are added to fill the record. If the I/O list specifies too many characters for the record, an error occurs.

If the file is connected for formatted, list-directed, or namelist I/O, unformatted data transfer is prohibited.

Examples

The following example shows unformatted, direct-access WRITE statements:


WRITE (1, REC=10) LIST(1), LIST(8) 
WRITE (4, REC=58, IOSTAT=K, ERR=500) (RHO(N), N=1,5) 

10.5.3 Forms for Indexed WRITE Statements

Indexed WRITE statements transfer output data to external records that have keyed access. (The OPEN statement establishes the attributes of an indexed file.)

Indexed WRITE statements always write a new record. You should use the REWRITE statement to update an existing record.

The syntax of an indexed WRITE statement is similar to a sequential WRITE statement, but an indexed WRITE statement refers to an I/O unit connected to an indexed file, whereas the sequential WRITE statement refers to an I/O unit connected to a sequential file.

An indexed WRITE statement can be formatted or unformatted, and takes one of the following forms:

Formatted

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

Unformatted

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

eunit

Is an external unit specifier ([UNIT=]io-unit).

format

Is a format specifier ([FMT=]format).

iostat

Is a status specifier (IOSTAT=i-var).

err

Is a branch specifier (ERR=label) if an error condition occurs.

io-list

Is an I/O list.

For More Information:

10.5.3.1 Rules for Formatted Indexed WRITE Statements

Formatted, indexed WRITE statements translate data from binary to character form by using format specifications for editing (if any). The translated data is written to an external file that is connected for keyed access.

No key parameters are required in the list of control parameters, because all necessary key information is contained in the output record.

When you use a formatted indexed WRITE statement to write an INTEGER key, the key is translated from internal binary form to external character form. A subsequent attempt to read the record by using an integer key may not match the key field in the record.

If the file is connected for unformatted I/O, formatted data transfer is prohibited.

Examples

Consider the following example (which assumes that the first 10 bytes of a record are a character key):


      WRITE (4,100) KEYVAL, (RDATA(I), I=1, 20) 
100   FORMAT (A10, 20F15.7) 

The WRITE statement writes the translated values of each of the 20 elements of the array RDATA to a new formatted record in the indexed file connected to I/O unit 4. KEYVAL is the key by which the record is accessed.

10.5.3.2 Rules for Unformatted Indexed WRITE Statements

Unformatted, indexed WRITE statements transfer binary data (without translation) between the entities specified in the I/O list and the current record.

No key parameters are required in the list of control parameters, because all necessary key information is contained in the output record.

If the values specified by the I/O list do not fill a fixed-length record being written, the unused portion of the record is filled with zeros. If the values specified do not fit in the record, an error occurs.

Since derived data types of sequence type usually have a fixed record format, you can write to indexed files by using a sequence derived-type structure that models the file's record format. This lets you perform the I/O operation with a single derived-type variable instead of a potentially long I/O list. Nonsequence derived types should not be used for this purpose.

If the file is connected for formatted I/O, unformatted data transfer is prohibited.

Examples

The following example shows an unformatted, indexed WRITE statement:


WRITE (UNIT=8, IOSTAT=IO_STATUS) A, B, C 

10.5.4 Forms and Rules for Internal WRITE Statements

Internal WRITE statements transfer output data to an internal file.

An internal WRITE statement can only be formatted. It must include format specifiers (which can use list-directed formatting). Namelist formatting is not permitted.

An internal WRITE statement takes the following form:

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

iunit

Is an internal unit specifier ([UNIT=]io-unit). It must be a default character variable. It must not be an array section with a vector subscript.

format

Is a format specifier ([FMT=]format). An asterisk (*) indicates list-directed formatting.

iostat

Is a status specifier (IOSTAT=i-var).

err

Is a branch specifier (ERR=label) if an error condition occurs.

io-list

Is an I/O list.

Formatted, internal WRITE statements translate data from binary to character form by using format specifications for editing (if any). The translated data is written to an internal file.

Values can be transferred from objects of intrinsic or derived types. For derived types, values of intrinsic types are transferred from the components of intrinsic types that ultimately make up these structured objects.

If the number of characters written in a record is less than the length of the record, the rest of the record is filled with blanks. The number of characters to be written must not exceed the length of the record.

Character constants are not delimited by apostrophes or quotation marks, and each internal apostrophe or quotation mark is represented externally by one apostrophe or quotation mark.

Examples

The following example shows an internal WRITE statement:


INTEGER J, K, STAT_VALUE 
CHARACTER*50 CHAR_50 
... 
WRITE (FMT=*, UNIT=CHAR_50, IOSTAT=STAT_VALUE) J, K 

For More Information:

10.6 PRINT and TYPE Statements

The PRINT statement is a data transfer output statement. TYPE is a synonym for PRINT. All forms and rules for the PRINT statement also apply to the TYPE statement.

The PRINT statement is the same as a formatted, sequential WRITE statement, except that the PRINT statement must never transfer data to user-specified I/O units.

A PRINT statement takes one of the following forms:

Formatted

  • PRINT form [,io-list]

Formatted: List-Directed

  • PRINT * [,io-list]

Formatted: Namelist

  • PRINT nml

form

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

io-list

Is an I/O list.

*

Is the format specifier indicating list-directed formatting.

nml

Is the nonkeyword form of a namelist specifier (no NML=) indicating namelist formatting.

Examples

In the following example, one record (containing four fields of data) is printed to the implicit output device:


      CHARACTER*16 NAME, JOB 
      PRINT 400, NAME, JOB 
400   FORMAT ('NAME=', A, 'JOB=', A) 

For More Information:

10.7 REWRITE Statement

The REWRITE statement is a data transfer output statement that rewrites the current record.

A REWRITE statement can be formatted or unformatted, and takes one of the following forms:

Formatted

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

Unformatted

  • REWRITE (eunit [,iostat] [,err]) [io-list]

eunit

Is an external unit specifier ([UNIT=]io-unit).

format

Is a format specifier ([FMT=]format).

iostat

Is a status specifier (IOSTAT=i-var).

err

Is a branch specifier (ERR=label) if an error condition occurs.

io-list

Is an I/O list.

In the REWRITE statement, data (translated if formatted; untranslated if unformatted) is written to the current (existing) record in one of the following types of external files:

The current record is the last record accessed by a preceding, successful sequential, indexed, or direct-access READ statement.

Between a READ and REWRITE statement, you should not specify any other I/O statement (except INQUIRE) on that logical unit. Execution of any other I/O statement on the logical unit destroys the current-record context and causes the current record to become undefined.

Only one record can be rewritten in a single REWRITE statement operation.

The output list (and format specification, if any) must not specify more characters for a record than the record size. (Record size is specified by RECL in an OPEN statement.)

If the number of characters specified by the I/O list (and format, if any) do not fill a record, blank characters are added to fill the record.

If the primary key value is changed in a keyed-access file, an error occurs.

Examples

In the following example, the current record (contained in the relative organization file connected to logical unit 3) is updated with the values represented by NAME, AGE, and BIRTH:


      REWRITE (3, 10, ERR=99) NAME, AGE, BIRTH 
10    FORMAT (A16, I2, A8) 

For More Information:


Previous Next Contents Index