;******************************************************
; HKPLOT
; This is a driver program to plot MDI House Keeping 
; data. The file MDI_PLOTS.PRO contains all the
; procedures needed for these plots. 
;******************************************************

@mdi_plots

;**************************************************
; hkplot
; to use auto mode (no prompts) do a command line like:
; hkplot,'05-nov-93','00:00','12:00','frog',0,/auto
;**************************************************
pro hkplot,date,time,duration,mnemo_fn,hcopy,auto=auto,dev=plotdev,smooth=smooth_width

file_parms = {     date: '',   $
                   time: '',   $
               duration: '',   $
                 fn_arg: '',   $
             update_int: 300,  $
               n_mnemos: 0,    $
             max_mnemos: 16,   $
               max_args: 5,    $
              disp_msgs: 1,    $
                plotwin: 0,    $
               numplots: 0,    $
             local_time: 0     }

input_line = replicate( { str: string('', format='(a80)') } ,$
        file_parms.max_mnemos)

again = ''

set_plotdata                            ; initialize plotdata common

if n_params(0) ge 1 then begin          ; If at least 1 command line argument
  file_parms.date = date
  if n_params(0) ge 2 then begin
    file_parms.time = time
  endif
  if n_params(0) ge 3 then begin
    file_parms.duration = duration
  endif
  if n_params(0) ge 4 then begin
    file_parms.fn_arg = mnemo_fn
  endif
  if n_params(0) ge 5 then begin
    file_parms.hcopy = hcopy
    if keyword_set(auto) then file_parms.disp_msgs = 0
  endif
endif

if file_parms.disp_msgs eq 1 then begin
  print,"HKPLOT - History files are assumed to be in directory: ",$
    getenv("MDI_HISTORY_DIR")
endif
all_parm = 1
while again eq '' do begin
  get_input, all_parm, file_parms, input_line, auto=auto
  file_parms.plotwin = 0
  for i = 1, file_parms.n_mnemos do begin
      cmdline = input_line(i-1).str
      cmdstr = strmid (cmdline, 0, strpos(cmdline, ' ', 0))
      case cmdstr of
          'plot':     procname = 'DO_PLOT'
          'oplot':    procname = 'DO_OPLOT'
          'plotave':  procname = 'DO_PLOTAVE'
          'oplotave': procname = 'DO_PLOTAVE'
          else:       procname = 'XX'
      endcase
      if (procname ne 'XX') then $
          call_procedure, procname, file_parms,cmdline,auto=auto,dev=plotdev,smooth=smooth_width
  endfor
  ;do_plot,file_parms,input_line,auto=auto
  resp = ' '
  print, FORMAT = '($, "Select Hard Copy Option (a/0/1/2/3/p/<CR>)")'
  read, resp
      ;kb_inp = get_kbrd (0)
      ;print, 'kb_inp = ', kb_inp
      case 1 of
          (resp eq 'a'): $
          begin
              for w = 0, file_parms.numplots do begin
                  plot_hc, w
              endfor
              resp = ''
          end
          (resp eq 'p'): $
          begin
              plot_hc, old_hc_win
              resp = ''
          end
          ((resp ge '0') and (resp le '9')) : $
          begin
              hcwin = fix(resp)
              ;print, 'hc win = ', hcwin
              plot_hc, hcwin
              old_hc_win = hcwin
              resp = ''
          end
          else: qwerty =  ''
      endcase
  if keyword_set(auto) then begin
    again = 'n'
  end else begin
    print,FORMAT='($,"Plot again? (<CR>=YES,y=YES,n=NO)")'
    read,again
    if again eq 'y' then again = ''
  endelse
endwhile
end     ;end of hkplot
;******************************************************
end
