pro show_obs4, structure, selimg, ss, qstop=qstop
;
;+
;NAME:
;	show_obs4
;PURPOSE:
;	To plot when images are taken for each of the particular
;	observing regions.  Also mark where the sequence table or
;	entry table changed.  An option exists to select images with
;	the cursor (select time range).
;CALLING SEQUENCE:
;	show_obs4, roadmap
;	show_obs4, roadmap, sel
;	show_obs4, sxtp, sel, ss	;observing log vector
;INPUT:
;	Structure- Roadmap, index, or observing log entry.  
;OPTIONAL OUTPUT:
;	selimg	- If present, the user is prompted to mark a
;		  starting and ending time of interest.  The value
;                 returned is an array of the same length as
;                 the input array with the selected datasets
;                 having a "1".  The way to use this value is
;                 something like the following:
;                       ss = where(selimg)
;                       ss = where(selimg and (roadmap.percentd eq 255))
;       ss      - Return the list of indicies that were selected.
;                 This should be used only if you do not want to
;                 do other searches using the "where" function.
;HISTORY:
;	Written 7-Nov-91 by M.Morrison (using S.Freeland routine as a start)
;       12-Nov-91 (MDM) - Added "ss" parameter option
;	16-Nov-91 (MDM) - Changed to use UTPLOT instead of plot
;	20-Nov-91 (MDM) - Changed DP_MODE and DP_PLOT symbol from histogram
;			  (psym=10) to usersym (simple horizontal line) because
;			  histogram mode fools the user into thinking that data
;			  exists where it does not
;	11-Dec-91 (MDM) - Took "show_obs2" and made "show_obs3" which also
;			  plotted the s/c day times and SAA times.
;	18-Feb-92 (MDM) - Changed RD_TRN to use RD_FEM - allowed show_obs3 to
;			  be used with 1992 data.
;	 3-Mar-92 (MDM) - Added the times of KSC station contacts to be plotted
;			  ************ Expanded to SHOW_OBS4 *****************
;	 2-May-92 (MDM) - Added ability to zoom in on a time span
;	 5-May-92 (MDM) - Adjusted code to be able to use "BOX_CURSOR" within
;			  PLOT_LCUR more easily.
;-
;
ref_tim = structure(0)
x = int2secarr(structure, ref_tim)
xrange0 = [min(x), max(x)]
xrange = xrange0
dummy = fmt_tim(structure(0), day_str)
;
anytim2weeks, structure(0), structure(n_elements(structure)-1), weeks, years
rd_fem, weeks, years, fem_data
;
parts = [.18, .30, .40, .50]
;
if (!d.name eq 'PS') then device, /land
qdone = 0
qhard = 0
qzoom = 1	;always enable it for now

