pro quick_hkplot, sttim, entim, mnem2, win=win, style=style, mnem=mnem, $
		clean=clean, yrange=yrange, nolabel=nolabel, info=info, $
		hc=hc, help=help, nover=nover, exp_pkt=exp_pkt, qdebug=qdebug, $
		continuous=continuous, wait_time=wait_time, $
		text=text, outfil=outfil, pmulti=pmulti, every=every, $
		raw=raw, rd_group=rd_group, rd_full=rd_full, sea=sea, $
		psym=psym, $
		notyminmax=notyminmax, median_pm=median_pm, sigma=sigma, $
		pm_filter=pm_filter, filter1d=filter1d, last_tim_lab=last_tim_lab, $
		plot_times=plot_times
;+
;NAME:
;	quick_hkplot
;PURPOSE:
;	To read a list of mnemonics and plot them
;METHOD:
;	If no start/end date/times are passed in, then the current time is
;	used and the default window is 6 hours.
;SAMPLE CALLING SEQUENCES:
;	quick_hkplot, style=1
;	quick_hkplot, '14-jun 6:30','14-jun 8:00',style=-10,/hc
;	quick_hkplot, style=-1
;	quick_hkplot, style=0, mnem=['mipwa', 'mipwb'], yrange=[1, 1.2]
;	quick_hkplot, sttim, entim, win=win, style=style, mnem=mnem
;	quick_hkplot, style=1, /contin
;	quick_hkplot, '30-nov-95 20:12',style=1, /text, outfil='temps.txt'
;	quick_hkplot, /cont, mnem='ivcmp5', wait=10, win=0.5
;	quick_hkplot, /cont, pmulti=[0,2,2], mnem=['ivaep5', 'ivaep15', 'ivaen15', 'ivcmp5']
;	quick_hkplot, /rd_full, sea='volt'
;	quick_hkplot, sttim, entim, /rd_group
;	quick_hkplot, sttim, entim, mnem, pm_filter=100
;INPUT:
;	sttim	- starting time
;	entim	- ending time
;OPTIONAL KEYWORD INPUT:
;	win	- the window of time to use when no start/end times are 
;		  specified.  Default is 6 hours
;	style	- the style option (an integer value)
;	mnem	- the mnemonics to plot (manually defined)
;	yrange	- Force the plotting range for the y axis
;	exp_pkt	- Force it to use the emergency low rate experiment packets 
;		  instead of the MDI packets (sc1,2,4 are still available)
;	continous - Loop through continuously.  If the letter "h" is hit
;		  while running continuously, a hardcopy is made.  Any other
;		  key will exit the continuous wait.  Default wait is 60 sec.
;	wait	- How much time to wait between real time plotting. Default 
;		  is 60 seconds.
;	text	- If set, then show the mnemonic values in ASCII form to the
;		  IDL terminal
;	outfil	- If /TEXT option is used, the results can also be saved to
;		  a file.
;	every	- If set, only read every "every" data points in the HK
;		  file
;	raw	- If set, then do not convert to engineering units
;	pmulti	- Optionally make several plots per page.
;	rd_group - If set, then the user will be prompted by Xwidget for
;		  the list of mnemonics from the group list 
;		  specified in $MDI_CAL_INFO/xhkplot_mnem.lst
;	rd_full	- If set, then the user will be prompted by Xwidget for
;		  the full mnemonics list 
;	sea	- Used with the /RD_FULL option to specify a string to
;		  search through and reduce the mnemonic list
;	pm_filter - The value to search for valid data, ie: pm_filter=100
;		  will only plot data between -100 and 100 ("pm" is plus/
;		  minus)
;	filter1d- Remove bad data by finding where values exceed the
;		  "smoothed 100" values by more than 3 sigma
;	plot_times- If set, then set the plot range to be the time span
;		  requested
;DETAILS
;	The following style options are available for MDI
;		1  - ALL temperatures
;		2  = optics temperatures
;		3  = oven temperatures
;		4  = camera temperatures
;		5  = structural temperatures
;		6  = outside MLI and front window temps
;		7  = electronics
;		9  = temperatures in S/C packets only
;		-1 = 6 panel plots with styles 2,3,4,5,6
;
;		10 = ALL voltages
;		11 = +5 voltages
;		12 = +15 voltages
;		13 = -15 voltages
;		14 = +30 and +75 volts
;		-10 = 4 panel plot with styles 11,12,13,14
;	
;		20 = All Currents
;
;		30 = PZT error signals
;HISTORY:
;	Written 21-Nov-95 by M.Morrison
;	29-Nov-95 (MDM) - Added /EXP_PKT keyword option and /QDEBUG
;	30-Nov-95 (MDM) - Added /continuous switch and WAIT option
;			- Modified to purge out mnemonics which are not
;			  available when /EXP_PKT option is used
;			- Added currents style option
;			- Added /TEXT and OUTFIL options
;	 1-Dec-95 (MDM) - Added style 9 for SC temperatures
;	 5-Dec-95 (MDM) - Removed mtsqopt* mnemonics from styles 3-6
;			- Passed the input keywords through to the recursive
;			  calls to QUICK_HKPLOT
;	13-Dec-95 (MDM) - Added /nostring option to get_hk_info call
;			- put on-line (5-dec version was not put online)
;	 6-Feb-96 (MDM) - Added PZT error signals
;	10-Feb-96 (MDM) - Added information to the header (re: outfil)
;	28-May-96 (MDM) - Added PMULTI option
;	 6-Jun-96 (MDM) - Added EVERY option
;	19-Sep-96 (MDM) - Added RAW option (only available for non multi
;			  plot pages)
;	 2-Jan-97 (MDM) - Added PMULTI option to the continuous option
;	22-Jan-97 (MDM) - Added /RD_GROUP, /RD_FULL and SEA options
;	19-May-97 (MDM) - Added setting of entim if not defined
;			- Added psym
;	 2-Apr-98 (MDM) - Added pm_filter
;			- Allowed mnemonic list to be the third arg
;			- Pass through all of the new_hkplot filters
;	16-Apr-98 (MDM) - Added filter1d and last_tim_lab options
;			- 
;-
;
top:
;
if (keyword_set(mnem2)) then mnem = mnem2
if (keyword_set(rd_group)) then mnem = get_hk_mnem(1)
if (keyword_set(rd_full)) then mnem = get_hk_mnem(0, sea=sea)
if (keyword_set(rd_group) or keyword_set(rd_full)) then if (mnem(0) eq '') then return
if (n_elements(psym) eq 0) then psym = 0
;
if (n_elements(style) eq 0) then style = 1
if (keyword_set(mnem)) then style = 0	;MDM 29-Nov-95
if (n_elements(win) eq 0) then win = 6		;hours
if (keyword_set(text)) then begin
    if (n_elements(sttim) eq 0) then sttim = ut_time()
    if (n_elements(entim) eq 0) then entim = anytim2ints(sttim, off=15)
