;+
; Project     : SOHO - CDS     
;                   
; Name        : PLOT_QCM
;               
; Purpose     : Plots QCM log data
;               
; Explanation : Reads QCM log and does simple plot
;               
; Use         : IDL> plot_qcm
;    
; Inputs      : None
;               
; Opt. Inputs : None
;               
; Outputs     : None
;               
; Opt. Outputs: None
;               
; Keywords    : XMINOR    - request minor time axis ticks marks be plotted
;               TIMERANGE - specify (2-element string) start/stop dates to 
;                           plot
;
; Calls       : utplot
;
; Common      : None
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Telemetry, QCM
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 18-Jan-96
;               
; Modified    : Change from frequency to areal density.  CDP, 30-Jan-96
;               Change  plot symbol size.  CDP, 10-Feb-96
;               Fix plot label.  CDP, 27-Feb-96
;               Add XMINOR (ticks) keyword.  CDP, 25-Mar-96
;               Add TIMERANGE keyword.  CDP, 19-Jul-96
;               Change utplot name.  CDP, 2-Oct-96
;               Change plot range.  CDP, 15-Jan-97
;               Use standard UTPLOT.  CDP, 12-Sep-97
;               Changed scales, NIS/GIS filter, plotting symbol etc 
;                 to cope with post-recovery data.  CDP, 20-Oct-98
;               Update axis label,  CDP.  4 July 2001.
;  
; Version     : Version 11, 4-Jul-2001
;-            

pro plot_qcm, xminor=xminor,timerange=timerange


;
;  set good window size
;
if !d.name eq 'X' then window,xs=640,ys=800,/free

;
;  2 plots per page
;
!p.multi = [0,1,2]

;
;  x tick marks?
;
if not keyword_set(xminor) then xminor=0

;
;  read the qcm log
;
get_qcm, qcm

;
;  get start values
;
n1 = where(qcm.freq gt 1215)
n2 = where(qcm.freq gt 100 and qcm.freq lt 1215)
ad1 = qcm(n1).freq  & ad1 = ad1(0)
ad2 = qcm(n2).freq  & ad2 = ad2(0)

;
;  any time limits?
;
if keyword_set(timerange) then begin
   if n_elements(timerange) ne 2 then begin
      print,'TIMERANGE must have 2 values'
      return
   endif
   if datatype(timerange,1) ne 'String' then begin
      print,'TIMERANGE must be string values'
      return
   endif

   t0 = utc2tai(str2utc(timerange(0)))
   t1 = utc2tai(str2utc(timerange(1)))
   n = where(qcm.time lt t1 and qcm.time ge t0)
   qcm = qcm(n)
endif

;
;  plot the frequency data
;
circle_sym,/fill

n1 = where(qcm.freq gt 1215)
n2 = where(qcm.freq gt 100 and qcm.freq lt 1215)

ad =  qcm(n1).freq
ad = (ad - ad1)*3.5
print,last_item(ad)

lim1 = tai2utc(qcm(min(n1)).time -  20.0d0*864000.0d0)
lim2 = tai2utc(qcm(max(n1)).time +  20.0d0*864000.0d0)

utplot,tai2utc(qcm(n1).time), ad, psym=1,yr=[-100,500],/yst,$
        ytit = 'Areal Density (nanogram/cm!E2!N)', tit='CDS QCM record',$
        syms=0.8, xminor=xminor,timerange=[lim1,lim2],/xst,$
        xtit='Year',chars=1.3 

;
;  key code
;
xst = !x.crange(0) + (!x.crange(1)-!x.crange(0))/20.0d0
xint = xst + (!x.crange(1)-!x.crange(0))/40.0d0
nist = xint-15.*24.*3600.

outplot,[nist,nist],[100,100],psym=1,syms=1.5
xyouts, [xint,xint],[99,99],'GIS'

circle_sym
outplot,[nist,nist],[60,60],psym=8,syms=1.5
xyouts, [xint,xint],[59,59],'NIS'


ad =  qcm(n2).freq
ad = (ad - ad2)*3.5
outplot,tai2utc(qcm(n2).time), ad, psym=8,syms=0.8
print,last_item(ad)


;
;  plot temperature variations
;
circle_sym,/fill
utplot,tai2utc(qcm(n1).time), qcm(n1).t1, psym=1, yr=[12,26],$
        ytit = 'QCM temperature',syms=0.8, xminor=xminor,$
        timerange=[lim1,lim2],/xst,chars=1.3,$ 
        xtit='Year'

circle_sym
outplot,tai2utc(qcm(n2).time), qcm(n2).t2, psym=8,syms=0.8

!p.multi = 0

end


