;Mod: 1995 July Elaine Einfalt - force slit check if angstroms selected

function uvsp_catexpand, params, floater=floater

 if keyword_set(floater) then floater=1 else floater=0

 expand_array = [-999,-999]
 params = ',' + params + ','
 byte_line = byte(params)
 fields = where(byte_line eq 44b, n_fields)	; where are commas

 for i = 0, n_fields-2 do begin
     ; get either a single number or range from a single field
     value = strmid(params, fields(i)+1, fields(i+1)-fields(i)-1 )

     range = where(byte(value) eq 45b)		; is there a dash

     if range(0) eq -1 then begin
	if not(floater) then begin
	   num_1 = long(value)
	   num_2 = long(value)
	endif else begin
	   num_1 = float(value)
	   num_2 = float(value)
	endelse
     endif else begin
	if not(floater) then begin
	   num_1 = long(strmid(value,0,range(0)))
	   num_2 = long(strmid(value,range(0)+1, strlen(value)-1))
	endif else begin
	   num_1 = float(strmid(value,0,range(0)))
	   num_2 = float(strmid(value,range(0)+1, strlen(value)-1))
	endelse
     endelse

     expand_array = [temporary(expand_array), [num_1, num_2]] 
 endfor

 n_el = n_elements(expand_array) 
 if n_el gt 2 then expand_array = reform(expand_array(2:*), 2, (n_el-2)/2)

return, expand_array
end

;================================================================

function uvsp_angsdet, slit=slit, det=det, exp=exp, wave=wave 

; have start and end wavelenth (angs) for 1st det in experiment (WAVE),
; convert them to WLD step numbers
; use those step numbers to get start and end wavelenths for any other
;	detectors in this experiment


	ioff = intarr(5,22)
	IOFF(0,0) =([ 105, 2364, 2936,  663,   00])	; SLIT  1 (P)
     	IOFF(0,1) =([ 105, 2364, 2936,  663,   00])	; SLIT  2 (Q)
	IOFF(0,2) =([-101, -101, 2750, 2750,   00])	; SLIT  3 (L)
	IOFF(0,3) =([-101, -101, 2750, 2750,   00])	; SLIT  4 (M)
	IOFF(0,4) =([1689, 1689, 4463, 4463,   00])	; SLIT  5 (D)
	IOFF(0,5) =([1689, 1689, 4463, 4463,   00])	; SLIT  6 (E)
	IOFF(0,6) =([-101, -101, 3398, 3398,   00])	; SLIT  7 (H)
	IOFF(0,7) =([-101, -101, 3398, 3398,   00])	; SLIT  8 (I)
	IOFF(0,8) =([1511, 2253, 2936, 1256, 3939])	; SLIT  9 (R)
	IOFF(0,9) =([1511, 2253, 2936, 1256,   00])	; SLIT 10 (S)
	IOFF(0,10)=([   0, -202, 4340, 4404,   00])	; SLIT 11 (A)
	IOFF(0,11)=([   0, -202, 4340, 4404, 3939])	; SLIT 12 (B)
	IOFF(0,12)=([1689, 1689, 3545, 3545,   00])	; SLIT 13 (F)
	IOFF(0,13)=([1689, 1689, 3545, 3545,   00])	; SLIT 14 (G)
	IOFF(0,14)=([-101, -101, 4463, 4463,   00])	; SLIT 15 (C) 
	IOFF(0,15)=([2277, 2277, 3236, 3236,   00])	; SLIT 16 (J)
	IOFF(0,16)=([2277, 2277, 3236, 3236,   00])	; SLIT 17 (K)
	IOFF(0,17)=([   2, 1852, 4259,  921,   00])	; SLIT 18 (N)
	IOFF(0,18)=([   2, 1852, 4259,  921,   00])	; SLIT 19 (O)
	IOFF(0,19)=([ 216, 1647, 4585,   00, 4126])	; SLIT 20 (V)
	IOFF(0,20)=([ 202, 1466, 4377,  359,   00])	; SLIT 21 (T)
	IOFF(0,21)=([ 182,   00,   00,  378,   00])	; SLIT 22 (U)


 det = det(where(det ne 0))

 ;   note: 30685 is Joe Gurman's value
 ;         30719 is Bill Henzze's value

 if exp gt 30685 then WLD = [115380, 115380] $		; WLD stuck here
 else begin                                             ; (same as STCAL.FTN)
	; given wavelength (WAVE) angstroms for the 1st det.
	; find start and end WLD step number for 1st det

	IF (det(0) EQ 5) then wave = wave/2.
        XWLD = 376298.34000 - 186.93864440 * wave
        XWLD = XWLD - 0.0020276718 * wave * wave
        WLD = XWLD + ioff(det(0)-1,slit-1)
	WLD = WLD - 216			; DIFF. ZERO POINT;  SEE ABOVE.
 endelse 

 ; given WLD step number from 1st det
 ; find wavelength in angstroms for each detector      (same as WCAL.FTN)

 ndet = n_elements(det)
 xwld = rebin(WLD,2,ndet) - transpose(rebin(ioff(det-1,slit-1),ndet,2))


 XWLD = XWLD+216.			; DIFF. ZERO POINT;  SEE ABOVE.
 WL = 1970.7373047
 WL = WL - XWLD * 0.005128015298
 WL = WL - XWLD * XWLD * 2.8786E-10

 where_5 = where(det eq 5)
 if (where_5(0) ne -1) then wl(0,where_5(0)) = wl(*,where_5(0)) * 2.  $
 else begin
	where_1050 = where(wl lt 1050.)
	if (where_1050(0) ne -1) then wl(0,where_1050) = wl(*,where_1050) * 2.
 endelse

