      SUBROUTINE QSIMP1(ainteg1,zs,ze,S)
        implicit real*8(a-h,o-z)
	common		elong,ass,bee, 		! extra parameters used by make_model
     &                  zss,zee,xs,xe,ccc,PI,au,au2,anu,alamb,freq,twopi,qxf,
     &			L1,L2,L3,L4,L5,L6,L7,L8,L9,A1,A2,A3,A4,A5,A6,A7,A8,A9,
     &			z,z0,R,p,Vx,Xnorm,XMnorm,ahpow,anoise,
     &			er1,er2,er3,er4,er5,er6,er7,er8,er9,er10,
     &			ijsing,iFs(500),iFt(500),iFd(500),aispecq(500),ispecq1,iq1(500),ispecq2,iq2(500)
C        PARAMETER (EPS=1.0E-6, JMAX=20)
C
       PARAMETER (EPS=5.E-5, JMAX=17)
C
        save OST, OS
C
C	print *, 'inside qsimp1'

      OST=-1.E30
      OS= -1.E30
      DO 11 J=1,JMAX
        CALL TRAPZD1(ainteg1,zs,ze,ST,J)
        S=(4.*ST-OST)/3.
        IF (ABS(S-OS).LT.EPS*ABS(OS)) RETURN
        OS=S
        OST=ST
11    CONTINUE
          write(*,'(A,I3,3E15.7)') 'Error - at end of qsimp1',	J,zs,ze,S
          iq1(ispecq1) = iq1(ispecq1) + 1
C       PAUSE 'QSIMP1 Too many steps.'
      RETURN
      END