end
if (n_elements(sttim) eq 0) then sttim = anytim2ints(ut_time(), off=-60.*60.*win)
if (n_elements(entim) eq 0) then entim = anytim2ints(sttim, off=60.*60.*win)
;
sttim = fmt_tim(sttim)
entim = fmt_tim(entim)
;
save_psym = !psym
!psym = psym
if (keyword_set(hc)) then begin
    save_dev = !d.name
    set_plot, 'ps
    device, /land
end
;
case style of
     -1: begin
		!p.multi=[0,3,2]
		quick_hkplot, sttim, entim, style=2, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=3, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=4, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=5, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=6, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=7, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt
		!p.multi = 0
		if (keyword_set(hc)) then set_plot, save_dev
		return
	 end
    -10: begin
		!p.multi=[0,2,2]
		quick_hkplot, sttim, entim, style=11, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=12, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=13, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt, /nover
		quick_hkplot, sttim, entim, style=14, clean=clean, yrange=yrange, qdebug=qdebug, exp_pkt=exp_pkt
		!p.multi = 0
		if (keyword_set(hc)) then set_plot, save_dev
		return
	 end
    else:
end
;
mat = rd_tfile('$MDI_CAL_INFO/pr_hk_info.txt')
mat = mat(2:*)
all_mnem = strtrim(strmid(mat, 1, 10),2)
;
case style of
    0:
    ;------------------------ Temperature options
    1:  mnem = [all_mnem(where(strpos(all_mnem, 'opt') ne -1)), $
		all_mnem(where(strpos(all_mnem, 'epts') ne -1))]
    2:  mnem = ['mtopts1', 'mtopts2', 'mtopts3', 'qtopts1n', 'qtopts2n']	;optics
    3:  mnem = ['mtopts4', 'mtopts5', 'qtopts3n']				;oven
    4:  mnem = ['mtopts6', 'mtopts8', 'qtopts4n']				;camera
    5:  mnem = ['mtopts7', 'mtopts9', 'mtopts10', 'mtopts12', 'mtopts13', 'mtopts14', $
			'mtopts15', 'mtopts16', 'mtepts1', 'mtepts2', 'mtepts3', 'mtepts4']	;structure 
    6:  mnem = ['mtopts11']							;outside MLI, front window
    7:  mnem = ['mtopts7']		 					;electronics
    9:  mnem = [all_mnem(where(strpos(all_mnem, 'qtopt') ne -1)), $
		all_mnem(where(strpos(all_mnem, 'qtept') ne -1))]
    ;------------------------ Voltage options
    10:  mnem = [all_mnem(where(strpos(all_mnem, '+') ne -1)), $
		all_mnem(where(strpos(all_mnem, '-') ne -1))]
    11:  mnem = [all_mnem(where(strpos(all_mnem, '+5') ne -1))]
    12:  mnem = [all_mnem(where(strpos(all_mnem, '+15') ne -1))]
    13:  mnem = [all_mnem(where(strpos(all_mnem, '-15') ne -1))]
    14:  mnem = [all_mnem(where(strpos(all_mnem, '+30') ne -1)), $
		all_mnem(where(strpos(all_mnem, '+75') ne -1))]
    ;------------------------ Currents options
    20:  mnem = ['miaemtr', 'mipwa', 'mipwb', 'qim3']
    ;------------------------ PZT/ISS options
    30:  mnem = ['multxave', 'multyave', 'multxmax', 'multymax']

    else: begin
	message, 'Style not regcognized', /info
	return
      end
