;+
; Project     : SOHO - CDS     
;                   
; Name        : TP_COLBAR
;               
; Purpose     : Displays colour bar on TPLAN screen.
;               
; Explanation : Displays a colour bar to show the image-colour scaling
;               in the main TPLAN display window.
;               
; Use         : tp_colbar
;    
; Inputs      : None
;               
; Opt. Inputs : None
;               
; Outputs     : None
;               
; Opt. Outputs: None
;               
; Keywords    : None
;
; Calls       : None
;
; Common      : TPLAN common blocks
;               
; Restrictions: Only for use with TPLAN
;               
; Side effects: None
;               
; Category    : Planning, technical
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 18-Oct-94
;               
; Modified    : Version 1, C D Pike, RAL, 18-Oct-94
;		Version 2, William Thompson, GSFC, 20 October 1994
;			Modified to correctly reflect quasi-logarithmic nature
;			of tp_bscale.
;		Version 3, William Thompson, GSFC, 21 October 1994
;			Allow highest plotted color to vary, depending on the
;			data.
;		Version 4, William Thompson, GSFC, 21 March 1995
;			Added /DISABLE keyword to COLOR_BAR call
;
; Version     : Version 4, 21 March 1995
;-            

pro tp_colbar

;
;  common for widget IDs etc.
;
@tplan_com

;
;  save current window 
;
cwin = !d.window

;
;  go to colour bar window
;
widget_control, image_area2, get_val=wind
wset,wind

;
;  Get the tick positions and values.
;
if n_elements(vds_image_data) gt 1 then	$
    maxr = max(vds_image_data) else maxr = 4096
if maxr le 50 then begin
    top = 55
    tickv = [0,2,5,10,20,50]
end else if maxr le 200 then begin
    top = 210
    tickv = [0,3,10,30,100]
end else if maxr le 500 then begin
    top = 510
    tickv = [0,3,10,30,100,300]
end else if maxr le 1000 then begin
    top = 1050
    tickv = [0,3,10,30,100,300,1000]
end else if maxr le 2000 then begin
    top = 2050
    tickv = [0,10,20,50,100,200,500,1000,2000]
end else begin
    top = 4096
    tickv = [0,10,30,100,300,1000,3000]
endelse
tickname = strtrim(tickv,2)
tickv = tp_bscale(tickv)
top = (tp_bscale([top,0]))(0)

;
;  clear image area and display new colour bar
;

erase
tvlct,/get,r,g,b
n = where(r eq 255 and g eq 255 and b eq 255)
if n(0) ge 0 then n = n(0) else n = 255

color_bar, 200, 20, 20, 40, col=n, ticklen=0.1,	$;title='Counts/pixel',$
    tickv=tickv,tickname=tickname,ticks=n_elements(tickv)+1,top=top,max=top, $
    /disable

;
;  return to previous window
;
wset, cwin


end
