
pro pick_pix,index,bin=bin,side=side

;+
;NAME: 
; PICK_PIX 
;PURPOSE: 
; Get location of clicked pixel in IDL image coordinates.  
;CALLING SEQUENCE: 
; pick_pix, index 
; pick_pix, index, bin=2, side=9 
;INPUT: 
; data - 2-D image array already on screen
; index - corresponding index 
;OPTIONAL KEYWORD PARAMETERS: 
; side - Number of pixels on a side (if not passed, the default is 5) 
; bin - The rebin size used to display the image 
;OUTPUTS: 
; FFI IDL image location of clicked pixel in summation mode of image.  
;PROCEDURE: 
; Use get_pix_coord and index.sxt.corner_cmd to compute the position of 
; each image on the CCD.  Add to these the values derived by clicking 
; on the desired feature in the image.  
;HISTORY: 
; Written by LWA 10/15/92 by copying pieces of codes by Metcalf and Morrison. 
;-

;
if (n_elements(bin) eq 0) then bin=1
if (n_elements(side) eq 0) then side = 5
;

col = get_pix_coor(index)
lin = index.sxt.corner_cmd(1)

;  Locate bottom left corner in summed pixel coordinates

qcol = col/(2^gt_res(index))
qlin = lin/(2^gt_res(index))

;

qdone = 0
while not qdone do begin

    wait, 0.3
    cursor, x, y, /device
    button = !err
    case button of
        1: begin        ;left button
;		print, 'Click location: ', x, y
		x0 = (x/bin-side/2)
		y0 = (y/bin-side/2)
		x1 = (x/bin+side/2+1)
		y1 = (y/bin+side/2+1)
		draw_boxcorn, x0*bin, y0*bin, x1*bin,y1*bin, /device
		x=qcol+x/bin
		y=qlin+y/bin
		print, 'Image location: x =', x,'   y = ', y
           end
        4: begin        ;right button
           end
    endcase

;
    if (button eq 4) then qdone = 1
end
;

end


