;+
; NAME:
;     NAR2COORD 
; PURPOSE:
;     generate SXT pointing information from the NOAA AR number 
; CATEGORY:
; CALLING SEQUENCE:
; INPUTS:
;     time, the string time to rotate coordinates to
;     name, the string name of the AR sought (defaults to the first)
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;     angle allows input of angle coordinates 
;     /gif writes a .gif file to /home/www/sxt_co/obs_coord.gif
;       instead of to X
; OUTPUTS:
;     prints to screen and makes an image. The three verticals on
;       the image correspond to the NAR time, the LASTSFD time, and
;       the prediction time
; COMMON BLOCKS:
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     4-Apr-00, written (HSH)
;-
pro nar2coord, time, name, gif = gif, qdebug = qdebug, angle = angle
lastsfd,index,data,/notv
rd_nar,index,index,/nearest,nar
if n_elements(name) eq 0 then begin
  big = where(nar.area eq max(nar.area))
  name = nar(big).noaa
  print,' '
  print,'I have defaulted to NOAA # '+strtrim(string(name),1)
endif
ss = where(nar.noaa eq name) 
t1 = anytim(nar(ss))
t2 = anytim(index)
t3 = anytim(time)
deltat1 = (t2-t1)/86400. 
deltat2 = (t3-t1)/86400. 
latlon = nar(ss).location
if n_elements(angle) ne 0 then latlon = conv_a2h(angle, time)
pix0 = conv_h2p(latlon,index)/4.
latlon1 = latlon
latlon1(0) = latlon1(0)+13.5*deltat1
pix1 = conv_h2p(latlon1,index)/4.
if n_elements(angle) ne 0 then pix1 = pix0 
latlon2 = latlon
latlon2(0) = latlon2(0)+13.5*deltat2
pix2 = conv_h2p(latlon2,time)/4.
if n_elements(angle) ne 0 then pix2 = pix0 
print,' '
print,"N/S ", fix(pix2(1)), "  E/W ", fix(255-pix2(0)),$
  '   At epoch'+fmt_tim(time), format='(a,i3,a,i3,a)'
print,' '
if keyword_set(gif) then set_plot,'z' 
wdef,0,256
loadct,15
tvlct,r,g,b,/get
img = rebin(data,256,256)
img(*,pix1(1)) = 0
img(pix0(0),*) = 0
img(pix1(0),*) = 0
img(pix2(0),*) = 0
tvscl,rebin(img,256,256)
if keyword_set(gif) then begin
  out=tvrd()
  write_gif,'/home/www/sxt_co/obs_coord.gif',out,r,g,b
  print,' '
  print,'http://isass1.solar.isas.ac.jp/sxt_co/obs_coord.gif'
  print,' '
endif
if !D.NAME eq 'Z' then set_plot,'x' 
if keyword_set(qdebug) then stop
end
