      PROGRAM PROB07
C
C     PROBLEM 07
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,NK,MK
      PARAMETER (KASES=3)
      INTEGER N(KASES),M(KASES)
      DATA N /3,5,10/
      DATA M /2048,16384,32768/
      REAL P(4)
      REAL TARRAY(2),TIME1,TIME2

      DO 50 K =  1, KASES

      NK=N(K)
      DO 40 I = 1, KASES

      TIME1=DTIME(TARRAY)
      DO MANY=1,50
      MK=M(I)
      CALL DOIT(NK,MK,P)
      ENDDO
      TIME2=DTIME(TARRAY)

      PRINT *,'PROBLEM 7 WITH N,M =',NK,MK
         WRITE (6,*) 'GIVES P(',P(1),')  =',P(2)
         WRITE (6,*) 'AND   P(',P(3),')  =',P(4)

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

   40 CONTINUE
   50 CONTINUE
      STOP
      END

      SUBROUTINE DOIT(NK,MK,P)
      INTEGER NK,MK
      REAL P(4)
      REAL DX
      INTEGER NMAX,MMAX,I,J,K
      PARAMETER (NMAX=10)
      PARAMETER (MMAX=131072)
      DIMENSION XI(NMAX),XL(NMAX)
      DIMENSION TEMP(NMAX),TAMP(NMAX),TUMP(NMAX)
      DIMENSION X(MMAX)
      REAL DENOM(NMAX)
      REAL TP

         DO I = 1, NK
         XI(I)=FLOAT(I-1)
         ENDDO

         DX=XI(NK)/MK
         DO K = 1, MK
            X(K)=0.5+(K-1)*DX
         ENDDO
         P(1)=X(1)
         P(3)=X(MK)
C
C               DENOMINATOR
C
         DO I = 1, NK
            TEMP(I) = 1.
            DENOM(I) = 1.0
            DO  J = 1, NK
               IF (J.NE.I) THEN
                  TEMP(J) = XI(I)-XI(J)
                  DENOM(I) = DENOM(I)*TEMP(J)
               ENDIF
             ENDDO

C
C       NOTE: THE DENOMINATOR IS INVERTED HERE SO THAT A MULTIPLICATION
C               CAN BE DONE LATER
C
            DENOM(I) = 1.0/DENOM(I)
         ENDDO

         DO K = 1, MK
            DO  I = 1, NK
               DO J = 1, NK
                  IF (J.NE.I) THEN
                     TAMP(J) = X(K)-XI(J)
                  ENDIF
               ENDDO
               TAMP(I) = 1.0
               PTAMP = 1.0
               DO  J = 1, NK
                  PTAMP = PTAMP*TAMP(J)
              ENDDO

               XL(I) = PTAMP*DENOM(I)
            ENDDO

            TP = 0
            DO I = 1, NK
               TUMP(I) = F(XI(I))*XL(I)
               TP = TP+TUMP(I)
               IF(K.EQ.1) P(2)=TP
               IF(K.EQ.MK) P(4)=TP
           ENDDO
         ENDDO


      RETURN
      END

      FUNCTION F (X)
      F = X**2-3.0*X-4.0
c      F=EXP(X)
      RETURN
      END












