     	SUBROUTINE SCREEN( LTYP, IPEAK )
C
C  PROGRAMMER:  R.S. ZHOU
C		ALFRED UNIVERSITY, FEB-1987
C
C	THIS ROUTINE SCREENS THE LISTED PEAKS
C		BY INTENSITY CUTOFFS "CUTI" AND
C		BY FWHM CUTOFF "CUTF"
C		LTYP = OUTPUT PEAK TYPE
C		IPEAK = CURRENT PEAK POINTER (DIADIF)
C
     	INCLUDE 'FILECONV.CBS'
     	CHARACTER DUMY*4
     	DIMENSION FTEP(11)

     	LP = LTYP
     	IPKS = IPEAK
     	IF( NPKS.EQ.0 ) GOTO 111
C
C  RECALCULATE THE RELATIVE INTENSITY...
C
1	DUMM = AREA(1,JRES)
     	DO I=2, NPKS
     	   IF( AREA(I,JRES).GT.DUMM ) DUMM = AREA(I,JRES)
     	ENDDO
     	DO I=1, NPKS
     	   RELA(I) = 100.0*AREA(I,JRES)/DUMM
     	   IF( RELA(I).GT.100.0 ) RELA(I) = 100.0
     	   IF( AREA(I,JRES).LT.RELA(I) ) AREA(I,JRES) = RELA(I)
     	ENDDO
     	IFLAG = 0
C
C  START THE REJECTION CHECKS...
C
     	J = 0
100	J = J + 1
     	IF( J.GT.NPKS .AND. IFLAG.EQ.0 ) GOTO 111
     	IF( J.GT.NPKS .AND. IFLAG.EQ.1 ) GOTO 1
     	IF( LP.EQ.1 .AND. PEAK(J).EQ.'KA2' ) GOTO 101
     	IF( RELA(J).LT.CUTI(1) .OR. RELA(J).GT.CUTI(2) ) GOTO 101
     	IF( FWHM(J).LT.CUTF(1) .OR. FWHM(J).GT.CUTF(2) ) GOTO 101
     	GOTO 100
C
C  REMOVE A PEAK...
C
101	IF( RELA(J).EQ.100.0 ) IFLAG = 1
     	IF( J.LT.IPKS ) IPKS = IPKS - 1
     	NPKS = NPKS - 1
     	DO I=J, NPKS
     	   F2TH(I) = F2TH(I+1)
     	   C2TH(I) = C2TH(I+1)
     	   FDSP(I) = FDSP(I+1)
     	   CDSP(I) = CDSP(I+1)
     	   RELA(I) = RELA(I+1)
     	   AREA(I,JRES) = AREA(I+1,JRES)
     	   PHGH(I) = PHGH(I+1)
     	   FWHM(I) = FWHM(I+1)
     	   PHKL(1,I) = PHKL(1,I+1)
     	   PHKL(2,I) = PHKL(2,I+1)
     	   PHKL(3,I) = PHKL(3,I+1)
     	   PEAK(I) = PEAK(I+1)
     	ENDDO
     	J = J - 1
     	GOTO 100

111	IPEAK = IPKS
     	IF( NPKS.EQ.0 ) THEN
     	    IPEAK = 1
      	    F2TH(1) = 0.0
     	    C2TH(1) = 0.0
     	    FDSP(1) = 0.0
     	    CDSP(1) = 0.0
     	    RELA(1) = 0.0
     	    AREA(1,JRES) = 0.0
     	    PHGH(1) = 0.0
     	    FWHM(1) = 0.0
     	    PHKL(1,1) = 0
     	    PHKL(2,1) = 0
     	    PHKL(3,1) = 0
     	    PEAK(1) = ' '
     	ELSE
     	    IF( NPKS.EQ.1 ) GOTO 999
C
C  REARRANGE THE PEAKS IN ASCENDING TWO-THETA ORDER...
C
    	    IPKS = NPKS-1
    	    DO I=1, NPKS-1
    	       DO J=1, IPKS
     		  IF( F2TH(J) .GT. F2TH(J+1) ) THEN
     		      IF( IPEAK.EQ.J  ) IPEAK = IPEAK + 1
     		      IF( IPEAK.EQ.J+1) IPEAK = IPEAK - 1
     		      FTEP(1) = F2TH(J)
     	    	      FTEP(2) = C2TH(J)
     	    	      FTEP(3) = FDSP(J)
     	    	      FTEP(4) = CDSP(J)
     	    	      FTEP(5) = RELA(J)
     	    	      FTEP(6) = AREA(J,JRES)
     	    	      FTEP(7) = PHGH(J)
     	    	      FTEP(8) = FWHM(J)
     	    	      FTEP(9) = PHKL(1,J)
     	    	      FTEP(10)= PHKL(2,J)
     	    	      FTEP(11)= PHKL(3,J)
     	    	      DUMY = PEAK(J)
    		      F2TH(J) = F2TH(J+1)
     	   	      C2TH(J) = C2TH(J+1)
     	   	      FDSP(J) = FDSP(J+1)
     	   	      CDSP(J) = CDSP(J+1)
     	   	      RELA(J) = RELA(J+1)
     	   	      AREA(J,JRES) = AREA(J+1,JRES)
      	   	      PHGH(J) = PHGH(J+1)
     	   	      FWHM(J) = FWHM(J+1)
     	   	      PHKL(1,J) = PHKL(1,J+1)
     	   	      PHKL(2,J) = PHKL(2,J+1)
     	   	      PHKL(3,J) = PHKL(3,J+1)
     	   	      PEAK(J) = PEAK(J+1)
    		      F2TH(J+1) = FTEP(1)
     	    	      C2TH(J+1) = FTEP(2)
     	    	      FDSP(J+1) = FTEP(3)
     	    	      CDSP(J+1) = FTEP(4)
     	    	      RELA(J+1) = FTEP(5)
     	    	      AREA(J+1,JRES) = FTEP(6)
     	    	      PHGH(J+1) = FTEP(7)
     	    	      FWHM(J+1) = FTEP(8)
     	    	      PHKL(1,J+1) = FTEP(9)
     	    	      PHKL(2,J+1) = FTEP(10)
     	    	      PHKL(3,J+1) = FTEP(11)
     	    	      PEAK(J+1) = DUMY
    	          ENDIF
    	       ENDDO
    	       IPKS = IPKS - 1
    	    ENDDO
     	ENDIF
999	RETURN
     	END
