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 />

Description<br />

The WRITE statement transfers data from internal storage to an external or internal file. An<br />

external file can be opened for sequential access or direct access I/O. If it is opened for<br />

sequential access, the WRITE statement can perform the following types of I/O:<br />

464<br />

Formatted<br />

Unformatted<br />

List-directed<br />

Namelist-directed<br />

If the file is opened for direct access, the WRITE statement can perform formatted or<br />

unformatted I/O.<br />

WRITE statements operating on internal files can perform formatted or list-directed I/O.<br />

For detailed information about files and different types of I/O, see Chapter 8, “I/O and file<br />

handling,” on page 169.<br />

Examples<br />

The examples in this section illustrate different uses of the WRITE statement.<br />

Nonadvancing I/O<br />

CHARACTER(LEN=17) :: prompt = 'Enter a number: '<br />

WRITE (6, '(A)', ADVANCE='NO') prompt<br />

The WRITE statement outputs to the file connected to unit 6, which is preconnected to<br />

standard output. The ADVANCE='NO' specifier indicates the following:<br />

The file has been opened for formatted sequential I/O.<br />

The statement uses nonadvancing I/O to read an integer formatted as four characters into<br />

the variable prompt.<br />

TheeffectofthenonadvancingWRITE is to output the character string in prompt to standard<br />

output without a terminating newline. This means that anything subsequently entered by the<br />

user will appear on the same line.<br />

Internal file<br />

CHARACTER(LEN=80) :: cfile<br />

WRITE (cfile, '(I5, F10.5)') i, x<br />

The statement writes a string of characters into the internal file cfile, using the embedded<br />

format specification to perform the format conversion.<br />

Namelist-directed I/O<br />

Chapter 10

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

Saved successfully!

Ooh no, something went wrong!