      SUBROUTINE BACKGROUND
	1	(NBKG,CONST,PEAK,PWIDTH,PINT,Y,NPT,FIRST,D2T)
C
C  GENERATES BACKGROUND IN SIMULATED SPECTRUM
C         NBKG=1  CONSTANT BACKGROUND
C         NBKG=2  AMORPHOUS PEAK
C
      DIMENSION Y(8001)
      PI=3.1415926
C
C  CONSTANT BACKGROUND
C
      IF(NBKG.NE.1)GO TO 200
      DO 100 I=1,NPT
      Y(I)=Y(I)+CONST
100   CONTINUE
      RETURN
200   IF(NBKG.NE.2)RETURN
      SUM =0.
      DO 210 I=1,NPT
      SUM=SUM+Y(I)
210   CONTINUE
      AINT=PINT*SUM/100.
      DO 250 I=1,NPT
      T=I-1
      B=((2.0*AINT)/(PI*PWIDTH))/(1.+4.0*((FIRST+D2T*T-PEAK)/PWIDTH)**2)
      Y(I)=Y(I)+B
250   CONTINUE
      RETURN
      END
