24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Input/Output<br />

Although <strong>FORTRAN</strong> <strong>77</strong> states that list-directed formatted input/output to an internal file is<br />

not permitted, <strong>Open</strong> <strong>Watcom</strong> <strong>FORTRAN</strong> <strong>77</strong> allows you to use list-directed formatted<br />

input/output statements. This is an extension to the language standard.<br />

Example:<br />

WRITE(INTFIL,*) X, Y, Z<br />

No other input/output statements ( OPEN, ENDFILE, REWIND, etc.) may be used.<br />

Internal files may be used to convert data from one format to another. The following example illustrates<br />

one use of internal files.<br />

Example:<br />

CHARACTER*11 INPUT<br />

PRINT *, ’TYPE IN ’’I’’ FOLLOWED BY AN INTEGER’<br />

PRINT *, ’OR TYPE IN ’’R’’ FOLLOWED BY A REAL’<br />

READ 100, INPUT<br />

100 FORMAT( A11 )<br />

IF( INPUT(1:1) .EQ. ’I’ )THEN<br />

READ( UNIT=INPUT(2:11), FMT=’(I10)’ ) IVAR<br />

PRINT *, ’AN INTEGER WAS ENTERED ’, IVAR<br />

ELSE IF( INPUT(1:1) .EQ. ’R’ )THEN<br />

READ( UNIT=INPUT(2:11), FMT=’(F10.3)’ ) RVAR<br />

PRINT *, ’A REAL NUMBER WAS ENTERED ’, RVAR<br />

END IF<br />

END<br />

After checking for an "I" or "R" as the first character of the character variable INPUT, the appropriate<br />

internal READ statement is executed.<br />

10.5 Units<br />

Many <strong>FORTRAN</strong> <strong>77</strong> input/output statements refer to external files using a mechanism called the unit.<br />

There are many units available to the <strong>FORTRAN</strong> <strong>77</strong> programmer. <strong>Open</strong> <strong>Watcom</strong> <strong>FORTRAN</strong> <strong>77</strong> numbers<br />

these units from 0 to 999; thus the unit number is a non-negative integer less than 1000.<br />

A unit may be associated with a particular file. This association is called connection. Any unit may or may<br />

not be connected to a file. There are a number of ways in which this connection may be established.<br />

A unit may be preconnected to a file before execution of a program begins. The User’s Guide describes the<br />

mechanism for preconnecting a unit to a file.<br />

Alternatively, a unit may become connected to a file by the execution of an OPEN statement.<br />

All input/output statements except OPEN, CLOSE, and INQUIRE must refer to a unit that is connected to<br />

a file. <strong>Open</strong> <strong>Watcom</strong> <strong>FORTRAN</strong> <strong>77</strong> automatically establishes a connection of the unit to a file if no<br />

connection previously existed. Consider the following example in which unit number 1 is not previously<br />

connected to a file.<br />

Units 219

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

Saved successfully!

Ooh no, something went wrong!