selimg = bytarr(n_elements(x))
while (not qdone) do begin
			;---------------- Plot DP mode and rate

			usersym,[-0.5,0.5],[0,0]
                        !p.region = [0,0, .95,parts(0)]
                        dp_mode = gt_dp_mode(structure)
                        ytickv = indgen(7)+8
                        ytickname = [' ', 'FL', ' ', 'BCS', 'NGT', 'QT', ' ']
                        utplot, x, dp_mode, ref_tim, psym=8, $
                                yrange = [8,14], ytitle = 'DP Mode', $
                                yticks = 6, ytickv=ytickv, ytickname=ytickname, ystyle=1, ymargin=[4,0], $
				xrange = xrange, xstyle=8, xticklen=.2	;UTPLOT has a problem with ticklengths?
                                ;;xtitle='Hour of day starting ' + day_str, $

                        !p.region = [0,parts(0)+.01, .95,parts(1)]
                        dp_rate = gt_dp_rate(structure)
                        ytickv = indgen(6)
                        ytickname = [' ', 'Low', 'Med', ' ', 'High', ' ']
                        utplot, x, dp_rate, ref_tim, psym=8, /noerase, $
                                yrange = [0,5], ytitle = 'DP Rate', $
                                yticks = 5, ytickv=ytickv, ytickname=ytickname, ystyle=1, ymargin=[0,0], $
                                xrange = xrange, xstyle=4

			;---------------- SXT Sequence table

			!p.region = [0,parts(1)+.01, .95,parts(2)]
			utplot, x, gt_seq_tab(structure), ref_tim, /noerase, $
			        xrange = xrange, xstyle=4, $
				ystyle = 1, psym=10, ymargin=[0,0], $
				ytitle = 'Seq Table#', $
				yrange = [min(gt_seq_tab(structure))-1, max(gt_seq_tab(structure))+1]

			;---------------- S/C day/saa/ksc contacts

			!p.region = [0,parts(2)+.01, .95,parts(3)]
			ytickv = indgen(4)
			ytickname = [' ', 'SC Day', 'SAA', 'KSC']
			utplot, x, fltarr(n_elements(x)), ref_tim, /nodata, /noerase, $
			        xrange = xrange, xstyle=4, $
			        ystyle = 1, psym=10, ymargin=[0,0], $
			        ytitle = '', $
			        yrange = [0,3], yticks=3, ytickv=tickv, ytickname=ytickname
			for i=0,n_elements(fem_data)-1 do begin
			    xx = int2secarr(fem_data(i), ref_tim) + [0, fem_data(i).night]
			    oplot, xx, [1,1]
			    if (fem_data(i).st_saa ne 0) then begin
				xx = int2secarr(fem_data(i), ref_tim) + [fem_data(i).st_saa, fem_data(i).en_saa]
				oplot, xx, [2,2]
			    end
			    for j=0,2 do if (string(fem_data(i).st$station(j)) eq 'U') then begin
				xx = int2secarr(fem_data(i), ref_tim) + [fem_data(i).st_station(j), fem_data(i).en_station(j)]
				oplot, xx, [3,3]
			    end
			end

			;-------------- SXT images

			usersym,[0,0],[-1.5,1.5]

			!p.region = [0,parts(3)+.01, .95,.95]
			y = gt_seq_num(structure)
			ors = y(uniq(y,sort(y)))
			utplot, x, y, ref_tim, /noerase, $
			        xrange=xrange, xstyle=4, $
				ystyle=8, psym=8, title='Image Start Times!c', $
				yrange=[min(y)-1, $
			        max(y)+1], $
			        ; ytickname=[string(ors)],	$
				yticklen=-.01,$ 
				ytickv=ors, $ ; ytickname=[string(ors)], $
				yticks=n_elements(ors)+2, $
				ytitle='Sequence Number', ymargin=[0,1]

    qdone = 1
    qavoid = ((!d.name eq 'PS') and (not qhard))        ;user set device to 'PS' outside of routine
    if (qzoom and (not qavoid)) then begin
        if (qhard) then begin
            lprint
            set_plot, save_dev
            qhard = 0
        end
        ss=plot_lcur(structure, y, ref_tim, /noplot, extra1='Sel', qblowup=qblowup, qhard=qhard, qreset=qreset, qextra1=qextra1, $
										xsel=xsel, ysel=ysel, /nomultiset)
        qdone = (not qhard and not qblowup and not qreset)
        if (qblowup) then xrange=int2secarr(structure([ss(0), ss(n_elements(ss)-1)]), ref_tim)
        if (qreset) then begin
	    xrange = xrange0
	    selimg = bytarr(n_elements(x))	;clear all selections
	end
        if (qhard) then begin
            save_dev = !d.name
            set_plot,'ps
            device, /land
        end
	if (qextra1) then begin
	    n = 1
	    siz = size(xsel)
	    if (siz(0) eq 2) then n = siz(2)
	    for j=0,n-1 do begin
		draw_boxcorn, xsel(0,j), ysel(0,j), xsel(1,j), ysel(1,j), /data
		ss = where( (x ge xsel(0,j)) and (x le xsel(1,j)) and (y ge ysel(0,j)) and (y le ysel(1,j)))
		if (ss(0) ne -1) then selimg(ss) = 1
	    end
	    print, 'There are ', strtrim(fix(total(selimg)),2), ' images selected'
	end
    end
end
;
ss = where(selimg)
if (keyword_set(qstop)) then stop
!p.region = 0
end
