	SUBROUTINE NETINT
C**********************************************************************
C
C  SUBROUTINE TO CALCULATE PEAK AND/OR INTEGRATED INTENSITIES FOR
C  A LINE COLLECTED BY "AUTO"
C
C  CORRECTS FOR BACKGROUND AS REQUIRED BY DATA COLLECTION MODE
C
C  PROPAGATES ERRORS OF RAW DATA INTO NET INTENSITY VALUES BY SUM
C  OF SQUARES OF SIGMAS (VARIANCES)
C
C**********************************************************************
C  RELATIVE INTENSITY VALUES FOR THE INTERNAL STANDARD METHOD
C  IF ENTERED, WILL BE USED TO SCALE ALL LINES FROM EACH
C  STANDARD TO THE 100% LINE.  THIS ALLOWS COMPARISON
C  OF THE STANDARD INTENSITY VALUES WITH ALL ON THE SAME
C  SCALE.  IF RELATIVE INTENSITY VALUES WERE NOT INPUT
C  TO PROGRAM AUTO THEN THEY ARE
C  COMPUTED FOR EACH LINE OF EACH STANDARD.
C
C
C  THE FOLLOWING PARAMETER STATMENT DEFINES THE DIMENSIONS FOR
C  THE QUANTATATIVE ANALYSIS SUBROUTINES.  TO REDIMENSION
C  SIMPLY CHANGE THIS STATMENT HERE AND IN EACH SUBROUTINE.
C      NF = THE NUMBER OF DATA FILES ALLOWED FOR INPUT
C      NR = THE MAXIMUM NUMBER OF REFLECTIONS WHICH CAN BE PROCESSED
C      NP = THE MAXIMUM NUMBER OF PHASES ALLOWED
C      NT = THE MAXIMUM NUMBER OF DATA POINTS FOR ANY REFLECTION
C
	PARAMETER (NT=1250)
	COMMON /RECRD2/ XLAMBD,TAKEOF,DIVANG,RADIUS,SOLLIN,
     1 SOLLOT,RECSLT,DEADTM,STABIL,TBASE
	COMMON /RECR2C/ UNIT,TARGET,LINE,FOCAL,DIVSLT,MONOCH,DETECT
	COMMON/RECRD7/BANG,PANG,EANG,DANG,RATE,MVCNT,TIMLIM,FIXERR,
     * LIMCNT,KODE,IOVLP,IPK,NPK,NBG,FREL,STDREL,STD,SIGSTD,
     * WTPRCT,PKTIME,BKGTIM,IOPTIM,ILOC,CONSTD
	COMMON /RECR7C/ NAM,JKL
	COMMON/RECRD9/NPTS,X(NT),V(NT)
	COMMON/DATA/PEAK,VPEAK,AREA,VAREA,XBKG,VBKG
	CHARACTER*6 NAM,JKL
	CHARACTER*4 UNIT
	CHARACTER*2 TARGET,LINE,FOCAL,DIVSLT,MONOCH,DETECT
C
C-----INITIALIZE SUMMATION VARIABLES
C        BEGINING WITH 'X' ARE INTEGRAL INTENSITY VARIABLES
C                      'V' ARE VARIANCE OF INTEGRAL INTENSITY VARIABLES
C                      'P' ARE PEAK INTENSITY VARIABLES
C                      'W' ARE VARIANCE OF PEAK INTENSITY VARIABLES
C                      'N' ARE COUNTERS FOR NUMBER OF POINTS IN SUM
C
	XBKG = 0.0
	VBKG = 0.0
	NBKG = 0
	XINT = 0.0
	VINT = 0.0
	NINT = 0
	PINT = 0.0
	WINT = 0.0
	NPKS = 0
	PEAK = 0.0
	VPEAK = 0.0
	AREA = 0.0
	VAREA = 0.0
C
C-----LOWER BACKGROUND - IDENTICAL FOR PEAK AND INTEGRAL MEASUREMENTS
C
	IF(NBG.EQ.0) GOTO 200
	DO 100 I=1,NBG
	XBKG = XBKG + X(I)
	VBKG = VBKG + V(I)
	NBKG = NBKG + 1
100	CONTINUE
C
C-----WAS PEAK(IPK=1) OR INTEGRAL(IPK=0) INTENSITY DATA COLLECTED
C
200	IF(IPK.GT.0) GOTO 310
C
C-----INTEGRATE OVER THE PEAK AREA
C
	IBGN = NBG+1
	IEND = NPTS-NBG
	DO 220 I=IBGN,IEND
	XINT = XINT + X(I)
	VINT = VINT + V(I)
	NINT = NINT + 1
220	CONTINUE
C
C-----CALCULATE BEGINING AND ENDING ARRAY INDICIES FOR PEAK POINTS
C-----FOR INTEGRAL MODE
C
	IBGN = (PANG-BANG)/DANG+1.00001
	IBGN = IBGN - NPK/2
	IEND = IBGN + NPK/2
	GOTO 320
C-----CALCULATE BEGINING AND ENDING ARRAY INDICIES FOR PEAK POINTS
C-----FOR PEAK HEIGHT MODE
310	IBGN = NBG+1
	IEND = IBGN + NPK - 1
C-----PERFORM SUMMATION FOR PEAK INTENSITY
320	DO 330 I=IBGN,IEND
	PINT = PINT + X(I)
	WINT = WINT + V(I)
	NPKS = NPKS + 1
330	CONTINUE
C
C-----UPPER BACKGROUND SUMMATION (IF MEASURED)
C
	IF(IPK.GT.0 .AND. EANG.LT.0.01) GOTO 500
	IF(NBG.EQ.0) GOTO 500
	IBGN = NPTS-NBG+1
	IEND = NPTS
	DO 420 I=IBGN,IEND
	XBKG = XBKG + X(I)
	VBKG = VBKG + V(I)
	NBKG = NBKG + 1
420	CONTINUE
C
C-----DETERMINE THE AVERAGE BACKGROUND, Peakand Integrated intensity
C-----Since X(i)is in cps then XBKG, XINT, and PINT will be in cps
C
500	IF(NBKG.GT.0) GOTO 502
	XBKG=0.0
	VBKG=0.0
	GOTO 504
502	XBKG = XBKG/NBKG
	VBKG = VBKG/(NBKG*NBKG)
504	IF(IPK.GT.0) GOTO 510
510	PINT = PINT/NPKS
	WINT = WINT/(NPKS*NPKS)
C
C-----SUBTRACT BACKGROUNDS
C
	PEAK = PINT-XBKG
	VPEAK= WINT+VBKG
	IF(PEAK.GT.0.0)GO TO 520
C
C  RESET NEGAIVE INTENSITIES TO A SMALL POSITIVE NUMBER
C
	PEAK = 1.0E-10
	VPEAK = 1.0E-10
520	IF(IPK.GT.0) GOTO 999
C
C  THE FACTOR OF 5.0 BELOW IS TO GET INTEGRATED COUNTS ON THE
C  SAME ORDER AS PEAK COUNTS
C
	AREA = (XINT-XBKG*NINT) * DANG * 5.0
	VAREA= (VINT+VBKG*NINT*NINT) * DANG*DANG * 25.0
	IF(AREA.GT.0.0)GO TO 999
C
C  RESET NEGATIVE INTENSITIES TO A SMALL POSITIVE NUMBER
C
	AREA = 1.0E-10
	VAREA = 1.0E-10
C
C-----RETURN TO CALLING PROGRAM
C
999	RETURN
	END
