PROGRAM series8
!
! Author:  Br. David Carlson
!
! Date:  January 2, 2000
!
! Revised:  May 2, 2004
!
! This program prints out partial sums for the Fourier series in problem 5
! page 19 of Bressoud's text, A Radical Approach to Real Analysis.

IMPLICIT NONE

REAL::term, sum, f, x, piover2
INTEGER::n, sign, count, k

WRITE (*, 20)
20 FORMAT (1X, 'Program to investigate a Fourier series')

WRITE (*, *) 'Enter the number of terms N to use: '
READ (*, *) n

WRITE (*, *) 'Enter the value of X at which to evaluate the partial sums: '
READ (*, *) x

sum = 0.0
sign = 1
count = 0
piover2 = ASIN(1.0)

WRITE (*, 50)
50 FORMAT (' ', T5, 'count', T15, 'term', T35, 'partial sum', T55, 'f')

DO k = 1, 2 * n - 1, 2
   count = count + 1
   term = sign * COS(k * piover2 * x) / k
   sum = sum + term
   f = 2.0 * sum / piover2
   WRITE (*, 100) count, term, sum, f
   sign = -sign
END DO

100 FORMAT (' ', T5, I4, T15, E16.8, T35, E16.8, T55, E16.8)

END PROGRAM

