;+
; NAME:
;       SXT_ECLIPSE 
; PURPOSE:
;	enter Soma-san's calculations for an eclipse
; CATEGORY:
;	Yohkoh
; CALLING SEQUENCE:
;       sxt_eclipse, eclipse, date=date, data_file=data_file, $
;         plot=plot, skip=skip
;       sxt_eclipse, eclipse, /plot
; INPUTS:
;	data_file gives (string) file ID for Soma_san's data.
;         Default is '/ys/ucon/soft/hudson/oct95_eclipse.dat'
;       date is the date of the eclipse, default '24-oct-95'
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;       plot makes a plot of radial distance, with fem_grid
;       skip is the number of lines to skip at the top of the
;         data file, default 20
; OUTPUTS:
;	structure with many things,
;	among which eclipse.xx is the WEST departure
;                   eclipse.yy is the NORTH departure
;                   eclipse.daylight is a D/N flag
; WARNINGS
;       Zaps your windows
;       Soma_san's e-mail messages are used as input. They must be
;         edited to leave 20 unused lines at the top, or 
;         the actual number of lines to be skipped should be entered
;       The Yohkoh ephemeris normally won't be available until 4 weeks
;         before the fact
; MODIFICATION HISTORY:
;	HSH written 8 April 1994
;	HSH added d/n and saa 10 April 1994
;	HSH updated to Nov eclipse 13-May-94
;       HSH added /plot 28-Sep-94
;       HSH hard-wired "final" Soma predictions from 18-Oct elements
;       HSH converted to general use and tidied up some things 20-Sep-95
;       HSH converted .xx from EAST departure to WEST departure
;       HSH patched it up again for 17-18 April 1996
;       HSH patched it up again for 7-Mar 1997. It is almost robust.
;-

pro sxt_eclipse, eclipse, date=date, data_file=data_file, plot=plot, $
  skip=skip, qstop = qstop,frames
if n_elements(date) eq 0 then date = '8-mar-97' 
if n_elements(data_file) eq 0 then $
  data_file = '/ys/ucon/idl/hudson/soma_7mar97.dat'
file = data_file
if n_elements(skip) eq 0 then skip = 0
data=rd_tfile(file,10,skip)
data = float(data)
n_read = n_elements(data(0,*))
eclipse = {soma_str, time:0., day:0, tt:0., dd:0., pp:0.0, r_moon:0.0, $
  r_sun:0.0, pp_sun:0.0, xx:0.0, yy:0.0, daylight:0, saa:0}
eclipse = replicate(eclipse, n_read) 
eclipse.tt = reform(data(0,*))*3600 + reform(data(1,*))*60
eclipse.time = float(eclipse.tt)*1000
eclipse.day = gt_day(anytim(date,/yoh)) 
for i = 0, n_read-1 do begin
  if eclipse(i).time gt 8.64e7 then begin
    eclipse(i).time = eclipse(i).time - 8.64e7
    eclipse(i).day = eclipse(i).day + 1
  endif
endfor
eclipse.dd = reform(data(5,*))
eclipse.pp = reform(data(3,*))
eclipse.r_moon = reform(data(7,*))
eclipse.r_sun = reform(data(6,*))
rad = 180/!pi
fmt_timer,eclipse,t1,t2
pangle = get_rb0p(t1,/pangle)*rad
eclipse.pp_sun = eclipse.pp-pangle              ; corrects for solar tilt
eclipse.xx = -sin(eclipse.pp_sun/rad)*eclipse.dd ; xx is W departure
eclipse.yy =  cos(eclipse.pp_sun/rad)*eclipse.dd ; yy is N departure
t1 = anytim(t1,/ext)
t1(0) = t1(0)-3
t2 = anytim(t2,/ext)
t2(0) = t2(0)+6
fmt_timer,eclipse,t1,t2
rd_fem,t1,t2,fem_dat
;eclipse.daylight = day_in(fem_dat, eclipse.tt)
eclipse.daylight = day_in(fem_dat, eclipse.time)
if n_elements(plot) ne 0 then eclipse_plotter,eclipse,date=date,frames 
if n_elements(qstop) then stop
end