RETURN, fix(wl + 0.5)
end

;+
;
; NAME: 
;	UVSP_CATREAD
;
; PURPOSE:
;
;
; CATEGORY:
;
;
; CALLING SEQUENCE:
;	From the SCREEN interface:   result = UVSP_CATREAD(OUT=OUT)
;	From the WIDGET interface:   result = UVSP_CATREAD(OUT=OUT, $
;							   INHIB=INHIB,
;							   YIELD=YIELD)
;
; CALLED BY:
;
;
; CALLS TO:
;	none
;
; INPUTS:
;       none explicit, only through commons;
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; COMMON BLOCKS:
;	COMMON AEROCASE,
;		 FLAGAERO, 		; flag if !AERO was used at all.
;		 AERORANGE              ; 2xN array containing the start and
;					;     end values for ranges when !AERO
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	none
;
; MODIFICATION HISTORY:
;
;-

pro uvsp_catread, out=out, str=str, yield=yield, font=font, inhib=inhib, $
		  nofull=nofull, cat_widg=cat_widg

common uvcat, cat
common uvcattext, cat_text   		; so can return experiment #s for the
					; case of SCREEN mode 
common aerocase, flagaero, aerorange

 if n_elements(font) eq 0 then font=''  

 if (nofull ne 0) then begin       	; was a "FULL" earlier
    ;
    ; Don't have the full catalog in memory so just assign the part 
    ; that is needed (the maximum extent).
    ;

    print,'Wait a moment while part of UVSP catalog is placed ', $
		'in memory (', strmid(!stime,12,8),').'

    if !version.os eq 'vms' then ass_off = out.ran_min $
			    else ass_off = out.ran_min*(64*2)

    cat_assoc = assoc(nofull, intarr(64, out.ran_max-out.ran_min+1), ass_off)

    cat = cat_assoc(0)
    print,'Thank you (', strmid(!stime,12,8),').'

    offset = out.ran_min + 1	; To get from indices of CAT to exp number
    catoff = 0			; To get from indices of USE to indices of CAT

 endif else  begin

    offset = 1		; To get from indices of CAT to exp number
    catoff = out.ran_min    ; To get from indices of USE to indices of CAT

 endelse

 use = bytarr(out.ran_max - out.ran_min + 1)    ; size is maximum extent

 useoff = out.ran_min + 1			; offset between indices of USE
						; and experiment numbers
 ;
 ; Set the bytes corresponding to the experiment ranges selected
 ;

