pro plot_fem, weeks, years, fem_data=fem_data, fem_asca=fem_asca, $
		asca=asca, both=both, zoom=zoom, timerange=timerange
;
;+
;NAME:
;	plot_fem
;PURPOSE:
;	To plot the data held in the fem_data structure (s/c day/night,
;	saa, station contacts, ...)
;CALLING SEQUENCE:
;	plot_fem, sttim
;	plot_fem, sttim, entim
;	plot_fem, '1-jun-93', '10-jun-93'
;	plot_fem, weeks, years
;	plot_fem, fem_data=fem_data
;INPUT:
;	weeks	- week(s) scalar or integer array
;	years	- year(s) scalar or integer array
;OPTIONAL KEYWORD INPUT:
;	fem_data- Pass in the FEM structure instead of reading it
;	fem_asca- Pass in the ASCA FEM structure instead of reading it
;	asca	- If set, plot ASCA FEM information (default is Yohkoh)
;	both	- If set, plot both ASCA and Yohkoh FEM data
;	zoom	- If set, Allow interactive zooming
;HISTORY:
;	Written 1-Mar-92 by M.Morrison
;	 8-Apr-93 (MDM) - Added /ASCA and /BOTH options
;	10-Aug-93 (MDM) - Added /ZOOM option
;	23-Mar-95 (MDM) - Modifications to handle Wallops
;	 2-May-95 (MDM) - Modified to trap on cases where the time
;			  span is too short.
;V3.2	15-May-95 (MDM) - Added Santiago
;-
;
COMMON UTCOMMON, UTBASE, UTSTART, UTEND, xst_plot
;
ist = 0
ien = 0
if (keyword_set(asca)) then begin
   ist = 1
   ien = 1
end
if (keyword_set(both)) then begin
    ist = 0
    ien = 1
end
;
if (n_elements(years) eq 0) then years = anytim2ints(weeks, off=24*60.*60.)
;
for iloop=ist,ien do begin
    case iloop of
	0: if (not keyword_set(fem_data)) then rd_fem, weeks, years, fem		else fem = fem_data
	1: if (not keyword_set(fem_asca)) then rd_fem, weeks, years, fem, /asca		else fem = fem_asca
    endcase
    ;
    if (data_type(fem) ne 8) then begin		;MDM added 2-May-95
	print, 'PLOT_FEM: You must choose a longer time period'
	print, 'PLOT_FEM: No start of orbit times encompassed by your times'
	return
    end
    ;
    case iloop of
	0: str = 'Yohkoh'
	1: str = 'ASCA'
    endcase
    off = (iloop-ist) * (ien-ist)*0.25
    if (keyword_set(both) and (iloop eq 0)) then thick=4 else thick=0
    ;
    ref_tim = fem(0)
    x = int2secarr(fem)
    if (n_elements(x) eq 1) then x = [x, 100*60.]
    ;
    ytickv = indgen(12)
    ytickname = [' ', 'SC Day', 'SAA', ' ', ' ', 'KSC', 'Canberra', 'Madrid', 'Goldstone', 'Wallops', 'Santiago', '??', ' ']
    if (iloop eq ist) then utplot, x, fltarr(n_elements(x)), ref_tim, /nodata, $
	        ystyle = 1, psym=0, $
	        ytitle = '', $
	        yrange = [0,12], yticks=12, ytickv=tickv, ytickname=ytickname, timerange=timerange
    if (keyword_set(both)) then begin
	x0 = .90 * (!x.crange(1)-!x.crange(0)) + !x.crange(0)
	xyouts, x0, 1+off, str
	xyouts, x0, 2+off, str
	xyouts, x0, 5+off, str
	xyouts, x0, 6+off, str
	xyouts, x0, 7+off, str
	xyouts, x0, 8+off, str
    end
    for i=0,n_elements(fem)-1 do begin
	xx = int2secarr(fem(i), ref_tim) + [0, fem(i).night]
	oplot, xx, [1,1]+off, thick=thick
	if (fem(i).st_saa ne 0) then begin
	    xx = int2secarr(fem(i), ref_tim) + [fem(i).st_saa, fem(i).en_saa]
	    oplot, xx, [2,2]+off, thick=thick
	end
	;for j=0,2 do if (string(fem(i).st$station(j)) ne '') then begin
	for j=0,2 do if (fem(i).st_station(j) ne 0) then begin
	    case string(fem(i).st$station(j)) of
		'U': offset = 5
		'C': offset = 6
		'M': offset = 7
		'G': offset = 8
		'W': offset = 9
		'S': offset = 10
		else: offset = 11
	    endcase
	    xx = int2secarr(fem(i), ref_tim) + [fem(i).st_station(j), fem(i).en_station(j)]
	    oplot, xx, [0,0]+offset+off, thick=thick
	end
    end
end

plottime
plottime, 0, 0, 'PLOT_FEM  Ver 3.2
;
if (keyword_set(zoom)) then begin
    xrange0 = anytim2ints( anytim2ints(xst_plot), off=!x.crange)
    qdone = 0
    qhard = 0
    while (not qdone) do begin
        if (qhard) then begin
            lprint
            set_plot, save_dev
            qhard = 0
        end

        ss=plot_lcur(fem, intarr(1000), /noplot, qblowup=qblowup, qhard=qhard, qreset=qreset, xsel=xsel, /nowhere)

        qdone = (not qhard and not qblowup and not qreset)
        if (qblowup) then xrange = anytim2ints(anytim2ints(xst_plot), off=xsel)
        if (qreset) then xrange = xrange0
        if (qhard) then begin
            save_dev = !d.name
            set_plot,'ps
            device, /land
        end

	if (not qdone) then plot_fem, weeks, years, fem_data=fem_data, fem_asca=fem_asca, asca=asca, both=both, timerange=xrange
    end
end
;
end
