home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / xephem / part08 < prev    next >
Encoding:
Text File  |  1992-03-05  |  50.2 KB  |  1,532 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: v16i119: xephem - astronomical ephemeris program., Part08/24
  5. Message-ID: <1992Mar6.135351.2289@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:51 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 119
  15. Archive-name: xephem/part08
  16.  
  17. # this is part.08 (part 8 of a multipart archive)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file plot_aux.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" != 8; 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 plot_aux.c'
  35. else
  36. echo 'x - continuing file plot_aux.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'plot_aux.c' &&
  38. X
  39. /* plot the given file in the drawing area in cartesian coords.
  40. X * drawing space is from 0..(nx-1) and 0..(ny-1).
  41. X * TODO: add z tags somehow
  42. X * return 0 if ok, else give a message about trouble and return -1.
  43. X */
  44. plot_cartesian (pfp, widget, nx, ny, flipx, flipy, grid)
  45. FILE *pfp;
  46. Widget widget;
  47. unsigned int nx, ny;
  48. int flipx, flipy;    /* respectively true to flip their axis */
  49. int grid;        /* whether to include a grid with the tick marks */
  50. {
  51. #define    TL    5    /* tick mark length, in pixels */
  52. #define    NT    10    /* rought number of tick marks on each axis */
  53. X    Display *dsp = XtDisplay(widget);
  54. X    Window win = XtWindow(widget);
  55. X    double ticks[NT+2];
  56. X    int nt;
  57. X    static char fmt[] = "%c,%lf,%lf";
  58. X    double x, y;    /* N.B. be sure these match what scanf's %lf wants*/
  59. X    double minx, maxx, miny, maxy, xscale, yscale;
  60. X    char buf[128];
  61. X    int lx[MAXPLTLINES], ly[MAXPLTLINES], one[MAXPLTLINES];
  62. X    char c, tags[MAXPLTLINES];
  63. X    XCharStruct overall;
  64. X    int sawtitle;
  65. X    int ylblw;
  66. X    int nlines;
  67. X    int ix, iy;    /* misc X drawing coords */
  68. X    int x0;        /* X x coord of lower left of plotting box, in pixels */
  69. X    int y0;        /* X y coord of lower left of plotting box, in pixels */
  70. X    int h, w;    /* width of height of plotting box, in pixels */
  71. X    int asc, desc;    /* font ascent and descent, in pixels */
  72. X    int maxlblw;    /* width of longest y axis label, in pixels */
  73. X    int i;
  74. #define    XCORD(x)    (x0 + (int)((flipx?maxx-(x):(x)-minx)*xscale + 0.5))
  75. #define    YCORD(y)    (y0 - (int)((flipy?maxy-(y):(y)-miny)*yscale + 0.5))
  76. X
  77. X    /* find ranges and number of and tags for each unique line */
  78. X    nlines = 0;
  79. X    while (fgets (buf, sizeof(buf), pfp)) {
  80. X        if (sscanf (buf, fmt, &c, &x, &y) != 3)
  81. X        continue;
  82. X        if (nlines == 0) {
  83. X        maxx = minx = x;
  84. X        maxy = miny = y;
  85. X        }
  86. X        for (i = 0; i < nlines; i++)
  87. X        if (c == tags[i])
  88. X            break;
  89. X        if (i == nlines) {
  90. X        if (nlines == MAXPLTLINES) {
  91. X           (void) sprintf (buf,
  92. X             "Plot file contains more than %d functions.", MAXPLTLINES);
  93. X           f_msg (buf, 0);
  94. X           return(-1);
  95. X        }
  96. X        tags[nlines++] = c;
  97. X        }
  98. X        if (x > maxx) maxx = x;
  99. X        else if (x < minx) minx = x;
  100. X        if (y > maxy) maxy = y;
  101. X        else if (y < miny) miny = y;
  102. X    }
  103. X
  104. X    if (nlines == 0) {
  105. X        f_msg ("Plot file appears to be empty.", 0);
  106. X        return(-1);
  107. X    }
  108. #define    SMALL    (1e-6)
  109. X    if (fabs(minx-maxx) < SMALL || fabs(miny-maxy) < SMALL) {
  110. X        f_msg ("Plot file values contain insufficient spread.", 0);
  111. X        return(-1);
  112. X    }
  113. X
  114. X    if (!plt_gc) {
  115. X        unsigned long da_p;    /* the foreground color of the drawing area */
  116. X        XGCValues gcv;
  117. X        unsigned gcm = GCForeground;
  118. X        Colormap def_cm = DefaultColormap(dsp, 0);
  119. X        XColor defxc, dbxc;
  120. X
  121. X        /* create the annotation and default plot color gc,
  122. X         * using the foreground color of the PlotDA.
  123. X         */
  124. X        get_something (widget, XmNforeground, &da_p);
  125. X        gcv.foreground = da_p;
  126. X        plt_gc = XCreateGC (dsp, win, gcm, &gcv);
  127. X        plt_fs = XQueryFont (dsp, XGContextFromGC (plt_gc));
  128. X
  129. X        /* fill in plt_gcc array with gc's to use for function plotting.
  130. X         * Use colors defined in the plotColor[0-9] resources, else
  131. X         * reuse plt_gc.
  132. X         */
  133. X        for (i = 0; i < MAXPLTLINES; i++) {
  134. X        char cnum[100], *cname;
  135. X        sprintf (cnum, "plotColor%d", i);
  136. X        cname = XGetDefault (dsp, "XEphem", cnum);
  137. X        if (!cname ||
  138. X            !XAllocNamedColor (dsp,def_cm,cname,&defxc,&dbxc)) {
  139. X            if (!cname)
  140. X            printf ("can't find resource \"%s\"", cnum);
  141. X            else
  142. X            printf ("can't Alloc color \"%s\"", cname);
  143. X            printf ("... using PlotDA's foreground color.\n");
  144. X            plt_gcc[i] = plt_gc;
  145. X        } else {
  146. X            gcv.foreground = defxc.pixel;
  147. X            plt_gcc[i] = XCreateGC (dsp, win, gcm, &gcv);
  148. X        }
  149. X        }
  150. X    }
  151. X
  152. X    /* add y-axis tick marks.
  153. X     * first compute length of longest y-axis label and other char stuff.
  154. X     */
  155. X    nt = tickmarks (miny, maxy, NT, ticks);
  156. X    maxlblw = 0;
  157. X    for (i = 0; i < nt; i++) {
  158. X        int dir;
  159. X        int l;
  160. X        if (ticks[i] < miny || ticks[i] > maxy)
  161. X        continue;
  162. X        (void) sprintf (buf, "%g", ticks[i]);
  163. X        l = strlen(buf);
  164. X        XTextExtents (plt_fs, buf, l, &dir, &asc, &desc, &overall);
  165. X        if (overall.width > maxlblw)
  166. X        maxlblw = overall.width;
  167. X    }
  168. X
  169. X    /* now we can compute border sizes and the scaling factors */
  170. X    x0 = maxlblw+TL+3;
  171. X    w = nx - x0 - 30;
  172. X    y0 = ny - (asc+desc+2+2*TL);
  173. X    h = y0 - (asc+desc+2);
  174. X    xscale = w/(maxx-minx);
  175. X    yscale = h/(maxy-miny);
  176. X
  177. X    /* now draw y axis, its labels, and optionally the horizontal grid */
  178. X    for (i = 0; i < nt; i++) {
  179. X        int l;
  180. X        if (ticks[i] < miny || ticks[i] > maxy)
  181. X        continue;
  182. X        (void) sprintf (buf, "%g", ticks[i]);
  183. X        l = strlen(buf);
  184. X        iy = YCORD(ticks[i]);
  185. X        XDrawLine (dsp, win, plt_gc, x0-TL, iy, x0, iy);
  186. X        XDrawString (dsp, win, plt_gc, 1, iy+(asc-desc)/2, buf, l);
  187. X        if (grid)
  188. X        XDrawLine (dsp, win, plt_gc, x0, iy, x0+w-1, iy);
  189. X    }
  190. X
  191. X    /* now draw x axis and label it's first and last tick mark.
  192. X     * if there's room, label the center tickmark too.
  193. X     * also grid, if requested.
  194. X     */
  195. X    nt = tickmarks (minx, maxx, NT, ticks);
  196. X    ylblw = 0;
  197. X    for (i = 0; i < nt; i++) {
  198. X        if (ticks[i] < minx || ticks[i] > maxx)
  199. X        continue;
  200. X        ix = XCORD(ticks[i]);
  201. X        XDrawLine (dsp, win, plt_gc, ix, y0+TL, ix, y0);
  202. X        if (grid)
  203. X        XDrawLine (dsp, win, plt_gc, ix, y0, ix, y0-h-1);
  204. X    }
  205. X    for (i = 0; i < nt; i++)
  206. X        if (ticks[i] >= minx) {
  207. X        int di, as, de;
  208. X        XCharStruct ovl;
  209. X        int l;
  210. X        (void) sprintf (buf, "%g", ticks[i]);
  211. X        l = strlen(buf);
  212. X        ix = XCORD(ticks[i]);
  213. X        XTextExtents (plt_fs, buf, l, &di, &as, &de, &ovl);
  214. X        ylblw += ovl.width;
  215. X        XDrawLine (dsp, win, plt_gc, ix, y0+TL, ix, y0+2*TL);
  216. X        XDrawString (dsp, win, plt_gc, ix-ovl.width/2, y0+2*TL+asc+1,
  217. X                                    buf, l);
  218. X        break;
  219. X        }
  220. X    for (i = nt; --i >= 0;)
  221. X        if (ticks[i] <= maxx) {
  222. X        int di, as, de;
  223. X        XCharStruct ovl;
  224. X        int l;
  225. X        (void) sprintf (buf, "%g", ticks[i]);
  226. X        l = strlen(buf);
  227. X        ix = XCORD(ticks[i]);
  228. X        XTextExtents (plt_fs, buf, l, &di, &as, &de, &ovl);
  229. X        ylblw += ovl.width;
  230. X        XDrawLine (dsp, win, plt_gc, ix, y0+TL, ix, y0+2*TL);
  231. X        XDrawString (dsp, win, plt_gc, ix-ovl.width/2, y0+2*TL+asc+1,
  232. X                                    buf, l);
  233. X        break;
  234. X        }
  235. X    if (ylblw < w/2) {
  236. X        /* pretty likely to be room for another label */
  237. X        int di, as, de;
  238. X        XCharStruct ovl;
  239. X        int l;
  240. X        (void) sprintf (buf, "%g", ticks[nt/2]);
  241. X        l = strlen(buf);
  242. X        ix = XCORD(ticks[nt/2]);
  243. X        XTextExtents (plt_fs, buf, l, &di, &as, &de, &ovl);
  244. X        XDrawLine (dsp, win, plt_gc, ix, y0+TL, ix, y0+2*TL);
  245. X        XDrawString (dsp, win, plt_gc, ix-ovl.width/2, y0+2*TL+asc+1,
  246. X                                    buf, l);
  247. X    }
  248. X
  249. X    /* draw border of actual plotting area */
  250. X    XDrawLine (dsp, win, plt_gc, x0, y0-h, x0, y0);
  251. X    XDrawLine (dsp, win, plt_gc, x0, y0, x0+w, y0);
  252. X    XDrawLine (dsp, win, plt_gc, x0+w, y0, x0+w, y0-h);
  253. X    XDrawLine (dsp, win, plt_gc, x0+w, y0-h, x0, y0-h);
  254. X
  255. X    /* read file again, this time plotting the data (finally!).
  256. X     * also, the first line we see that doesn't look like a point
  257. X     * is put up as a title line (minus its first two char and trailing \n).
  258. X     */
  259. X    sawtitle = 0;
  260. X    rewind (pfp);
  261. X    for (i = 0; i < nlines; i++)
  262. X        one[i] = 0;
  263. X    while (fgets (buf, sizeof(buf), pfp)) {
  264. X        if (sscanf (buf, fmt, &c, &x, &y) != 3) {
  265. X        /* a title line ? */
  266. X        int l;
  267. X        if (!sawtitle && (l = strlen(buf)) > 2) {
  268. X            int di, as, de;
  269. X            XCharStruct ovl;
  270. X            XTextExtents (plt_fs, buf+2, l-2, &di, &as, &de, &ovl);
  271. X            XDrawString (dsp, win, plt_gc, x0+(w-ovl.width)/2, asc+1,
  272. X                                buf+2, l-3);
  273. X            sawtitle = 1;
  274. X        }
  275. X        continue;
  276. X        }
  277. X        for (i = 0; i < nlines; i++)
  278. X        if (c == tags[i])
  279. X            break;
  280. X        ix = XCORD(x);
  281. X        iy = YCORD(y);
  282. X        if (one[i]++ > 0)
  283. X        XDrawLine (dsp, win, plt_gcc[i], ix, iy, lx[i], ly[i]);
  284. X        else {
  285. X        int ytop = y0 - h + asc;
  286. X        XDrawString(dsp,win,plt_gcc[i], ix, iy<ytop ? ytop : iy, &c, 1);
  287. X        }
  288. X        lx[i] = ix;
  289. X        ly[i] = iy;
  290. X    }
  291. X    return (0);
  292. }
  293. X
  294. X
  295. /* given min and max and an approximate number of divisions desired,
  296. X * fill in ticks[] with nicely spaced values and return how many.
  297. X * N.B. return value, and hence number of entries to ticks[], might be as
  298. X *   much as 2 more than numdiv.
  299. X */
  300. static int
  301. tickmarks (min, max, numdiv, ticks)
  302. double min, max;
  303. int numdiv;
  304. double ticks[];
  305. {
  306. X        static int factor[] = { 1, 2, 5 };
  307. X        double minscale;
  308. X        double delta;
  309. X    double lo;
  310. X        double v;
  311. X        int n;
  312. X
  313. X        minscale = fabs(max - min);
  314. X        delta = minscale/numdiv;
  315. X        for (n=0; n < sizeof(factor)/sizeof(factor[0]); n++) {
  316. X        double scale;
  317. X        double x = delta/factor[n];
  318. X            if ((scale = (pow(10.0, ceil(log10(x)))*factor[n])) < minscale)
  319. X        minscale = scale;
  320. X    }
  321. X        delta = minscale;
  322. X
  323. X        lo = floor(min/delta);
  324. X        for (n = 0; (v = delta*(lo+n)) < max+delta; )
  325. X        ticks[n++] = v;
  326. X
  327. X    return (n);
  328. }
  329. SHAR_EOF
  330. echo 'File plot_aux.c is complete' &&
  331. chmod 0644 plot_aux.c ||
  332. echo 'restore of plot_aux.c failed'
  333. Wc_c="`wc -c < 'plot_aux.c'`"
  334. test 9197 -eq "$Wc_c" ||
  335.     echo 'plot_aux.c: original size 9197, current size' "$Wc_c"
  336. rm -f _shar_wnt_.tmp
  337. fi
  338. # ============= precess.c ==============
  339. if test -f 'precess.c' -a X"$1" != X"-c"; then
  340.     echo 'x - skipping precess.c (File already exists)'
  341.     rm -f _shar_wnt_.tmp
  342. else
  343. > _shar_wnt_.tmp
  344. echo 'x - extracting precess.c (Text)'
  345. sed 's/^X//' << 'SHAR_EOF' > 'precess.c' &&
  346. #include <stdio.h>
  347. #include <math.h>
  348. #include "astro.h"
  349. X
  350. #define    DCOS(x)        cos(degrad(x))
  351. #define    DSIN(x)        sin(degrad(x))
  352. #define    DASIN(x)    raddeg(asin(x))
  353. #define    DATAN2(y,x)    raddeg(atan2((y),(x)))
  354. X
  355. /* corrects ra and dec, both in radians, for precession from epoch 1 to epoch 2.
  356. X * the epochs are given by their modified JDs, mjd1 and mjd2, respectively.
  357. X * N.B. ra and dec are modifed IN PLACE.
  358. X */
  359. X
  360. /*
  361. X * Copyright (c) 1990 by Craig Counterman. All rights reserved.
  362. X *
  363. X * This software may be redistributed freely, not sold.
  364. X * This copyright notice and disclaimer of warranty must remain
  365. X *    unchanged. 
  366. X *
  367. X * No representation is made about the suitability of this
  368. X * software for any purpose.  It is provided "as is" without express or
  369. X * implied warranty, to the extent permitted by applicable law.
  370. X *
  371. X * Rigorous precession. From Astronomical Ephemeris 1989, p. B18
  372. X */
  373. X
  374. precess (mjd1, mjd2, ra, dec)
  375. double mjd1, mjd2;    /* initial and final epoch modified JDs */
  376. double *ra, *dec;    /* ra/dec for mjd1 in, for mjd2 out */
  377. {
  378. X    double zeta_A, z_A, theta_A;
  379. X    double T;
  380. X    double A, B, C;
  381. X    double alpha, delta;
  382. X    double alpha_in, delta_in;
  383. X    double from_equinox, to_equinox;
  384. X    double alpha2000, delta2000;
  385. X
  386. X    mjd_year (mjd1, &from_equinox);
  387. X    mjd_year (mjd2, &to_equinox);
  388. X    alpha_in = raddeg(*ra);
  389. X    delta_in = raddeg(*dec);
  390. X
  391. X    /* From from_equinox to 2000.0 */
  392. X    if (from_equinox != 2000.0) {
  393. X        T = (from_equinox - 2000.0)/100.0;
  394. X        zeta_A  = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
  395. X        z_A     = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
  396. X        theta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T;
  397. X
  398. X        A = DSIN(alpha_in - z_A) * DCOS(delta_in);
  399. X        B = DCOS(alpha_in - z_A) * DCOS(theta_A) * DCOS(delta_in)
  400. X          + DSIN(theta_A) * DSIN(delta_in);
  401. X        C = -DCOS(alpha_in - z_A) * DSIN(theta_A) * DCOS(delta_in)
  402. X          + DCOS(theta_A) * DSIN(delta_in);
  403. X
  404. X        alpha2000 = DATAN2(A,B) - zeta_A;
  405. X        range (&alpha2000, 360.0);
  406. X        delta2000 = DASIN(C);
  407. X    } else {
  408. X        /* should get the same answer, but this could improve accruacy */
  409. X        alpha2000 = alpha_in;
  410. X        delta2000 = delta_in;
  411. X    };
  412. X
  413. X
  414. X    /* From 2000.0 to to_equinox */
  415. X    if (to_equinox != 2000.0) {
  416. X        T = (to_equinox - 2000.0)/100.0;
  417. X        zeta_A  = 0.6406161* T + 0.0000839* T*T + 0.0000050* T*T*T;
  418. X        z_A     = 0.6406161* T + 0.0003041* T*T + 0.0000051* T*T*T;
  419. X        theta_A = 0.5567530* T - 0.0001185* T*T + 0.0000116* T*T*T;
  420. X
  421. X        A = DSIN(alpha2000 + zeta_A) * DCOS(delta2000);
  422. X        B = DCOS(alpha2000 + zeta_A) * DCOS(theta_A) * DCOS(delta2000)
  423. X          - DSIN(theta_A) * DSIN(delta2000);
  424. X        C = DCOS(alpha2000 + zeta_A) * DSIN(theta_A) * DCOS(delta2000)
  425. X          + DCOS(theta_A) * DSIN(delta2000);
  426. X
  427. X        alpha = DATAN2(A,B) + z_A;
  428. X        range(&alpha, 360.0);
  429. X        delta = DASIN(C);
  430. X    } else {
  431. X        /* should get the same answer, but this could improve accruacy */
  432. X        alpha = alpha2000;
  433. X        delta = delta2000;
  434. X    };
  435. X
  436. X    *ra = degrad(alpha);
  437. X    *dec = degrad(delta);
  438. }
  439. SHAR_EOF
  440. chmod 0644 precess.c ||
  441. echo 'restore of precess.c failed'
  442. Wc_c="`wc -c < 'precess.c'`"
  443. test 2952 -eq "$Wc_c" ||
  444.     echo 'precess.c: original size 2952, current size' "$Wc_c"
  445. rm -f _shar_wnt_.tmp
  446. fi
  447. # ============= query.c ==============
  448. if test -f 'query.c' -a X"$1" != X"-c"; then
  449.     echo 'x - skipping query.c (File already exists)'
  450.     rm -f _shar_wnt_.tmp
  451. else
  452. > _shar_wnt_.tmp
  453. echo 'x - extracting query.c (Text)'
  454. sed 's/^X//' << 'SHAR_EOF' > 'query.c' &&
  455. /* general purpose way to ask a question, in X.
  456. X */
  457. X
  458. #include <stdio.h>
  459. #include <X11/Xlib.h>
  460. #include <Xm/Xm.h>
  461. #include <Xm/MessageB.h>
  462. X
  463. /* put up a query message with up to three buttons.
  464. X * all args can safely be NULL; buttons without labels will be turned off.
  465. X */
  466. query (tw, msg, label1, label2, label3, func1, func2, func3)
  467. Widget tw;        /* toplevel widget */
  468. char *msg;        /* query message */
  469. char *label1;        /* label for button 1 */
  470. char *label2;        /* label for button 2 */
  471. char *label3;        /* label for button 3 */
  472. void (*func1)();    /* func to call if button 1 is pushed */
  473. void (*func2)();    /* func to call if button 2 is pushed */
  474. void (*func3)();    /* func to call if button 3 is pushed */
  475. {
  476. X    void query_cb();
  477. X    Widget qw;
  478. X    XmString strm, str1, str2, str3;
  479. X    Arg args[20];
  480. X    int n;
  481. X
  482. X    n = 0;
  483. X    if (label1) {
  484. X        str1 = XmStringCreate (label1, XmSTRING_DEFAULT_CHARSET);
  485. X        XtSetArg(args[n], XmNokLabelString, str1);  n++;
  486. X    }
  487. X    if (label2) {
  488. X        str2 = XmStringCreate (label2, XmSTRING_DEFAULT_CHARSET);
  489. X        XtSetArg(args[n], XmNcancelLabelString, str2);  n++;
  490. X    }
  491. X    if (label3) {
  492. X        str3 = XmStringCreate (label3, XmSTRING_DEFAULT_CHARSET);
  493. X        XtSetArg(args[n], XmNhelpLabelString, str3);  n++;
  494. X    }
  495. X    if (msg) {
  496. X        strm = XmStringCreate (msg, XmSTRING_DEFAULT_CHARSET);
  497. X        XtSetArg(args[n], XmNmessageString, strm);  n++;
  498. X    }
  499. X
  500. X    XtSetArg(args[n], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL);  n++;
  501. X    qw = XmCreateQuestionDialog(tw, "Query", args, n);
  502. X    XtAddCallback (qw, XmNokCallback, query_cb, func1);
  503. X    XtAddCallback (qw, XmNcancelCallback, query_cb, func2);
  504. X    XtAddCallback (qw, XmNhelpCallback, query_cb, func3);
  505. X    XtManageChild (qw);
  506. X
  507. X    if (label1)
  508. X        XmStringFree (str1);
  509. X    else
  510. X        XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_OK_BUTTON));
  511. X    if (label2)
  512. X        XmStringFree (str2);
  513. X    else
  514. X        XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_CANCEL_BUTTON));
  515. X    if (label3)
  516. X        XmStringFree (str3);
  517. X    else
  518. X        XtUnmanageChild (XmMessageBoxGetChild (qw, XmDIALOG_HELP_BUTTON));
  519. X    if (msg)
  520. X        XmStringFree (strm);
  521. }
  522. X
  523. static void
  524. query_cb (w, client, call)
  525. Widget w;
  526. caddr_t client;
  527. caddr_t call;
  528. {
  529. X    void (*f)() = (void (*)()) client;
  530. X    if (f)
  531. X        (*f)();
  532. X    XtDestroyWidget(w);
  533. X
  534. }
  535. SHAR_EOF
  536. chmod 0644 query.c ||
  537. echo 'restore of query.c failed'
  538. Wc_c="`wc -c < 'query.c'`"
  539. test 2191 -eq "$Wc_c" ||
  540.     echo 'query.c: original size 2191, current size' "$Wc_c"
  541. rm -f _shar_wnt_.tmp
  542. fi
  543. # ============= reduce.c ==============
  544. if test -f 'reduce.c' -a X"$1" != X"-c"; then
  545.     echo 'x - skipping reduce.c (File already exists)'
  546.     rm -f _shar_wnt_.tmp
  547. else
  548. > _shar_wnt_.tmp
  549. echo 'x - extracting reduce.c (Text)'
  550. sed 's/^X//' << 'SHAR_EOF' > 'reduce.c' &&
  551. #include <math.h>
  552. #include "astro.h"
  553. X
  554. /* convert those orbital elements that change from epoch mjd0 to epoch mjd.
  555. X */
  556. reduce_elements (mjd0, mjd, inc0, ap0, om0, inc, ap, om)
  557. double mjd0;    /* initial epoch */
  558. double mjd;    /* desired epoch */
  559. double inc0;    /* initial inclination, rads */
  560. double ap0;    /* initial argument of perihelion, as an mjd */
  561. double om0;    /* initial long of ascending node, rads */
  562. double *inc;    /* desired inclination, rads */
  563. double *ap;    /* desired epoch of perihelion, as an mjd */
  564. double *om;    /* desired long of ascending node, rads */
  565. {
  566. X    double t0, t1;
  567. X    double tt, tt2, t02, tt3;
  568. X    double eta, th, th0;
  569. X    double a, b;
  570. X    double dap;
  571. X    double cinc, sinc;
  572. X    double ot, sot, cot, ot1;
  573. X    double seta, ceta;
  574. X
  575. X    t0 = mjd0/365250.0;
  576. X    t1 = mjd/365250.0;
  577. X
  578. X    tt = t1-t0;
  579. X    tt2 = tt*tt;
  580. X        t02 = t0*t0;
  581. X    tt3 = tt*tt2;
  582. X        eta = (471.07-6.75*t0+.57*t02)*tt+(.57*t0-3.37)*tt2+.05*tt3;
  583. X        th0 = 32869.0*t0+56*t02-(8694+55*t0)*tt+3*tt2;
  584. X        eta = degrad(eta/3600.0);
  585. X        th0 = degrad((th0/3600.0)+173.950833);
  586. X        th = (50256.41+222.29*t0+.26*t02)*tt+(111.15+.26*t0)*tt2+.1*tt3;
  587. X        th = th0+degrad(th/3600.0);
  588. X    cinc = cos(inc0);
  589. X        sinc = sin(inc0);
  590. X    ot = om0-th0;
  591. X    sot = sin(ot);
  592. X        cot = cos(ot);
  593. X    seta = sin(eta);
  594. X        ceta = cos(eta);
  595. X    a = sinc*sot;
  596. X        b = ceta*sinc*cot-seta*cinc;
  597. X    ot1 = atan(a/b);
  598. X        if (b<0) ot1 += PI;
  599. X        b = sinc*ceta-cinc*seta*cot;
  600. X        a = -1*seta*sot;
  601. X    dap = atan(a/b);
  602. X        if (b<0) dap += PI;
  603. X
  604. X        *ap = ap0+dap;
  605. X    range (ap, 2*PI);
  606. X        *om = ot1+th;
  607. X    range (om, 2*PI);
  608. X
  609. X        if (inc0<.175)
  610. X        *inc = asin(a/sin(dap));
  611. X    else
  612. X        *inc = 1.570796327-asin((cinc*ceta)+(sinc*seta*cot));
  613. }
  614. SHAR_EOF
  615. chmod 0644 reduce.c ||
  616. echo 'restore of reduce.c failed'
  617. Wc_c="`wc -c < 'reduce.c'`"
  618. test 1691 -eq "$Wc_c" ||
  619.     echo 'reduce.c: original size 1691, current size' "$Wc_c"
  620. rm -f _shar_wnt_.tmp
  621. fi
  622. # ============= refract.c ==============
  623. if test -f 'refract.c' -a X"$1" != X"-c"; then
  624.     echo 'x - skipping refract.c (File already exists)'
  625.     rm -f _shar_wnt_.tmp
  626. else
  627. > _shar_wnt_.tmp
  628. echo 'x - extracting refract.c (Text)'
  629. sed 's/^X//' << 'SHAR_EOF' > 'refract.c' &&
  630. #include <stdio.h>
  631. #include <math.h>
  632. #include "astro.h"
  633. X
  634. /* correct the true altitude, ta, for refraction to the apparent altitude, aa,
  635. X * each in radians, given the local atmospheric pressure, pr, in mbars, and
  636. X * the temperature, tr, in degrees C.
  637. X */
  638. refract (pr, tr, ta, aa)
  639. double pr, tr;
  640. double ta;
  641. double *aa;
  642. {
  643. X    double r;    /* refraction correction*/
  644. X
  645. X        if (ta >= degrad(15.)) {
  646. X        /* model for altitudes at least 15 degrees above horizon */
  647. X            r = 7.888888e-5*pr/((273+tr)*tan(ta));
  648. X    } else if (ta > degrad(-5.)) {
  649. X        /* hairier model for altitudes at least -5 and below 15 degrees */
  650. X        double a, b, tadeg = raddeg(ta);
  651. X        a = ((2e-5*tadeg+1.96e-2)*tadeg+1.594e-1)*pr;
  652. X        b = (273+tr)*((8.45e-2*tadeg+5.05e-1)*tadeg+1);
  653. X        r = degrad(a/b);
  654. X    } else {
  655. X        /* do nothing if more than 5 degrees below horizon.
  656. X         */
  657. X        r = 0;
  658. X    }
  659. X
  660. X    *aa  =  ta + r;
  661. }
  662. X
  663. /* correct the apparent altitude, aa, for refraction to the true altitude, ta,
  664. X * each in radians, given the local atmospheric pressure, pr, in mbars, and
  665. X * the temperature, tr, in degrees C.
  666. X */
  667. unrefract (pr, tr, aa, ta)
  668. double pr, tr;
  669. double aa;
  670. double *ta;
  671. {
  672. X    double err;
  673. X    double appar;
  674. X    double true;
  675. X
  676. X    /* iterative solution: search for the true that refracts to the
  677. X     *   given apparent.
  678. X     * since refract() is discontinuous at -5 degrees, there is a range
  679. X     *   of apparent altitudes between about -4.5 and -5 degrees that are
  680. X     *   not invertable (the graph of ap vs. true has a vertical step at
  681. X     *   true = -5). thus, the iteration just oscillates if it gets into
  682. X     *   this region. if this happens the iteration is forced to abort.
  683. X     *   of course, this makes unrefract() discontinuous too.
  684. X     */
  685. X    true = aa;
  686. X    do {
  687. X        refract (pr, tr, true, &appar);
  688. X        err = appar - aa;
  689. X        true -= err;
  690. X    } while (fabs(err) >= 1e-6 && true > degrad(-5));
  691. X
  692. X    *ta = true;
  693. }
  694. SHAR_EOF
  695. chmod 0644 refract.c ||
  696. echo 'restore of refract.c failed'
  697. Wc_c="`wc -c < 'refract.c'`"
  698. test 1857 -eq "$Wc_c" ||
  699.     echo 'refract.c: original size 1857, current size' "$Wc_c"
  700. rm -f _shar_wnt_.tmp
  701. fi
  702. # ============= riset.c ==============
  703. if test -f 'riset.c' -a X"$1" != X"-c"; then
  704.     echo 'x - skipping riset.c (File already exists)'
  705.     rm -f _shar_wnt_.tmp
  706. else
  707. > _shar_wnt_.tmp
  708. echo 'x - extracting riset.c (Text)'
  709. sed 's/^X//' << 'SHAR_EOF' > 'riset.c' &&
  710. #include <stdio.h>
  711. #include <math.h>
  712. #include "astro.h"
  713. X
  714. /* given the true geocentric ra and dec of an object, the observer's latitude,
  715. X *   lat, and a horizon displacement correction, dis, all in radians, find the
  716. X *   local sidereal times and azimuths of rising and setting, lstr/s
  717. X *   and azr/s, also all in radians, respectively.
  718. X * dis is the vertical displacement from the true position of the horizon. it
  719. X *   is positive if the apparent position is higher than the true position.
  720. X *   said another way, it is positive if the shift causes the object to spend
  721. X *   longer above the horizon. for example, atmospheric refraction is typically
  722. X *   assumed to produce a vertical shift of 34 arc minutes at the horizon; dis
  723. X *   would then take on the value +9.89e-3 (radians). On the other hand, if
  724. X *   your horizon has hills such that your apparent horizon is, say, 1 degree
  725. X *   above sea level, you would allow for this by setting dis to -1.75e-2
  726. X *   (radians).
  727. X *
  728. X * algorithm:
  729. X *   the situation is described by two spherical triangles with two equal angles
  730. X *    (the right horizon intercepts, and the common horizon transverse):
  731. X *   given lat, d(=d1+d2), and dis find z(=z1+z2) and rho, where      /| eq pole
  732. X *     lat = latitude,                                              /  |
  733. X *     dis = horizon displacement (>0 is below ideal)             / rho|
  734. X *     d = angle from pole = PI/2 - declination                /       |
  735. X *     z = azimuth east of north                            /          |
  736. X *     rho = polar rotation from down = PI - hour angle    /           | 
  737. X *   solve simultaneous equations for d1 and d2:         /             |
  738. X *     1) cos(d) = cos(d1+d2)                           / d2           | lat
  739. X *            = cos(d1)cos(d2) - sin(d1)sin(d2)        /               |
  740. X *     2) sin(d2) = sin(lat)sin(d1)/sin(dis)          /                |
  741. X *   then can solve for z1, z2 and rho, taking       /                 |
  742. X *     care to preserve quadrant information.       /                 -|
  743. X *                                              z1 /        z2       | |
  744. X *                      ideal horizon ------------/--------------------| 
  745. X *                                         | |   /                     N
  746. X *                                          -|  / d1
  747. X *                                       dis | /
  748. X *                                           |/
  749. X *                  apparent horizon  ---------------------------------
  750. X *
  751. X * note that when lat=0 this all breaks down (because d2 and z2 degenerate to 0)
  752. X *   but fortunately then we can solve for z and rho directly.
  753. X *
  754. X * status: 0: normal; 1: never rises; -1: circumpolar; 2: trouble.
  755. X */
  756. riset (ra, dec, lat, dis, lstr, lsts, azr, azs, status)
  757. double ra, dec;
  758. double lat, dis;
  759. double *lstr, *lsts;
  760. double *azr, *azs;
  761. int *status;
  762. {
  763. #define    EPS    (1e-6)    /* math rounding fudge - always the way, eh? */
  764. X    double d;    /* angle from pole */
  765. X    double h;    /* hour angle */
  766. X    double crho;    /* cos hour-angle complement */
  767. X    int shemi;    /* flag for southern hemisphere reflection */
  768. X
  769. X    d = PI/2 - dec;
  770. X
  771. X    /* reflect if in southern hemisphere.
  772. X     * (then reflect azimuth back after computation.)
  773. X     */
  774. X    if (shemi = lat < 0) {
  775. X        lat = -lat;
  776. X        d = PI - d;
  777. X    }
  778. X
  779. X    /* do the easy ones (and avoid violated assumptions) if d arc never
  780. X     * meets horizon. 
  781. X     */
  782. X    if (d <= lat + dis + EPS) {
  783. X        *status = -1; /* never sets */
  784. X        return;
  785. X    }
  786. X    if (d >= PI - lat + dis - EPS) {
  787. X        *status = 1; /* never rises */
  788. X        return;
  789. X    }
  790. X
  791. X    /* find rising azimuth and cosine of hour-angle complement */
  792. X    if (lat > EPS) {
  793. X        double d2, d1; /* polr arc to ideal hzn, and corrctn for apparent */
  794. X        double z2, z1; /* azimuth to ideal horizon, and " */
  795. X        double a;       /* intermediate temp */
  796. X        double sdis, slat, clat, cz2, cd2;    /* trig temps */
  797. X        sdis = sin(dis);
  798. X        slat = sin(lat);
  799. X        a = sdis*sdis + slat*slat + 2*cos(d)*sdis*slat;
  800. X        if (a <= 0) {
  801. X        *status = 2; /* can't happen - hah! */
  802. X        return;
  803. X        }
  804. X        d1 = asin (sin(d) * sdis / sqrt(a));
  805. X        d2 = d - d1;
  806. X        cd2 = cos(d2);
  807. X        clat = cos(lat);
  808. X        cz2 = cd2/clat;
  809. X        z2 = acos (cz2);
  810. X        z1 = acos (cos(d1)/cos(dis));
  811. X        if (dis < 0)
  812. X        z1 = -z1;
  813. X        *azr = z1 + z2;
  814. X        range (azr, PI);
  815. X        crho = (cz2 - cd2*clat)/(sin(d2)*slat);
  816. X    } else {
  817. X        *azr = acos (cos(d)/cos(dis));
  818. X        crho = sin(dis)/sin(d);
  819. X    }
  820. X
  821. X    if (shemi)
  822. X        *azr = PI - *azr;
  823. X        *azs = 2*PI - *azr;
  824. X    
  825. X    /* find hour angle */
  826. X    h = PI - acos (crho);
  827. X        *lstr = radhr(ra-h);
  828. X    *lsts = radhr(ra+h);
  829. X    range (lstr, 24.0);
  830. X    range (lsts, 24.0);
  831. X
  832. X    *status = 0;
  833. }
  834. SHAR_EOF
  835. chmod 0644 riset.c ||
  836. echo 'restore of riset.c failed'
  837. Wc_c="`wc -c < 'riset.c'`"
  838. test 4591 -eq "$Wc_c" ||
  839.     echo 'riset.c: original size 4591, current size' "$Wc_c"
  840. rm -f _shar_wnt_.tmp
  841. fi
  842. # ============= riset_c.c ==============
  843. if test -f 'riset_c.c' -a X"$1" != X"-c"; then
  844.     echo 'x - skipping riset_c.c (File already exists)'
  845.     rm -f _shar_wnt_.tmp
  846. else
  847. > _shar_wnt_.tmp
  848. echo 'x - extracting riset_c.c (Text)'
  849. sed 's/^X//' << 'SHAR_EOF' > 'riset_c.c' &&
  850. /* find rise and set circumstances, ie, riset_cir() and related functions. */
  851. X
  852. #include <stdio.h>
  853. #include <math.h>
  854. #include "astro.h"
  855. #include "circum.h"
  856. #include "moreobjs.h"
  857. X
  858. #define    TRACE(x)    {FILE *fp = fopen("trace","a"); fprintf x; fclose(fp);}
  859. X
  860. #define    STDREF    degrad(34./60.)    /* nominal horizon refraction amount */
  861. #define    TWIREF    degrad(18.)    /* twilight horizon displacement */
  862. #define    TMACC    (15./3600.)    /* convergence accuracy, hours */
  863. X
  864. /* find where and when a body, p, will rise and set and
  865. X *   it's transit circumstances. all times are local, angles rads e of n.
  866. X * return 0 if just returned same stuff as previous call, else 1 if new.
  867. X * status is set from the RS_* #defines in circum.h.
  868. X * also used to find astro twilight by calling with hzn TWILIGHT.
  869. X */
  870. riset_cir (p, np, force, hzn, ltr, lts, ltt, azr, azs, altt, status)
  871. int p;        /* one of the body defines in astro.h or moreobjs.h */
  872. Now *np;
  873. int force;    /* set !=0 to force computations */
  874. int hzn;    /* STDHZN or ADPHZN or TWILIGHT */
  875. double *ltr, *lts; /* local rise and set times */
  876. double *ltt;    /* local transit time */
  877. double *azr, *azs; /* local rise and set azimuths, rads e of n */
  878. double *altt;    /* local altitude at transit */
  879. int *status;    /* one or more of the RS_* defines */
  880. {
  881. X    typedef struct {
  882. X        Now l_now;
  883. X        double l_ltr, l_lts, l_ltt, l_azr, l_azs, l_altt;
  884. X        int l_hzn;
  885. X        int l_status;
  886. X    } Last;
  887. X    /* must be in same order as the astro.h/moreobjs.h #define's */
  888. X    static Last last[NOBJ] = {
  889. X        {NOMJD}, {NOMJD}, {NOMJD}, {NOMJD}, {NOMJD}, {NOMJD},
  890. X        {NOMJD}, {NOMJD}, {NOMJD}, {NOMJD}, {NOMJD}, {NOMJD}
  891. X    };
  892. X    Last *lp;
  893. X    int new;
  894. X
  895. X    lp = last + p;
  896. X    if (!force && same_cir (np, &lp->l_now) && same_lday (np, &lp->l_now)
  897. X                        && lp->l_hzn == hzn) {
  898. X        *ltr = lp->l_ltr;
  899. X        *lts = lp->l_lts;
  900. X        *ltt = lp->l_ltt;
  901. X        *azr = lp->l_azr;
  902. X        *azs = lp->l_azs;
  903. X        *altt = lp->l_altt;
  904. X        *status = lp->l_status;
  905. X        new = 0;
  906. X    } else {
  907. X        *status = 0;
  908. X        iterative_riset (p, np, hzn, ltr, lts, ltt, azr, azs, altt, status);
  909. X        lp->l_ltr = *ltr;
  910. X        lp->l_lts = *lts;
  911. X        lp->l_ltt = *ltt;
  912. X        lp->l_azr = *azr;
  913. X        lp->l_azs = *azs;
  914. X        lp->l_altt = *altt;
  915. X        lp->l_status = *status;
  916. X        lp->l_hzn = hzn;
  917. X        lp->l_now = *np;
  918. X        new = 1;
  919. X    }
  920. X    return (new);
  921. }
  922. X
  923. static
  924. iterative_riset (p, np, hzn, ltr, lts, ltt, azr, azs, altt, status)
  925. int p;
  926. Now *np;
  927. int hzn;
  928. double *ltr, *lts, *ltt;    /* local times of rise, set and transit */
  929. double *azr, *azs, *altt;/* local azimuths of rise, set and transit altitude */
  930. int *status;
  931. {
  932. #define    MAXPASSES    6
  933. X    double lstr, lsts, lstt; /* local sidereal times of rising/setting */
  934. X    double mjd0;        /* mjd estimates of rise/set event */
  935. X    double lnoon;        /* mjd of local noon */
  936. X    double x;        /* discarded tmp value */
  937. X    Now n;            /* just used to call now_lst() */
  938. X    double lst;        /* lst at local noon */
  939. X    double diff, lastdiff;    /* iterative improvement to mjd0 */
  940. X    int pass;
  941. X    int rss;
  942. X
  943. X    /* first approximation is to find rise/set times of a fixed object
  944. X     * in its position at local noon.
  945. X     */
  946. X    lnoon = mjd_day(mjd - tz/24.0) + (12.0 + tz)/24.0; /*mjd of local noon*/
  947. X    n.n_mjd = lnoon;
  948. X    n.n_lng = lng;
  949. X    now_lst (&n, &lst);    /* lst at local noon */
  950. X    mjd0 = lnoon;
  951. X    stationary_riset (p,mjd0,np,hzn,&lstr,&lsts,&lstt,&x,&x,&x,&rss);
  952. X    chkrss:
  953. X    switch (rss) {
  954. X    case  0:  break;
  955. X    case  1: *status = RS_NEVERUP; return;
  956. X    case -1: *status = RS_CIRCUMPOLAR; goto transit;
  957. X    default: *status = RS_ERROR; return;
  958. X    }
  959. X
  960. X    /* find a better approximation to the rising circumstances based on
  961. X     * more passes, each using a "fixed" object at the location at
  962. X     * previous approximation of the rise time.
  963. X     */
  964. X    lastdiff = 1000.0;
  965. X    for (pass = 1; pass < MAXPASSES; pass++) {
  966. X        diff = (lstr - lst)*SIDRATE; /* next guess at rise time wrt noon */
  967. X        if (diff > 12.0)
  968. X        diff -= 24.0*SIDRATE;    /* not tomorrow, today */
  969. X        else if (diff < -12.0)
  970. X        diff += 24.0*SIDRATE;    /* not yesterday, today */
  971. X        mjd0 = lnoon + diff/24.0;    /* next guess at mjd of rise */
  972. X        stationary_riset (p,mjd0,np,hzn,&lstr,&x,&x,azr,&x,&x,&rss);
  973. X        if (rss != 0) goto chkrss;
  974. X        if (fabs (diff - lastdiff) < TMACC)
  975. X        break;
  976. X        lastdiff = diff;
  977. X    }
  978. X    if (pass == MAXPASSES)
  979. X        *status |= RS_NORISE;    /* didn't converge - no rise today */
  980. X    else {
  981. X        *ltr = 12.0 + diff;
  982. X        if (p != MOON &&
  983. X            (*ltr <= 24.0*(1.0-SIDRATE) || *ltr >= 24.0*SIDRATE))
  984. X        *status |= RS_2RISES;
  985. X    }
  986. X
  987. X    /* find a better approximation to the setting circumstances based on
  988. X     * more passes, each using a "fixed" object at the location at
  989. X     * previous approximation of the set time.
  990. X     */
  991. X    lastdiff = 1000.0;
  992. X    for (pass = 1; pass < MAXPASSES; pass++) {
  993. X        diff = (lsts - lst)*SIDRATE; /* next guess at set time wrt noon */
  994. X        if (diff > 12.0)
  995. X        diff -= 24.0*SIDRATE;    /* not tomorrow, today */
  996. X        else if (diff < -12.0)
  997. X        diff += 24.0*SIDRATE;    /* not yesterday, today */
  998. X        mjd0 = lnoon + diff/24.0;    /* next guess at mjd of set */
  999. X        stationary_riset (p,mjd0,np,hzn,&x,&lsts,&x,&x,azs,&x,&rss);
  1000. X        if (rss != 0) goto chkrss;
  1001. X        if (fabs (diff - lastdiff) < TMACC)
  1002. X        break;
  1003. X        lastdiff = diff;
  1004. X    }
  1005. X    if (pass == MAXPASSES)
  1006. X        *status |= RS_NOSET;    /* didn't converge - no set today */
  1007. X    else {
  1008. X        *lts = 12.0 + diff;
  1009. X        if (p != MOON &&
  1010. X            (*lts <= 24.0*(1.0-SIDRATE) || *lts >= 24.0*SIDRATE))
  1011. X        *status |= RS_2SETS;
  1012. X    }
  1013. X
  1014. X    transit:
  1015. X    /* find a better approximation to the transit circumstances based on
  1016. X     * more passes, each using a "fixed" object at the location at
  1017. X     * previous approximation of the transit time.
  1018. X     */
  1019. X    lastdiff = 1000.0;
  1020. X    for (pass = 1; pass < MAXPASSES; pass++) {
  1021. X        diff = (lstt - lst)*SIDRATE; /*next guess at transit time wrt noon*/
  1022. X        if (diff > 12.0)
  1023. X        diff -= 24.0*SIDRATE;    /* not tomorrow, today */
  1024. X        else if (diff < -12.0)
  1025. X        diff += 24.0*SIDRATE;    /* not yesterday, today */
  1026. X        mjd0 = lnoon + diff/24.0;    /* next guess at mjd of transit */
  1027. X        stationary_riset (p,mjd0,np,hzn,&x,&x,&lstt,&x,&x,altt,&rss);
  1028. X        if (fabs (diff - lastdiff) < TMACC)
  1029. X        break;
  1030. X        lastdiff = diff;
  1031. X    }
  1032. X    if (pass == MAXPASSES)
  1033. X        *status |= RS_NOTRANS;    /* didn't converge - no transit today */
  1034. X    else {
  1035. X        *ltt = 12.0 + diff;
  1036. X        if (p != MOON &&
  1037. X            (*ltt <= 24.0*(1.0-SIDRATE) || *ltt >= 24.0*SIDRATE))
  1038. X        *status |= RS_2TRANS;
  1039. X    }
  1040. }
  1041. X
  1042. static
  1043. stationary_riset (p, mjd0, np, hzn, lstr, lsts, lstt, azr, azs, altt, status)
  1044. int p;
  1045. double mjd0;
  1046. Now *np;
  1047. int hzn;
  1048. double *lstr, *lsts, *lstt;
  1049. double *azr, *azs, *altt;
  1050. int *status;
  1051. {
  1052. X    extern void bye();
  1053. X    double dis;
  1054. X    Now n;
  1055. X    Sky s;
  1056. X
  1057. X    /* find object p's topocentric ra/dec at mjd0
  1058. X     * (this must include parallax)
  1059. X     */
  1060. X    n = *np;
  1061. X    n.n_mjd = mjd0;
  1062. X    (void) body_cir (p, 0.0, &n, &s);
  1063. X    if (epoch != EOD)
  1064. X        precess (epoch, mjd0, &s.s_ra, &s.s_dec);
  1065. X    if (s.s_edist > 0) {
  1066. X        /* parallax, if we can */
  1067. X        double ehp, lst, ha;
  1068. X        if (p == MOON)
  1069. X        ehp = asin (6378.14/s.s_edist);
  1070. X        else
  1071. X        ehp = (2.*6378./146e6)/s.s_edist;
  1072. X        now_lst (&n, &lst);
  1073. X        ha = hrrad(lst) - s.s_ra;
  1074. X        ta_par (ha, s.s_dec, lat, height, ehp, &ha, &s.s_dec);
  1075. X        s.s_ra = hrrad(lst) - ha;
  1076. X        range (&s.s_ra, 2*PI);
  1077. X    }
  1078. X
  1079. X    switch (hzn) {
  1080. X    case STDHZN:
  1081. X        /* nominal atmospheric refraction.
  1082. X         * then add nominal moon or sun semi-diameter, as appropriate.
  1083. X         * other objects assumes to be negligibly small.
  1084. X         */
  1085. X        dis = STDREF;
  1086. X        if (p == MOON || p == SUN)
  1087. X        dis += degrad (32./60./2.);
  1088. X        break;
  1089. X    case TWILIGHT:
  1090. X        dis = TWIREF;
  1091. X        break;
  1092. X    case ADPHZN:
  1093. X        /* adaptive includes actual refraction conditions and also
  1094. X         * includes object's semi-diameter.
  1095. X         */
  1096. X        unrefract (pressure, temp, 0.0, &dis);
  1097. X        dis = -dis;
  1098. X        dis += degrad(s.s_size/3600./2.0);
  1099. X        break;
  1100. X    }
  1101. X
  1102. X    riset (s.s_ra, s.s_dec, lat, dis, lstr, lsts, azr, azs, status);
  1103. X    transit (s.s_ra, s.s_dec, np, lstt, altt);
  1104. }
  1105. X
  1106. X
  1107. /* find when and how hi object at (r,d) is when it transits. */
  1108. static
  1109. transit (r, d, np, lstt, altt)
  1110. double r, d;    /* ra and dec, rads */
  1111. Now *np;    /* for refraction info */
  1112. double *lstt;    /* local sidereal time of transit */
  1113. double *altt;    /* local, refracted, altitude at time of transit */
  1114. {
  1115. X    *lstt = radhr(r);
  1116. X    *altt = PI/2 - lat + d;
  1117. X    if (*altt > PI/2)
  1118. X        *altt = PI - *altt;
  1119. X    refract (pressure, temp, *altt, altt);
  1120. }
  1121. SHAR_EOF
  1122. chmod 0644 riset_c.c ||
  1123. echo 'restore of riset_c.c failed'
  1124. Wc_c="`wc -c < 'riset_c.c'`"
  1125. test 8189 -eq "$Wc_c" ||
  1126.     echo 'riset_c.c: original size 8189, current size' "$Wc_c"
  1127. rm -f _shar_wnt_.tmp
  1128. fi
  1129. # ============= risetmenu.c ==============
  1130. if test -f 'risetmenu.c' -a X"$1" != X"-c"; then
  1131.     echo 'x - skipping risetmenu.c (File already exists)'
  1132.     rm -f _shar_wnt_.tmp
  1133. else
  1134. > _shar_wnt_.tmp
  1135. echo 'x - extracting risetmenu.c (Text)'
  1136. sed 's/^X//' << 'SHAR_EOF' > 'risetmenu.c' &&
  1137. /* code to manage the stuff on the "rise / set" menu.
  1138. X */
  1139. X
  1140. #include <stdio.h>
  1141. #include <ctype.h>
  1142. #include <math.h>
  1143. #ifdef VMS
  1144. #include <stdlib.h>
  1145. #endif
  1146. #include <X11/Xlib.h>
  1147. #include <Xm/Xm.h>
  1148. #include <Xm/Form.h>
  1149. #include <Xm/LabelG.h>
  1150. #include <Xm/PushBG.h>
  1151. #include <Xm/ToggleBG.h>
  1152. #include <Xm/RowColumn.h>
  1153. #include "fieldmap.h"
  1154. #include "astro.h"
  1155. #include "circum.h"
  1156. #include "moreobjs.h"
  1157. X
  1158. extern char *strncpy();
  1159. extern char *getenv();
  1160. extern Now *mm_get_now();
  1161. extern Widget toplevel_w;
  1162. extern XmString str_width();
  1163. extern char *objname[];
  1164. #define    XtD    XtDisplay(toplevel_w)
  1165. X
  1166. /* locations of each field.
  1167. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  1168. X * historical reasons.
  1169. X */
  1170. #define    NR    14
  1171. #define    NC    80
  1172. X
  1173. #define    HZN_ROW        1
  1174. X
  1175. /* planet rows */
  1176. #define    R_PLANTAB    (1)
  1177. #define    R_SUN        (R_PLANTAB+1)
  1178. #define    R_MOON        (R_PLANTAB+2)
  1179. #define    R_MERCURY    (R_PLANTAB+3)
  1180. #define    R_VENUS        (R_PLANTAB+4)
  1181. #define    R_MARS        (R_PLANTAB+5)
  1182. #define    R_JUPITER    (R_PLANTAB+6)
  1183. #define    R_SATURN    (R_PLANTAB+7)
  1184. #define    R_URANUS    (R_PLANTAB+8)
  1185. #define    R_NEPTUNE    (R_PLANTAB+9)
  1186. #define    R_PLUTO        (R_PLANTAB+10)
  1187. #define    R_OBJX        (R_PLANTAB+11)
  1188. #define    R_OBJY        (R_PLANTAB+12)
  1189. #define    R_CONTROL    (R_PLANTAB+13)
  1190. X
  1191. #define    C_OBJ        1
  1192. X
  1193. /* menu 2 screen items */
  1194. #define    C_RISETM    7
  1195. #define    C_RISEAZ    18
  1196. #define    C_TRANSTM    29
  1197. #define    C_TRANSALT    40
  1198. #define    C_SETTM        51
  1199. #define    C_SETAZ        62
  1200. #define    C_TUP        73
  1201. X
  1202. #define    TIME_WIDTH    5
  1203. #define    AZ_WIDTH    6
  1204. #define    ALT_WIDTH    5
  1205. X
  1206. static FieldMap rm_field_map[] = {
  1207. X    {mkid(R_JUPITER,C_RISEAZ), PLT, AZ_WIDTH, 0, "Jup.RiseAz"},
  1208. X    {mkid(R_JUPITER,C_RISETM), PLT, TIME_WIDTH, 0, "Jup.RiseTm"},
  1209. X    {mkid(R_JUPITER,C_RISETM+TIME_WIDTH), 0, 1},
  1210. X    {mkid(R_JUPITER,C_SETAZ), PLT, AZ_WIDTH, 0, "Jup.SetAz"},
  1211. X    {mkid(R_JUPITER,C_SETTM), PLT, TIME_WIDTH, 0, "Jup.SetTm"},
  1212. X    {mkid(R_JUPITER,C_SETTM+TIME_WIDTH), 0, 1},
  1213. X    {mkid(R_JUPITER,C_TRANSALT), PLT, ALT_WIDTH, 0, "Jup.TransAlt"},
  1214. X    {mkid(R_JUPITER,C_TRANSTM), PLT, TIME_WIDTH, 0, "Jup.TransTm"},
  1215. X    {mkid(R_JUPITER,C_TRANSTM+TIME_WIDTH), 0, 1},
  1216. X    {mkid(R_JUPITER,C_TUP), PLT, TIME_WIDTH, 0, "Jup.TmUp"},
  1217. X    {mkid(R_JUPITER,C_TUP+TIME_WIDTH), 0, 1},
  1218. X    {mkid(R_MARS,C_RISEAZ), PLT, AZ_WIDTH, 0, "Mars.RiseAz"},
  1219. X    {mkid(R_MARS,C_RISETM), PLT, TIME_WIDTH, 0, "Mars.RiseTm"},
  1220. X    {mkid(R_MARS,C_RISETM+TIME_WIDTH), 0, 1},
  1221. X    {mkid(R_MARS,C_SETAZ), PLT, AZ_WIDTH, 0, "Mars.SetAz"},
  1222. X    {mkid(R_MARS,C_SETTM), PLT, TIME_WIDTH, 0, "Mars.SetTm"},
  1223. X    {mkid(R_MARS,C_SETTM+TIME_WIDTH), 0, 1},
  1224. X    {mkid(R_MARS,C_TRANSALT), PLT, ALT_WIDTH, 0, "Mars.TransAlt"},
  1225. X    {mkid(R_MARS,C_TRANSTM), PLT, TIME_WIDTH, 0, "Mars.TransTm"},
  1226. X    {mkid(R_MARS,C_TRANSTM+TIME_WIDTH), 0, 1},
  1227. X    {mkid(R_MARS,C_TUP), PLT, TIME_WIDTH, 0, "Mars.TmUp"},
  1228. X    {mkid(R_MARS,C_TUP+TIME_WIDTH), 0, 1},
  1229. X    {mkid(R_MERCURY,C_RISEAZ), PLT, AZ_WIDTH, 0, "Merc.RiseAz"},
  1230. X    {mkid(R_MERCURY,C_RISETM), PLT, TIME_WIDTH, 0, "Merc.RiseTm"},
  1231. X    {mkid(R_MERCURY,C_RISETM+TIME_WIDTH), 0, 1},
  1232. X    {mkid(R_MERCURY,C_SETAZ), PLT, AZ_WIDTH, 0, "Merc.SetAz"},
  1233. X    {mkid(R_MERCURY,C_SETTM), PLT, TIME_WIDTH, 0, "Merc.SetTm"},
  1234. X    {mkid(R_MERCURY,C_SETTM+TIME_WIDTH), 0, 1},
  1235. X    {mkid(R_MERCURY,C_TRANSALT), PLT, ALT_WIDTH, 0, "Merc.TransAlt"},
  1236. X    {mkid(R_MERCURY,C_TRANSTM), PLT, TIME_WIDTH, 0, "Merc.TransTm"},
  1237. X    {mkid(R_MERCURY,C_TRANSTM+TIME_WIDTH), 0, 1},
  1238. X    {mkid(R_MERCURY,C_TUP), PLT, TIME_WIDTH, 0, "Merc.TmUp"},
  1239. X    {mkid(R_MERCURY,C_TUP+TIME_WIDTH), 0, 1},
  1240. X    {mkid(R_MOON,C_RISEAZ), PLT, AZ_WIDTH, 0, "Moon.RiseAz"},
  1241. X    {mkid(R_MOON,C_RISETM), PLT, TIME_WIDTH, 0, "Moon.RiseTm"},
  1242. X    {mkid(R_MOON,C_RISETM+TIME_WIDTH), 0, 1},
  1243. X    {mkid(R_MOON,C_SETAZ), PLT, AZ_WIDTH, 0, "Moon.SetAz"},
  1244. X    {mkid(R_MOON,C_SETTM), PLT, TIME_WIDTH, 0, "Moon.SetTm"},
  1245. X    {mkid(R_MOON,C_SETTM+TIME_WIDTH), 0, 1},
  1246. X    {mkid(R_MOON,C_TRANSALT), PLT, ALT_WIDTH, 0, "Moon.TransAlt"},
  1247. X    {mkid(R_MOON,C_TRANSTM), PLT, TIME_WIDTH, 0, "Moon.TransTm"},
  1248. X    {mkid(R_MOON,C_TRANSTM+TIME_WIDTH), 0, 1},
  1249. X    {mkid(R_MOON,C_TUP), PLT, TIME_WIDTH, 0, "Moon.TmUp"},
  1250. X    {mkid(R_MOON,C_TUP+TIME_WIDTH), 0, 1},
  1251. X    {mkid(R_NEPTUNE,C_RISEAZ), PLT, AZ_WIDTH, 0, "Nep.RiseAz"},
  1252. X    {mkid(R_NEPTUNE,C_RISETM), PLT, TIME_WIDTH, 0, "Nep.RiseTm"},
  1253. X    {mkid(R_NEPTUNE,C_RISETM+TIME_WIDTH), 0, 1},
  1254. X    {mkid(R_NEPTUNE,C_SETAZ), PLT, AZ_WIDTH, 0, "Nep.SetAz"},
  1255. X    {mkid(R_NEPTUNE,C_SETTM), PLT, TIME_WIDTH, 0, "Nep.SetTm"},
  1256. X    {mkid(R_NEPTUNE,C_SETTM+TIME_WIDTH), 0, 1},
  1257. X    {mkid(R_NEPTUNE,C_TRANSALT), PLT, ALT_WIDTH, 0, "Nep.TransAlt"},
  1258. X    {mkid(R_NEPTUNE,C_TRANSTM), PLT, TIME_WIDTH, 0, "Nep.TransTm"},
  1259. X    {mkid(R_NEPTUNE,C_TRANSTM+TIME_WIDTH), 0, 1},
  1260. X    {mkid(R_NEPTUNE,C_TUP), PLT, TIME_WIDTH, 0, "Nep.TmUp"},
  1261. X    {mkid(R_NEPTUNE,C_TUP+TIME_WIDTH), 0, 1},
  1262. X    {mkid(R_OBJX,C_RISEAZ), PLT, AZ_WIDTH, 0, "ObjX.RiseAz"},
  1263. X    {mkid(R_OBJX,C_RISETM), PLT, TIME_WIDTH, 0, "ObjX.RiseTm"},
  1264. X    {mkid(R_OBJX,C_RISETM+TIME_WIDTH), 0, 1},
  1265. X    {mkid(R_OBJX,C_SETAZ), PLT, AZ_WIDTH, 0, "ObjX.SetAz"},
  1266. X    {mkid(R_OBJX,C_SETTM), PLT, TIME_WIDTH, 0, "ObjX.SetTm"},
  1267. X    {mkid(R_OBJX,C_SETTM+TIME_WIDTH), 0, 1},
  1268. X    {mkid(R_OBJX,C_TRANSALT), PLT, ALT_WIDTH, 0, "ObjX.TransAlt"},
  1269. X    {mkid(R_OBJX,C_TRANSTM), PLT, TIME_WIDTH, 0, "ObjX.TransTm"},
  1270. X    {mkid(R_OBJX,C_TRANSTM+TIME_WIDTH), 0, 1},
  1271. X    {mkid(R_OBJX,C_TUP), PLT, TIME_WIDTH, 0, "ObjX.TmUp"},
  1272. X    {mkid(R_OBJX,C_TUP+TIME_WIDTH), 0, 1},
  1273. X    {mkid(R_OBJY,C_RISEAZ), PLT, AZ_WIDTH, 0, "ObjY.RiseAz"},
  1274. X    {mkid(R_OBJY,C_RISETM), PLT, TIME_WIDTH, 0, "ObjY.RiseTm"},
  1275. X    {mkid(R_OBJY,C_RISETM+TIME_WIDTH), 0, 1},
  1276. X    {mkid(R_OBJY,C_SETAZ), PLT, AZ_WIDTH, 0, "ObjY.SetAz"},
  1277. X    {mkid(R_OBJY,C_SETTM), PLT, TIME_WIDTH, 0, "ObjY.SetTm"},
  1278. X    {mkid(R_OBJY,C_SETTM+TIME_WIDTH), 0, 1},
  1279. X    {mkid(R_OBJY,C_TRANSALT), PLT, ALT_WIDTH, 0, "ObjY.TransAlt"},
  1280. X    {mkid(R_OBJY,C_TRANSTM), PLT, TIME_WIDTH, 0, "ObjY.TransTm"},
  1281. X    {mkid(R_OBJY,C_TRANSTM+TIME_WIDTH), 0, 1},
  1282. X    {mkid(R_OBJY,C_TUP), PLT, TIME_WIDTH, 0, "ObjY.TmUp"},
  1283. X    {mkid(R_OBJY,C_TUP+TIME_WIDTH), 0, 1},
  1284. X    {mkid(R_PLUTO,C_RISEAZ), PLT, AZ_WIDTH, 0, "Pluto.RiseAz"},
  1285. X    {mkid(R_PLUTO,C_RISETM), PLT, TIME_WIDTH, 0, "Pluto.RiseTm"},
  1286. X    {mkid(R_PLUTO,C_RISETM+TIME_WIDTH), 0, 1},
  1287. X    {mkid(R_PLUTO,C_SETAZ), PLT, AZ_WIDTH, 0, "Pluto.SetAz"},
  1288. X    {mkid(R_PLUTO,C_SETTM), PLT, TIME_WIDTH, 0, "Pluto.SetTm"},
  1289. X    {mkid(R_PLUTO,C_SETTM+TIME_WIDTH), 0, 1},
  1290. X    {mkid(R_PLUTO,C_TRANSALT), PLT, ALT_WIDTH, 0, "Pluto.TransAlt"},
  1291. X    {mkid(R_PLUTO,C_TRANSTM), PLT, TIME_WIDTH, 0, "Pluto.TransTm"},
  1292. X    {mkid(R_PLUTO,C_TRANSTM+TIME_WIDTH), 0, 1},
  1293. X    {mkid(R_PLUTO,C_TUP), PLT, TIME_WIDTH, 0, "Pluto.TmUp"},
  1294. X    {mkid(R_PLUTO,C_TUP+TIME_WIDTH), 0, 1},
  1295. X    {mkid(R_SATURN,C_RISEAZ), PLT, AZ_WIDTH, 0, "Sat.RiseAz"},
  1296. X    {mkid(R_SATURN,C_RISETM), PLT, TIME_WIDTH, 0, "Sat.RiseTm"},
  1297. X    {mkid(R_SATURN,C_RISETM+TIME_WIDTH), 0, 1},
  1298. X    {mkid(R_SATURN,C_SETAZ), PLT, AZ_WIDTH, 0, "Sat.SetAz"},
  1299. X    {mkid(R_SATURN,C_SETTM), PLT, TIME_WIDTH, 0, "Sat.SetTm"},
  1300. X    {mkid(R_SATURN,C_SETTM+TIME_WIDTH), 0, 1},
  1301. X    {mkid(R_SATURN,C_TRANSALT), PLT, ALT_WIDTH, 0, "Sat.TransAlt"},
  1302. X    {mkid(R_SATURN,C_TRANSTM), PLT, TIME_WIDTH, 0, "Sat.TransTm"},
  1303. X    {mkid(R_SATURN,C_TRANSTM+TIME_WIDTH), 0, 1},
  1304. X    {mkid(R_SATURN,C_TUP), PLT, TIME_WIDTH, 0, "Sat.TmUp"},
  1305. X    {mkid(R_SATURN,C_TUP+TIME_WIDTH), 0, 1},
  1306. X    {mkid(R_SUN,C_RISEAZ), PLT, AZ_WIDTH, 0, "Sun.RiseAz"},
  1307. X    {mkid(R_SUN,C_RISETM), PLT, TIME_WIDTH, 0, "Sun.RiseTm"},
  1308. X    {mkid(R_SUN,C_RISETM+TIME_WIDTH), 0, 1},
  1309. X    {mkid(R_SUN,C_SETAZ), PLT, AZ_WIDTH, 0, "Sun.SetAz"},
  1310. X    {mkid(R_SUN,C_SETTM), PLT, TIME_WIDTH, 0, "Sun.SetTm"},
  1311. X    {mkid(R_SUN,C_SETTM+TIME_WIDTH), 0, 1},
  1312. X    {mkid(R_SUN,C_TRANSALT), PLT, ALT_WIDTH, 0, "Sun.TransAlt"},
  1313. X    {mkid(R_SUN,C_TRANSTM), PLT, TIME_WIDTH, 0, "Sun.TransTm"},
  1314. X    {mkid(R_SUN,C_TRANSTM+TIME_WIDTH), 0, 1},
  1315. X    {mkid(R_SUN,C_TUP), PLT, TIME_WIDTH, 0, "Sun.TmUp"},
  1316. X    {mkid(R_SUN,C_TUP+TIME_WIDTH), 0, 1},
  1317. X    {mkid(R_URANUS,C_RISEAZ), PLT, AZ_WIDTH, 0, "Uranus.RiseAz"},
  1318. X    {mkid(R_URANUS,C_RISETM), PLT, TIME_WIDTH, 0, "Uranus.RiseTm"},
  1319. X    {mkid(R_URANUS,C_RISETM+TIME_WIDTH), 0, 1},
  1320. X    {mkid(R_URANUS,C_SETAZ), PLT, AZ_WIDTH, 0, "Uranus.SetAz"},
  1321. X    {mkid(R_URANUS,C_SETTM), PLT, TIME_WIDTH, 0, "Uranus.SetTm"},
  1322. X    {mkid(R_URANUS,C_SETTM+TIME_WIDTH), 0, 1},
  1323. X    {mkid(R_URANUS,C_TRANSALT), PLT, ALT_WIDTH, 0, "Uranus.TransAlt"},
  1324. X    {mkid(R_URANUS,C_TRANSTM), PLT, TIME_WIDTH, 0, "Uranus.TransTm"},
  1325. X    {mkid(R_URANUS,C_TRANSTM+TIME_WIDTH), 0, 1},
  1326. X    {mkid(R_URANUS,C_TUP), PLT, TIME_WIDTH, 0, "Uranus.TmUp"},
  1327. X    {mkid(R_URANUS,C_TUP+TIME_WIDTH), 0, 1},
  1328. X    {mkid(R_VENUS,C_RISEAZ), PLT, AZ_WIDTH, 0, "Ven.RiseAz"},
  1329. X    {mkid(R_VENUS,C_RISETM), PLT, TIME_WIDTH, 0, "Ven.RiseTm"},
  1330. X    {mkid(R_VENUS,C_RISETM+TIME_WIDTH), 0, 1},
  1331. X    {mkid(R_VENUS,C_SETAZ), PLT, AZ_WIDTH, 0, "Ven.SetAz"},
  1332. X    {mkid(R_VENUS,C_SETTM), PLT, TIME_WIDTH, 0, "Ven.SetTm"},
  1333. X    {mkid(R_VENUS,C_SETTM+TIME_WIDTH), 0, 1},
  1334. X    {mkid(R_VENUS,C_TRANSALT), PLT, ALT_WIDTH, 0, "Ven.TransAlt"},
  1335. X    {mkid(R_VENUS,C_TRANSTM), PLT, TIME_WIDTH, 0, "Ven.TransTm"},
  1336. X    {mkid(R_VENUS,C_TRANSTM+TIME_WIDTH), 0, 1},
  1337. X    {mkid(R_VENUS,C_TUP), PLT, TIME_WIDTH, 0, "Ven.TmUp"},
  1338. X    {mkid(R_VENUS,C_TUP+TIME_WIDTH), 0, 1},
  1339. X
  1340. X    {mkid(R_PLANTAB,C_OBJ), 0, 0, "Ob"},
  1341. X    {mkid(R_PLANTAB,C_RISETM-2), 0, 0, "Rise Time"},
  1342. X    {mkid(R_PLANTAB,C_RISEAZ), 0, 0, "Rise Az"},
  1343. X    {mkid(R_PLANTAB,C_TRANSTM-2), 0, 0, "Trans Time"},
  1344. X    {mkid(R_PLANTAB,C_TRANSALT-1), 0, 0, "Trans Alt"},
  1345. X    {mkid(R_PLANTAB,C_SETTM-1), 0, 0, "Set Time"},
  1346. X    {mkid(R_PLANTAB,C_SETAZ), 0, 0, "Set Az"},
  1347. X    {mkid(R_PLANTAB,C_TUP-1), 0, 0, "Hours Up"},
  1348. };
  1349. #define    NFM    (sizeof(rm_field_map)/sizeof(rm_field_map[0]))
  1350. #define    LFM    (&rm_field_map[NFM])
  1351. #define    fw(r,c)    (fm(r,c)->w)
  1352. X
  1353. static Widget risetform_w;
  1354. static Widget objs_w[NOBJ];    /* object selector toggle buttons */
  1355. static unsigned objs_on;    /* (1<<<OBJ>) when object is active */
  1356. static int hzn = ADPHZN;    /* N.B. must match the initial True TB */
  1357. static int rm_selecting;        /* set while our fields are being selected */
  1358. X
  1359. X
  1360. static short bodyrow[NOBJ] = {
  1361. X    R_MERCURY, R_VENUS, R_MARS, R_JUPITER, R_SATURN,
  1362. X    R_URANUS, R_NEPTUNE, R_PLUTO, R_SUN, R_MOON, R_OBJX, R_OBJY
  1363. };
  1364. X
  1365. static FieldMap *
  1366. fm(r,c)
  1367. int r, c;
  1368. {
  1369. X    FieldMap *fp;
  1370. X    int id = mkid(r,c);
  1371. X
  1372. X    for (fp = rm_field_map; fp < LFM; fp++)
  1373. X        if (fp->id == id)
  1374. X        return (fp);
  1375. X    printf ("fm: can't find id 0x%x (%d,%d)\n", id, r, c);
  1376. X    exit (1);
  1377. X    return(0);    /* for lint */
  1378. }
  1379. X
  1380. /* method by which another module can access our field map.
  1381. X * this is used by the search compiler.
  1382. X */
  1383. rm_getfieldmap (fmpp)
  1384. FieldMap **fmpp;
  1385. {
  1386. X    *fmpp = rm_field_map;
  1387. X    return (NFM);
  1388. }
  1389. X
  1390. /* called when the riset menu is activated via the main menu pulldown.
  1391. X * if never called before, create and manage all the widgets as a child of a
  1392. X * form. otherwise, just toggle whether the form is managed.
  1393. X */
  1394. rm_manage ()
  1395. {
  1396. X    if (!risetform_w) {
  1397. X        void rm_activate_cb();
  1398. X        void rm_hzn_cb();
  1399. X        void rm_obj_cb();
  1400. X        void rm_toggle_cb();
  1401. X        void rm_close_cb();
  1402. X        void rm_help_cb();
  1403. X        FieldMap *fp;
  1404. X        XmString str;
  1405. X        Arg args[20];
  1406. X        int i, n;
  1407. X        Widget rb_w, w;
  1408. X
  1409. X        /* create the form */
  1410. X        n = 0;
  1411. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  1412. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  1413. X        XtSetArg (args[n], XmNfractionBase, 1000); n++;
  1414. X        XtSetArg (args[n], XmNallowOverlap, False); n++;
  1415. X        risetform_w = XmCreateFormDialog (toplevel_w, "Riset", args, n);
  1416. X
  1417. X        /* set some stuff in the parent DialogShell.
  1418. X         * setting XmNdialogTitle in the Form didn't work..
  1419. X         */
  1420. X        n = 0;
  1421. X        XtSetArg (args[n], XmNtitle, "xephem Rise/Set Table"); n++;
  1422. X        XtSetValues (XtParent(risetform_w), args, n);
  1423. X
  1424. X        /* establish the buttons and labels */
  1425. X        for (fp = rm_field_map; fp < LFM; fp++) {
  1426. X        int free_str;
  1427. X        n = 0;
  1428. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1429. X        XtSetArg (args[n], XmNtopPosition, ypos(fp->id)); n++;
  1430. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1431. X        XtSetArg (args[n], XmNleftPosition, xpos(fp->id)); n++;
  1432. X        free_str = 0;
  1433. X        if (fp->prompt) {
  1434. X            str = XmStringCreate (fp->prompt,XmSTRING_DEFAULT_CHARSET);
  1435. X            free_str = 1;
  1436. X        } else if (fp->width) {
  1437. X            str = str_width (fp->width);
  1438. X            XtSetArg(args[n], XmNrecomputeSize, False); n++;
  1439. X        } else {
  1440. X            str = XmStringCreate("?",XmSTRING_DEFAULT_CHARSET);
  1441. X            free_str = 1;
  1442. X        }
  1443. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1444. X        if (fp->how) {
  1445. X            /* pushbutton */
  1446. X            XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  1447. X            fp->w = XtCreateManagedWidget ("RisetButton",
  1448. X                xmPushButtonGadgetClass, risetform_w, args, n);
  1449. X            XtAddCallback (fp->w, XmNactivateCallback, rm_activate_cb,
  1450. X                                    fp);
  1451. X        } else {
  1452. X            /* label */
  1453. X            fp->w = XtCreateManagedWidget ("RisetLabel",
  1454. X                    xmLabelGadgetClass, risetform_w, args, n);
  1455. X        }
  1456. X        if (free_str)
  1457. X            XmStringFree(str);
  1458. X        }
  1459. X
  1460. X        /* make the object control toggle buttons */
  1461. X        for (i = 0; i < NOBJ; i++) {
  1462. X        str = XmStringCreate (objname[i], XmSTRING_DEFAULT_CHARSET);
  1463. X        n = 0;
  1464. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1465. X        XtSetArg (args[n], XmNset, objs_on & (1<<i) ? True : False);n++;
  1466. X        XtSetArg (args[n], XmNindicatorOn, False); n++;
  1467. X        XtSetArg (args[n], XmNshadowThickness, 2); n++;
  1468. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1469. X        XtSetArg (args[n], XmNtopPosition, r2ypos(bodyrow[i])); n++;
  1470. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1471. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_OBJ)); n++;
  1472. X        objs_w[i] = XmCreateToggleButtonGadget (risetform_w, "RmObjs",
  1473. X                                    args, n);
  1474. X        XtAddCallback(objs_w[i], XmNvalueChangedCallback, rm_obj_cb, i);
  1475. X        XtManageChild (objs_w[i]);
  1476. X        XmStringFree (str);
  1477. X        }
  1478. X
  1479. X        /* make the close button */
  1480. X        str = XmStringCreate ("Close", XmSTRING_DEFAULT_CHARSET);
  1481. X        n = 0;
  1482. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1483. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1484. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  1485. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1486. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  1487. X        w = XmCreatePushButtonGadget (risetform_w, "RisetClose", args, n);
  1488. X        XtAddCallback (w, XmNactivateCallback, rm_close_cb, 0);
  1489. X        XtManageChild (w);
  1490. X        XmStringFree (str);
  1491. X
  1492. X        /* make the horizon control radio box */
  1493. X        n = 0;
  1494. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1495. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  1496. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1497. X        XtSetArg (args[n], XmNleftPosition, 250); n++;
  1498. X        XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  1499. X        rb_w = XmCreateRadioBox (risetform_w, "HznRadioBox", args, n);
  1500. X        XtManageChild (rb_w);
  1501. X
  1502. X        str = XmStringCreate("Adaptive", XmSTRING_DEFAULT_CHARSET);
  1503. X        n = 0;
  1504. X        XtSetArg (args[n], XmNset, hzn == ADPHZN); n++;
  1505. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1506. X        w = XmCreateToggleButtonGadget (rb_w, "AdpHznTB", args, n);
  1507. X        XtAddCallback (w, XmNvalueChangedCallback, rm_hzn_cb, ADPHZN);
  1508. X        XtManageChild (w);
  1509. X        XmStringFree (str);
  1510. X
  1511. X        str = XmStringCreate("Standard", XmSTRING_DEFAULT_CHARSET);
  1512. X        n = 0;
  1513. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1514. X        w = XmCreateToggleButtonGadget (rb_w, "StdHznTB", args, n);
  1515. X        XtAddCallback (w, XmNvalueChangedCallback, rm_hzn_cb, STDHZN);
  1516. X        XtManageChild (w);
  1517. X        XmStringFree (str);
  1518. X
  1519. X        /* make the all on/off pushbutton */
  1520. SHAR_EOF
  1521. true || echo 'restore of risetmenu.c failed'
  1522. fi
  1523. echo 'End of  part 8'
  1524. echo 'File risetmenu.c is continued in part 9'
  1525. echo 9 > _shar_seq_.tmp
  1526. exit 0
  1527. -- 
  1528. --
  1529. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1530. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1531. Sunnyvale, California 94086            at&t: 408/522-9236
  1532.