      PROGRAM PROB15
C
C     PROBLEM 15
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
      PARAMETER (KASES=2)
      INTEGER N(KASES)
      DATA N /8192,16384/
      INTEGER NK,NPTS
      PARAMETER(NPTS=10)
      REAL ERRMAX(NPTS,2),DECAY(NPTS,2)
      REAL TARRAY(2),TIME1,TIME2

      DO 50 K = 1, KASES

      TIME1=DTIME(TARRAY)
      DO MANY=1,10
      NK=N(K)
      CALL DOIT(NK,ERRMAX,DECAY)
      ENDDO
      TIME2=DTIME(TARRAY)

      DO 170 KASE=1,2
         IF (KASE.EQ.1) THEN
            PRINT 110,NK
  110       FORMAT (4X,'PROBLEM 15 WITH NK=',I8/)
            PRINT 120
  120       FORMAT (9X,'EQUALLY SPACED POINTS'/)
            PRINT 130
  130       FORMAT (4X,'N      MAX ERROR      DECAY EXPONENT')
         ELSE
            PRINT 140
  140       FORMAT (/9X,'CHEBYSHEV SPACED POINTS'/)
            PRINT 130
         ENDIF
         DO 160 I = 2, NPTS
            PRINT 150,I,ERRMAX(I,KASE),DECAY(I,KASE)
  150       FORMAT (1X,I4,4X,E12.4,3X,F11.2)
  160    CONTINUE
C
C             PRINT OUT OF INTERPOLATION POINT ARRAY XPTS(J,N,KASE)
C             SUPPRESSED HERE TO REDUCE AMOUNT OF OUTPUT
C
  170 CONTINUE


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

   50 CONTINUE
      STOP
      END

      SUBROUTINE DOIT(NK,ERRMAX,DECAY)
      INTEGER NK,NPTS
      PARAMETER(NPTS=10)
      REAL ERRMAX(NPTS,2),DECAY(NPTS,2)
      INTEGER NMAX,I,K,KNOTSMAX
      PARAMETER (NMAX=2*NPTS,KNOTSMAX=NPTS+2)
      COMMON /POINTS/ N,KASE
      REAL XPTS(NPTS),COEF(NMAX),H
      REAL TKNOTS(KNOTSMAX)
      REAL LOGERR,OLDERR,INTERP,RATIO,A,B
      DATA A,B / -1.,1. /,PI / 3.141592654 /
      INTEGER ERRTYP1,ERRTYP2
      DATA ERRTYP1,ERRTYP2 /31,32/
      REAL ERR1

      DO KASE = 1, 2
C
C        BEGIN             'NUMBER OF POINTS USED'
C
         DO 80 N = 2, NPTS

C
C           BEGIN                'CASES OF POINT DISTRIBUTION'
C
            IF (KASE.EQ.1) THEN
               H = (B-A)/(N-1)
               DO 10 J = 1, N
                  XPTS(J) = A+(J-1)*H
   10          CONTINUE
            ELSE
               DO 20 J = 1, N
                  XPTS(J) = (A+B)/2+(A-B)/2*COS((2*J-1)*PI/(2*N))
   20          CONTINUE
               RATIO = (B-A)/(XPTS(N)-XPTS(1))
               DO 30 J = 1, N
                  XPTS(J) = (XPTS(J)-(A+B)/2)*
     *                                RATIO+(A+B)/2
   30          CONTINUE
            ENDIF

            DO 40 J = 1, N
               COEF(2*J-1) = F(XPTS(J))
   40       CONTINUE
            DO 50 J = 1, N
               COEF(2*J) = FPRIME(XPTS(J))
   50       CONTINUE

            DO 60 J = 1, N
               TKNOTS(J+1) = XPTS(J)
   60       CONTINUE
