pro plot2offset,cen,out,blokcmd=blokcmd,yohkoh=yohkoh,sft=sft,sxtf=sxtf, $
	noplot=noplot, noklix=noklix, orb_bias=orb_bias, blowup=blowup

;+
;  TITLE:	plot2offset
;  PURPOSE:
;  	Program to scale klik'd plot coordinates into Yohkoh offset in 
;  	degrees from present pointing. Plots pointings.
;	Units:  Degree changes in Yohkoh pointing.
;			+ means point Yohkoh E or S.
;			- means point Yohkoh W or N
;       Orbital pointing offset bias of terminators removed.
;  CALLLING SEQUENCE:
; 	plot2offset,cen [,out,blokcmd=blokcmd,yohkoh=yohkoh,sft=sft,sxtf=sxtf, $
;		noplot=noplot,noklix=noklix,orb_bias=orb_bias,blowup=blowup]
;	plot2offset,cen,out,/blokcmd,/sft,/sxtf,blowup=[534,544,560,600]
;	plot2offset,cen,/blokcmd,/noplot
;  INPUT:
;	cen, the suncenter position for present normal pointing.
;	sxtf=sxtf causes plotting of sfr (or spr flare_mode) pointings.
;	sft=sft causes plotting or overplotting of SFT pointings.
;  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]
;	noplot, /noplot assumes data already displayed, used for getting
;		new Yohkoh pointings from existing plot.
;	noklix, /noklix bypasses whole klik pointing selection process
;	orb_bias, offset in FR pixels of terminator offset from avg pointing.
;		default:  orb_bias=[0.277.4.921]
;	blowup, array to specify expanded region, blowup=[x0,x1,y0,y1]
;		default:  blowup=[0,1023,0,1023]
;  OPTIONAL OUTPUT:
;	out, array of Yohkoh Euler angles for offpoints.
;  PROGRAMS CALLED:
;	klik.pro, point_hex2.pro
;  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',$
;        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.
;  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.
;	LWA 5/25/95  Separated plotting of SXTF and SFT points.
;		     Added /noplot option and cleaned up header.
;	HSH 6/5/95   Added /name in call to point_hex2
;	LWA 11/11/95	Removed '(92-Nov to Present)' from title of plot.
;			Added orb_bias and blowup keywords.
;			Changed window call to use free_win.
;			Corrected error in scaling from window.
;-

if NOT keyword_set(noplot) then begin

   ; ----------------------------------------------
   ; Addition: plot data for you
   ; ----------------------------------------------

   if NOT keyword_set(blowup) then blowup=[0,1023,0,1023] else blowup=blowup
   blowup=float(blowup)

   if keyword_set(sxtf) then begin
   if (!d.window eq -1) or (!d.x_size ne 980) or (!d.y_size ne 980) then $
	wdef,free_win,/ur,980,980
      plot, sxtf(0,*), sxtf(1,*),yr=[blowup(2),blowup(3)],ystyle=1, $
	 xr=[blowup(0),blowup(1)],xstyle=1,$
         title='Sun Center on CCD',xtit='CCD FR pixel',$
         ytit='CCD FR pixel',charsize=1.4,psym=2,symsize=1.
   endif

   if keyword_set(sft) and NOT keyword_set(sxtf) then begin
   if (!d.window eq -1) or (!d.x_size ne 980) or (!d.y_size ne 980) then $
        wdef,free_win,/ur,980,980
      plot, sxtf(0,*), sxtf(1,*),yr=[blowup(2),blowup(3)],ystyle=1, $
         xr=[blowup(0),blowup(1)],xstyle=1,$
         ytit='CCD FR pixel',charsize=1.4,psym=2,symsize=1.
   endif

   if keyword_set(sft) and keyword_set(sxtf) then begin
      oplot, sft(0,*), sft(1,*), psym=1,color=50
   endif

endif

if not keyword_set(noklix) then begin

   ; 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.-83.))
;      yk(i)=float(ysave(i)-56.)*(1024./(952.-55.))
       xk(i)=float(xsave(i)-84.)*((blowup(1)-blowup(0))/(954.-83.))+blowup(0)
       yk(i)=float(ysave(i)-56.)*((blowup(3)-blowup(2))/(952.-55.))+blowup(2)
   endfor

; Draw boxes and number klik points
   for i=0,n_elements(xsave)-1 do begin
      oplot,[xk(i),xk(i)],[yk(i),yk(i)],psym=6,symsize=3,color=128
      xyouts,/dev,xsave(i)-75,ysave(i)+15,i,charsize=2,color=128
      xyouts,/dev,xsave(i)-75-22,ysave(i)+15-23,i,charsize=2,color=128
   endfor

; Here we correct for orbital bias of the terminators. (11/11/95)
   if NOT keyword_set(orb_bias) then orb_bias=[0.277,4.921] else orb_bias=orb_bias
      xk=xk+orb_bias(0)
      yk=yk+orb_bias(1)

   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),/name
      endfor
   endif

endif

end
