/* Solar system barycentric velocity and position
 * state of Mercury, Venus, EMB, ..., Pluto, MOON, Sun
 * in the order dx/dt, x, dy/dt, y, dz/dt, z for each object.
 *
 * EMB is the arithmetic average of Earth and Moon, weighted by
 * their masses. The coordinates of the Moon variable are the
 * the solar system barycentric coordinates of the Moon
 * minus those of the Earth.
 */

/* Note, these particular numbers are derived from the heliocentric
 * planet states and barycentric Sun state given in the
 * documentation for the DE118.
 */

/* June 28.0, 1969 */
#define JD0 ((DOUBLE )2440400.50)

static DOUBLE yn[6*NTOTAL] = {
/* Lunar librations */
 1.00015500951082782e-4,
 6.03343019729665792e-3,
 1.49039876740924137e-5,
 3.82393007236771923e-1,
-1.19434270765326686e-4,
 1.28120436555489181e0,
/* Mercury */
 3.70850697982103829e-003,
 3.60306633689753378e-001,
 2.48549587674309461e-002,
-9.48128767417716903e-002,
 1.29291090146778447e-002,
-8.74668401172331392e-002,
/* Venus */
 1.11566457112640169e-002,
 6.07864664917315859e-001,
 1.54940755136387952e-002,
-3.55183624636756179e-001,
 6.27739045466966071e-003,
-1.98241429098555142e-001,
 /* EMB */
 1.68332510200514981e-002,
 1.08207477549383116e-001,
 1.56020361769191054e-003,
-9.27111107394306078e-001,
 6.76461740158472728e-004,
-4.02093478559440896e-001,
/* Mars */
 1.44819192982779250e-002,
-1.27964086113695310e-001,
 8.05285383904474964e-005,
-1.32626180053336168e+000,
-3.51889310293970921e-004,
-6.05308086525239662e-001,
/* Jupiter */
 1.00534525699240981e-003,
-5.38968245446090619e+000,
-6.52984251916894136e-003,
-7.70265495186165883e-001,
-2.82587875324296108e-003,
-1.98664311659075230e-001,
/* Saturn */
-3.15946625040129280e-003,
 7.95277685302573603e+000,
 4.37146342783726215e-003,
 4.50788221840065556e+000,
 1.94413951691371048e-003,
 1.52019552531833395e+000,
/* Uranus */
 1.71083105648068177e-004,
-1.82782365863531465e+001,
-3.76467046828158997e-003,
-9.57645728814820519e-001,
-1.65196786102570005e-003,
-1.61321903972710355e-001,
/* Neptune */
 2.62252427642892151e-003,
-1.63671913587708898e+001,
-1.52774731238589037e-003,
-2.37608967253730776e+001,
-6.91831975621827998e-004,
-9.32138661794972907e+000,
/* Pluto */
 2.81777580903603727e-004,
-3.04476802551693642e+001,
-3.14695908049462038e-003,
-5.31779349602613694e-001,
-1.07942380492891125e-003,
 9.05965848862749295e+000,
#if MOON
 5.98752118417335956e-4,
-8.35703164195952601e-4,
-1.74153713527242722e-4,
-1.98543915768166071e-3,
-8.84771962437116281e-5,
-1.08326877048661754e-3,
#endif
/* Sun */
-2.836944634081352e-7,
 4.514411871435667e-3,
 5.181194408646328e-6,
 7.228284115206592e-4,
 2.230658834062127e-6,
 2.465910049256800e-4,
/* Asteroid states follow */
};



/* Test state, 100 days later: */
#if 0
#define JD1 ((DOUBLE )2440500.50)

