      SUBROUTINE trapzd1(ainteg1,A,B,S,N)
	implicit real*8(a-h,o-z)
	save IT

C	print *, 'inside trapzd1',A,B,N

      IF (N.EQ.1) THEN
        S=0.5*(B-A)*(ainteg1(A)+ainteg1(B))
        IT=1
      ELSE
        TNM=IT
        DEL=(B-A)/TNM
        X=A+0.5*DEL
        SUM=0.
        DO 11 J=1,IT
          SUM=SUM+ainteg1(X)
          X=X+DEL
11      CONTINUE
        S=0.5*(S+(B-A)*SUM/TNM)
        IT=2*IT
      ENDIF

C	write(*,'(A,2E15.7,I3,2E15.7)') 'At end of trapzd1', A,B,N,S
      RETURN
      END