endcase
;
if (keyword_set(exp_pkt)) then begin
    if (keyword_set(qdebug)) then print, 'Trimming out the not exp_pkt mnemonics'
    ss = where_arr(all_mnem, mnem)
    lines = mat(ss)
    ss2 = where((strmid(lines, 54, 3) eq 'MDI') and (strmid(lines, 59, 3) ge ' 50'), nss)
    if (nss eq n_elements(mnem)) then begin
	print, 'No Mnemonics selected which are in the EXP_PKT'
	return
    end
    if (nss ne 0) then mnem = mnem(rem_elem(indgen(n_elements(mnem)), ss2))
end
;
if (keyword_set(help)) then begin
    ss = where_arr(all_mnem, mnem)
    if (ss(0) ne -1) then begin
	print, 'Mnemonics to be plotted for STYLE = ' + strtrim(style,2)
	prstr, mat(ss), /nomore
    end else begin
	print, 'Sorry - no help available
    end
    return
end
;
n = n_elements(mnem)
print, 'Reading: ', mnem
print, 'Time range: ', sttim, ' to ', entim
info = get_hk_info([sttim,entim], mnem, clean=clean, exp_pkt=exp_pkt, qdebug=qdebug, /nostring, every=every, raw=raw)
if (data_type(info) ne 8) then begin
    print, 'Read of the database failed.  Returning......'
    return
end
;
if (keyword_set(text)) then begin
    times = info.(0).daytime
    if (n_elements(times) le 4) then out = hkplot_info(info, times=times, /list) $
				else out = hkplot_info(info,times=[sttim, entim])

    prstr, out, /nomore
    if (keyword_set(outfil)) then prstr, out, file=outfil
    return
end
;
if (keyword_set(plot_times)) then timerange = [anytim2ints(sttim), anytim2ints(entim)]
;
if (keyword_set(pmulti)) then begin
    if (n_elements(pmulti) gt 1) then !p.multi = pmulti else !p.multi = [0,1,n]
    for i=0,n-1 do begin
        npp = (!p.multi(1) * !p.multi(2) )>1
	qnover = ((i mod npp) ne npp-1) and (i ne n-1)
        new_hkplot, info, yrange=yrange, codelist=i, $
                nover=qnover, label=(1-keyword_set(nolabel)), $
		notyminmax=notyminmax, median_pm=median_pm, sigma=sigma, $
		pm_filter=pm_filter, filter1d=filter1d, $
		last_tim_lab=last_tim_lab, timerange=timerange
    end
end else begin
    new_hkplot, info, yrange=yrange, label=(1-keyword_set(nolabel)), $
		/qlinestyle, nover=nover, $
		notyminmax=notyminmax, median_pm=median_pm, sigma=sigma, $
		pm_filter=pm_filter, filter1d=filter1d, $
		last_tim_lab=last_tim_lab, timerange=timerange
end
;
if (keyword_set(hc)) then begin
    ;;pprint		;already done in NEW_HKPLOT!
    set_plot, save_dev
end
;
;----- Logic to run continuously
;
if (keyword_set(continuous) or keyword_set(wait_time)) then begin
    if (n_elements(wait_time) eq 0) then wait_time = 60		;wait 60 seconds
    redo_tim = systime(1) + wait_time
    qdone = 0
    print, 'Waiting', format='($,a)'
    while (not qdone) do begin
	kb_inp = strlowcase(get_kbrd(0))
	case kb_inp of
	    '': wait,1		;nothing typed
	    'h': quick_hkplot, sttim, entim, style=style, mnem=mnem, $
		clean=clean, yrange=yrange, nolabel=nolabel, $
		/hc, exp_pkt=exp_pkt, pmulti=pmulti
	    else: qdone =1
	endcase
	if (not qdone) then print, '.', format='($,a)'
	if (not qdone) and (systime(1) ge redo_tim) then begin
	    delvarx, sttim
	    delvarx, entim
	    print, ''
	    goto, top		;sorry for the after thought
	end
    end
    print ,''
end

!psym = save_psym
end