static DOUBLE yn1[6*NTOTAL] = {
-3.85893930164594646e-5,
 1.29694398195755468e-2,
 1.14905257263582262e-5,
 3.82508699238156682e-1,
 4.75391383166468672e-5,
 1.27428371119265801e0,

-2.43015281791706444e-002,
 2.40773527079857565e-001,
 1.87910251556777273e-002,
 1.96954621939863219e-001,
 1.25591312851252066e-002,
 8.10048178490518384e-002,

-1.63440955802718280e-002,
-4.21860322028048782e-001,
-1.14246422850682140e-002,
 5.17869026250609690e-001,
-4.11622909296383714e-003,
 2.60203829195766570e-001,

-3.94484632235194096e-003,
 9.81177706008309405e-001,
 1.53727031456690289e-002,
 1.96484576859672724e-001,
 6.66612671337020014e-003,
 8.51297144135776147e-002,

 8.50596535330489333e-003,
 1.14162585220489816e+000,
 1.16329928693268469e-002,
-7.02290330317807430e-001,
 5.11130674190038601e-003,
-3.52984793305744779e-001,

 1.97739891612302323e-003,
-5.24031415190823051e+000,
-6.33006771988879063e-003,
-1.41424053721658884e+000,
-2.76393462026492719e-003,
-4.78580847895956282e-001,

-3.45070902605290058e-003,
 7.62218572268596801e+000,
 4.19480008161587867e-003,
 4.93634138197818904e+000,
 1.88368464231530789e-003,
 1.71165065659011950e+000,

 2.59339002502375430e-004,
-1.82567140746315272e+001,
-3.75914213576224408e-003,
-1.33385143258585295e+000,
-1.65079191573496991e-003,
-3.26466517509008289e-001,

 2.63977839373647663e-003,
-1.61040739057229584e+001,
-1.50241016013489575e-003,
-2.39124059584972814e+001,
-6.81887221476645979e-004,
-9.39007319300685950e+000,

 3.09967640221318611e-004,
-3.04180939220586550e+001,
-3.14632190270354497e-003,
-8.46445850516399332e-001,
-1.08776892324236050e-003,
 8.95129835863062695e+000,

#if MOON
-4.22681402426694080e-4,
-1.72474926563029233e-3,
-3.21609581451700993e-4,
 1.82647356024942241e-3,
-1.82676776570974036e-4,
 9.67995005426182924e-4,
#endif
-9.96208174079740373e-007,  /* rotated from DE200 */
 4.45122038203489470e-003,
 5.06057698826071977e-006,
 1.23363163514498492e-003,
 2.19376032512757903e-006,
 4.67156762898216060e-004,
};
#endif

#if 1
#define JD1 ((DOUBLE )2440800.50)

static DOUBLE yn1[6*NTOTAL] = {
 1.19798509852348462e-4,
 3.26749396278042651e-2,
-6.85863913398886621e-5,
 3.85255316277713118e-1,
-9.87921606265917336e-5,
 1.25594900035445747e0,

 1.16400599590709378e-002,
-3.43502974085638263e-001,
-1.79648756442312690e-002,
-2.51189103151684107e-001,
-1.08173110052101742e-002,
-9.91708912278380685e-002,

 1.85972822037830606e-002,
-2.69146300759618345e-001,
-6.58647992286510395e-003,
-6.16556617575103467e-001,
-4.14285174909157588e-003,
-2.60707312022570557e-001,

 1.30835811975501964e-002,
 6.42602154654604158e-001,
 9.88461075609808887e-003,
-7.20835972945166410e-001,
 4.28627972070984268e-003,
-3.12638398680068517e-001,

-1.02892028157957345e-002,
-1.03949414284686800e+000,
-7.07233349894180468e-003,
 1.15224038363122796e+000,
-2.97031383092754239e-003,
 5.56774011571334240e-001,

 4.62286536662021211e-003,
-4.23736157223559948e+000,
-5.05559186926155592e-003,
-3.14647330912772225e+000,
-2.28184557224936431e-003,
-1.24622416590313742e+000,

-4.25567400448740861e-003,
 6.46339795349710736e+000,
 3.56330471723796016e-003,
 6.10375641424371387e+000,
 1.65737685411555284e-003,
 2.24446184491419578e+000,

 5.22747767909456640e-004,
-1.81393409040076883e+001,
-3.73174578901609845e-003,
-2.45788882882470081e+000,
-1.64250784791677429e-003,
-8.20639431858232602e-001,

 2.68985885761790640e-003,
-1.53045649313923750e+001,
-1.42543853688965150e-003,
-2.43516187624950325e+001,
-6.51617375893783151e-004,
-9.59011501709625544e+000,

 3.95182012280367390e-004,
-3.03123449857665570e+001,
-3.14262518699528998e-003,
-1.78985538895795679e+000,
-1.11243507076690517e-003,
 8.62125354433360383e+000,

#if MOON
-4.58408893102436927e-4,
-1.60130208907259920e-3,
-2.78697065392994499e-4,
 1.95720839700677492e-3,
-1.70697259101564644e-4,
 9.68483037769266028e-4,
#endif
-3.44322101864905357e-006, /* rotated from DE200 */
 3.77983010651375442e-003,
 4.03605242892639870e-006,
 2.63055823065286220e-003,
 1.81002374725178528e-006,
 1.08188006521861207e-003,
};
#endif

/* Initial accelerations, at yn[] epoch
 * for test purposes
 */
DOUBLE amoon[3] = {
/* 2440800.5
 7.15594681675682288e-5,
-8.75946974075530210e-5,
-4.34450706411772946e-5,
 */
/* 2440500.5
 7.89576335053339950e-5,
-8.49773001348712375e-5,
-4.50154759417189494e-5,
 */
/* 2440400.5 */
 5.40548681996079620e-5,
 1.26326595513576372e-4,
 6.91101026282511274e-5,

};

DOUBLE aearth[3] = { /* EMB */
/* 2440800.5 Rotated from DE200:
-1.80867010974314369e-004,
 2.04819104947531037e-004,
 8.88168560187238438e-005,
 */
/* 2440400.5 Rotated from DE200: */
-2.92121526132486938e-005,
 2.61316117176934541e-004,
 1.13315571890405062e-004,

/* heliocentric acceleration data:
-2.92050891691249361e-5,
 2.61318585392418325e-4,
 1.13316577018344841e-4,
*/
};

