      PROGRAM POLLUT
************************************************************************
* This program reads the entries of the two-dimensional array  POLTAB  *
* from a file and produces a report showing a table of pollution       *
* levels, the average pollution level for each day, and the average    *
* pollution level for each sampling time.  Identifiers used are:       *
*     NDAYS   : parameter giving the number of rows (days)             *
*     NTIMES  : parameter giving the number of columns (times)         *
*     POLTAB  : an NDAYS X NTIMES array of pollution levels            *
*     DAY,TIME: row, column subscripts                                 *
*     SUM     : variable used in accumulating row & column sums        *
*                                                                      *
* Input (file):    the pollution levels                                *
* Output (screen): the array POLTAB in table format, the average       *
*                  pollution level for each day, and the average       *
*                  pollution level for each sampling time              *
************************************************************************

      INTEGER NDAYS, NTIMES
      PARAMETER (NDAYS = 7, NTIMES = 12)
      INTEGER POLTAB(NDAYS,NTIMES), DAY, TIME
      REAL SUM

* Read in the pollution levels and display them in a table
* of the required form

      OPEN (UNIT = 15, FILE = 'FIL8-5.DAT', STATUS = 'OLD')
      READ (15,*) ((POLTAB(DAY,TIME), TIME = 1, NTIMES), DAY = 1, NDAYS)
      PRINT 100, (TIME, TIME = 1, NTIMES)
100   FORMAT(T30, 'TIME' / 1X, 'DAY:', 12I4 / 1X, 53('-'))
      PRINT 110,
     +    (DAY, (POLTAB(DAY,TIME), TIME = 1, NTIMES), DAY = 1, NDAYS)
110   FORMAT(1X, I2, ' :', 12I4)

* Calculate average pollution level for each day (row averages)

      PRINT *
      DO 20 DAY = 1, NDAYS
          SUM = 0
          DO 10 TIME = 1, NTIMES
              SUM = SUM + POLTAB(DAY,TIME)
10        CONTINUE
          PRINT 120, 'FOR DAY', DAY, SUM / REAL(NTIMES)
120       FORMAT(1X, 'AVERAGE POLLUTION LEVEL ', A7, I3, ':', F6.1)
20    CONTINUE

* Calculate average pollution level for each time (column averages)

      PRINT *
      DO 40 TIME = 1, NTIMES
          SUM = 0
          DO 30 DAY = 1, NDAYS
              SUM = SUM + POLTAB(DAY,TIME)
30        CONTINUE
          PRINT 120, 'AT TIME', TIME, SUM / REAL(NDAYS)
40    CONTINUE
      CLOSE (15)
      END
