pro pr_teem,ind,dat,comp=comp 
;+
; NAME
;   pr_teem 
;
; PURPOSE
;   To interactively select regions, and obtain temp and em for.
;
; CALLING SEQUENCE
;   pr_teem,index,data,comp=comp
;
; INPUT
;   Index : Index ¿
;    Data : Data Cube contining two images through separate SXT
;           filters.
;
; OUTPUT
;         Interactive temperatures and emission measures.
;
; OPTIONAL OUTPUT
;	 none
;
; OPTIONAL KEYWORD INPUT
;	comp : display images on a log scale.
;
; RESTRICTION
;       some-- delta version 0.1415927
;
; HISTORY
;    Written CRF 12 Nov 95 : caf@mssl.ucl.ac.uk
;-

szd1 = size(dat(*,*,0))
szd2 = size(dat(*,*,1))
szi1 = size(ind(0))
szi2 = size(ind(1))

if (szi1(szi1(0)+1) ne 8) or (szi2(szi2(0)+1) ne 8) then begin   ; index must be a structure
  print,'Make sure 1st and 3rd args are sxt index structure'
  help,ind(0),ind(1)
  return
endif

if (szd1(0) ne 2) or (szd2(0) ne 2) or 	$
   (szd1(szd1(0)+1) eq 1) or (szd2(szd2(0)+1) eq 1) then begin
  print,'Image arrays must be 2-d and decompressed (and backgrounded subtracted)'
  help,ind(0),ind(1)
  return
endif

if total(szd1(0:2)-szd2(0:2)) ne 0 then begin
  print,'Image sizes are not the same'
  help,ind(0),ind(1)
  return
endif

xsize = szd1(1)
ysize = szd1(2)
zoom_fac = 1
nxsize = xsize * zoom_fac
nysize = ysize * zoom_fac

if keyword_set(comp) then img0 = sxt_comp(dat(*,*,0)) else img0 = dat(*,*,0)
win,img0
tvscl,img0
;...........................................................
;pro pr_image, data, side, nomark=nomark, raw=raw, bin=bin, index=index
siz = size(dat)
nx = siz(1)
ny = siz(2)
;
if (n_elements(bin) eq 0) then bin=1
if (n_elements(side) eq 0) then side = 9
;
tvscl, rebin(dat(*,*,0), nx*bin, ny*bin, /sample)
;
qdone = 0
while not qdone do begin
    print, '* Use left button to mark the center
    print, '  (box size will be ' + strtrim(side,2) + ')'
    print, '* Use the middle button to mark two corners
    print, '* Use the right button to exit'

    wait, 0.3
    cursor, x, y, /device
    button = !err
    case button of
	1: begin	;left button
		print, 'Center location: ', x, y

		if (n_elements(index) ne 0) then begin
		    xx0 = get_pix_coor(index, offset=x/bin)					;added 7-May-92
		    yy0 = get_pix_coor(index, offset=y/bin, /line)				;added 7-May-92
		    print, 'Location in full res "IDL array" coordinates: ', xx0, yy0		;added 7-May-92
		    xx0 = get_pix_coor(index, offset=x/bin, /img)				;added 7-May-92
		    print, 'Location in full res CCD "IMG" coordinates:   ', xx0, yy0		;added 7-May-92
		end

		x0 = (x/bin-side/2)
		y0 = (y/bin-side/2)
		x1 = x0 + side-1
		y1 = y0 + side-1
	   end
	2: begin	;middle button
		wait, 0.5
		print, 'Mark the other corner'
		cursor, x2, y2, /device
		x0=(x<x2)/bin
		x1=(x>x2)/bin
		y0=(y<y2)/bin
		y1=(y>y2)/bin
	   end
	4: begin	;right button
	   end
    endcase
    ;
    if (button ne 4) then begin
	x0 = x0 > 0 < (nx-1)
	x1 = x1 > 0 < (nx-1)
	y0 = y0 > 0 < (nx-1)
	y1 = y1 > 0 < (nx-1)
	if (not keyword_set(nomark)) then draw_boxcorn, x0*bin, y0*bin, (x1+1)*bin, (y1+1)*bin, /device
	;
	print, 'Region marked is: ', strtrim(x0,2), ':', strtrim(x1,2), ',  ', $
				strtrim(y0,2), ':', strtrim(y1,2)
	temp1 = dat(x0:x1, y0:y1,0)
	temp2 = dat(x0:x1, y0:y1,1)
	ny0 = y1-y0+1
	nx0 = x1-x0+1
	avg1 = total(temp1) / n_elements(temp1)
	avg2 = total(temp2) / n_elements(temp2)
	print, 'Average is: ', avg1,' DAG: ', avg2, ' Ratio: ',avg2/avg1
	;
  sxt_teem,ind(0),temp1,ind(1),temp2,te,em,dte,dem,/average
  print,get_info(nind1,/noninter)
  print,get_info(nind2,/noninter)
  print,'Te = ',10.^te/1.e6,' MK  +/- ',10.^dte/1.e6
  print,'EM = ',em,'     +/-',dem
  npercent = .05
  ij = where(temp1 gt .05*max(temp1),nj)
  print,'Total Pixels = ',n_elements(a),';  above ',npercent,' = ',nj

if (keyword_set(raw)) then begin
	    print, '      ', bindgen(nx0)+x0

for i=ny0-1,0,-1 do begin		;reverse the order printed out (to match the image)
		print, i+y0, temp1(*,i)
end
	end
    end
    ;
    if (button eq 4) then qdone = 1
end
;;

;........................................................................................


end
