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.

OPEN (9, FILE='new_file')<br />

...<br />

! process file<br />

...<br />

! terminate connection<br />

CLOSE (9)<br />

Performing I/O on internal files<br />

I/O and file handling<br />

Connecting a file to a unit<br />

An internal file is not connected to a unit number and therefore does not require an OPEN<br />

statement. It is referenced as a character variable. In the following example, the WRITE<br />

statement transfers the data from char_var to the internal file int_file, using list-directed<br />

formatting. Because int_file is declared to be 80 characters long, it is assumed that the<br />

length of char_var will be no more than 80 characters.<br />

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

...<br />

WRITE (FILE=int_file, FMT=*) char_var<br />

For information about internal files, see “Internal files” on page 172.<br />

Preconnected unit numbers<br />

Unit numbers 5, 6, and 7 are preconnected; that is, they do not have to be explicitly opened<br />

and are connected to system-defined files, as follows:<br />

Unit 5 is connected to standard input—by default, the keyboard of the machine on which<br />

the program is running.<br />

Unit 6 is connected to standard output—by default, the terminal/display of the machine<br />

on which the program is running.<br />

Unit 7 is connected to standard error—by default, the terminal/display of the machine on<br />

which the program is running.<br />

Each predefined logical unit is automatically opened when a <strong>Fortran</strong> 90 program begins<br />

executing and remains open for the duration of the program. This means, for example, that<br />

standard output can be used by a PRINT statement without prior execution of an OPEN<br />

statement. Attempting to CLOSE a preconnected logical unit has no effect.<br />

A preconnected unit number can be reused with an OPEN statement that assigns it to a new<br />

file. Once a preconnected unit number is connected to a new file, however, it cannot be<br />

reconnected to its original designation.<br />

You can use the <strong>HP</strong>-UX input/output redirection (< and >) and piping (|) operators to redirect<br />

from standard input, standard output, or standard error to a file of your own choosing.<br />

Chapter 8 175

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

Saved successfully!

Ooh no, something went wrong!