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

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

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

Program Structure Control Statements<br />

Example:<br />

LOOP : PRLOOP<br />

GUESS<br />

LINE = LINE + 1<br />

READ *, ICODE, X<br />

AT END, QUIT :PRLOOP<br />

IF( ICODE .NE. 1 )QUIT<br />

LINE = LINE + 1<br />

READ *, ICODE, Y<br />

AT END, QUIT<br />

IF( ICODE .NE. 2 )QUIT<br />

PRINT *, X, Y<br />

CALL PROCES(X, Y)<br />

ADMIT<br />

PRINT *, ’INVALID SEQUENCE: LINE =’, LINE<br />

QUIT :PRLOOP<br />

END GUESS<br />

END LOOP<br />

The above example attempts to read a code and number. If an end of file occurs then the loop is terminated<br />

by the QUIT statement.<br />

If the code is not 1 then we did not get what we expected and an error situation has arisen. Control is<br />

passed to the statement following the ADMIT statement. An error message is printed and the loop is<br />

terminated by the QUIT statement.<br />

If the code is 1 then a second code and number are read. If an end of file occurs then we are missing a set<br />

of data and an error situation has arisen. Control is passed to the statement following the ADMIT statement.<br />

An error message is printed and the loop is terminated by the QUIT statement. Similarly if the expected<br />

code is not 2 an error situation has arisen. Control is passed to the statement following the ADMIT<br />

statement. An error message is printed and the loop is terminated by the QUIT statement.<br />

If the second code is 2, the values of variables X and Y are printed. A subroutine is then called to process<br />

the data. Control resumes at the statement following the END GUESS statement. Since this statement is an<br />

END LOOP, control is transferred to the beginning of the loop.<br />

The above example illustrates the point that all the information required to make a choice (in this case<br />

between a valid set of data and an invalid set) is not available from the beginning. In this case we make an<br />

assumption that the data values are correct (our hypothesis) and then test the assumption at various points in<br />

the algorithm. If any of the tests fail we reject the hypothesis (and, perhaps, select a new hypothesis).<br />

It should be noted that no alternative selection need be coded (i.e., we need not use any ADMIT-blocks).<br />

This is illustrated in the following example.<br />

Example:<br />

GUESS<br />

X=SQRT( X )<br />

IF( X .LT. EPS )QUIT<br />

X=Y+SQRT(Y)<br />

IF( X .LT. EPS )QUIT<br />

CALL INTGRT( X, Y )<br />

END GUESS<br />

It might be noted that the IF-ELSE-END IF construct is simply a specific instance of the more general<br />

GUESS-ADMIT-END GUESS construct wherein the data values are known beforehand (as could be<br />

illustrated using the previous example).<br />

GUESS-ADMIT-END GUESS 207

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

Saved successfully!

Ooh no, something went wrong!