next up previous contents
Next: Subprograms Up: Introduction to FORTRAN Previous: I/O

   
LOGICAL Data

FORTRAN supports LOGICAL data. This only has two values - true and false. The constants are coded .TRUE. and .FALSE. Like CHARACTER data, all variables and arrays must be explicitly declared e.g:-
LOGICAL TEST,FLAGS(20)
Assignments now involve logical expressions, so the following are all legal:-

    TEST=.TRUE.
    FLAGS(4)=.FALSE.
    FLAGS(7)=A.GT.B
    FlAGS(9)=.NOT.TEST
    FLAGS(13)=2.*X.LT.Y.AND.TEST
The last assignment sets FLAGS(13) to .TRUE. if 2.*X is less than Y and TEST is .TRUE. otherwise it is set to .FALSE. Logical data can be used wherever logical expressions are required e.g.:-

 
    IF (FLAGS(9)) GOTO 100
    IF (I.EQ.J+2.AND..NOT.TEST) X=X+1.0

I/O using FORMATS use the L field descriptor. The first non-blank characters in the field on input must be T, t, .T or .t for .TRUE. and F, f, .F or .f for .FALSE. On the output the letter T or F is right justified and padded with spaces.



n west (APC)
2000-03-08