;12/93 if not(flagaero) then ranges = uvsp_catexpand(str.exp)  $
;12/93		  else ranges = aerorange

 if n_elements(flagaero) eq 0 then ranges = uvsp_catexpand(str.exp)   $
 else if not(flagaero) then ranges = uvsp_catexpand(str.exp)  $
		       else ranges = aerorange

 siz = size(ranges)
 for i = 0, siz(2)-1 do use(ranges(0,i)-useoff : ranges(1,i)-useoff) = 1b
 w_cat = where(use eq 1b, n_cat) + catoff 	; indices of CAT

 t_cat = where(cat(6,w_cat) eq 0, n_cat)	; indices of W_CAT
 if n_cat ne 0 then use(w_cat(t_cat)-catoff) = 0b ; undo invalid entries

 w_cat = where(use eq 1b, n_cat) + catoff	; indices of CAT
 if n_cat eq 0 then goto, NOEXPERIMENTS         ; when only invalids are picked

 if (out.type) then begin
    ranges = uvsp_catexpand(str.type)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       t_cat = $
          where(cat(43,w_cat) ge ranges(0,i) and cat(43,w_cat) le ranges(1,i), $
          n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.slit)  or (out.angs) then begin
    ; forces slit check if angstroms is selected.

    ranges = uvsp_catexpand(str.slit)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(15,w_cat) ge ranges(0,i) and cat(15,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.det) then begin
    ranges = uvsp_catexpand(str.det)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       t_cat = $
        where((cat(17,w_cat) ge ranges(0,i) and cat(17,w_cat) le ranges(1,i)) $
          or  (cat(18,w_cat) ge ranges(0,i) and cat(18,w_cat) le ranges(1,i)) $
          or  (cat(19,w_cat) ge ranges(0,i) and cat(19,w_cat) le ranges(1,i)) $
          or  (cat(20,w_cat) ge ranges(0,i) and cat(20,w_cat) le ranges(1,i)),$
          n_cat) 
        if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of cat
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.spec) then begin
    t_cat = where(cat(29,w_cat) gt 1, n_cat)
    if n_cat eq 0 then goto, NOEXPERIMENTS
    use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of cat
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.wld) then begin
    ranges = uvsp_catexpand(str.wld)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(29,w_cat) ge (ranges(0,i)-1)>0 and $
		cat(29,w_cat) le (ranges(1,i)-1)>0, $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.shft) then begin
    ranges = uvsp_catexpand(str.shft)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(15,w_cat) ge ranges(0,i) and cat(15,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.intvl) then begin
    ranges = uvsp_catexpand(str.intvl)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(40,w_cat) ge ranges(0,i) and cat(40,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.noaa)  ne '' then begin
    ranges = uvsp_catexpand(str.noaa)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(7,w_cat) ge ranges(0,i) and cat(7,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.xpix) then begin
    ranges = uvsp_catexpand(str.xpix)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(25,w_cat) ge ranges(0,i) and cat(25,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.ypix)  then begin
    ranges = uvsp_catexpand(str.ypix)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(26,w_cat) ge ranges(0,i) and cat(26,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.xres) then begin
    ranges = uvsp_catexpand(str.xres)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(27,w_cat) ge ranges(0,i) and cat(27,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.yres) then begin
    ranges = uvsp_catexpand(str.yres)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(28,w_cat) ge ranges(0,i) and cat(28,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.npol)  then begin
    ranges = uvsp_catexpand(str.npol)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(31,w_cat) ge ranges(0,i)-1 and $
	        cat(31,w_cat) le ranges(1,i)-1, $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.dur) then begin
    ranges = uvsp_catexpand(str.dur)  &  siz = size(ranges)
    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $
	  where(cat(12,w_cat) ge ranges(0,i) and cat(12,w_cat) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.pol) then begin
    sep = where(byte(str.pol+',') eq 44b, ncomma)	; commas separate char
    pol = ["O","A","B"]

    if ncomma eq 1 then t_cat = $
	where(cat(16,w_cat) eq (where(pol eq strmid(str.pol,0,1)))(0), n_cat) $
    else if ncomma eq 2 then t_cat = $
	where(cat(16,w_cat) eq (where(pol eq strmid(str.pol,0,1)))(0) or $
	      cat(16,w_cat) eq (where(pol eq strmid(str.pol,2,1)))(0), n_cat) $
    else if ncomma eq 3 then t_cat = $
	where(cat(16,w_cat) eq (where(pol eq strmid(str.pol,0,1)))(0) or $
	      cat(16,w_cat) eq (where(pol eq strmid(str.pol,2,1)))(0) or $
	      cat(16,w_cat) eq (where(pol eq strmid(str.pol,4,1)))(0), n_cat) 

    if n_cat eq 0 then goto, NOEXPERIMENTS
    use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.rsun) then begin
    ;
    ; Calculate Rsun for experiments that qualify so far.
    ;
 
    radtht = fltarr(2,n_cat)				; Rsun, Theta
    for i = 0l, n_cat-1l do $
       radtht(0,i) = UVSP_CATRADTHT(jexp=w_cat(i)+offset, ic=cat(*,w_cat(i)))
    radtht(0,*) = fix(temporary(radtht(0,*))*100.+0.5)/100.  ; round

    ranges = uvsp_catexpand(str.rsun,/floater)  &  siz = size(ranges)

    for i = 0, siz(2)-1 do begin 		; for each user range
       	t_cat = $                               ; indices of radtht
	  where(radtht(0,*) ge ranges(0,i) and radtht(0,*) le ranges(1,i), $
	  n_cat)
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    radtht = temporary(radtht(*,t_cat))		; just the qualifing exps
        
    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 if (out.angs) then begin
    ;
    ; Calculate wavelength in angstroms for each qualifing experiment.
    ;
 
    angs_det = fltarr(2,4,n_cat)
    for i = 0l, n_cat-1l do $
       angs_det(0,0,i) = uvsp_angsdet(slit = cat(15,w_cat(i)), $
				    det = cat(17:20,w_cat(i)), $
				    exp = w_cat(i), $
				    wave = cat(13:14,w_cat(i)) )

    ranges = uvsp_catexpand(str.angs,/floater)  &  siz = size(ranges)

    for i = 0, siz(2)-1 do begin 		; for each user range
