;+
; NAME:
;     PLOT_TPCAL
; PURPOSE:
;     Plot new total power calibration factors, and overplot old
;     factors for a check on data quality.
; CATEGORY:
;     OVRO APC DATA CALIBRATION
; CALLING SEQUENCE:
;     plot_tpcal,newtp,oldtp
; INPUTS:
;     newtp   an array of size [1024,2] containing the two records
;               of a newly determined TPCAL segment, as the result
;               of total power calibration analysis.
;     oldtp   an array of size [1024,2] containing the two records
;               of the old TPCAL segment, as indicated in the INDEX
;               record for the REF-TPCAL segment.
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
;     get_screen, decode
; OUTPUTS:
; COMMENTS:
;     I anticipate further changes to make this suitable for automation.
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     Written 28-Aug-2000 by Dale E. Gary
;     25-Nov-2000  DG
;       Major changes to input total power calibration segment records
;       rather than the TPCAL factors themselves.  This change simplifies
;       things considerably, since the noise diode factors are already
;       applied properly, and the TLS is included in the records.
;-
pro plot_tpcal,newtp,oldtp

   fghz = (findgen(86)+5)*0.2
   titles = ['Ant 1, Lin Feed','Ant 1, LCP Feed',$
             'Ant 2, RCP Feed','Ant 2, Lin Feed']

   tpnew = decode([newtp[0:1015,0],newtp[12:*,1]],!SEGM.TPCAL)
   tpold = decode([oldtp[0:1015,0],oldtp[12:*,1]],!SEGM.TPCAL)
   xy = get_screen_size()
   window,/free,xsiz=xy[0]*0.8,ysiz=xy[1]*0.8
   tvlct,/get,r,g,b
   loadct,39
   psav = !p
   !p.multi=[0,2,2,0,0]
   feed2pol = [[2,1],[0,2]]
   ; Loop over feeds
   for i = 0, 3 do begin

         ; Plot the actual calibration factors and error bars
         plot_io,fghz,tpnew.tpfac[i,*],yran=[20,2000],ysty=1,$
                   tit=titles[i],xtit='Freq (GHz)',psym=3
         oploterr,fghz,tpnew.tpfac[i,*],tpnew.tprms[i,*]
         oplot,fghz,tpold.tpfac[i,*],psym=6,color=80
         xyouts,10,1300,'These data: '+tpnew.tls27m.date
         xyouts,10,900, '  Previous: '+tpold.tls27m.date,color=80
   endfor
   tvlct,r,g,b
   !p = psav

return
end