function scale_teem,Te,dTe,level=level,qtest=qtest
;+
;  NAME:
;    scale_teem
;  PURPOSE:
;    Scale the results from sxt_teem to that they can be displayed
;  CALLING SEQUENCE:
;    out_te = scale_teem(Te,dTe)
;    out_te = scale_teem(Te,dTe,level=level)
;  INPUTS:
;    Te	    = Log10(Te) of Temperatures
;    dTe    = d(Log10(Te)) of Temperatures
;  OPTIONAL INPUT PARAMETER:
;    level = Cutoff value of dTe for plotting Te
;  MODIFICATION HISTORY:
;    14-oct-94, J. R. Lemen, LPARL (adapted from J. McTiernan's t664_screen)
;-

nparams = n_params()			; Get the number of parameters
max_level = !d.n_colors - 1		; Get the number of colors for the display

ieq0 = where(Te le 0.,neq0)		; Get the invalid cases
ine0 = where(Te gt 0.,nne0)		; Valid cases

if nne0 gt 0 then min_img = min(Te(ine0)) else min_img = 0
img = Te
if neq0 gt 0 then img(ieq0) =  min_img
sz  = size(Te)

if nparams gt 1 then begin
  if n_elements(level) eq 0 then begin
     level = .7
     message,string('Defaulting to level = ',level,format='(a,f4.1)'),/info
  endif
  kk = where(dte gt level,nkk)
  if nkk gt 0 then img(kk) = min_img
endif

return,bytscl(img,top=max_level)
;;n_x = sz(1)
;;n_y = sz(2)
;;bin = !d.y_size / n_y
;;tv, rebin(bytscl(img, top = max_level), bin*n_x, bin*n_y, /sample)
;;stop

; Add on the titles/scale if possible:

if bin*n_x lt !d.x_size then begin
  bar = transpose(bytscl(indgen(bin*n_y)))
  bar = rebin(bar, 16,bin*n_y,/sample)
  tv,bar,n_x*bin,0

; Now label 16-2 levels

  ymin = min(img) & ymax = max(img) & dy = (ymax-ymin) / (16.-1)
  x0 = n_x * bin + n_elements(bar(*,0)) + 8
  for i=1,14 do xyouts,x0,(i/15.)*bin*n_y,	$
		string(ymin+i*dy,format='(f5.2)'),charsize=1.26,/dev
endif

if keyword_set(qtest) then stop		;***
end
