pro plot2offset,cen,out,blokcmd=blokcmd,yohkoh=yohkoh,sft=sft,sxtf=sxtf

;+
;  TITLE:	plot2offset
;  PURPOSE:
;  Program to scale klik'd plot coordinates into Yohkoh offset in 
;  degrees from present pointing.
;	Units:  Degree changes in Yohkoh pointing.
;			+ means point Yohkoh E or S.
;			- means point Yohkoh W or N
;  CALLLING SEQUENCE:
; 	plot2offset,cen [,out,blokcmd=blokcmd,yohkoh=yohkoh]
;  RESTRICTIONS:
;  Only valid for 980x980 window and plot made with the following
;  idl call:
;    IDL> plot,[x0,x0],[y0,y0],yr=[0,1023],ystyle=1,xr=[0,1023],xstyle=1,$
;     title='Sun Center on CCD (92-Nov to Present)',$
;     xtit='CCD FR pixel',ytit='CCD FR pixel',charsize=1.4,$
;     psym=2,symsize=1.
;  where x0,y0 can be anything you like, e.g., suncenter of current 
;  normal pointing.
;  INPUT:
;	cen, the suncenter position for present normal pointing.
;  OPTIONAL KEYWORD INPUT:
;	/blokcmd prints out block commands for desired pointing
;	yohkoh, Euler angles of Yohkoh boresight.
;	       default: yohkoh=[-0.0797222,0.0302778]
;                              [S/C north , S/C east]
;  OPTIONAL OUTPUT:
;	out, array of Yohkoh Euler angles for offpoints.
;  PROGRAMS CALLED:
;	klik.pro, point_hex2.pro
;  HISTORY:
;	LWA 2/15/95
;	LWA 3/8/95, updated header.
;       Sometime in March '95, Weber added plot capability.
;	22-apr-95, JRL, If !d.window is already 980x980, don't create a new one.
;			Don't bomb out if no pointings are selected.
;	LWA 5/13/95, Changed plot3offset name back to plot2offset.
;-

; ----------------------------------------------
; Addition: plot data for you
; ----------------------------------------------
if (keyword_set(sft) and keyword_set(sxtf)) then begin
if (!d.x_size ne 980) or (!d.y_size ne 980) then wdef, !d.window+1, 980, 980
plot, sxtf(0,*), sxtf(1,*),yr=[0,1023],ystyle=1,xr=[0,1023],xstyle=1,$
   title='Sun Center on CCD (92-Nov to Present)',xtit='CCD FR pixel',$
   ytit='CCD FR pixel',charsize=1.4,psym=2,symsize=1.
oplot, sft(0,*), sft(1,*), psym=1,color=50
endif
; -----------------------------------------------

; Euler angles of Yohkoh boresight. 

if NOT keyword_set(yohkoh) then yohkoh=[-0.0797222,0.0302778] $
	 else yohkoh=yohkoh

print, '  CLICK ON DESIRED POINTINGS WITH LEFT BUTTON'
print, '  RIGHT BUTTON TO EXIT AND RETURN'

klik,xsave,ysave,/nomark

if n_elements(xsave) eq 0 then return
xk=fltarr(n_elements(xsave))
yk=fltarr(n_elements(ysave))

;NOTE: It is the following scaling that requires the specific size
; window and plot command specified in RESTRICTIONS above.

;Pointing coord in FR pix.
for i=0,n_elements(xsave)-1 do begin  
   xk(i)=float(xsave(i)-84.)*(1024./(954.-84.))
   yk(i)=float(ysave(i)-67.)*(1024./(946.-67.))
endfor

for i=0,n_elements(xsave)-1 do begin
   oplot,[xk(i),xk(i)],[yk(i),yk(i)],psym=6,symsize=3
   xyouts,/dev,xsave(i)-75,ysave(i)+15,i,charsize=2
   xyouts,/dev,xsave(i)-75-22,ysave(i)+15-23,i,charsize=2
endfor

print
print,'  Coordinates of sun center location in FR pixels.'
for i=0,n_elements(xsave)-1 do print,i,xk(i),yk(i)

;Prepare offsets in degrees for point_hex2.
out=fltarr(2,n_elements(xsave))  
out(0,*)=(xk-cen(0))*2.45/3600.
out(1,*)=(yk-cen(1))*2.45/3600.

print
print,'  Yohkoh offsets in arcminutes: '
print,'  (positive ->S&E offpoint, negative -> N&W offpoint)'
print,'     Case    EW-direction  NS-direction'

for i=0,n_elements(xsave)-1 do print,i,out(0,i)*60.,out(1,i)*60.

if keyword_set(blokcmd) then begin
   yout=out
   yout(0,*)=-out(1,*)
   yout(1,*)=-out(0,*)
   for i=0,n_elements(xsave)-1 do begin
      print
      point_hex2,yohkoh-yout(*,i)
   endfor
endif

end
