	SUBROUTINE check(DIREC,jcmiss,obmiss,STATUS)
C**********************************************************************
C This subroutine matches an unknown pattern against a JCPDS pattern
C 
C Two peaks are considered to match if the JCPDS peak is between 
C OBL and OBH. (note that a JCPDS peak may match more than one OBS peak
C and vice-versa). 
C
C The program compares each JCPDS peak with the bitmap table of peaks
C and excluded areas, CTBL. The number of peaks which are not matched
C is counted as JCMISS. If JCMISS exceeds JCMSMX, the subroutine
C immediately exits at the alternate return address.
C 
C The number of lines in the Obs pattern which do not have matches 
C are counted and returned as OBMISS (the subroutine uses the alternate
C exit if OBMISS > OBMSMX)
C 
C						Brian Toby 7/88
C**********************************************************************
	integer*4 DIREC,jcmiss,obmiss
       LOGICAL STATUS
			     
	include '[-.shared]jcpds.parms'
	include 'SEARCH.cmn'
	include 'SEARCH.par'

	LOGICAL EXRtst
	INTEGER*2 JC(210)
	INTEGER*2 JC1(42),JC2(42),JC3(42),JC4(42),JC5(42)
	EQUIVALENCE (JC1(1),JC(1))
	EQUIVALENCE (JC2(1),JC(43))
	EQUIVALENCE (JC3(1),JC(85))
	EQUIVALENCE (JC4(1),JC(127))
	EQUIVALENCE (JC5(1),JC(169))

	BYTE INTB(210)
	BYTE IN1(42),IN2(42),IN3(42),IN4(42),IN5(42)
	EQUIVALENCE (IN1(1),INTB(1))
	EQUIVALENCE (IN2(1),INTB(43))
	EQUIVALENCE (IN3(1),INTB(85))
	EQUIVALENCE (IN4(1),INTB(127))
	EQUIVALENCE (IN5(1),INTB(169))
	INTEGER*2    NUMJC,dummy2
	INTEGER OP

C
C number of observed peaks that not matched
	obmiss = 0
C number of jcpds peaks that not matched
	jcmiss = 0
C assume failure
	STATUS = .FALSE.

C	get D/I info -- 1st record
	READ(LPDF,REC=DIREC) NUMJC,JC1,IN1

C	Check JCPDS card against the CTBL bitmap
	DO I=1,NUMJC
	  IF (I .eq. 43) THEN 
	    READ(LPDF,REC=DIREC+1) dummy2,JC2,IN2
	  ELSEIF (I .eq. 85) THEN
	    READ(LPDF,REC=DIREC+2) dummy2,JC3,IN3
	  ELSEIF (I .eq. 127) THEN
	    READ(LPDF,REC=DIREC+3) dummy2,JC4,IN4
	  ELSEIF (I .eq. 169) THEN
	    READ(LPDF,REC=DIREC+4) dummy2,JC5,IN5
	  ENDIF

	  if (INTB(I) .gt. IMIN .and. .not. EXRtst(ctbl,JC(I))) then
C the peak is significant and has not been found
	    jcmiss = jcmiss+1
	    IF (jcmiss.GT.JCMSMX) return
	  ENDIF
	ENDDO

C---------------------------------------------------------------------------
	I = 1
	DO OP=1,nobs
C if the jcpds line is too low go on to the next jcpds line, if there are more 
15	  IF (JC(I) .LT. OBL(OP)) then
	    IF (I .lt. numjc) then
	      I = I + 1
	      goto 15
	    ENDIF
C there are no more JCPDS lines so reject this Obs line
	    IF (SIobs(OP)) obmiss = obmiss + 1
	    if (obmiss .gt. OBMSMX) return
C the obs line is too low so count as a miss and go on to the next
	  ELSEIF (JC(I) .GT. OBH(OP)) then
	    IF (SIobs(OP)) obmiss = obmiss + 1
	    if (obmiss .gt. OBMSMX) return
	  ENDIF
	ENDDO
C this card is a match!
	STATUS = .true.
	RETURN
	end
