      PROGRAM PROB11
C
C     PROBLEM 11
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,NFMOM
      PARAMETER (KASES=4)
      PARAMETER (NFMOM=4)
      INTEGER N(KASES)
      DATA N / 16384,32768,65536,262144/
      REAL TFMOM(NFMOM)
      REAL TARRAY(2),TIME1,TIME2

      DO 50 K = 1, KASES

      TIME1=DTIME(TARRAY)
      DO MANY=1,100
      NK=N(K)
      CALL DOIT(NK,TFMOM)
      ENDDO
      TIME2=DTIME(TARRAY)

      PRINT *,'PROBLEM 11 WITH N =',NK
      DO I=1,NFMOM
      PRINT *,'MOMENT ',I,' = ',TFMOM(I)
      ENDDO


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

   50 CONTINUE
      STOP
      END

      SUBROUTINE DOIT(NK,TFMOM)
      INTEGER NK,NFMOM
      PARAMETER (NFMOM = 4)
      REAL TFMOM(NFMOM)
      REAL PI
      DATA PI / 3.1415926 /
      INTEGER NMAX,I,K
      PARAMETER (NMAX=262144)
      DIMENSION DATA(NMAX),COSWT(NMAX)
         DO I = 1, NK
            DATA(I) = -I*10.0+1080*SIN(1+I*0.0623)
            DATA(I) = AMAX1(0.0,AMIN1(1000.,DATA(I)))
            DATA(I) = ALOG(DATA(I)+1.0)
         ENDDO

         TFMOM(1) = SUM(DATA,NK)/NK
         DO  K = 2, NFMOM
            DO I = 1, NK
               COSWT(I) = COS(PI*I*(K-1)/(NK+1)) * DATA(I)
            ENDDO
            TFMOM(K) = SUM(COSWT,NK)/NK
        ENDDO


      RETURN
      END



      FUNCTION SUM (X,N)
      DIMENSION X(N)
      S = 0
      DO 10 I = 1, N
         S = S+X(I)
   10 CONTINUE
      SUM = S
      RETURN
      END





