      PROGRAM PROB05
C
C     PROBLEM 5
C
C  REFERENCE:  PROBLEMS TO TEST PARALLEL AND VECTOR LANGUAGES
C              CSD-TR 516, COMPUTER SCIENCE, PURDUE UNIVERSITY
C              JOHN R. RICE, MAY 1, 1985
C
C              REVISED BY JOHN R. RICE AND J. JING, OCT. 1, 1990
C
C
C      *************************************************
C      *      Adapted for FORTRAN D benchmarking       *
C      *    by  T. HAUPT  (haupt@sccs.npac.syr.edu)    *
C      *                                               *
C      *    Northeast Parallel Architectures Center    *
C      *   at Syracuse University, Syracuse, NY, USA   *
C      *************************************************
C
C
C       VERSION SEQUENTIAL-1.00  (PLAIN FORTRAN77)
C       ==================================================
      INTEGER KASES,NS,NT
      PARAMETER (KASES=5)
      INTEGER N(KASES),M(KASES)
      DATA N / 64,1024,64,256,128 /
      DATA M / 128,64,1024,256,4092 /
      INTEGER NABOVE
      REAL AVER,AVERTOP,LOWABO
      LOGICAL GENIUS
      REAL TARRAY(2),TIME1,TIME2

      DO 50 K = 1, KASES

      TIME1=DTIME(TARRAY)

      DO MANY=1,200
      NS=N(K)
      NT=M(K)
      CALL DOIT(NS,NT,AVER,AVERTOP,GENIUS,NABOVE,LOWABO)

      ENDDO
      TIME2=DTIME(TARRAY)

      PRINT 60, NS,NT
  60  FORMAT ('PROBLEM 5 WITH ',I6,' STUDENTS AND ',I6,' TESTS')
      PRINT *,'AVERAGE TEST SCORE .....:',AVER
      PRINT *,'# SCORES ABOVE AVERAGE..:',NABOVE
      PRINT *,'AVERAGE ABOVE ..........:',AVERTOP
      PRINT *,'LOWEST SCORE ABOVE .....:',LOWABO
      PRINT *,'THERE IS GENIUS ........:',GENIUS

      PRINT *, 'TIME',TIME2,' SECONDS'
      PRINT *, 'USER:',TARRAY(1),' SYSTEM:',TARRAY(2)

   50 CONTINUE

      STOP
      END

      SUBROUTINE DOIT(NS,NT,AVER,AVERTOP,GENIUS,NABOVE,LOWABO)
      INTEGER NABOVE
      REAL AVER,AVERTOP,LOWABO
      LOGICAL GENIUS
      INTEGER NTDIM,NSDIM
      PARAMETER (NTDIM = 4092)
      PARAMETER (NSDIM = 1024)
      DIMENSION SCORES(NTDIM,NSDIM)
      REAL SSUM
      LOGICAL GEN

      DO 10 I = 1, NT
         DO 10 J = 1, NS
            SCORES(I,J) = 60.+40.*SIN(I*J*0.0006321)
   10 CONTINUE


         NABOVE = 0
         LOWABO = 9.9E10
         AVERTOP = 0.0
         SSUM = 0.0
         DO 30 I = 1, NT
            DO 30 J = 1, NS
               SSUM = SSUM+SCORES(I,J)
   30    CONTINUE
         AVER = SSUM/(NS*NT)

         GENIUS=.FALSE.
         DO J = 1, NS
           GEN=.TRUE.
           DO I = 1, NT
              IF(SCORES(I,J).GT.AVER) THEN
                NABOVE=NABOVE+1
                SCORES(I,J)=SCORES(I,J)*1.1
                AVERTOP=AVERTOP+SCORES(I,J)
                IF(SCORES(I,J).LT.LOWABO) LOWABO=SCORES(I,J)
              ELSE
                GEN=.FALSE.
              ENDIF
           ENDDO
         GENIUS=GENIUS.OR.GEN
         ENDDO
         AVERTOP=AVERTOP/NABOVE

      RETURN
      END



