ccccccccccccccccccccccccc     Program 2.5     cccccccccccccccccccccccccc
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c                                                                      c
c Please Note:                                                         c
c                                                                      c
c (1) This computer program is part of the book, "An Introduction to   c
c     Computational Physics," written by Tao Pang and published and    c
c     copyrighted by Cambridge University Press in 1997.               c
c                                                                      c
c (2) No warranties, express or implied, are made for this program.    c
c                                                                      c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      PROGRAM INTEGRAL
C
C Main program for evaluation of an integral with integrand
C sin(x) in the region of [0,pi/2].
C
      PARAMETER (N =   9)
      DIMENSION X(N),F(N)
      PI = 4.*ATAN(1.)
      H  = PI/2./(N-1)
      DO      100  I = 1, N
        X(I) = H*(I-1)
        F(I) = SIN(X(I))
  100 CONTINUE
      CALL SIMP(N,H,F,S)
      WRITE (6,999) S
      STOP
  999 FORMAT (F16.8)
      END
C
      SUBROUTINE SIMP (N,H,FI,S)
C
C Subroutine for integration over f(x) with the Simpson rule.
C FI: integrand f(x); H: interval; S: integral.
C
      DIMENSION FI(N)
C
      S  = 0.
      S0 = 0.
      S1 = 0.
      S2 = 0.
      DO      100 I = 2, N-1, 2
        S1 = S1 + FI(I-1)
        S0 = S0 + FI(I)
        S2 = S2 + FI(I+1)
  100 CONTINUE
      S = H*(S1 + 4.*S0 + S2)/3.
C
C If N is even, add the last slice separately
C
      IF(MOD(N,2).EQ.0) S = S
     *  + H*(5.*FI(N) + 8.*FI(N-1) - FI(N-2))/12.
      RETURN
      END