;     t_cat = $                               ; indices of radtht
;      where( (angs_det(0,0,*) > angs_det(1,0,*) ) ge ranges(0,i) and $angs_det(0,0,*) le ranges(1,i) $
;         or angs_det(1,1,*) ge ranges(0,i) and angs_det(0,1,*) le ranges(1,i) $
;         or angs_det(1,2,*) ge ranges(0,i) and angs_det(0,2,*) le ranges(1,i) $
;         or angs_det(1,3,*) ge ranges(0,i) and angs_det(0,3,*) le ranges(1,i), $
;	  n_cat)
     t_cat = $                               ; indices of radtht
      where( (angs_det(0,0,*) > angs_det(1,0,*) ) ge ranges(0,i) and $
	     (angs_det(0,0,*) < angs_det(1,0,*) ) le ranges(1,i) $
         or  (angs_det(0,1,*) > angs_det(1,1,*) ) ge ranges(0,i) and $
	     (angs_det(0,1,*) < angs_det(1,1,*) ) le ranges(1,i) $
         or  (angs_det(0,2,*) > angs_det(1,2,*) ) ge ranges(0,i) and $
	     (angs_det(0,2,*) < angs_det(1,2,*) ) le ranges(1,i) $
         or  (angs_det(0,3,*) > angs_det(1,3,*) ) ge ranges(0,i) and $
	     (angs_det(0,3,*) < angs_det(1,3,*) ) le ranges(1,i), $
	  n_cat)
    
	if n_cat eq 0 then goto, NOEXPERIMENTS
   	use(w_cat(t_cat)-catoff) = 2b 		; mark qualifing exps/bytes
    endfor

    angs_det = temporary(angs_det(0,0,t_cat))	; just the qualifing exps
						; and just the start wavelength
						; of the 1st det

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects

 endif

 if (out.name) then begin
    name = str.name + ','
    sep = where(byte(name) eq 44b, ncomma)	; commas separate names

    name_arr = strmid(name, 0, sep(0))
    for i = 0, ncomma-2 do $
	name_arr = [name_arr, strmid(name, sep(i)+1, sep(i+1)-sep(i)-1 )]

    for i = 0l, n_cat-1l do begin   		; each thus far qualifing exp
       for n = 0, ncomma-1 do begin             ; each name the user entered

	  starname = name_arr(n)
          if strpos(starname, '*') ne 0 then starname = '*' + starname 

          if strpos(starname, '*', strlen(starname)-1 ) eq -1 $
	     then starname = starname + '*'

	  star = where(byte(starname) eq 42b, nstar)  ; where are "*" wildcards
	  ok   = bytarr(nstar-1) - 1

          expname = string(byte(cat(53:59,w_cat(i)), 0, 14))

	  ok(0) = strpos(strmid(expname,0,14), strmid(starname, 1, star(1)-1) )

	  for k = 1, nstar-2 do $
	     ok(k) = strpos(strmid(expname, ok(k)+1, 14), $
			    strmid(starname, star(k)+1, star(k+1)-star(k)-1) )

	  nogood = where(ok eq -1, failed)
