00001 #include "jpleph.c"
00002
00003 #define TABLEDIR ("/home/rick/src/ephem/tables")
00004
00005 #define AU_METERS (1.49597870691e11)
00006
00007 void hc_earth_ephem (double jd, double pos[6], char *table) {
00008
00009
00010
00011
00012
00013 long i;
00014 int targ = 3, ctr = 11;
00015 if (strlen (table)) pleph_ext (jd, targ, ctr, 0, pos, table);
00016 else pleph (jd, targ, ctr, pos);
00017 for (i=0; i<3; i++) pos[i] *= AU_METERS;
00018 for (i=3; i<6; i++) pos[i] *= AU_METERS / 86400.0;
00019 }
00020
00021 int earth_ephemeris (TIME obs_time, double *r, double *b, double *l,
00022 double *vr, double *vn, double *vw) {
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 double gcitdt, jd, posvel[6];
00035 double ex, ey, ez, evx, evy, evz;
00036 double evr, evw, evn;
00037 double lapp, w, lx, rx, bx, cx, ce, vx, vy, vz;
00038 int icar;
00039 char tablename[256], tstr[64];
00040
00041 static double txx, txy, txz, tyx, tyy, tyz, tzx, tzy, tzz;
00042 static int first_call = 1;
00043
00044 double deg2rad = M_PI / 180;
00045 double rad2deg = 1.0 / deg2rad;
00046
00047 double alpha = 16.13 * deg2rad;
00048
00049
00050 double delta = 26.13 * deg2rad;
00051 double car0 = 1650.0;
00052 double carrate = 4.2434255e-7;
00053
00054
00055 gcitdt = obs_time + 32.184;
00056 jd = gcitdt / 86400.0 + 2443144.5;
00057 if (jd < 2378448.5) {
00058 sprint_time (tstr, gcitdt, "Z", -1);
00059 fprintf (stderr, "Error: time %s is earlier than any tabulated values\n",
00060 tstr);
00061 return 1;
00062 } else if (jd < 2433264.5) sprintf (tablename, "%s/unxp1800.406", TABLEDIR);
00063 else if (jd < 2451536.5) sprintf (tablename, "%s/unxp1950.405", TABLEDIR);
00064 else if (jd < 2469808.5) sprintf (tablename, "%s/unxp2000.405", TABLEDIR);
00065 else {
00066 sprint_time (tstr, gcitdt, "Z", -1);
00067 fprintf (stderr, "Error: time %s is later than any tabulated values\n",
00068 tstr);
00069 return 1;
00070 }
00071
00072 if (first_call) {
00073 txx = cos (alpha);
00074 txy = sin (alpha);
00075 txz = 0.0;
00076 tyx = -sin (alpha) * cos (delta);
00077 tyy = cos (alpha) * cos (delta);
00078 tyz = sin (delta);
00079 tzx = sin (alpha) * sin (delta);
00080 tzy = -cos (alpha) * sin (delta);
00081 tzz = cos (delta);
00082 first_call = 0;
00083 }
00084
00085 hc_earth_ephem (jd, posvel, tablename);
00086 ex = posvel[0];
00087 ey = posvel[1];
00088 ez = posvel[2];
00089 evx = posvel[3];
00090 evy = posvel[4];
00091 evz = posvel[5];
00092
00093 rx = sqrt (ex*ex + ey*ey + ez*ez);
00094 *r = rx / AU_METERS;
00095
00096 bx = asin ((tzx*ex + tzy*ey + tzz*ez) / rx);
00097 *b = rad2deg * bx;
00098
00099
00100 lapp = car0 + carrate * gcitdt;
00101 w = (84.10 + 14.1844*(jd - 2451545.0))*deg2rad;
00102 lx = atan2 ((tyx*ex + tyy*ey + tyz*ez),(txx*ex + txy*ey + txz*ez));
00103 cx = 1.0 - 0.5 * fmod (lx-w, 2 * M_PI) / M_PI;
00104 icar = lapp - cx + 0.5;
00105 ce = cx + icar;
00106 icar = ce + 1;
00107 *l = 360.0 * (icar - ce);
00108
00109 vx = txx*evx + txy*evy + txz*evz;
00110 vy = tyx*evx + tyy*evy + tyz*evz;
00111 vz = tzx*evx + tzy*evy + tzz*evz;
00112 *vr = cos(lx)*cos(bx)*vx + sin(lx)*cos(bx)*vy + sin(bx)*vz;
00113 *vw = -sin(lx)*vx + cos(lx)*vy;
00114 *vn = -cos(lx)*sin(bx)*vx - sin(lx)*sin(bx)*vy + cos(bx)*vz;
00115
00116 return 0;
00117 }
00118
00119 #define E_CRR0 (1650)
00120 #define E_ERR (0.0000770)
00121 #define E_LONN0 (357.894)
00122
00123
00124 #define E_K (6546.07452)
00125
00126
00127
00128
00129 TIME earth_meridian_crossing (double lonn, int crr) {
00130
00131
00132
00133
00134 double au, lon, lat, vr, vn, vw;
00135 double phi, secapp;
00136
00137 secapp = ((crr - E_CRR0) * 360.0 - (lonn - E_LONN0)) * E_K;
00138 earth_ephemeris (secapp, &au, &lat, &lon, &vr, &vn, &vw);
00139
00140 while (lonn >= 360.0) lonn -= 360.0;
00141 while (lonn < 0.0) lonn += 360.0;
00142 phi = lon - lonn;
00143 while (phi > 180.0) phi -= 360.0;
00144 while (phi < -180.0) phi += 360.0;
00145 while (fabs (phi) > E_ERR) {
00146 secapp += phi * E_K;
00147 earth_ephemeris (secapp, &au, &lat, &lon, &vr, &vn, &vw);
00148 phi = lon - lonn;
00149 while (phi > 180.0) phi -= 360.0;
00150 while (phi < -180.0) phi += 360.0;
00151 }
00152 return secapp;
00153 }