;
; venus_ephem returns values from the ephemeris file SOHO_venus_snp.txt
; in SOHO (X,Y) coordinates.


FUNCTION venus_ephem_data
  
; Reference = snp                                                 
;                   ---------Venus -----------    Sun/Venus       Ang radius      Ang radius              
;    Time (UTC)      Long(deg)       Lat(deg)       Sep(deg)       Sun (deg)      Venus (deg)     Sun dist (km)   Venus dist (km)
; 20040608.085900   0.332852094   -0.310234363    0.455010762     0.264855363     0.008270023     150565214.7     41927924.37
; 20040608.090000   0.3316922     -0.310259666    0.454180251     0.264855338     0.008270024     150565228.7     41927920.25
; 20040608.090100   0.330532305   -0.310284969    0.453351187     0.264855314     0.008270024     150565242.6     41927916.15
; 20040608.090200   0.32937241    -0.310310272    0.452523578     0.264855289     0.008270025     150565256.6     41927912.08
  
  tx = rd_ascii('SOHO_venus_snp.txt')
  tx = tx[3:*]
  
  return,tx
END 

PRO venus_ephem,x,y,sep,delta_time,timestr=timestr,reset=reset
  
  COMMON venus_ephem,txm,c_time,c_timestr,c_d,c_i,c_x,c_y,c_min,c_sep
  
  IF keyword_set(reset) THEN delvarx,txm
  
  IF n_elements(txm) EQ 0 THEN BEGIN
     txm = venus_ephem_data()
     tstr = strmid(txm,0,15)
     hour = float(strmid(tstr,9,2))
     minute = float(strmid(tstr,11,2))
     second = float(strmid(tstr,13,2))
     c_timestr = $
        strmid(tstr,0,4)+"/"+strmid(tstr,4,2)+"/"+strmid(tstr,6,2)+" "+$
        strmid(tstr,9,2)+":"+strmid(tstr,11,2)+":"+strmid(tstr,13,2)
     c_time = minute + hour*60.0 + second/60.0
     c_time = anytim2tai(c_timestr)/60. ; Historical reasons...
     c_x = -3600*double(strmid(txm,17,13))
     c_y = 3600*double(strmid(txm,32,13))
     c_sep = double(strmid(txm,48,13))
     c_d = sqrt(c_x^2+c_y^2)
     c_min = min(c_d,c_i)
  END 
  
  delta_time = c_time-c_time[c_i]
  
  IF arg_present(timestr) THEN timestr = c_timestr
  
  x = c_x
  y = c_y
  sep = c_sep
  
  n = n_elements(x)
  
  ;; Fit only original points:

END
