home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / xephem / part07 < prev    next >
Encoding:
Text File  |  1992-03-05  |  50.2 KB  |  1,679 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!think.com!mips!msi!dcmartin
  3. From: e_downey@hwking.cca.cr.rockwell.com (Elwood Downey)
  4. Subject: v16i118: xephem - astronomical ephemeris program., Part07/24
  5. Message-ID: <1992Mar6.135334.2230@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. References: <csx-16i112-xephem@uunet.UU.NET>
  10. Date: Fri, 6 Mar 1992 13:53:34 GMT
  11. Approved: dcmartin@msi.com
  12.  
  13. Submitted-by: e_downey@hwking.cca.cr.rockwell.com (Elwood Downey)
  14. Posting-number: Volume 16, Issue 118
  15. Archive-name: xephem/part07
  16.  
  17. # this is part.07 (part 7 of a multipart archive)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file pelement.c continued
  20. #
  21. if test ! -r _shar_seq_.tmp; then
  22.     echo 'Please unpack part 1 first!'
  23.     exit 1
  24. fi
  25. (read Scheck
  26.  if test "$Scheck" != 7; then
  27.     echo Please unpack part "$Scheck" next!
  28.     exit 1
  29.  else
  30.     exit 0
  31.  fi
  32. ) < _shar_seq_.tmp || exit 1
  33. if test ! -f _shar_wnt_.tmp; then
  34.     echo 'x - still skipping pelement.c'
  35. else
  36. echo 'x - continuing file pelement.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'pelement.c' &&
  38. X    int planet, i;
  39. X
  40. X    for (planet = 0; planet < 8; planet++) {
  41. X        ep = elements[planet];
  42. X        pp = plan[planet];
  43. X        aa = ep[1]*t;
  44. X        pp[0] = ep[0] + 360.*(aa-(long)aa) + (ep[3]*t + ep[2])*t*t;
  45. X        range (pp, 360.);
  46. X        pp[1] = (ep[1]*9.856263e-3) + (ep[2] + ep[3])/36525;
  47. X
  48. X        for (i = 4; i < 20; i += 4)
  49. X        pp[i/4+1] = ((ep[i+3]*t + ep[i+2])*t + ep[i+1])*t + ep[i+0];
  50. X
  51. X        pp[6] = ep[20];
  52. X        pp[7] = ep[21];
  53. X        pp[8] = ep[22];
  54. X    }
  55. }
  56. SHAR_EOF
  57. echo 'File pelement.c is complete' &&
  58. chmod 0644 pelement.c ||
  59. echo 'restore of pelement.c failed'
  60. Wc_c="`wc -c < 'pelement.c'`"
  61. test 4797 -eq "$Wc_c" ||
  62.     echo 'pelement.c: original size 4797, current size' "$Wc_c"
  63. rm -f _shar_wnt_.tmp
  64. fi
  65. # ============= plans.c ==============
  66. if test -f 'plans.c' -a X"$1" != X"-c"; then
  67.     echo 'x - skipping plans.c (File already exists)'
  68.     rm -f _shar_wnt_.tmp
  69. else
  70. > _shar_wnt_.tmp
  71. echo 'x - extracting plans.c (Text)'
  72. sed 's/^X//' << 'SHAR_EOF' > 'plans.c' &&
  73. #include <stdio.h>
  74. #include <math.h>
  75. #include "astro.h"
  76. X
  77. #define    TWOPI        (2*PI)
  78. #define    mod2PI(x)    ((x) - (long)((x)/TWOPI)*TWOPI)
  79. X
  80. /* given a modified Julian date, mjd, and a planet, p, find:
  81. X *   lpd0: heliocentric longitude, 
  82. X *   psi0: heliocentric latitude,
  83. X *   rp0:  distance from the sun to the planet, 
  84. X *   rho0: distance from the Earth to the planet,
  85. X *         none corrected for light time, ie, they are the true values for the
  86. X *         given instant.
  87. X *   lam:  geocentric ecliptic longitude, 
  88. X *   bet:  geocentric ecliptic latitude,
  89. X *         each corrected for light time, ie, they are the apparent values as
  90. X *       seen from the center of the Earth for the given instant.
  91. X *   dia:  angular diameter in arcsec at 1 AU, 
  92. X *   mag:  visual magnitude when 1 AU from sun and earth at 0 phase angle.
  93. X *
  94. X * all angles are in radians, all distances in AU.
  95. X * the mean orbital elements are found by calling pelement(), then mutual
  96. X *   perturbation corrections are applied as necessary.
  97. X *
  98. X * corrections for nutation and abberation must be made by the caller. The RA 
  99. X *   and DEC calculated from the fully-corrected ecliptic coordinates are then
  100. X *   the apparent geocentric coordinates. Further corrections can be made, if
  101. X *   required, for atmospheric refraction and geocentric parallax although the
  102. X *   intrinsic error herein of about 10 arcseconds is usually the dominant
  103. X *   error at this stage.
  104. X * TODO: combine the several intermediate expressions when get a good compiler.
  105. X */
  106. plans (mjd, p, lpd0, psi0, rp0, rho0, lam, bet, dia, mag)
  107. double mjd;
  108. int p;
  109. double *lpd0, *psi0, *rp0, *rho0, *lam, *bet, *dia, *mag;
  110. {
  111. X    static double plan[8][9];
  112. X    static double lastmjd = -10000;
  113. X    double dl;    /* perturbation correction for longitude */
  114. X    double dr;    /*  "   orbital radius */
  115. X    double dml;    /*  "   mean longitude */
  116. X    double ds;    /*  "   eccentricity */
  117. X    double dm;    /*  "   mean anomaly */
  118. X    double da;    /*  "   semi-major axis */
  119. X    double dhl;    /*  "   heliocentric longitude */
  120. X    double lsn, rsn;/* true geocentric longitude of sun and sun-earth rad */
  121. X    double mas;    /* mean anomaly of the sun */
  122. X    double re;    /* radius of earth's orbit */
  123. X    double lg;    /* longitude of earth */
  124. X    double map[8];    /* array of mean anomalies for each planet */
  125. X    double lpd, psi, rp, rho;
  126. X    double ll, sll, cll;
  127. X    double t;
  128. X    double dt;
  129. X    int pass;
  130. X    int j;
  131. X    double s, ma;
  132. X    double nu, ea;
  133. X    double lp, om;
  134. X    double lo, slo, clo;
  135. X    double inc, y;
  136. X    double spsi, cpsi;
  137. X    double rpd;
  138. X
  139. X    /* only need to fill in plan[] once for a given mjd */
  140. X    if (mjd != lastmjd) {
  141. X        pelement (mjd, plan);
  142. X        lastmjd = mjd;
  143. X    }
  144. X
  145. X    dt = 0;
  146. X    t = mjd/36525.;
  147. X    sunpos (mjd, &lsn, &rsn);
  148. X    masun (mjd, &mas);
  149. X        re = rsn;
  150. X    lg = lsn+PI;
  151. X
  152. X    /* first find the true position of the planet at mjd.
  153. X     * then repeat a second time for a slightly different time based
  154. X     * on the position found in the first pass to account for light-travel
  155. X     * time.
  156. X     */
  157. X    for (pass = 0; pass < 2; pass++) {
  158. X
  159. X        for (j = 0; j < 8; j++)
  160. X        map[j] = degrad(plan[j][0]-plan[j][2]-dt*plan[j][1]);
  161. X
  162. X        /* set initial corrections to 0.
  163. X         * then modify as necessary for the planet of interest.
  164. X         */
  165. X        dl = 0;
  166. X        dr = 0;
  167. X        dml = 0;
  168. X        ds = 0;
  169. X        dm = 0;
  170. X        da = 0;
  171. X        dhl = 0;
  172. X
  173. X        switch (p) {
  174. X
  175. X        case MERCURY:
  176. X        p_mercury (map, &dl, &dr);
  177. X        break;
  178. X
  179. X        case VENUS:
  180. X        p_venus (t, mas, map, &dl, &dr, &dml, &dm);
  181. X        break;
  182. X
  183. X        case MARS:
  184. X        p_mars (mas, map, &dl, &dr, &dml, &dm);
  185. X        break;
  186. X
  187. X        case JUPITER:
  188. X        p_jupiter (t, plan[p][3], &dml, &ds, &dm, &da);
  189. X        break;
  190. X
  191. X        case SATURN:
  192. X        p_saturn (t, plan[p][3], &dml, &ds, &dm, &da, &dhl);
  193. X        break;
  194. X
  195. X        case URANUS:
  196. X        p_uranus (t, plan[p][3], &dl, &dr, &dml, &ds, &dm, &da, &dhl);
  197. X        break;
  198. X
  199. X        case NEPTUNE:
  200. X        p_neptune (t, plan[p][3], &dl, &dr, &dml, &ds, &dm, &da, &dhl);
  201. X        break;
  202. X
  203. X        case PLUTO:
  204. X        /* no perturbation theory for pluto */
  205. X        break;
  206. X        }
  207. X
  208. X        s = plan[p][3]+ds;
  209. X        ma = map[p]+dm;
  210. X        anomaly (ma, s, &nu, &ea);
  211. X        rp = (plan[p][6]+da)*(1-s*s)/(1+s*cos(nu));
  212. X        lp = raddeg(nu)+plan[p][2]+raddeg(dml-dm);
  213. X        lp = degrad(lp);
  214. X        om = degrad(plan[p][5]);
  215. X        lo = lp-om;
  216. X        slo = sin(lo);
  217. X        clo = cos(lo);
  218. X        inc = degrad(plan[p][4]);
  219. X        rp = rp+dr;
  220. X        spsi = slo*sin(inc);
  221. X        y = slo*cos(inc);
  222. X        psi = asin(spsi)+dhl;
  223. X        spsi = sin(psi);
  224. X        lpd = atan(y/clo)+om+degrad(dl);
  225. X        if (clo<0) lpd += PI;
  226. X        range (&lpd, TWOPI);
  227. X        cpsi = cos(psi);
  228. X        rpd = rp*cpsi;
  229. X        ll = lpd-lg;
  230. X        rho = sqrt(re*re+rp*rp-2*re*rp*cpsi*cos(ll));
  231. X
  232. X        /* when we view a planet we see it in the position it occupied
  233. X         * dt days ago, where rho is the distance between it and earth,
  234. X         * in AU. use this as the new time for the next pass.
  235. X         */
  236. X        dt = rho*5.775518e-3;
  237. X
  238. X        if (pass == 0) {
  239. X        /* save heliocentric coordinates after first pass since, being
  240. X         * true, they are NOT to be corrected for light-travel time.
  241. X         */
  242. X        *lpd0 = lpd;
  243. X        range (lpd0, TWOPI);
  244. X        *psi0 = psi;
  245. X        *rp0 = rp;
  246. X        *rho0 = rho;
  247. X        }
  248. X    }
  249. X
  250. X        sll = sin(ll);
  251. X    cll = cos(ll);
  252. X        if (p < MARS) 
  253. X        *lam = atan(-1*rpd*sll/(re-rpd*cll))+lg+PI;
  254. X    else
  255. X        *lam = atan(re*sll/(rpd-re*cll))+lpd;
  256. X    range (lam, TWOPI);
  257. X        *bet = atan(rpd*spsi*sin(*lam-lpd)/(cpsi*re*sll));
  258. X    *dia = plan[p][7];
  259. X    *mag = plan[p][8];
  260. }
  261. X
  262. /* set auxilliary variables used for jupiter, saturn, uranus, and neptune */
  263. static
  264. aux_jsun (t, x1, x2, x3, x4, x5, x6)
  265. double t;
  266. double *x1, *x2, *x3, *x4, *x5, *x6;
  267. {
  268. X        *x1 = t/5+0.1;
  269. X        *x2 = mod2PI(4.14473+5.29691e1*t);
  270. X        *x3 = mod2PI(4.641118+2.132991e1*t);
  271. X        *x4 = mod2PI(4.250177+7.478172*t);
  272. X        *x5 = 5 * *x3 - 2 * *x2;
  273. X    *x6 = 2 * *x2 - 6 * *x3 + 3 * *x4;
  274. }
  275. X
  276. /* find the mean anomaly of the sun at mjd.
  277. X * this is the same as that used in sun() but when it was converted to C it
  278. X * was not known it would be required outside that routine.
  279. X * TODO: add an argument to sun() to return mas and eliminate this routine.
  280. X */
  281. static
  282. masun (mjd, mas)
  283. double mjd;
  284. double *mas;
  285. {
  286. X    double t, t2;
  287. X    double a, b;
  288. X
  289. X    t = mjd/36525;
  290. X    t2 = t*t;
  291. X    a = 9.999736042e1*t;
  292. X    b = 360.*(a-(long)a);
  293. X    *mas = degrad (3.5847583e2-(1.5e-4+3.3e-6*t)*t2+b);
  294. }
  295. X
  296. /* perturbations for mercury */
  297. static
  298. p_mercury (map, dl, dr)
  299. double map[];
  300. double *dl, *dr;
  301. {
  302. X    *dl = 2.04e-3*cos(5*map[2-1]-2*map[1-1]+2.1328e-1)+
  303. X         1.03e-3*cos(2*map[2-1]-map[1-1]-2.8046)+
  304. X         9.1e-4*cos(2*map[3]-map[1-1]-6.4582e-1)+
  305. X         7.8e-4*cos(5*map[2-1]-3*map[1-1]+1.7692e-1);
  306. X
  307. X    *dr = 7.525e-6*cos(2*map[3]-map[1-1]+9.25251e-1)+
  308. X         6.802e-6*cos(5*map[2-1]-3*map[1-1]-4.53642)+
  309. X         5.457e-6*cos(2*map[2-1]-2*map[1-1]-1.24246)+
  310. X         3.569e-6*cos(5*map[2-1]-map[1-1]-1.35699);
  311. }
  312. X
  313. /* ....venus */
  314. static
  315. p_venus (t, mas, map, dl, dr, dml, dm)
  316. double t, mas, map[];
  317. double *dl, *dr, *dml, *dm;
  318. {
  319. X    *dml = degrad (7.7e-4*sin(4.1406+t*2.6227));
  320. X    *dm = *dml;
  321. X
  322. X    *dl = 3.13e-3*cos(2*mas-2*map[2-1]-2.587)+
  323. X         1.98e-3*cos(3*mas-3*map[2-1]+4.4768e-2)+
  324. X         1.36e-3*cos(mas-map[2-1]-2.0788)+
  325. X         9.6e-4*cos(3*mas-2*map[2-1]-2.3721)+
  326. X         8.2e-4*cos(map[3]-map[2-1]-3.6318);
  327. X
  328. X    *dr = 2.2501e-5*cos(2*mas-2*map[2-1]-1.01592)+
  329. X         1.9045e-5*cos(3*mas-3*map[2-1]+1.61577)+
  330. X         6.887e-6*cos(map[3]-map[2-1]-2.06106)+
  331. X         5.172e-6*cos(mas-map[2-1]-5.08065e-1)+
  332. X         3.62e-6*cos(5*mas-4*map[2-1]-1.81877)+
  333. X         3.283e-6*cos(4*mas-4*map[2-1]+1.10851)+
  334. X         3.074e-6*cos(2*map[3]-2*map[2-1]-9.62846e-1);
  335. }
  336. X
  337. /* ....mars */
  338. static
  339. p_mars (mas, map, dl, dr, dml, dm)
  340. double mas, map[];
  341. double *dl, *dr, *dml, *dm;
  342. {
  343. X    double a;
  344. X
  345. X    a = 3*map[3]-8*map[2]+4*mas;
  346. X    *dml = degrad (-1*(1.133e-2*sin(a)+9.33e-3*cos(a)));
  347. X    *dm = *dml;
  348. X
  349. X    *dl = 7.05e-3*cos(map[3]-map[2]-8.5448e-1)+
  350. X         6.07e-3*cos(2*map[3]-map[2]-3.2873)+
  351. X         4.45e-3*cos(2*map[3]-2*map[2]-3.3492)+
  352. X         3.88e-3*cos(mas-2*map[2]+3.5771e-1)+
  353. X         2.38e-3*cos(mas-map[2]+6.1256e-1)+
  354. X         2.04e-3*cos(2*mas-3*map[2]+2.7688)+
  355. X         1.77e-3*cos(3*map[2]-map[2-1]-1.0053)+
  356. X         1.36e-3*cos(2*mas-4*map[2]+2.6894)+
  357. X         1.04e-3*cos(map[3]+3.0749e-1);
  358. X
  359. X    *dr = 5.3227e-5*cos(map[3]-map[2]+7.17864e-1)+
  360. X         5.0989e-5*cos(2*map[3]-2*map[2]-1.77997)+
  361. X         3.8278e-5*cos(2*map[3]-map[2]-1.71617)+
  362. X         1.5996e-5*cos(mas-map[2]-9.69618e-1)+
  363. X         1.4764e-5*cos(2*mas-3*map[2]+1.19768)+
  364. X         8.966e-6*cos(map[3]-2*map[2]+7.61225e-1);
  365. X     *dr += 7.914e-6*cos(3*map[3]-2*map[2]-2.43887)+
  366. X         7.004e-6*cos(2*map[3]-3*map[2]-1.79573)+
  367. X         6.62e-6*cos(mas-2*map[2]+1.97575)+
  368. X         4.93e-6*cos(3*map[3]-3*map[2]-1.33069)+
  369. X         4.693e-6*cos(3*mas-5*map[2]+3.32665)+
  370. X         4.571e-6*cos(2*mas-4*map[2]+4.27086)+
  371. X         4.409e-6*cos(3*map[3]-map[2]-2.02158);
  372. }
  373. X
  374. /* ....jupiter */
  375. static
  376. p_jupiter (t, s, dml, ds, dm, da)
  377. double t, s;
  378. double *dml, *ds, *dm, *da;
  379. {
  380. X    double dp;
  381. X    double x1, x2, x3, x4, x5, x6, x7;
  382. X    double sx3, cx3, s2x3, c2x3;
  383. X        double sx5, cx5, s2x5;
  384. X    double sx6;
  385. X        double sx7, cx7, s2x7, c2x7, s3x7, c3x7, s4x7, c4x7, c5x7;
  386. X
  387. X    aux_jsun (t, &x1, &x2, &x3, &x4, &x5, &x6);
  388. X        x7 = x3-x2;
  389. X    sx3 = sin(x3);
  390. X    cx3 = cos(x3);
  391. X        s2x3 = sin(2*x3);
  392. X    c2x3 = cos(2*x3);
  393. X        sx5 = sin(x5);
  394. X    cx5 = cos(x5);
  395. X        s2x5 = sin(2*x5);
  396. X    sx6 = sin(x6);
  397. X        sx7 = sin(x7);
  398. X    cx7 = cos(x7);
  399. X        s2x7 = sin(2*x7);
  400. X    c2x7 = cos(2*x7);
  401. X        s3x7 = sin(3*x7);
  402. X    c3x7 = cos(3*x7);
  403. X        s4x7 = sin(4*x7);
  404. X    c4x7 = cos(4*x7);
  405. X        c5x7 = cos(5*x7);
  406. X
  407. X    *dml = (3.31364e-1-(1.0281e-2+4.692e-3*x1)*x1)*sx5+
  408. X          (3.228e-3-(6.4436e-2-2.075e-3*x1)*x1)*cx5-
  409. X          (3.083e-3+(2.75e-4-4.89e-4*x1)*x1)*s2x5+
  410. X          2.472e-3*sx6+1.3619e-2*sx7+1.8472e-2*s2x7+6.717e-3*s3x7+
  411. X          2.775e-3*s4x7+6.417e-3*s2x7*sx3+
  412. X          (7.275e-3-1.253e-3*x1)*sx7*sx3+
  413. X          2.439e-3*s3x7*sx3-(3.5681e-2+1.208e-3*x1)*sx7*cx3;
  414. X        *dml += -3.767e-3*c2x7*sx3-(3.3839e-2+1.125e-3*x1)*cx7*sx3-
  415. X          4.261e-3*s2x7*cx3+
  416. X          (1.161e-3*x1-6.333e-3)*cx7*cx3+
  417. X          2.178e-3*cx3-6.675e-3*c2x7*cx3-2.664e-3*c3x7*cx3-
  418. X          2.572e-3*sx7*s2x3-3.567e-3*s2x7*s2x3+2.094e-3*cx7*c2x3+
  419. X          3.342e-3*c2x7*c2x3;
  420. X    *dml = degrad(*dml);
  421. X
  422. X    *ds = (3606+(130-43*x1)*x1)*sx5+(1289-580*x1)*cx5-6764*sx7*sx3-
  423. X         1110*s2x7*sx3-224*s3x7*sx3-204*sx3+(1284+116*x1)*cx7*sx3+
  424. X         188*c2x7*sx3+(1460+130*x1)*sx7*cx3+224*s2x7*cx3-817*cx3+
  425. X         6074*cx3*cx7+992*c2x7*cx3+
  426. X         508*c3x7*cx3+230*c4x7*cx3+108*c5x7*cx3;
  427. X    *ds += -(956+73*x1)*sx7*s2x3+448*s2x7*s2x3+137*s3x7*s2x3+
  428. X         (108*x1-997)*cx7*s2x3+480*c2x7*s2x3+148*c3x7*s2x3+
  429. X         (99*x1-956)*sx7*c2x3+490*s2x7*c2x3+
  430. X         158*s3x7*c2x3+179*c2x3+(1024+75*x1)*cx7*c2x3-
  431. X         437*c2x7*c2x3-132*c3x7*c2x3;
  432. X    *ds *= 1e-7;
  433. X
  434. X    dp = (7.192e-3-3.147e-3*x1)*sx5-4.344e-3*sx3+
  435. X         (x1*(1.97e-4*x1-6.75e-4)-2.0428e-2)*cx5+
  436. X         3.4036e-2*cx7*sx3+(7.269e-3+6.72e-4*x1)*sx7*sx3+
  437. X         5.614e-3*c2x7*sx3+2.964e-3*c3x7*sx3+3.7761e-2*sx7*cx3+
  438. X         6.158e-3*s2x7*cx3-
  439. X         6.603e-3*cx7*cx3-5.356e-3*sx7*s2x3+2.722e-3*s2x7*s2x3+
  440. X         4.483e-3*cx7*s2x3-2.642e-3*c2x7*s2x3+4.403e-3*sx7*c2x3-
  441. X         2.536e-3*s2x7*c2x3+5.547e-3*cx7*c2x3-2.689e-3*c2x7*c2x3;
  442. X
  443. X    *dm = *dml-(degrad(dp)/s);
  444. X
  445. X    *da = 205*cx7-263*cx5+693*c2x7+312*c3x7+147*c4x7+299*sx7*sx3+
  446. X         181*c2x7*sx3+204*s2x7*cx3+111*s3x7*cx3-337*cx7*cx3-
  447. X         111*c2x7*cx3;
  448. X    *da *= 1e-6;
  449. }
  450. X
  451. /* ....saturn */
  452. static
  453. p_saturn (t, s, dml, ds, dm, da, dhl)
  454. double t, s;
  455. double *dml, *ds, *dm, *da, *dhl;
  456. {
  457. X    double dp;
  458. X    double x1, x2, x3, x4, x5, x6, x7, x8;
  459. X    double sx3, cx3, s2x3, c2x3, s3x3, c3x3, s4x3, c4x3;
  460. X        double sx5, cx5, s2x5, c2x5;
  461. X    double sx6;
  462. X        double sx7, cx7, s2x7, c2x7, s3x7, c3x7, s4x7, c4x7, c5x7, s5x7;
  463. X    double s2x8, c2x8, s3x8, c3x8;
  464. X
  465. X    aux_jsun (t, &x1, &x2, &x3, &x4, &x5, &x6);
  466. X        x7 = x3-x2;
  467. X    sx3 = sin(x3);
  468. X    cx3 = cos(x3);
  469. X        s2x3 = sin(2*x3);
  470. X    c2x3 = cos(2*x3);
  471. X        sx5 = sin(x5);
  472. X    cx5 = cos(x5);
  473. X        s2x5 = sin(2*x5);
  474. X    sx6 = sin(x6);
  475. X        sx7 = sin(x7);
  476. X    cx7 = cos(x7);
  477. X        s2x7 = sin(2*x7);
  478. X    c2x7 = cos(2*x7);
  479. X        s3x7 = sin(3*x7);
  480. X    c3x7 = cos(3*x7);
  481. X        s4x7 = sin(4*x7);
  482. X    c4x7 = cos(4*x7);
  483. X        c5x7 = cos(5*x7);
  484. X
  485. X    s3x3 = sin(3*x3);
  486. X    c3x3 = cos(3*x3);
  487. X    s4x3 = sin(4*x3);
  488. X    c4x3 = cos(4*x3);
  489. X    c2x5 = cos(2*x5);
  490. X    s5x7 = sin(5*x7);
  491. X    x8 = x4-x3;
  492. X    s2x8 = sin(2*x8);
  493. X    c2x8 = cos(2*x8);
  494. X    s3x8 = sin(3*x8);
  495. X    c3x8 = cos(3*x8);
  496. X
  497. X    *dml = 7.581e-3*s2x5-7.986e-3*sx6-1.48811e-1*sx7-4.0786e-2*s2x7-
  498. X          (8.14181e-1-(1.815e-2-1.6714e-2*x1)*x1)*sx5-
  499. X          (1.0497e-2-(1.60906e-1-4.1e-3*x1)*x1)*cx5-1.5208e-2*s3x7-
  500. X          6.339e-3*s4x7-6.244e-3*sx3-1.65e-2*s2x7*sx3+
  501. X          (8.931e-3+2.728e-3*x1)*sx7*sx3-5.775e-3*s3x7*sx3+
  502. X          (8.1344e-2+3.206e-3*x1)*cx7*sx3+1.5019e-2*c2x7*sx3;
  503. X    *dml += (8.5581e-2+2.494e-3*x1)*sx7*cx3+1.4394e-2*c2x7*cx3+
  504. X          (2.5328e-2-3.117e-3*x1)*cx7*cx3+
  505. X          6.319e-3*c3x7*cx3+6.369e-3*sx7*s2x3+9.156e-3*s2x7*s2x3+
  506. X          7.525e-3*s3x8*s2x3-5.236e-3*cx7*c2x3-7.736e-3*c2x7*c2x3-
  507. X          7.528e-3*c3x8*c2x3;
  508. X    *dml = degrad(*dml);
  509. X
  510. X    *ds = (-7927+(2548+91*x1)*x1)*sx5+(13381+(1226-253*x1)*x1)*cx5+
  511. X         (248-121*x1)*s2x5-(305+91*x1)*c2x5+412*s2x7+12415*sx3+
  512. X         (390-617*x1)*sx7*sx3+(165-204*x1)*s2x7*sx3+26599*cx7*sx3-
  513. X         4687*c2x7*sx3-1870*c3x7*sx3-821*c4x7*sx3-
  514. X         377*c5x7*sx3+497*c2x8*sx3+(163-611*x1)*cx3;
  515. X    *ds += -12696*sx7*cx3-4200*s2x7*cx3-1503*s3x7*cx3-619*s4x7*cx3-
  516. X         268*s5x7*cx3-(282+1306*x1)*cx7*cx3+(-86+230*x1)*c2x7*cx3+
  517. X         461*s2x8*cx3-350*s2x3+(2211-286*x1)*sx7*s2x3-
  518. X         2208*s2x7*s2x3-568*s3x7*s2x3-346*s4x7*s2x3-
  519. X         (2780+222*x1)*cx7*s2x3+(2022+263*x1)*c2x7*s2x3+248*c3x7*s2x3+
  520. X         242*s3x8*s2x3+467*c3x8*s2x3-490*c2x3-(2842+279*x1)*sx7*c2x3;
  521. X    *ds += (128+226*x1)*s2x7*c2x3+224*s3x7*c2x3+
  522. X         (-1594+282*x1)*cx7*c2x3+(2162-207*x1)*c2x7*c2x3+
  523. X         561*c3x7*c2x3+343*c4x7*c2x3+469*s3x8*c2x3-242*c3x8*c2x3-
  524. X         205*sx7*s3x3+262*s3x7*s3x3+208*cx7*c3x3-271*c3x7*c3x3-
  525. X         382*c3x7*s4x3-376*s3x7*c4x3;
  526. X    *ds *= 1e-7;
  527. X
  528. X    dp = (7.7108e-2+(7.186e-3-1.533e-3*x1)*x1)*sx5-7.075e-3*sx7+
  529. X         (4.5803e-2-(1.4766e-2+5.36e-4*x1)*x1)*cx5-7.2586e-2*cx3-
  530. X         7.5825e-2*sx7*sx3-2.4839e-2*s2x7*sx3-8.631e-3*s3x7*sx3-
  531. X         1.50383e-1*cx7*cx3+2.6897e-2*c2x7*cx3+1.0053e-2*c3x7*cx3-
  532. X         (1.3597e-2+1.719e-3*x1)*sx7*s2x3+1.1981e-2*s2x7*c2x3;
  533. X    dp += -(7.742e-3-1.517e-3*x1)*cx7*s2x3+
  534. X         (1.3586e-2-1.375e-3*x1)*c2x7*c2x3-
  535. X         (1.3667e-2-1.239e-3*x1)*sx7*c2x3+
  536. X         (1.4861e-2+1.136e-3*x1)*cx7*c2x3-
  537. X         (1.3064e-2+1.628e-3*x1)*c2x7*c2x3;
  538. X
  539. X    *dm = *dml-(degrad(dp)/s);
  540. X
  541. X    *da = 572*sx5-1590*s2x7*cx3+2933*cx5-647*s3x7*cx3+33629*cx7-
  542. X         344*s4x7*cx3-3081*c2x7+2885*cx7*cx3-1423*c3x7+
  543. X         (2172+102*x1)*c2x7*cx3-671*c4x7+296*c3x7*cx3-320*c5x7-
  544. X         267*s2x7*s2x3+1098*sx3-778*cx7*s2x3-2812*sx7*sx3;
  545. X    *da += 495*c2x7*s2x3+688*s2x7*sx3+250*c3x7*s2x3-393*s3x7*sx3-
  546. X         856*sx7*c2x3-228*s4x7*sx3+441*s2x7*c2x3+2138*cx7*sx3+
  547. X         296*c2x7*c2x3-999*c2x7*sx3+211*c3x7*c2x3-642*c3x7*sx3-
  548. X         427*sx7*s3x3-325*c4x7*sx3+398*s3x7*s3x3-890*cx3+
  549. X         344*cx7*c3x3+2206*sx7*cx3-427*c3x7*c3x3;
  550. X    *da *= 1e-6;
  551. X
  552. X    *dhl = 7.47e-4*cx7*sx3+1.069e-3*cx7*cx3+2.108e-3*s2x7*s2x3+
  553. X          1.261e-3*c2x7*s2x3+1.236e-3*s2x7*c2x3-2.075e-3*c2x7*c2x3;
  554. X    *dhl = degrad(*dhl);
  555. }
  556. X
  557. /* ....uranus */
  558. static
  559. p_uranus (t, s, dl, dr, dml, ds, dm, da, dhl)
  560. double t, s;
  561. double *dl, *dr, *dml, *ds, *dm, *da, *dhl;
  562. {
  563. X    double dp;
  564. X    double x1, x2, x3, x4, x5, x6;
  565. X    double x8, x9, x10, x11, x12;
  566. X    double sx4, cx4, s2x4, c2x4;
  567. X    double sx9, cx9, s2x9, c2x9;
  568. X    double sx11, cx11;
  569. X
  570. X    aux_jsun (t, &x1, &x2, &x3, &x4, &x5, &x6);
  571. X
  572. X        x8 = mod2PI(1.46205+3.81337*t);
  573. X        x9 = 2*x8-x4;
  574. X    sx9 = sin(x9);
  575. X    cx9 = cos(x9);
  576. X        s2x9 = sin(2*x9);
  577. X    c2x9 = cos(2*x9);
  578. X
  579. X    x10 = x4-x2;
  580. X    x11 = x4-x3;
  581. X    x12 = x8-x4;
  582. X
  583. X    *dml = (8.64319e-1-1.583e-3*x1)*sx9+(8.2222e-2-6.833e-3*x1)*cx9+
  584. X          3.6017e-2*s2x9-3.019e-3*c2x9+8.122e-3*sin(x6);
  585. X    *dml = degrad(*dml);
  586. X
  587. X    dp = 1.20303e-1*sx9+6.197e-3*s2x9+(1.9472e-2-9.47e-4*x1)*cx9;
  588. X    *dm = *dml-(degrad(dp)/s);
  589. X
  590. X    *ds = (163*x1-3349)*sx9+20981*cx9+1311*c2x9;
  591. X    *ds *= 1e-7;
  592. X
  593. X    *da = -3.825e-3*cx9;
  594. X
  595. X    *dl = (1.0122e-2-9.88e-4*x1)*sin(x4+x11)+
  596. X         (-3.8581e-2+(2.031e-3-1.91e-3*x1)*x1)*cos(x4+x11)+
  597. X         (3.4964e-2-(1.038e-3-8.68e-4*x1)*x1)*cos(2*x4+x11)+
  598. X         5.594e-3*sin(x4+3*x12)-1.4808e-2*sin(x10)-
  599. X         5.794e-3*sin(x11)+2.347e-3*cos(x11)+9.872e-3*sin(x12)+
  600. X         8.803e-3*sin(2*x12)-4.308e-3*sin(3*x12);
  601. X
  602. X    sx11 = sin(x11);
  603. X    cx11 = cos(x11);
  604. X    sx4 = sin(x4);
  605. X    cx4 = cos(x4);
  606. X    s2x4 = sin(2*x4);
  607. X    c2x4 = cos(2*x4);
  608. X    *dhl = (4.58e-4*sx11-6.42e-4*cx11-5.17e-4*cos(4*x12))*sx4-
  609. X          (3.47e-4*sx11+8.53e-4*cx11+5.17e-4*sin(4*x11))*cx4+
  610. X          4.03e-4*(cos(2*x12)*s2x4+sin(2*x12)*c2x4);
  611. X    *dhl = degrad(*dhl);
  612. X
  613. X    *dr = -25948+4985*cos(x10)-1230*cx4+3354*cos(x11)+904*cos(2*x12)+
  614. X         894*(cos(x12)-cos(3*x12))+(5795*cx4-1165*sx4+1388*c2x4)*sx11+
  615. X         (1351*cx4+5702*sx4+1388*s2x4)*cos(x11);
  616. X    *dr *= 1e-6;
  617. }
  618. X
  619. /* ....neptune */
  620. static
  621. p_neptune (t, s, dl, dr, dml, ds, dm, da, dhl)
  622. double t, s;
  623. double *dl, *dr, *dml, *ds, *dm, *da, *dhl;
  624. {
  625. X    double dp;
  626. X    double x1, x2, x3, x4, x5, x6;
  627. X    double x8, x9, x10, x11, x12;
  628. X    double sx8, cx8;
  629. X    double sx9, cx9, s2x9, c2x9;
  630. X    double s2x12, c2x12;
  631. X
  632. X    aux_jsun (t, &x1, &x2, &x3, &x4, &x5, &x6);
  633. X
  634. X        x8 = mod2PI(1.46205+3.81337*t);
  635. X        x9 = 2*x8-x4;
  636. X    sx9 = sin(x9);
  637. X    cx9 = cos(x9);
  638. X        s2x9 = sin(2*x9);
  639. X    c2x9 = cos(2*x9);
  640. X
  641. X    x10 = x8-x2;
  642. X    x11 = x8-x3;
  643. X    x12 = x8-x4;
  644. X
  645. X    *dml = (1.089e-3*x1-5.89833e-1)*sx9+(4.658e-3*x1-5.6094e-2)*cx9-
  646. X          2.4286e-2*s2x9;
  647. X    *dml = degrad(*dml);
  648. X
  649. X    dp = 2.4039e-2*sx9-2.5303e-2*cx9+6.206e-3*s2x9-5.992e-3*c2x9;
  650. X
  651. X    *dm = *dml-(degrad(dp)/s);
  652. X
  653. X    *ds = 4389*sx9+1129*s2x9+4262*cx9+1089*c2x9;
  654. X    *ds *= 1e-7;
  655. X
  656. X    *da = 8189*cx9-817*sx9+781*c2x9;
  657. X    *da *= 1e-6;
  658. X
  659. X    s2x12 = sin(2*x12);
  660. X    c2x12 = cos(2*x12);
  661. X    sx8 = sin(x8);
  662. X    cx8 = cos(x8);
  663. X    *dl = -9.556e-3*sin(x10)-5.178e-3*sin(x11)+2.572e-3*s2x12-
  664. X         2.972e-3*c2x12*sx8-2.833e-3*s2x12*cx8;
  665. X
  666. X    *dhl = 3.36e-4*c2x12*sx8+3.64e-4*s2x12*cx8;
  667. X    *dhl = degrad(*dhl);
  668. X
  669. X    *dr = -40596+4992*cos(x10)+2744*cos(x11)+2044*cos(x12)+1051*c2x12;
  670. X    *dr *= 1e-6;
  671. }
  672. X
  673. SHAR_EOF
  674. chmod 0644 plans.c ||
  675. echo 'restore of plans.c failed'
  676. Wc_c="`wc -c < 'plans.c'`"
  677. test 17647 -eq "$Wc_c" ||
  678.     echo 'plans.c: original size 17647, current size' "$Wc_c"
  679. rm -f _shar_wnt_.tmp
  680. fi
  681. # ============= plot.c ==============
  682. if test -f 'plot.c' -a X"$1" != X"-c"; then
  683.     echo 'x - skipping plot.c (File already exists)'
  684.     rm -f _shar_wnt_.tmp
  685. else
  686. > _shar_wnt_.tmp
  687. echo 'x - extracting plot.c (Text)'
  688. sed 's/^X//' << 'SHAR_EOF' > 'plot.c' &&
  689. /* code to manage the stuff on the "plot" menu.
  690. X */
  691. X
  692. #include <stdio.h>
  693. #include <ctype.h>
  694. #include <math.h>
  695. #ifdef VMS
  696. #include <stdlib.h>
  697. #endif
  698. #include <X11/Xlib.h>
  699. #include <Xm/Xm.h>
  700. #include <Xm/Form.h>
  701. #include <Xm/DrawingA.h>
  702. #include <Xm/LabelG.h>
  703. #include <Xm/PushBG.h>
  704. #include <Xm/ToggleBG.h>
  705. #include <Xm/Text.h>
  706. #include "fieldmap.h"
  707. /* N.B. if you need circum.h for something, beware of the height #define - it
  708. X * interferes with the height member of the XResizeRequestEvent structure.
  709. X */
  710. X
  711. extern Widget toplevel_w;
  712. #define    XtD    XtDisplay(toplevel_w)
  713. X
  714. #ifdef VMS
  715. #include <perror.h>
  716. #include <errno.h>
  717. #else
  718. extern char *sys_errlist[];
  719. extern errno;
  720. #endif
  721. X
  722. #define    errsys    (sys_errlist[errno])
  723. X
  724. #define    MAXPLTLINES    10
  725. X
  726. /* locations of each field.
  727. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  728. X * historical reasons.
  729. X */
  730. #define    NR    (R_TABLE+MAXPLTLINES+1)    /* +1 for close/help buttons */
  731. #define    NC    34
  732. X
  733. #define    R_SELECT    1
  734. #define    R_ACTIVE    2
  735. #define    R_SHOW        3
  736. X
  737. #define    R_FNLABEL    5
  738. #define    R_FILENAME    6
  739. X
  740. #define    R_TLABEL    8
  741. #define    R_TITLE        9
  742. X
  743. #define    R_PROMPT    11
  744. #define    R_HEADERS    12
  745. #define    R_TABLE        13
  746. #define    R_CONTROL    NR
  747. X
  748. #define    C_TAG        (1*NC/9)
  749. #define    C_X        (3*NC/9)
  750. #define    C_Y        (6*NC/9)
  751. X
  752. static Widget plotform_w;
  753. static Widget select_w, active_w, prompt_w;
  754. static Widget title_w, filename_w;
  755. static Widget table_w[MAXPLTLINES][3];    /* column indeces follow.. */
  756. static int selecting_xy;        /* also one of ... */
  757. #define    T    0
  758. #define    X    1
  759. #define    Y    2
  760. X
  761. #define    DEF_PLTFN    "ephem.plt"    /* default plot file name */
  762. static FILE *plt_fp;            /* the plot file; == 0 means don't plot */
  763. X
  764. X
  765. /* plt_activate_cb client values. */
  766. #define    SELECT    0
  767. #define    ACTIVE    1
  768. #define    SHOW    2
  769. X
  770. /* store the Widget for each x and y line to track.
  771. X * we get the label straight from the Text widget in the table as needed.
  772. X */
  773. typedef struct {
  774. X    Widget pl_xw, pl_yw;
  775. } PltLine;
  776. static PltLine pltlines[MAXPLTLINES];
  777. static int npltlines;        /* number of pltlines[] in actual use */
  778. X
  779. /* one of these gets malloced and passed to the drawing area expose callback via
  780. X * its client parameter. be sure to free it when the parent FormDialog goes
  781. X * away too.
  782. X * by doing this, we can have lots of different plots up at once and yet we
  783. X * don't have to keep track of them - they track themselves.
  784. X */
  785. typedef struct {
  786. X    char *filename;    /* name of file being plotted (also malloced) */
  787. X    FILE *fp;        /* FILE pointer for the file */
  788. X    int flipx, flipy;    /* flip state for this instance */
  789. X    int grid;        /* whether to include a grid */
  790. } DrawInfo;
  791. X
  792. /* called when the plot menu is activated via the main menu pulldown.
  793. X * if never called before, create and manage all the widgets as a child of a
  794. X * form. otherwise, just toggle whether the form is managed.
  795. X */
  796. plot_manage ()
  797. {
  798. X    if (!plotform_w) {
  799. X        void plt_activate_cb();
  800. X        void plt_close_cb();
  801. X        void plt_help_cb();
  802. X        XmString str;
  803. X        Widget w;
  804. X        Arg args[20];
  805. X        int i, n;
  806. X
  807. X        /* create form */
  808. X        n = 0;
  809. X        XtSetArg (args[n], XmNfractionBase, 1000); n++;
  810. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  811. X        XtSetArg (args[n], XmNhorizontalSpacing, 50); n++;
  812. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  813. X        XtSetArg (args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
  814. X        XtSetArg (args[n], XmNwidth, char_width()*NC); n++;
  815. X        plotform_w = XmCreateFormDialog (toplevel_w, "Plot", args, n);
  816. X
  817. X        /* set some stuff in the parent DialogShell.
  818. X         * setting XmNdialogTitle in the Form didn't work..
  819. X         */
  820. X        n = 0;
  821. X        XtSetArg (args[n], XmNtitle, "xephem Plot Control"); n++;
  822. X        XtSetValues (XtParent(plotform_w), args, n);
  823. X
  824. X        /* make the control controls */
  825. X
  826. X        str = XmStringCreate("Select fields", XmSTRING_DEFAULT_CHARSET);
  827. X        n = 0;
  828. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  829. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_SELECT)); n++;
  830. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  831. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  832. X        XtSetArg (args[n], XmNlabelString, str); n++;
  833. X        select_w = XmCreateToggleButtonGadget(plotform_w, "PlotSelect",
  834. X                                    args, n);
  835. X        XmStringFree (str);
  836. X        XtManageChild (select_w);
  837. X        XtAddCallback(select_w,XmNvalueChangedCallback, plt_activate_cb,
  838. X                                    SELECT);
  839. X
  840. X        str = XmStringCreate("Plot to file", XmSTRING_DEFAULT_CHARSET);
  841. X        n = 0;
  842. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  843. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_ACTIVE)); n++;
  844. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  845. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  846. X        XtSetArg (args[n], XmNlabelString, str); n++;
  847. X        active_w = XmCreateToggleButtonGadget(plotform_w, "PlotActive",
  848. X                                    args, n);
  849. X        XmStringFree (str);
  850. X        XtManageChild (active_w);
  851. X        XtAddCallback (active_w, XmNvalueChangedCallback, plt_activate_cb,
  852. X                                    ACTIVE);
  853. X
  854. X        n = 0;
  855. X        str = XmStringCreate("Show plot file", XmSTRING_DEFAULT_CHARSET);
  856. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  857. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_SHOW)); n++;
  858. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  859. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  860. X        XtSetArg (args[n], XmNlabelString, str); n++;
  861. X        w = XmCreateToggleButtonGadget(plotform_w, "PlotShow", args, n);
  862. X        XmStringFree (str);
  863. X        XtManageChild (w);
  864. X        XtAddCallback (w, XmNvalueChangedCallback, plt_activate_cb, SHOW);
  865. X
  866. X        /* make the close button */
  867. X
  868. X        str = XmStringCreate ("Close", XmSTRING_DEFAULT_CHARSET);
  869. X        n = 0;
  870. X        XtSetArg (args[n], XmNlabelString, str); n++;
  871. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  872. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  873. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  874. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  875. X        w = XmCreatePushButtonGadget (plotform_w, "PlotClose", args, n);
  876. X        XtAddCallback (w, XmNactivateCallback, plt_close_cb, 0);
  877. X        XtManageChild (w);
  878. X        XmStringFree (str);
  879. X
  880. X        /* make the help button */
  881. X
  882. X        str = XmStringCreate ("Help", XmSTRING_DEFAULT_CHARSET);
  883. X        n = 0;
  884. X        XtSetArg (args[n], XmNlabelString, str); n++;
  885. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  886. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  887. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  888. X        XtSetArg (args[n], XmNrightPosition, 1000); n++;
  889. X        w = XmCreatePushButtonGadget (plotform_w, "PlotHelp", args, n);
  890. X        XtAddCallback (w, XmNactivateCallback, plt_help_cb, 0);
  891. X        XtManageChild (w);
  892. X        XmStringFree (str);
  893. X
  894. X        /* create filename text area and its label */
  895. X        n = 0;
  896. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  897. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_FILENAME)); n++;
  898. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  899. X        XtSetArg (args[n], XmNleftPosition, 50); n++;
  900. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  901. X        XtSetArg (args[n], XmNrightPosition, 950); n++;
  902. X        filename_w = XmCreateText (plotform_w, "PlotFilename", args, n);
  903. X        XmTextSetString (filename_w, DEF_PLTFN);
  904. X        XtManageChild (filename_w);
  905. X
  906. X        n = 0;
  907. X        str = XmStringCreate("File name:", XmSTRING_DEFAULT_CHARSET);
  908. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  909. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_FNLABEL)); n++;
  910. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  911. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  912. X        XtSetArg (args[n], XmNlabelString, str); n++;
  913. X        w = XmCreateLabelGadget (plotform_w, "PlotFnL", args, n);
  914. X        XmStringFree (str);
  915. X        XtManageChild (w);
  916. X
  917. X        /* create title text area and its label */
  918. X        n = 0;
  919. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  920. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TITLE)); n++;
  921. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  922. X        XtSetArg (args[n], XmNleftPosition, 50); n++;
  923. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  924. X        XtSetArg (args[n], XmNrightPosition, 950); n++;
  925. X        title_w = XmCreateText (plotform_w, "PlotTitle", args, n);
  926. X        XtManageChild (title_w);
  927. X
  928. X        n = 0;
  929. X        str = XmStringCreate("Title:", XmSTRING_DEFAULT_CHARSET);
  930. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  931. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TLABEL)); n++;
  932. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  933. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  934. X        XtSetArg (args[n], XmNlabelString, str); n++;
  935. X        w = XmCreateLabelGadget (plotform_w, "PlotTL", args, n);
  936. X        XtManageChild (w);
  937. X        XmStringFree (str);
  938. X
  939. X        /* create prompt line and table headings */
  940. X
  941. X        n = 0;
  942. X        str = XmStringCreate("", XmSTRING_DEFAULT_CHARSET);
  943. X        XtSetArg (args[n], XmNlabelString, str); n++;
  944. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  945. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_PROMPT)); n++;
  946. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  947. X        XtSetArg (args[n], XmNleftPosition, 50); n++;
  948. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  949. X        XtSetArg (args[n], XmNrightPosition, 950); n++;
  950. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  951. X        prompt_w = XmCreateLabelGadget (plotform_w, "PlotPrompt", args, n);
  952. X        XtManageChild (prompt_w);
  953. X        XmStringFree (str);
  954. X
  955. X        n = 0;
  956. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  957. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_HEADERS)); n++;
  958. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  959. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_TAG-1));n++;
  960. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  961. X        w = XmCreateLabelGadget (plotform_w, "Tag", args, n);
  962. X        XtManageChild (w);
  963. X
  964. X        n = 0;
  965. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  966. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_HEADERS)); n++;
  967. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  968. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_X));n++;
  969. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  970. X        w = XmCreateLabelGadget (plotform_w, "X", args, n);
  971. X        XtManageChild (w);
  972. X
  973. X        n = 0;
  974. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  975. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_HEADERS)); n++;
  976. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  977. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_Y));n++;
  978. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  979. X        w = XmCreateLabelGadget (plotform_w, "Y", args, n);
  980. X        XtManageChild (w);
  981. X
  982. X        /* make the tag/x/y controls, but don't manage them now */
  983. X        for (i = 0; i < MAXPLTLINES; i++) {
  984. X        n = 0;
  985. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  986. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TABLE+i)); n++;
  987. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  988. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_TAG)); n++;
  989. X        XtSetArg (args[n], XmNmaxLength, 1); n++;
  990. X        XtSetArg (args[n], XmNcolumns, 1); n++;
  991. X        table_w[i][T] = XmCreateText (plotform_w, "PlotTag", args, n);
  992. X
  993. X        n = 0;
  994. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  995. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TABLE+i)); n++;
  996. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  997. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_X)); n++;
  998. X        table_w[i][X] = XmCreateLabelGadget (plotform_w, "PlotX",
  999. X                                    args, n);
  1000. X
  1001. X        n = 0;
  1002. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1003. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_TABLE+i)); n++;
  1004. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1005. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_Y)); n++;
  1006. X        table_w[i][Y] = XmCreateLabelGadget (plotform_w, "PlotY",
  1007. X                                    args, n);
  1008. X
  1009. X        }
  1010. X    }
  1011. X    
  1012. X    if (XtIsManaged(plotform_w))
  1013. X        XtUnmanageChild (plotform_w);
  1014. X    else
  1015. X        XtManageChild (plotform_w);
  1016. }
  1017. X
  1018. /* called by the other menus (data, riset, etc) as their buttons are
  1019. X * selected to inform us that that button is to be included in a plot.
  1020. X */
  1021. plt_selection (fp)
  1022. FieldMap *fp;
  1023. {
  1024. X    Widget tw;
  1025. X
  1026. X    if (!plotform_w
  1027. X        || !XtIsManaged(plotform_w)
  1028. X        || !XmToggleButtonGadgetGetState(select_w))
  1029. X        return;
  1030. X
  1031. X    if (flog_add(fp->w) < 0) {
  1032. X        f_msg ("Sorry; can not log any more fields.", 0);
  1033. X        if (selecting_xy == Y) {
  1034. X        /* if yth one won't fit, discard the xth one too */
  1035. X        Widget w = pltlines[npltlines].pl_xw;
  1036. X        (void) flog_delete (w);
  1037. X        plt_stop_selecting();
  1038. X        }
  1039. X        return;
  1040. X    }
  1041. X
  1042. X    tw = table_w[npltlines][selecting_xy];
  1043. X    set_xmstring (tw, XmNlabelString, fp->name);
  1044. X    XtManageChild (tw);
  1045. X
  1046. X    if (selecting_xy == X) {
  1047. X        pltlines[npltlines].pl_xw = fp->w;
  1048. X        selecting_xy = Y;
  1049. X        f_string (prompt_w, "Select quantity for Y..");
  1050. X    } else {
  1051. X        pltlines[npltlines].pl_yw = fp->w;
  1052. X        if (++npltlines == MAXPLTLINES)
  1053. X        plt_stop_selecting();
  1054. X        else {
  1055. X        selecting_xy = X;
  1056. X        init_next_tag();
  1057. X        }
  1058. X    }
  1059. }
  1060. X
  1061. /* write the active plotfields to the current plot file, if one is open. */
  1062. plot()
  1063. {
  1064. X    if (plt_fp) {
  1065. X        /* plot in order of original selection */
  1066. X        PltLine *plp;
  1067. X        double x, y;
  1068. X        for (plp = pltlines; plp < &pltlines[npltlines]; plp++)
  1069. X        if (flog_get (plp->pl_xw, &x, (char *)0) == 0 
  1070. X                && flog_get (plp->pl_yw, &y, (char *)0) == 0) {
  1071. X            char *lbl = XmTextGetString (table_w[plp-pltlines][T]);
  1072. X            (void) fprintf (plt_fp, "%c,%.12g,%.12g\n", lbl[0], x, y);
  1073. X            XtFree (lbl);
  1074. X        }
  1075. X    }
  1076. }
  1077. X
  1078. plot_ison()
  1079. {
  1080. X    return (plt_fp != 0);
  1081. }
  1082. X
  1083. /* callback from any of the plot menu toggle buttons being activated.
  1084. X */
  1085. void
  1086. plt_activate_cb (w, client, call)
  1087. Widget w;
  1088. caddr_t client;
  1089. caddr_t call;
  1090. {
  1091. X    XmToggleButtonCallbackStruct *t = (XmToggleButtonCallbackStruct *) call;
  1092. X    int what = (int) client;
  1093. X
  1094. X    switch (what) {
  1095. X    case SELECT:
  1096. X        if (t->set) {
  1097. X        /* first turn off plotting, if on, while we change things */
  1098. X        if (XmToggleButtonGadgetGetState(active_w))
  1099. X            XmToggleButtonGadgetSetState(active_w, False, True);
  1100. X        plt_reset();    /* reset pltlines array and unmanage the table*/
  1101. X        plt_select(1);    /* inform other menus to inform us of fields */
  1102. X        init_next_tag();/* set first tag to something and show it */
  1103. X        selecting_xy = X;
  1104. X        } else
  1105. X        plt_stop_selecting();
  1106. X        break;
  1107. X    case ACTIVE:
  1108. X        if (t->set) {
  1109. X        /* first turn off selecting, if on */
  1110. X        if (XmToggleButtonGadgetGetState(select_w))
  1111. X            XmToggleButtonGadgetSetState(select_w, False, True);
  1112. X        plt_try_turn_on();
  1113. X        } else
  1114. X        plt_turn_off();
  1115. X        break;
  1116. X    case SHOW:
  1117. X        /* turn off plotting, if on, to make sure file is complete. */
  1118. X        if (XmToggleButtonGadgetGetState(active_w))
  1119. X        XmToggleButtonGadgetSetState(active_w, False, True);
  1120. X        plt_da_manage();
  1121. X        /* we want this to work like it was a pushbutton, really */
  1122. X        XmToggleButtonGadgetSetState(w, False, False);
  1123. X        break;
  1124. X    }
  1125. }
  1126. X
  1127. /* callback from the Close button.
  1128. X */
  1129. void
  1130. plt_close_cb (w, client, call)
  1131. Widget w;
  1132. caddr_t client;
  1133. caddr_t call;
  1134. {
  1135. X    XtUnmanageChild (plotform_w);
  1136. }
  1137. X
  1138. /* callback from the Help button.
  1139. X */
  1140. void
  1141. plt_help_cb (w, client, call)
  1142. Widget w;
  1143. caddr_t client;
  1144. caddr_t call;
  1145. {
  1146. static char *help_msg[] = {
  1147. "This menu controls the plot generation and display functionality of xephem.",
  1148. "Select fields to form x/y pairs, enable plotting to write them to a file on",
  1149. "each xephem iteration step, then view. Each file may be titled, as desired."
  1150. };
  1151. X    hlp_dialog ("Plot", help_msg, sizeof(help_msg)/sizeof(help_msg[0]));
  1152. }
  1153. X
  1154. /* inform the other menues whether we are setting up for them to tell us
  1155. X * what fields to plot.
  1156. X */
  1157. plt_select(whether)
  1158. int whether;
  1159. {
  1160. X    dm_selection_mode(whether);
  1161. X    mm_selection_mode(whether);
  1162. X    rm_selection_mode(whether);
  1163. X    sm_selection_mode(whether);
  1164. X    jm_selection_mode(whether);
  1165. X    srch_selection_mode(whether);
  1166. }
  1167. X
  1168. /* stop logging our collection of selected widgets, forget our list,
  1169. X * and unmanage the table.
  1170. X */
  1171. static
  1172. plt_reset()
  1173. {
  1174. X    PltLine *plp;
  1175. X    int i;
  1176. X
  1177. X    for (plp = &pltlines[npltlines]; --plp >= pltlines; ) {
  1178. X        (void) flog_delete (plp->pl_xw);
  1179. X        (void) flog_delete (plp->pl_yw);
  1180. X        plp->pl_xw = plp->pl_yw = 0;
  1181. X    }
  1182. X
  1183. X    for (i = 0; i < npltlines; i++) {
  1184. X        XtUnmanageChild (table_w[i][T]);
  1185. X        XtUnmanageChild (table_w[i][X]);
  1186. X        XtUnmanageChild (table_w[i][Y]);
  1187. X    }
  1188. X
  1189. X    npltlines = 0;
  1190. }
  1191. X
  1192. /* stop selecting: unmanage a partitially filled in line specs; tell
  1193. X * everybody else to drop their buttons, make sure toggle is off.
  1194. X */
  1195. static
  1196. plt_stop_selecting()
  1197. {
  1198. X    /* harmless to unmanage something already unmanaged so do them all */
  1199. X    if (npltlines < MAXPLTLINES) {
  1200. X        XtUnmanageChild (table_w[npltlines][T]);
  1201. X        XtUnmanageChild (table_w[npltlines][X]);
  1202. X        XtUnmanageChild (table_w[npltlines][Y]);
  1203. X    }
  1204. X
  1205. X    XmToggleButtonGadgetSetState (select_w, False, False);
  1206. X    plt_select(0);
  1207. X    f_string (prompt_w, "");
  1208. }
  1209. X
  1210. static
  1211. plt_turn_off ()
  1212. {
  1213. X    if (plt_fp) {
  1214. X        (void) fclose (plt_fp);
  1215. X        plt_fp = 0;
  1216. X    }
  1217. }
  1218. X
  1219. init_next_tag()
  1220. {
  1221. X    char buf[100];
  1222. X    Widget w = table_w[npltlines][T];
  1223. X
  1224. X    f_string (prompt_w, "Select quantity for X..");
  1225. X    (void) sprintf (buf, "%d", npltlines);
  1226. X    XmTextSetString (w, buf);
  1227. X    XtManageChild (w);
  1228. }
  1229. X
  1230. /* called from the query routine when want to append to an existing plot file.*/
  1231. static void
  1232. plt_try_append()
  1233. {
  1234. X    plt_turn_on("a");
  1235. }
  1236. X
  1237. /* called from the query routine when want to overwrite to an existing plot
  1238. X * file.
  1239. X */
  1240. static void
  1241. plt_try_overwrite()
  1242. {
  1243. X    plt_turn_on("w");
  1244. }
  1245. X
  1246. /* called from the query routine when want decided not to make a plot file.  */
  1247. static void
  1248. plt_try_cancel()
  1249. {
  1250. X    XmToggleButtonGadgetSetState (active_w, False, False);
  1251. }
  1252. X
  1253. /* attempt to open file for use as a plot file.
  1254. X * if it doesn't exist, then go ahead and make it.
  1255. X * but if it does, first ask wheher to append or overwrite.
  1256. X */
  1257. static
  1258. plt_try_turn_on()
  1259. {
  1260. X    char *txt = XmTextGetString (filename_w);
  1261. X    if (access (txt, 0) == 0) {
  1262. X        char *buf;
  1263. X        buf = XtMalloc (strlen(txt)+100);
  1264. X        (void) sprintf (buf, "%s exists: Append or Overwrite?", txt);
  1265. X        query (toplevel_w, buf, "Append", "Overwrite", "Cancel",
  1266. X                plt_try_append, plt_try_overwrite, plt_try_cancel);
  1267. X        XtFree (buf);
  1268. X    } else
  1269. X        plt_turn_on("w");
  1270. X    XtFree (txt);
  1271. }
  1272. X
  1273. /* turn on plotting.
  1274. X * establish a file to use (and thereby set plt_fp, the plotting_is_on flag).
  1275. X */
  1276. static
  1277. plt_turn_on (how)
  1278. char *how;    /* fopen how argument */
  1279. {
  1280. X    char *txt;
  1281. X
  1282. X    /* plotting is on if file opens ok */
  1283. X    txt = XmTextGetString (filename_w);
  1284. X    plt_fp = fopen (txt, how);
  1285. X    if (!plt_fp) {
  1286. X        char *buf;
  1287. X        XmToggleButtonGadgetSetState (active_w, False, False);
  1288. X        buf = XtMalloc (strlen(txt)+100);
  1289. X        (void) sprintf (buf, "Can not open %s: %s", txt, errsys);
  1290. X        f_msg (buf, 0);
  1291. X        XtFree (buf);
  1292. X    }
  1293. X    XtFree (txt);
  1294. X    
  1295. X    if (plt_fp) {
  1296. X        /* add a title if it's not null */
  1297. X        txt = XmTextGetString (title_w);
  1298. X        if (txt[0] != '\0')
  1299. X        (void) fprintf (plt_fp, "* %s\n", txt);
  1300. X        XtFree (txt);
  1301. X    }
  1302. }
  1303. X
  1304. /* make a new drawing area widget and manage it. it's unmanaged and destroyed
  1305. X *   with its own button via autoUnmanage.
  1306. X * open the plot file and save it, the current state of the flipx/flipy/grid
  1307. X *   buttons and the filename in a DrawInfo struct in the userData resource
  1308. X *   for the FormDialog where the drawingarea callback can get at it each time.
  1309. X * this way, we can have lots of different plots up at once yet we don't
  1310. X *   have to keep track of them.
  1311. X * by leaving the file open, we gain some protection against it being removed
  1312. X *   or renamed.
  1313. X */
  1314. static
  1315. plt_da_manage()
  1316. {
  1317. X    void plt_da_exp_cb(), plt_da_unmap_cb();
  1318. X    void plt_da_flipx_cb(), plt_da_flipy_cb(), plt_da_grid_cb();
  1319. X    Widget daform_w;
  1320. X    Widget da_w, w;
  1321. X    XmString str;
  1322. X    Arg args[20];
  1323. X    int n;
  1324. X    DrawInfo *di;
  1325. X    FILE *fp;
  1326. X    char *fn;
  1327. X
  1328. X    /* first make sure we can open the plot file */
  1329. X    fn = XmTextGetString (filename_w);
  1330. X    fp = fopen (fn, "r");
  1331. X    if (!fp) {
  1332. X        char *buf;
  1333. X        buf = XtMalloc (strlen(fn)+100);
  1334. X        (void) sprintf (buf, "Can not open %s: %s", fn, errsys);
  1335. X        f_msg (buf, 0);
  1336. X        XtFree (buf);
  1337. X        XtFree (fn);
  1338. X        return;
  1339. X    }
  1340. X
  1341. X    /* create the form dialog parent */
  1342. X    n = 0;
  1343. X    XtSetArg (args[n], XmNunitType, XmPIXELS); n++;
  1344. X    XtSetArg (args[n], XmNwidth, 350); n++;
  1345. X    XtSetArg (args[n], XmNheight, 375); n++;
  1346. X    XtSetArg (args[n], XmNautoUnmanage, True); n++;
  1347. X    XtSetArg (args[n], XmNdefaultPosition, True); n++;
  1348. X    daform_w = XmCreateFormDialog (toplevel_w, "PlotD", args, n);
  1349. X    XtAddCallback (daform_w, XmNunmapCallback, plt_da_unmap_cb, 0);
  1350. X
  1351. X    /* make the DrawInfo structure and save it in the userData of the Form.
  1352. X     * it gets freed when the it is unmanaged.
  1353. X     */
  1354. X    di = (DrawInfo *) XtMalloc (sizeof(DrawInfo));
  1355. X    di->filename = fn;
  1356. X    di->fp = fp;
  1357. X    di->flipx = 0;
  1358. X    di->flipy = 0;
  1359. X    di->grid = 0;
  1360. X    set_something (daform_w, XmNuserData, (caddr_t)di);
  1361. X
  1362. X    /* set some stuff in the parent DialogShell.
  1363. X     * setting XmNdialogTitle in the Form didn't work..
  1364. X     */
  1365. X    n = 0;
  1366. X    XtSetArg (args[n], XmNtitle, "xephem Plot"); n++;
  1367. X    XtSetValues (XtParent(daform_w), args, n);
  1368. X
  1369. X    /* create a "Close" button. it will bring down the plot
  1370. X     * automatically because of autoUnmanage being set in daform_w.
  1371. X     */
  1372. X    n = 0;
  1373. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1374. X    XtSetArg (args[n], XmNbottomOffset, 5); n++;
  1375. X    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1376. X    w = XmCreatePushButtonGadget (daform_w, "Close", args, n);
  1377. X    XtManageChild (w);
  1378. X
  1379. X    /* create the drawing area and connect plt_da_exp_cb().
  1380. X     * N.B. be sure this guys parent is the FormDialog so exp_cb can find
  1381. X     *   the DrawInfo by looking there at its userData.
  1382. X     */
  1383. X    n = 0;
  1384. X    XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  1385. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  1386. X    XtSetArg (args[n], XmNbottomOffset, 2); n++;
  1387. X    XtSetArg (args[n], XmNbottomWidget, w); n++;
  1388. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1389. X    XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1390. X    XtSetArg (args[n], XmNmarginWidth, 0); n++;
  1391. X    XtSetArg (args[n], XmNmarginHeight, 0); n++;
  1392. X    da_w = XmCreateDrawingArea (daform_w, "PlotDA", args, n);
  1393. X    XtAddCallback (da_w, XmNexposeCallback, plt_da_exp_cb, 0);
  1394. X    XtAddCallback (da_w, XmNresizeCallback, plt_da_exp_cb, 0);
  1395. X    XtManageChild (da_w);
  1396. X
  1397. X    /* make the flipx/y and grid buttons */
  1398. X
  1399. X    n = 0;
  1400. X    str = XmStringCreate("Flip X", XmSTRING_DEFAULT_CHARSET);
  1401. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1402. X    XtSetArg (args[n], XmNbottomOffset, 5); n++;
  1403. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1404. X    XtSetArg (args[n], XmNlabelString, str); n++;
  1405. X    XtSetArg (args[n], XmNset, di->flipx); n++;
  1406. X    w = XmCreateToggleButtonGadget(daform_w, "DAFlipX", args, n);
  1407. X    XmStringFree (str);
  1408. X    XtAddCallback (w, XmNvalueChangedCallback, plt_da_flipx_cb, da_w);
  1409. X    XtManageChild (w);
  1410. X
  1411. X    n = 0;
  1412. X    str = XmStringCreate("Flip Y", XmSTRING_DEFAULT_CHARSET);
  1413. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1414. X    XtSetArg (args[n], XmNbottomOffset, 5); n++;
  1415. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1416. X    XtSetArg (args[n], XmNleftPosition, 25); n++;
  1417. X    XtSetArg (args[n], XmNlabelString, str); n++;
  1418. X    XtSetArg (args[n], XmNset, di->flipy); n++;
  1419. X    w = XmCreateToggleButtonGadget(daform_w, "DAFlipY", args, n);
  1420. X    XmStringFree (str);
  1421. X    XtAddCallback (w, XmNvalueChangedCallback, plt_da_flipy_cb, da_w);
  1422. X    XtManageChild (w);
  1423. X
  1424. X    n = 0;
  1425. X    str = XmStringCreate("Grid", XmSTRING_DEFAULT_CHARSET);
  1426. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1427. X    XtSetArg (args[n], XmNbottomOffset, 5); n++;
  1428. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1429. X    XtSetArg (args[n], XmNleftPosition, 50); n++;
  1430. X    XtSetArg (args[n], XmNlabelString, str); n++;
  1431. X    XtSetArg (args[n], XmNset, di->grid); n++;
  1432. X    w = XmCreateToggleButtonGadget(daform_w, "DAGrid", args, n);
  1433. X    XmStringFree (str);
  1434. X    XtAddCallback (w, XmNvalueChangedCallback, plt_da_grid_cb, da_w);
  1435. X    XtManageChild (w);
  1436. X    
  1437. X    /* go. the expose will do the actual plotting */
  1438. X    XtManageChild (daform_w);
  1439. }
  1440. X
  1441. /* unmap callback from the FormDialog managing the drawing area.
  1442. X * free the DrawInfo and destroy ourselves.
  1443. X */
  1444. static void
  1445. plt_da_unmap_cb (w, client, call)
  1446. Widget w;
  1447. caddr_t client;
  1448. caddr_t call;
  1449. {
  1450. X    DrawInfo *di;
  1451. X
  1452. X    get_something (w, XmNuserData, (caddr_t)&di);
  1453. X    fclose (di->fp);
  1454. X    XtFree(di->filename);
  1455. X    XtFree((char *)di);
  1456. X    XtDestroyWidget(w);
  1457. }
  1458. X
  1459. /* callback from the Flip X toggle button within the drawing FormDiag itself.
  1460. X * toggle the x bit in the parent's DrawInfo structure and fake an expose.
  1461. X */
  1462. static void
  1463. plt_da_flipx_cb (w, client, call)
  1464. Widget w;
  1465. caddr_t client;
  1466. caddr_t call;
  1467. {
  1468. X    XmToggleButtonCallbackStruct *t = (XmToggleButtonCallbackStruct *) call;
  1469. X    Widget da_w = (Widget) client;
  1470. X    Widget daform_w = XtParent(da_w);
  1471. X    Display *dsp = XtDisplay(da_w);
  1472. X    Window win = XtWindow(da_w);
  1473. X    DrawInfo *di;
  1474. X    XExposeEvent ev;
  1475. X    Window root;
  1476. X    int x, y;
  1477. X    unsigned int nx, ny, bw, d;
  1478. X
  1479. X    get_something (daform_w, XmNuserData, (caddr_t)&di);
  1480. X    di->flipx = t->set;
  1481. X
  1482. X    XGetGeometry(dsp, win, &root, &x, &y, &nx, &ny, &bw, &d);
  1483. X
  1484. X    ev.type = Expose;
  1485. X    ev.send_event = 1;    /* gets set anyways */
  1486. X    ev.display = dsp;
  1487. X    ev.window = win;
  1488. X    ev.x = ev.y = 0;
  1489. X    ev.width = nx;
  1490. X    ev.height = ny;
  1491. X    ev.count = 0;
  1492. X
  1493. X    XSendEvent (dsp, win, /*propagate*/False, ExposureMask, &ev);
  1494. }
  1495. X
  1496. /* callback from the Flip Y toggle button within the drawing FormDiag itself.
  1497. X * toggle the y bit in the parent's DrawInfo structure and fake an expose.
  1498. X */
  1499. static void
  1500. plt_da_flipy_cb (w, client, call)
  1501. Widget w;
  1502. caddr_t client;
  1503. caddr_t call;
  1504. {
  1505. X    XmToggleButtonCallbackStruct *t = (XmToggleButtonCallbackStruct *) call;
  1506. X    Widget da_w = (Widget) client;
  1507. X    Widget daform_w = XtParent(da_w);
  1508. X    Display *dsp = XtDisplay(da_w);
  1509. X    Window win = XtWindow(da_w);
  1510. X    DrawInfo *di;
  1511. X    XExposeEvent ev;
  1512. X    Window root;
  1513. X    int x, y;
  1514. X    unsigned int nx, ny, bw, d;
  1515. X
  1516. X    get_something (daform_w, XmNuserData, (caddr_t)&di);
  1517. X    di->flipy = t->set;
  1518. X
  1519. X    XGetGeometry(dsp, win, &root, &x, &y, &nx, &ny, &bw, &d);
  1520. X
  1521. X    ev.type = Expose;
  1522. X    ev.send_event = 1;    /* gets set anyways */
  1523. X    ev.display = dsp;
  1524. X    ev.window = win;
  1525. X    ev.x = ev.y = 0;
  1526. X    ev.width = nx;
  1527. X    ev.height = ny;
  1528. X    ev.count = 0;
  1529. X
  1530. X    XSendEvent (dsp, win, /*propagate*/False, ExposureMask, &ev);
  1531. }
  1532. X
  1533. /* callback from the grid toggle button within the drawing FormDiag itself.
  1534. X * toggle the grid flag in the parent's DrawInfo structure and fake an expose.
  1535. X */
  1536. static void
  1537. plt_da_grid_cb (w, client, call)
  1538. Widget w;
  1539. caddr_t client;
  1540. caddr_t call;
  1541. {
  1542. X    XmToggleButtonCallbackStruct *t = (XmToggleButtonCallbackStruct *) call;
  1543. X    Widget da_w = (Widget) client;
  1544. X    Widget daform_w = XtParent(da_w);
  1545. X    Display *dsp = XtDisplay(da_w);
  1546. X    Window win = XtWindow(da_w);
  1547. X    DrawInfo *di;
  1548. X    XExposeEvent ev;
  1549. X    Window root;
  1550. X    int x, y;
  1551. X    unsigned int nx, ny, bw, d;
  1552. X
  1553. X    get_something (daform_w, XmNuserData, (caddr_t)&di);
  1554. X    di->grid = t->set;
  1555. X
  1556. X    XGetGeometry(dsp, win, &root, &x, &y, &nx, &ny, &bw, &d);
  1557. X
  1558. X    ev.type = Expose;
  1559. X    ev.send_event = 1;    /* gets set anyways */
  1560. X    ev.display = dsp;
  1561. X    ev.window = win;
  1562. X    ev.x = ev.y = 0;
  1563. X    ev.width = nx;
  1564. X    ev.height = ny;
  1565. X    ev.count = 0;
  1566. X
  1567. X    XSendEvent (dsp, win, /*propagate*/False, ExposureMask, &ev);
  1568. }
  1569. X
  1570. /* plot drawing area's expose and resize callback.
  1571. X * redraw the graph to the (new?) size.
  1572. X * get a DrawInfo from our parent's userData.
  1573. X */
  1574. static void
  1575. plt_da_exp_cb (w, client, call)
  1576. Widget w;
  1577. caddr_t client;
  1578. caddr_t call;
  1579. {
  1580. X    XmDrawingAreaCallbackStruct *c = (XmDrawingAreaCallbackStruct *)call;
  1581. X    DrawInfo *di;
  1582. X    unsigned int nx, ny;
  1583. X    Window root;
  1584. X    int x, y;
  1585. X    unsigned int bw, d;
  1586. X
  1587. X    /* fill in nx and ny with our current size */
  1588. X    switch (c->reason) {
  1589. X    case XmCR_RESIZE:
  1590. X        /* seems we can get one resize before the first expose.
  1591. X         * hence, we don't have a good window to use yet. just let it
  1592. X         * go; we'll get the expose soon.
  1593. X         */
  1594. X        if (!XtWindow(w))
  1595. X        return;
  1596. X        XGetGeometry(XtDisplay(w),XtWindow(w),&root,&x,&y, &nx,&ny, &bw,&d);
  1597. X        break;
  1598. X    case XmCR_EXPOSE: {
  1599. X        XExposeEvent *e = &c->event->xexpose;
  1600. X        /* wait for the last in the series */
  1601. X        if (e->count != 0)
  1602. X        return;
  1603. X        XGetGeometry(XtDisplay(w),XtWindow(w),&root,&x,&y, &nx,&ny, &bw,&d);
  1604. X        break;
  1605. X        }
  1606. X    default:
  1607. X        printf ("Unexpected daform_w event. type=%d\n", c->reason);
  1608. X        return;
  1609. X    }
  1610. X
  1611. X    /* by now, nx and ny are set to the correct window size. 
  1612. X     * get di from the FormDiaglog parent and plot fresh.
  1613. X     */
  1614. X
  1615. X    get_something (XtParent(w), XmNuserData, (caddr_t)&di);
  1616. X    XClearWindow (XtDisplay(w), XtWindow(w));
  1617. X    rewind (di->fp);
  1618. X    if (plot_cartesian (di->fp,w,nx,ny,di->flipx,di->flipy,di->grid) < 0) {
  1619. X        /* had trouble, so done with this FormDialog.
  1620. X         * it frees its DrawInfo and gets destroyed automatically when 
  1621. X         * unmapped.
  1622. X         */
  1623. X        XtUnmanageChild(XtParent(w));
  1624. X    }
  1625. }
  1626. SHAR_EOF
  1627. chmod 0644 plot.c ||
  1628. echo 'restore of plot.c failed'
  1629. Wc_c="`wc -c < 'plot.c'`"
  1630. test 28540 -eq "$Wc_c" ||
  1631.     echo 'plot.c: original size 28540, current size' "$Wc_c"
  1632. rm -f _shar_wnt_.tmp
  1633. fi
  1634. # ============= plot_aux.c ==============
  1635. if test -f 'plot_aux.c' -a X"$1" != X"-c"; then
  1636.     echo 'x - skipping plot_aux.c (File already exists)'
  1637.     rm -f _shar_wnt_.tmp
  1638. else
  1639. > _shar_wnt_.tmp
  1640. echo 'x - extracting plot_aux.c (Text)'
  1641. sed 's/^X//' << 'SHAR_EOF' > 'plot_aux.c' &&
  1642. /* code to manage the actual drawing of plots.
  1643. X */
  1644. X
  1645. #include <stdio.h>
  1646. #include <ctype.h>
  1647. #include <math.h>
  1648. #ifdef VMS
  1649. #include <stdlib.h>
  1650. #endif
  1651. #include <X11/Xlib.h>
  1652. #include <Xm/Xm.h>
  1653. #include <Xm/Form.h>
  1654. #include <Xm/DrawingA.h>
  1655. #include <Xm/LabelG.h>
  1656. #include <Xm/PushBG.h>
  1657. #include <Xm/ToggleBG.h>
  1658. #include <Xm/Text.h>
  1659. X
  1660. /* maximum number of unique functions (ie tags) in the plot file.
  1661. X * to be fair, it should be at least as large as the value in plot.
  1662. X */
  1663. #define    MAXPLTLINES    10
  1664. X
  1665. static GC plt_gc, plt_gcc[MAXPLTLINES];    /* annotation and plot gcs */
  1666. static XFontStruct *plt_fs;
  1667. SHAR_EOF
  1668. true || echo 'restore of plot_aux.c failed'
  1669. fi
  1670. echo 'End of  part 7'
  1671. echo 'File plot_aux.c is continued in part 8'
  1672. echo 8 > _shar_seq_.tmp
  1673. exit 0
  1674. -- 
  1675. --
  1676. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1677. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1678. Sunnyvale, California 94086            at&t: 408/522-9236
  1679.