;+
; Project     : SOHO - CDS     
;                   
; Name        : PLOT_TM_CALIB
;               
; Purpose     : Standard plot of calibrated CDS telemetry data.
;               
; Explanation : Takes output from tm_calib and, together with time array,
;               performs a standard cds_utplot plot of the calibrated data as in
;               EMON itself.
;               
; Use         : IDL> plot_tm_calib, time_arr, data, words [,/hard]
;    
; Inputs      : time_arr - as returned by EMON
;               data     - calibrated data as returned by TM_CALIB
;               words    - axis labels as returned by TM_CALIB
;               
; Opt. Inputs : None
;               
; Outputs     : Just plots
;               
; Opt. Outputs: None
;               
; Keywords    : HARD - set to get hardcopy as well as screen plot
;
; Calls       : None
;
; Common      : None
;               
; Restrictions: None
;               
; Side effects: None
;               
; Category    : Telemetry
;               
; Prev. Hist. : None
;
; Written     : C D Pike, 3-Feb-95
;               
; Modified    : Cater for log plots in calib type 7.
;               Change utplot name.  CDP, 2-Oct-96
;
; Version     : Version 3, 2-Oct-95
;-            

pro plot_tm_calib, ut_data, parm_data, words, hard=hard

;
;  better sort in case of funnies
;
utt = utc2sec(str2utc(ut_data,/dmy))
nutt = sort(utt)
uts = ut_data(nutt)
pds = parm_data(nutt)

;
;  plot symbol
;
circle_sym,/fill

;
;  hard copy as well?
;
if not keyword_set(hard) then hard = 0

 
;
;  set up fancy axis labels
;
case words(0) of
   'title':  begin
                yt = strtrim(words(1),2)
                yr=ext_range(pds,100)
                get_mask_etc,details
                n = where(strtrim(details(17,*),2) eq words(1))

                if n(0) ge 0 then begin
                   pname = details(0,n(0))
                   title = 'Engineering '+strupcase(strmid(pname,0,1))+$
                           ': parameter - '+pname
                endif else begin
                   title = 'CDS Engineering parameter'
                endelse
                cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                        symsize=0.3, ytitle=yt,yrange=yr,chars=1.2
                if hard then begin
                   ps
                   cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                           symsize=0.3,ytitle=yt,yrange=yr,chars=1.2
                   psplot
                endif
             end

   'Ltitle': begin
                yt = strtrim(words(1),2)
                yr=ext_range(pds,100)
                get_mask_etc,details
                n = where(strtrim(details(17,*),2) eq words(1))

                if n(0) ge 0 then begin
                   pname = details(0,n(0))
                   title = 'Engineering '+strupcase(strmid(pname,0,1))+$
                           ': parameter - '+pname
                endif else begin
                   title = 'CDS Engineering parameter'
                endelse
                cds_utplot, uts, pds, /dmy, psym=8, title=title, /log,$
                        symsize=0.3, ytitle=yt,yrange=yr,chars=1.2
                if hard then begin
                   ps
                   cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                           symsize=0.3,ytitle=yt,yrange=yr,$
                           chars=1.2, /log
                   psplot
                endif
             end

'Uncalibrated': begin            
                  yt = strtrim(words(1),2)+' (Error)'
                  yr=ext_range(pds,100)
                  get_mask_etc,details
                  n = where(strtrim(details(17,*),2) eq words(1))
                  if n(0) ge 0 then begin
                     pname = details(0,n(0))
                     title = 'Engineering '+strupcase(strmid(pname,0,1))+$
                             ': parameter - '+pname
                  endif else begin
                     title = 'CDS Engineering parameter'
                  endelse
                  cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                          symsize=0.3, ytitle=yt,yrange=yr,chars=1.2
                  if hard then begin
                     ps
                     cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                             symsize=0.3,ytitle=yt,yrange=yr,chars=1.2
                     psplot
                  endif
               end

    'Label': begin
                nw = n_elements(words)
                yt = words(nw-1)
                yr = [0,nw-1]

                get_mask_etc,details
                n = where(strtrim(details(17,*),2) eq words(nw-1))
                if n(0) ge 0 then begin
                   pname = details(0,n(0))
                   title = 'Engineering '+strupcase(strmid(pname,0,1))+$
                           ': parameter - '+pname
                endif else begin
                   title = 'CDS Engineering parameter'
                endelse
                cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                        symsize=0.3, ytitle=yt,yrange=yr,$
                        ystyle=1,yticks=nw-1,chars=1.1,$
                        ytickname=[' ',words(1:nw-2),' ']
                if hard then begin
                   ps
                   cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                           symsize=0.3,ytitle=yt,yrange=yr,$
                           chars=1.1,yticks=nw-1,ystyle=1,$
                           ytickname=[' ',words(1:nw-2),' ']
                   psplot
                endif
             end
      else:  begin
                yt = strtrim(words(2),2)
                yr = [-1,2]
                ytn=[' ',words(0),words(1),' '] 
                get_mask_etc,details
                n = where(strtrim(details(17,*),2) eq words(2))
                if n(0) ge 0 then begin
                   pname = details(0,n(0))
                   title = 'Engineering '+strupcase(strmid(pname,0,1))+$
                           ': parameter - '+pname
                endif else begin
                   title = 'CDS Engineering parameter'
                endelse
                cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                        symsize=0.3, ytitle=yt,yrange=yr,$
                        ytickname=ytn,chars=1.2
                if hard then begin
                   ps
                   cds_utplot, uts, pds, /dmy, psym=8, title=title, $
                           symsize=0.3,ytitle=yt,yrange=yr,$
                           ytickname=ytn,chars=1.2
                   psplot
                endif
             end
endcase

end