C
C           ADD THE DUMMY POINTS AT EACH END OF TKNOTS ARRAY
C
            TKNOTS(1) = A-0.1*(ABS(A)+1.)
            TKNOTS(N+2) = B+0.1*(ABS(B)+1.)
            KNOTS = N+2

            ERRMAX(N,KASE) = -10E20
            DO 70 I = 1, NK
               X = A+(I-1)*(B-A)/(NK-1)
               ERROR = ABS(F(X)-INTERP(X,COEF,TKNOTS,KNOTS,NPTS,NMAX,
     *            KNOTSMAX))
               IF (ERROR.GT.ERRMAX(N,KASE)) THEN
                  ERRMAX(N,KASE) = ERROR
               ENDIF
   70       CONTINUE


C
C           END               'NUMBER OF POINTS USED'
C
   80    CONTINUE
         DO 90 N = 3, NPTS
            OLDERR = ALOG(ERRMAX(N-1,KASE))
            LOGERR = ALOG(ERRMAX(N,KASE))
            DECAY(N,KASE) = (LOGERR-OLDERR)/ALOG(FLOAT(N)/FLOAT(N-1))
   90    CONTINUE

      ENDDO


      RETURN
      END


      REAL FUNCTION INTERP (X,COEF,T,KNOTS,NPTS,NMAX,KNOTSMAX)
      REAL COEF(NMAX),T(KNOTSMAX)
      COMMON /POINTS/ N,KASE
C
C          PUT THE APPROPRIATE ARRAY OF KNOTS INTO THE T ARRAY

      INTERP = 0
      DO 10 J = 1, 2*N
         INTERP = INTERP+COEF(J)*HCUBIC(J,X,T,KNOTS)
   10 CONTINUE
      IF (INTERP.EQ.0) THEN
         INTERP = F(X)
      ENDIF
      RETURN
      END

      REAL FUNCTION HCUBIC (J,X,T,KNOTS)
C
C         THE HERMITE CUBIC KNOTS ARE IN THE ARRAY T OF LENGTH KNOTS
C           THERE ARE 2 SUCH ARRAYS, 1 FOR EACH CASE OF POINT DIST.
C         J = INDEX OF THE BASIS FUNCTION
C         X = POINT OF EVALUATION OF THE BASIS FUNCTION
C
      REAL T(KNOTS)
      IKNOT = (J+3)/2
      IF (MOD(J,2).EQ.1) THEN
         HCUBIC = HERMC(T,KNOTS,X,IKNOT)
      ELSE
         HCUBIC = HERMC1(T,KNOTS,X,IKNOT)
      ENDIF
      RETURN
      END

      REAL FUNCTION HERMC (T,KNOTS,X,IKNOT)
      REAL T(KNOTS)
      IF ((X.LT.T(IKNOT+1)).AND.(X.GT.T(IKNOT-1))) THEN
         HERMC = 0.0
         IF (X.GT.T(IKNOT)) THEN
            DT = T(IKNOT+1)-T(IKNOT)
            DX = T(IKNOT+1)-X
         ELSE
            DT = T(IKNOT)-T(IKNOT-1)
            DX = X-T(IKNOT-1)
         ENDIF
         HERMC = (3.-2.*DX/DT)*(DX**2)/DT**2
      ELSE
         HERMC = 0.0
      ENDIF
      RETURN
      END

      REAL FUNCTION HERMC1 (T,KNOTS,X,IKNOT)
      REAL T(KNOTS)
      IF ((X.LT.T(IKNOT+1)).AND.(X.GT.T(IKNOT-1))) THEN
         DX = X-T(IKNOT)
         IF (X.GT.T(IKNOT)) THEN
            DT2 = (T(IKNOT)-T(IKNOT+1))**2
            DX2 = (X-T(IKNOT+1))**2
         ELSE
            DT2 = (T(IKNOT)-T(IKNOT-1))**2
            DX2 = (X-T(IKNOT-1))**2
         ENDIF
         HERMC1 = DX2*DX/DT2
      ELSE
         HERMC1 = 0.0
      ENDIF
      RETURN
      END

      REAL FUNCTION F (X)
      F = 1./(X*X+25.0)
      RETURN
      END
      REAL FUNCTION FPRIME (X)
      FPRIME = -2.0*X/(X*X+25.)**2
      RETURN
      END









