02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

WRITE<br />

In the next example, each of the four WRITE statements following the NAMELIST statement<br />

usesadifferentstyleofsyntaxtodoexactlythesamething:<br />

NAMELIST /nl/ a, b, c<br />

WRITE (UNIT=6, NML=nl) ! 6 = standard output<br />

WRITE (6, nl)<br />

WRITE (*, NML=nl) ! * = standard output<br />

WRITE nl ! assume standard output<br />

List-directed I/O<br />

WRITE (6, *) int_var<br />

This statement converts the value of int_var to character format and outputs the character<br />

string to standard output. The format conversion is based on the type of int_var. If you knew<br />

the format, you could substitute for the asterisk one of the following:<br />

The label of the FORMAT statement with the format specification, as in:<br />

WRITE (6, 100) int_var<br />

100 FORMAT(I4)<br />

An embedded format specification itself, as in:<br />

WRITE (6, '(I4)') int_var<br />

Unformatted direct-access I/O<br />

WRITE (31, REC=rec_num, ERR=99, IOSTAT=ios) a, b<br />

This statement outputs to the file connected to unit 31. The REC= specifier indicates that the<br />

file has been opened for direct access and that this statement will output to the record whose<br />

number is stored in the variable rec_num. If an I/O error occurs during the execution of the<br />

statement, an error number will be stored in ios, and execution control will branch to the<br />

executable statement at label 99.<br />

Related statements<br />

CLOSE, OPEN, PRINT, andREAD<br />

Related concepts<br />

For information about I/O concepts, see Chapter 8, “I/O and file handling,” on page 169, which<br />

also lists example programs that use I/O. For information about I/O formatting, see<br />

Chapter 9, “I/O formatting,” on page 201.<br />

Chapter 10 465

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!