function get_pix_coor, input1, input2, img=img, line=line, offset=offset
;
;+
;NAME:
;	get_pix_coor
;PURPOSE:
;	To convert between various pixel coordinates and resolutions
;CALLING SEQUENCE:
;	a = get_pix_coor(index)
;	a = get_pix_coor(index, /line)
;	a = get_pix_coor(index, offset=b)
;INPUT:
;	input1	- Must be an index structure right now
;OPTIONAL KEYWORD INPUT:
;	img	- If set, return the CCD column address 
;	line	- If set, return the line number 
;	offset	- the offset in pixels (pixels out of camera) from the
;		  lower left corner.
;OUTPUT:
;	Defaults to output the column number in full resolution IDL
;	image array coordinates
;RESTRICTIONS:
;	This routine assumes that BLS is off (non-cal mode)
;HISTORY:
;	Written 6-May-92 by M.Morrison
;
;		************** TEMPORARY ROUTINE ***************
;-
;
;TODO - output in terms of corner of pixel or center of pixel?
;want to (1) take PFI index and give lower left coordinate in terms of ??	(dc subtraction)
;	(2) take FFI pixel location and give 1x1 coordinates			(logging purpose)
;	(3) take PFI index and new origin and return offset 			(mosaic)
;	(4) convert between image resolutions
;all for different resolutions!
;work in IDL address
;return location of pixel in lower left corner
;ASSUME: that commanded start column of N (0-255) 	in 1x1 gives img-(n*4) in pixels out of camera (=(n*4)+1 in CCD pixel
;                                			in 2x2 gives img-(n*4/2) in pixels out of camera
;
;	pixel out of 	"img" in	"img" in	"img" in		SXT cmd value
;	camera		1x1		2x2		4x4			in 1x1		in 2x2		in 4x4
;	0		img-1		img-1		img-1			0		0		0
;	1		img-2		img-2,3		img-2,3,4,5		0		0		1
;	2		img-3		img-4,5		img-6,7,8,9		0		1		2
;	3		img-4		img-6,7		img-10,11,12,13		0		1		3
;	4		img-5		img-8,9		img-14,15,16,17		1		2		4
;
;	509		img-510		img-1018,1019				127		254
;	510		img-511		img-1020,1021				127		255
;	511		img-512		img-1022,1023				127		255
;
;	1020		img-1021						255
;	1021		img-1022						255
;	1022		img-1023						255
;	1023		Overclock						255
;
;	1x1 IDL		1x1 CCD		2x2 IDL		4x4 IDL		SXT Cmd
;	Address		Address		Address		Address		Value
;	0		Overclock	-		-
;	1		img-1023	0		-
;	2		img-1022	0		-
;	3		img-1021	1		0
;	4		img-1020	1		0
;	5		img-1019	2		0
;	6		img-1018	2		0
;	7		img-1017	3		1
;
;	1018		img-6		508		253
;	1019		img-5		509 *		254 *
;	1020		img-4		509		254
;	1021		img-3		510 *		254
;	1022		img-2		510		254
;	1023		img-1		511 (unbin)	255 (unbin)
;	n/a		img-0
;
if (n_elements(offset) eq 0) then offset = 0
;
f_po2img = indgen(1024)+1
h_po2img = [1,indgen(511)*2+3]		;+2 for 1st pixel in "img" space, +3 for last pixel in "img" space (=1st pixel in IDL space)
q_po2img = [1,indgen(255)*4+5]
;
c_cmd = input1.sxt.corner_cmd(0)		;back to commanded value
s_cmd = input1.sxt.shape_cmd(0)			;already in output pixels
npix = 2^gt_res(input1)				;number of pixels binned (1,2 or 4)
st_pix_out = c_cmd/npix				;starting pixel out
en_pix_out = st_pix_out + s_cmd-1		;ending pixel out	- this is the left pixel most on reformatted data images
en_pix_out = en_pix_out - offset		;- offset because it reads out to the right, so it is an earlier output pix
;
if (keyword_set(line)) then begin
    out = input1.sxt.corner_cmd(1) + offset * npix
end else begin
    img0 = f_po2img(en_pix_out)
    for ipix=1,2 do begin
	ss = where(npix eq 2^ipix, count)
	if (count ne 0) then begin
	    case ipix of
	        1: img0(ss) = h_po2img(en_pix_out(ss))
	        2: img0(ss) = q_po2img(en_pix_out(ss))
	    endcase
        end
    end
    ;
    out = 1024-img0				;in IDL pixel coordinates
    if (keyword_set(img)) then out = img0	;in CCD coordinates
end
;
return, out
end
