pro ssw_cactus_bar,cmes, _extra=_extra,label=label, $
   tickpos=tickpos, ticklen=ticklen, debug=debug, thick=thick, $
   nofirst=nofirst, estimated=estimated, labcolor=labcolor, labpos=labpos, $
   labove=labove, lbelow=lbelow, blank=blank, testing=testing, $
   imagemap_coord=imagemap_coord, imap=imap, cacturls=cacturls, $
   width_sort=width_sort, labsize=labsize
;
;+
;   Name: ssw_cactus_bar
; 
;   Purpose: annotate utplot with cactus index colorbar
;
;   Input Paramters:
;      time0, time1 - optional time range - default is current UTPLOT
;
;   Keyword Paramters:
;      tickpos,ticklen,thick,labcolor,labpos - per evt_grid.pro definitions
;      label - string arry of lables or (if switch) label with WIDTH/CPA 
;      labove/lbelow (implies /LABEL) - relative label positions (def=/labove)
;      blank - if set, blank area around annotation
;
;   History:
;     6-feb-2005 - S.L.Freeland - annotate some space weather/latest events
;                  (from ssw_apkpbar)
;   
;   Side Effects:
;     clobbers 1st 15 r,g,b indices
;-
testing=keyword_set(testing) or n_params() eq 0

case 1 of 
   n_elements(blank) eq 0: noblank=1
   blank eq 1: background=!p.background
   else: background=blank
endcase
debug=keyword_set(debug)
if not data_chk(label,/string) then label=keyword_set(label) $
      or keyword_set(labove) or keyword_set(lbelow)
lbelow=keyword_set(lbelow)
labove=1-lbelow

if testing then begin  
   cmes=ssw_getcme_cactus(/quicklook)
endif
if n_params() lt 2 then begin 
   get_utevent,t0,t1,/ut
   if n_elements(t0) eq 0 then begin
      box_message,'No existing utplot - make one or supply time range...'
      return
   endif
endif else begin 
   t0=time0
   t1=time1
endelse
dtdays=ssw_deltat(t0,t1,/days)
if n_elements(labsize) eq 0 then labsize=.6
if keyword_set(width_sort) then begin
   sso=sort(cmes.width)
   cmes=cmes(sso)
endif
if not keyword_set(thick) then thick=20./(dtdays/6)
if not keyword_set(tickpos) then tickpos=.9
if not keyword_set(ticklen) then ticklen=.05
cwidth=gt_tagval(cmes,/width,missing=1)
case 1 of 
   n_elements(label) eq n_elements(cmes): labels=label  ; user supplied
   data_chk(label,/string): labels=replicate(label(0),n_elements(cmes))
   keyword_set(label):  labels=$
      strtrim(cwidth,2) + '/'+ strtrim(cmes.cpa,2) 
   else: lables=strarr(n_elements(cmes))
endcase
if not keyword_set(labpos) then begin 
   labpos=tickpos + (([-1,1])(labove)*(.01*ticklen + .005) )
   labpos=stag_lab(labels,min=labpos,max=labpos+.02,sep=.02)
endif
if keyword_set(width_sort) then labpos=labpos(sso)
if keyword_set(width_sort) then tickpos=tickpos(sso)

pixperhour=(convert_coord(60*60,0,/data,/to_device) - $
           convert_coord(0,0,/data,/to_device))(0)


ssw_lclimit_colors


; map index->temperature
ssw_lclimit_colors,cmes.width/36,kpout
 
if n_params() eq 2 then begin  ; no utplot assumed
   utplot,apkpind,kp,psym=10,color=5,background=11,/ystyle,/xstyle
endif
 

evt_grid,cmes,color=kpout,thick=(cmes.duration<2)*10>5, $
   tickpos=tickpos, ticklen=ticklen, labcolor=labcolor, $
   labsize=labsize, labpos=labpos, label=labels ,$
   no_blank =noblank,background=background, align=.5,/noarrow, $
   imap=imap, imagemap_coord=imagemap_coord
if debug then stop, 'debug'
cacturls=gt_tagval(cmes,/cmeurl)

if testing then begin 
   zbuff2file2,'cactus.png'
   
endif
return
end
