LOGICAL Input

Problem Statement

Suppose we have an input organized as follows. The first line gives the number of lines, followed by that number of input lines. Each line is divided into two parts with 10 positions each. Each part contains a LOGICAL input.
         1    1    2    2
....5....0....5....0....5
4
  T         .TR
.TRUE.        Franco
February   Truman
  .FALSE.  fake
Write a Fortran program that reads in the above input, and prints the input values and the results of .OR., .AND., .NEQV. and .EQV. in the following form:
         1    1    2    2    3    3    4    4
....5....0....5....0....5....0....5....0....5
   Truth Table
   -----------

     P      Q    P | Q  P & Q  P ^ Q  P = Q
   -----  -----  -----  -----  -----  -----
       T      T      T      T      F      T
       T      F      T      F      T      F
       F      T      T      F      T      F
       F      F      F      F      F      T
We use |, &, ^ and = to indicate .OR., .AND., .NEQV. and .EQV., respectively. Note that the first position is always for printer control.

Solution

PROGRAM  Logical_Input
   IMPLICIT  NONE
   LOGICAL           :: P, Q
   INTEGER           :: i, Number

   WRITE(*,"(A, A)")  " ", "  Truth Table"
   WRITE(*,"(A, A)")  " ", "  -----------"
   WRITE(*,*)
   WRITE(*,"(A,A)")   " ", "    P      Q    P | Q  P & Q  P ^ Q  P = Q"
   WRITE(*,"(A,6A)")  " ", ("  -----", i = 1, 6)
   READ(*,"(I5)")  Number
   DO i = 1, Number
      READ(*,"(2L10)")  P, Q
      WRITE(*,"(A, 6L7)")  " ", P, Q, &
                           P .OR. Q, P .AND. Q, P .NEQV. Q, P .EQV. Q
   END DO
END PROGRAM  Logical_Input
Click here to download this program.

Program Input and Output

The output of the program is:
         1    1    2    2    3    3    4    4
....5....0....5....0....5....0....5....0....5
   Truth Table
   -----------

     P      Q    P | Q  P & Q  P ^ Q  P = Q
   -----  -----  -----  -----  -----  -----
       T      T      T      T      F      T
       T      F      T      F      T      F
       F      T      T      F      T      F
       F      F      F      F      F      T

Discussion