DOUBLE alibr[3] = {
/* 2440800.5
-3.52790711562841495e-5,
-6.61679260759020606e-6,
 3.38440820180850657e-5,
 */
/* 2440500.5
 1.85257425909686695e-5,
 8.44619358009680861e-6,
-1.78073100984086293e-5,
 */
/* 2440400.5  */
-2.33840106202781591e-6,
 3.76106870289525089e-6,
-8.36366071885551190e-7,

};

/* Speed of light.
 */
#define CLIGHT (DOUBLE)2.99792458e5
#define C ((DOUBLE )173.1446328)

/* Earth's mass divided by Moon's mass
 */
#define EMRATd ((DOUBLE )81.300587)
DOUBLE EMRAT = EMRATd;

/* Gaussian gravitational constant */
#define KG 0.01720209895

/* GM's of the solar system bodies
 * These are scaled such that GMsun = k^2
 * (k = Gaussian gravitational constant).
 */
DOUBLE GMs[] = {
#if LIBRAT
 0.0, /*place holder for libration */
#endif
 4.912547451450812e-011, /* Mercury */
 7.243456209632766e-010, /* Venus */
#if MOON
/* (8.997011658557308e-010*EMRAT)/(1.0+EMRAT), Earth only */
 8.88769273403302352558E-10,
#else
 8.997011658557308e-010, /* EMB */
#endif
 9.549528942224058e-011, /* Mars */
 2.825342103445926e-007, /* Jupiter */
 8.459468504830660e-008, /* Saturn */
 1.288816238138035e-008, /* Uranus */
 1.532112481284276e-008, /* Neptune */
 2.276247751863699e-012, /* Pluto */
#if MOON
/* (8.997011658557308e-010)/(1.0+EMRAT),  Moon only */
 1.09318924524284474423E-11,
#endif
 2.959122082855911e-004, /* Sun */
#if AROIDS
 1.746e-13, /* Ceres */
 3.2e-14,   /* Pallas */
 4.08e-14,  /* Vesta */
 1.6e-15,   /* Iris */
 2.6e-15    /* Bamberga */
#endif
};


/* Astronomical unit */
#define AU 1.4959787066e11
/* kilometers: */
#define RADS 6.96e5
#define RADM 1738.0
#define RADE 6378.14


/* equatorial radius of Earth, in au */
DOUBLE AE = 4.263523250648178e-005;

DOUBLE Je[] = {
1.08263e-3, /* J2E */
-2.54e-6,   /* J3E */
-1.61e-6    /* J4E */
};

/* equatorial radius of Moon, in au */
#define AMd 1.161781241808197e-005
DOUBLE AM = AMd;

DOUBLE Jm[] = {
2.02150907893e-4,  /* J2M */
1.21260448837e-5,  /* J3M */
-1.45383007072e-7, /* J4M */
};

DOUBLE Cnm[8] = {
 2.230351309e-5,   /* C22 */
 3.07082741328e-5, /* C31 */
 4.88840471683e-6, /* C32 */
 1.43603108489e-6, /* C33 */
-7.17780149806e-6, /* C41 */
-1.43951838385e-6, /* C42 */
-8.54788154819e-8, /* C43 */
-1.5490389313e-7   /* C44 */
};

DOUBLE Snm[8] = {
 0.0,              /* S22 */
 5.61066891941e-6, /* S31 */
 1.68743052295e-6, /* S32 */
-3.343544677e-7,   /* S33 */
 2.94743374914e-6, /* S41 */
-2.8843721272e-6,  /* S42 */
-7.88967312839e-7, /* S43 */
 5.6404155572e-8   /* S44 */
};


#define K2M 2.22160557154e-2
DOUBLE LOVENO  = 0.30;
DOUBLE PHASE = 4.0700012e-2;

/* DE118 initial psidot: */
DOUBLE PSLP1 = 2.29971502189818919e-1;
DOUBLE JDEPOCH = 2440400.5;

/* (C-A)/B */
#define LBETd 6.31686773468e-4
DOUBLE LBET = LBETd;
/* (B-A)/C */
#define LGAMd 2.28022183594e-4
DOUBLE LGAM = LGAMd;
DOUBLE LGAMBET = (LGAMd - LBETd)/(1.0-LBETd*LGAMd);
/* C/MR^2 */
/*define CMRSQ 0.392*/
#define CMRSQ 0.39068952613208
DOUBLE CMR2 = CMRSQ*AMd*AMd;
DOUBLE BMR2 = CMRSQ*AMd*AMd*(1.0 + LGAMd)/(1.0 + LBETd);
DOUBLE AMR2 = CMRSQ*AMd*AMd*(1.0 - LBETd * LGAMd)/(1.0 + LBETd);
