	FUNCTION KeySea, key, invec
;	-------------------------------------------------------------
;+							10-Feb-92
;	Name:
;		KeySea
;	Purpose:
;		Decode item, operator, and value from 'key' parameter,
;		apply the search to the input data vectors and return
;		the success indices of the input data vector.  A single 
;		success index vector is always  returned for each call.
;		A multiple item search begins with the first item in 
;		the list which is "AND" to the
;		results of the next item search and so on.
;	CALLING SEQUENCE:
;		idx = KeySea(key, vec)
;	Input:
;		key 	(scalar) item, operator and value for Search
;		invec	data vector to be searched 
;	RETURNED:
;		idx	list of success indices for the search key.
;	History:
;		written 16-Oct-91 by GAL from 20-Aug-91 version of
;			KeySearch procedure.
;			17-Oct-91, deleted keywords and add internal
;			checks for input structure-type (ie sxt or bcs)
;			for future use with other instruments.
;			21-Oct-91, Minor correction to way the index
;			list is being made-- MDM and GAL
;			10-Jan-92, GAL opt and xray searches use gt
;			function values, see called rountines via SXTKaysea.
;			22-Jan-92, GAL, remove limitation nested structures
;			such as data-index from sxt.
;			28-Jan-92, minor update to fix bug on input key
;			4-Feb-92, added dpe search key (via gt_* function).
;			10-feb-92, added Dp_mode search key (via gt_* fun.).
;-
;	---------------------------------------------------------------
	vec = invec	;save input vector (do not over write)

	IF (N_ELEMENTS(key) eq 1 ) THEN BEGIN	;test input
	  skey = key(0)				;make key a scalar
	ENDIF ELSE BEGIN
	  Print, "'keysea' does not accept an array of keys as input."
	  Print, 'You must specify which element (e.g. i = keysea(key(2), rmap)'
	  return, -1
	ENDELSE

;	TO DO: add some syntax checker on Keys for novice users:
	keys = Str2Arr(skey, delimit=';')	;use ';' to parse keys
	siz_keys = SIZE(keys)
	nKeys = siz_keys(siz_keys(0)+2)	;total # elements
	match = 1			;assume all found
	firstTime = 1			;1st time thru flag

	FOR i= 0, nKeys-1 DO BEGIN	;do for all requests
	  IF (match) THEN BEGIN
	    ParsKey, keys(i), item, op, val, op2=op2, val2=val2, $
				op3=op3, val3=val3

;	    WHat kind of STRUCTURE Is This (sxt???)??? 
	    ck = fndfld(vec, 'PERIPH') 	;check for one of SXTs structures
	    IF (ck(0) ne -1) THEN BEGIN
	      sxt = 1			;set sxt data present flag
	    ENDIF
	    itemStat = Ck_Item(item, BCS=bcs, HXT=hxt, SXT=sxt, WBS=wbs)
	    IF (itemStat) THEN BEGIN	;valid search Key found	    
	      IF (sxt) THEN BEGIN	;SXT sea ok
	        idx = SXTKaySea(vec, item, op, val, op2=op2, val2=val2,$
				op3=op3, val3=val3)
	        IF (idx(0) ne -1) THEN BEGIN
	          vec = vec(idx)	;update search vector for next
					;call
		  IF (firstTime) THEN BEGIN
		    ret = idx		;save indics
		    firstTime = 0	;reset flag
		  ENDIF ELSE BEGIN
		    ret = ret(idx)	;Logical "AND" index list building
					;you get the subset!!!!!
		  ENDELSE
	        ENDIF ELSE BEGIN 	;NO matches FOUND!!!
	          vec = LONG(-1)
	          match = 0		;skip all other requests, if any
		  ret = -1		;found nothing-- this deletes any
					;earlier successes since logical
					;"AND" is used.
	        ENDELSE
	      ENDIF			;for SXT sea
	    ENDIF ELSE BEGIN            ;pass all back i.e. no search
              vec = vec			
	      ret = INDGEN(N_ELEMENTS(vec))	;got all
	    ENDELSE			;end of itemStat check

	  ENDIF				;for "match" check
	ENDFOR

	RETURN, ret
	END
