WHAT IS IN THIS DIRECTORY
  This is the src directory for the massratio95 project.
Some of these, if they prove generally useful, may be moved
to the real src directory, but the goal here is to GET SCIENCE DONE.
  There are also links to important other files, so that the
programs can call the files easily.

DESIGN PHILOSOPHY
  Each program is self-contained with the name <program>.c
If versions seem important, then program2.5 will be compiled from
program2.5.c.
  Even though it is redundant to have identical code or #defines in
different programs, the simplicity is worth it.
  
THE PROGRAMS
-----------------------------------------------------------------------
pleph < log > eph
 generate a pluto ephemeris

STDIN: a log of the observations
#expID    exp starttime ra (field) dec
01mar001a 20 14:03:18 16:xx:xx.xx -06:xx:xx.x

PROCESSING
The name of the ephemeris is written as a comment
Comment lines (starting with # or '\n') are passed unchanged
The midtime is found from starttime + exp/2
The JD is found from from the midtime
The geocentric RA, DEC, and range of the baryctr are found from naif.  
From this, the topocentric hour angle, ra, dec, and range are found.
This is all written out.

STDOUT pluto barycenter ephemeris
#exposure   midtime  julian date        ra (pluto, topo) dec       dist (AU)
01mar001a 14:03:28 JD 244xxxx.xxxxx 16:xx:xx.xxxxxx -06:xx:xx.xxxx 29.xx

OTHER FILES
leapseconds.ker
de245_1990_2010.bsp

HARD-WIRED
Year is 1995
Object is Pluto Barycenter
Location is Mauna Kea
Eqn of equinox only tabulated for Feb22 - March 9
----------------------------------------------------------------------------
----------------------------------------------------------------------------
grep -v # posn | sort +3n > posn_magsort
 sort positions by magnitude

STDIN (rd)
a list of comment lines and
id ra dec mag ...
or
id col row mag ...

PROCESSING
The grep culls the comment lines. The sort sorts by the 4th column
(3rd if oyu count 0-based) numberically.

STDOUT <posn_magsort>
The sorted position

OTHER FILES
None

HARD-WIRED
None
-------------------------------------------------------------
-------------------------------------------------------------
sel_rd < rd > rd_sel
 select ra and dec to lie within the large field of view.

STDIN (rd)
A list of ra and dec
id ra dec mag ...

PROCESSING
Comments and lines outside field-of-view are not written

STDOUT
Only those positions that are in our field of view

OTHER FILES
None

HARD-WIRED
Limits on the RA and DEC are for Pluto's extreme positions + 8.0 arcmin.

        PLUTO'S RANGE               SELECTION RANGE
 16:05:01.00 to  16:06:11.20    16:04:30.00 to  16:06:42.20
-06:50:35.0  to -07:00:28.8    -06:42:50.0  to -07:08:13.8
-------------------------------------------------------------
-------------------------------------------------------------
match_rd rd rd2 root
 match two lists of ra and dec

ARGUMENTS
rd, rd2 - radec lists
root - root for output filenames 

INPUTS (rd, rd2)
A list of ra and dec
id ra dec mag ...

rd should be a subset of rd2 (eg, rd is GSC and rd2 is stripsearch)

PROCESSING
For each star in the subset, look for a match in rd2.
If a match is found, write it to "root"
If not match is found, write it to "root.1"
After going through all the stars in rd, write unmatched stars to "root.2".
A match is made if the stars are within one arcsec of each otehr.

OUTPUT
in root --
id2 ra2 dec2 mag2 id1 (ra1-ra2) (dec1-dec2) (mag1-mag2)

in root.1
id1 ra1 dec1 mag1

in root.2
id2 ra2 dec2 mag2


HARD-WIRED
Match is FIVE ARCSECOND
---------------------------------------------------------------------
--------------------------------------------------------------------
rd2xy ra0 dec0 p11 p12 p21 p22
 translate ra,dec to x,y

ARGUMENTS
ra0, dec0 - center of plate (hh:mm:ss, dd:mm:ss)
x0, y0    - center of plate
p11, p12, p21, p22 - plate constants (mas/pixel)

STDIN
A list of ra, dec
id ra dec mag

PROCESSING
xi and eta are the std. coordinates, and

[x]   [p11 p12] -1    [  xi ]   [ y0 ]
[y] = [p21 p22]     x [ eta ] + [ x0 ]

Comments are passed unchanged.

STDOUT
id x y mag

HARDWIRED
center of chip is 1024, 1024.
-------------------------------------------------------------
-------------------------------------------------------------
sel_xy [margin] < xy > xy_sel
 select x and y that lie on the CCD

STDIN (xy)
A list of x and y (col and row)
id x y mag ...

PROCESSING
Comments and lines outside field-of-view are not written
The field-of-view is x > 0+margin && x < 2047-margin (same for y).
Default for margin is 0.

STDOUT
Only those positions that are in our field of view

OTHER FILES
None

HARD-WIRED
SIze of CCD is 2048x2048.
------------------------------------------------------------
------------------------------------------------------------
annotate fits < xy > fits_xy
 Add comments into the data portion of a FITS file

STDIN (xy)
A list of
id, x, y

ARGUMENTS (fits)
The name of a fits file

STDOUT (fits_xy)
The fits file with the id's written next to the stars

PROCESSING
For each star, the name is inserted at (x+10, y).

HARDWIRED
The font is vfont.
The names are (orig. data) + 20000
The data is 2048 x 2048 x 16 bits
---------------------------------------------------------------------
--------------------------------------------------------------------
orbit epoch semi-maj ecc incl ascnode longperi meanlong period < eph > xieta
  Find the xi, eta for Charon's orbit

ARGUMENTS
jd0       epoch for mean longitude, in Julian Days
semi-maj  semi-major axis of Charon's orbit, in km
ecc       eccentricity 
incl      inclination
ascnode   ascending node
longperi  longitude of periapsis
meanlong0 mean longitude at epoch
period    period (days)

STDOUT pluto barycenter ephemeris (eg, output of pleph)
#exposure   midtime  julian date hr ang      ra (pluto, topo) dec     dist (AU)
01mar001a 14:03:28 244xxxx.xxxxx -01:23:04 16:xx:xx.xxxxxx -06:xx:xx.xxxx 29.xx

PROCESSING
From input line, get exp, jd, ra, dec, dist 

mean_anomoly0 = mean_long0 - long_peri
mean_anom = mean_anom0 + 2*pi/period * (jd - dist/c - jd0); |mean_anom|<pi
ecc_anom - iterate to find ecc_anom(ecc, mean_anom)
true_anom = 2 arctan( sqrt((1+e)/(1-e)) tan(ecc_anom/2) )
r = a(1-e cos(ecc_anom))

arg_peri = long_peri - asc_node
u = true_anom + long_peri - asc_node

xi =(r/dist) * ( -sin(ra-asc_node) cosu + cos(ra-asc_node) cosi cosu)
eta=(r/dist) * ( -cos(ra-asc_node) sin(dec) sinu + 
                  (cod(dec) sini - sin(ra-asc_node)sindec cosi) sinu)

Comments are passed unchanged.

STDOUT pluto barycenter ephemeris (eg, output of pleph)
#exposure xi     eta
01mar001a 0.xxxx 0.xxxx

HARDWIRED
defaults are elements from buie & tholen