;	  if failed eq 0 then use(w_cat(i)) = 2b   ; mark qualifing experiment
;	  if failed eq 0 then use(i) = 2b   ; mark qualifing experiment
	  if failed eq 0 then use(w_cat(i)-catoff) = 2b   ; mark qualifing experiment

       endfor
    endfor

    w_cat = where(use eq 2b, n_cat) + catoff 	; indices of CAT
    use = temporary(use)/2b 			; only set qualifing exps/bytes
						; unset rejects
 endif

 ;
 ; Expression that the user may manually coded in, using IDL.
 ; No checking is performed here, so the user better know IDL.
 ; Replace the "*" with W_CAT, only use qualifing experiments
 ;

  if out.man ne '' then begin 	
    byte_line = byte(out.man + '*')  
    replace = where(byte_line eq 42b, n_star)		; where are the *'s 
    manline = string( byte_line(0:replace(0)-1 ))
    for i = 1, n_star-1 do $
       manline=manline+ 'w_cat'+ string(byte_line(replace(i-1)+1:replace(i)-1))
                                         
    ok = execute("w_cat = w_cat(where(" + string(manline) + ",n_cat)) ")

    if ok eq -1 then begin  		; manual inputs w/ errors fail here
       print,'Located 0 UVSP catalog entries with the current search parameters.'
       return
    endif 

 endif

; if out.name   ne '' then express = express + ' and ' + out.name


 ;
 ; Now know all the qualifing experiments entries
 ; 

 w_cat = w_cat + offset  		; turns these indices of CAT into 
					; experiment numbers

 print,'Located ',strtrim(n_cat,2), $
       		     ' UVSP catalog entries with the current search parameters.'
 if n_cat eq 0 then return

 if n_elements(yield) eq 0 then begin
   ;
   ; Yield was not passed. Ask user what to do with output.
   ;
   ans = ''
   repeat begin
      print,' '
      print,'Output to SCREEN          (S) '
      print,'Output to FILE            (F) '
      print,'Output to PRINTER         (P) '
      print,'Return experiment NUMBERS (N) '
      print,'Return calalog ARRAY      (A) '
      print,'or EXIT                   (E) '
      print,' '
      read,'Select one of the above letter codes : ', ans

      ans = strupcase(strmid(strtrim(ans,2),0,1))
   endrep until (ans eq 'S' or ans eq 'F' or ans eq 'P' or $
		 ans eq 'N' or ans eq 'A' or ans eq 'E')

   if ans eq 'E' then return
   if ans eq 'N' then begin
	cat_text = w_cat 		; return exp #s only as long
	return
   endif

   ;
   ; Set correct bit to get output
   ;

   if ans eq 'S' then yield=2 else $
	if ans eq 'P' then yield=4 else $
	     if ans eq 'F' then yield=8 else yield=1

 endif

;t if yield eq 0 then begin    ; not array, screen, disk or printer
;t	cat_text = w_cat     ; return just the indices
;t	return
;t endif

 ;
 ; If widget version, INHIB was set with a button.
 ; If screen version, then need to ask the user if should in provide gaps
 ; 

 if n_elements(inhib) eq 0 then begin
   gaps = ''
   read,'Do you want blank lines between orbit (Y/[N]) : ', gaps
   if strupcase(strmid(strtrim(gaps,2),0,1)) ne 'Y' then gaps = 0 else gaps = 1
   widget = 0				; terminal mode doesn't pass INHIB
   cat_widg = 0				; only applies to widgets
 endif else  begin
   widget = 1			; only a widget could pass INHIB
   gaps = not(inhib)
 endelse


 ;
 ; Go do some text outputting
 ;

  
 uvsp_catprint, w_cat=w_cat, radtht=radtht, yield=yield, cat_widg=cat_widg, $
		offset=offset, widget=widget, gaps=gaps, font=font, $
		angs_det=angs_det
		 

return 

NOEXPERIMENTS:

 if n_cat eq 0 then print,'Located 0 UVSP catalog entries with the ' + $
			  'current search parameters.'

return
end
