home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / xephem / part05 < prev    next >
Encoding:
Text File  |  1992-03-05  |  50.1 KB  |  1,885 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: v16i116: xephem - astronomical ephemeris program., Part05/24
  5. Message-ID: <1992Mar6.135302.2111@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:02 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 116
  15. Archive-name: xephem/part05
  16.  
  17. # this is part.05 (part 5 of a multipart archive)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file mainmenu.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" != 5; 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 mainmenu.c'
  35. else
  36. echo 'x - continuing file mainmenu.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'mainmenu.c' &&
  38. X            if (--*ac <= 0) usage("-d but no database file");
  39. X            obj_setdbfilename (*++*av);
  40. X            break;
  41. X        case 'h': /* set alternate help file name */
  42. X            if (--*ac <= 0) usage("-h but no help file");
  43. X            hlp_setfilename (*++*av);
  44. X            break;
  45. X        default:
  46. X            usage("Bad - option");
  47. X        }
  48. X    }
  49. }
  50. X
  51. /* process the field specs from the command line.
  52. X * if trouble call usage() (which exits).
  53. X */
  54. static
  55. read_fieldargs (ac, av)
  56. int ac;        /* number of such specs */
  57. char *av[];    /* array of strings in form <field_name value> */
  58. {
  59. X    while (--ac >= 0) {
  60. X        char *fs = *av++;
  61. X        if (crack_fieldset (fs) < 0) {
  62. X        char why[NC];
  63. X        (void) sprintf (why, "Bad command line spec: %.*s",
  64. X                            sizeof(why)-26, fs);
  65. X        usage (why);
  66. X        }
  67. X    }
  68. }
  69. X
  70. /* handy function to return the next planet in the order in which they are
  71. X * displayed in the lower half of the screen.
  72. X * input is a given planet, return is the next planet.
  73. X * if input is not legal, then first planet is returned; when input is the
  74. X * last planet, then -1 is returned.
  75. X * typical usage is something like:
  76. X *   for (p = nxtbody(-1); p != -1; p = nxtbody(p))
  77. X */
  78. nxtbody(p)
  79. int p;
  80. {
  81. X    static short nxtpl[NOBJ] = {
  82. X        VENUS, MARS, JUPITER, SATURN, URANUS,
  83. X        NEPTUNE, PLUTO, OBJX, MOON, MERCURY, OBJY, -1
  84. X    };
  85. X
  86. X    if (p < MERCURY || p >= NOBJ)
  87. X        return (SUN);
  88. X    else
  89. X        return (nxtpl[p]);
  90. }
  91. X
  92. /* called by other menus as they want to hear from our buttons or not.
  93. X * the "on"s and "off"s stack - only really redo the buttons if it's the
  94. X * first on or the last off.
  95. X */
  96. mm_selection_mode (whether)
  97. int whether;    /* whether setting up for plotting or for not plotting */
  98. {
  99. X    mm_selecting += whether ? 1 : -1;
  100. X
  101. X    if (whether && mm_selecting == 1     /* first one to want on */
  102. X        || !whether && mm_selecting == 0 /* last one to want off */)
  103. X        mm_set_buttons (whether);
  104. }
  105. X
  106. /* go through all the buttons just pickable for plotting and set whether they
  107. X * should appear to look like buttons or just flat labels.
  108. X */
  109. static
  110. mm_set_buttons (whether)
  111. int whether;
  112. {
  113. X    static Arg look_like_button[] = {
  114. X        {XmNshadowThickness, (XtArgVal) 2},
  115. X        {XmNfillOnArm, (XtArgVal) True},
  116. X    };
  117. X    static Arg look_like_label[] = {
  118. X        {XmNshadowThickness, (XtArgVal) 0},
  119. X        {XmNfillOnArm, (XtArgVal) False},
  120. X    };
  121. X    FieldMap *fp;
  122. X
  123. X    for (fp = mm_field_map; fp < LFM; fp++)
  124. X        if (whether) {
  125. X        if (fp->how & PLT)
  126. X            XtSetValues (fp->w, look_like_button,
  127. X                        XtNumber(look_like_button));
  128. X        else
  129. X            XtSetValues (fp->w, look_like_label,
  130. X                        XtNumber(look_like_label));
  131. X        } else {
  132. X        if (fp->how & CHG)
  133. X            XtSetValues (fp->w, look_like_button,
  134. X                        XtNumber(look_like_button));
  135. X        else
  136. X            XtSetValues (fp->w, look_like_label,
  137. X                        XtNumber(look_like_label));
  138. X        }
  139. }
  140. X
  141. /* callback from any of the main menu buttons being activated.
  142. X * if it's a CHGable field, ask op for a new setting.
  143. X */
  144. void
  145. mm_activate_cb (w, client, call)
  146. Widget w;
  147. caddr_t client;
  148. caddr_t call;
  149. {
  150. X    FieldMap *fp = (FieldMap *)client;
  151. X
  152. X    if (mm_selecting) {
  153. X        if (fp->how & PLT) {
  154. X        plt_selection (fp);
  155. X        lst_selection (fp);
  156. X        srch_selection (fp);
  157. X        }
  158. X    } else {
  159. X        if (fp->how & CHG)
  160. X        prompt (fp);
  161. X    }
  162. }
  163. X
  164. /* function called from the interval timer used to implement the
  165. X * auto repeat feature.
  166. X */
  167. void
  168. mm_timer_cb (client, id)
  169. caddr_t client;
  170. XXtIntervalId *id;
  171. {
  172. X    int waited_so_far = (int)client + 1;
  173. X
  174. X    mm_interval_id = 0;
  175. X
  176. X    if (waited_so_far < spause)
  177. X        mm_interval_id = XtAppAddTimeOut (xe_app, 1000, mm_timer_cb,
  178. X                                waited_so_far);
  179. X    else
  180. X        mm_go();
  181. }
  182. X
  183. /* callback from the main "go" button being armed.
  184. X * if we are looping (as evidenced by an active timer) then stop, else go.
  185. X */
  186. void
  187. mm_go_cb (w, client, call)
  188. Widget w;
  189. caddr_t client;
  190. caddr_t call;
  191. {
  192. X    if (mm_interval_id != 0) {
  193. X        XtRemoveTimeOut (mm_interval_id);
  194. X        mm_interval_id = 0;
  195. X        redraw_screen (1);
  196. X        print_idle();
  197. X    } else {
  198. X        if (nstep > 1)
  199. X        print_running();
  200. X        mm_go();
  201. X    }
  202. }
  203. X
  204. /* update all fields.
  205. X */
  206. mm_go()
  207. {
  208. X    int srchdone;
  209. X
  210. X    /* increment time only if op didn't change cirumstances */
  211. X    if (!newcir)
  212. X        inc_mjd (&now, tminc);
  213. X
  214. X    nstep -= 1;
  215. X
  216. X    /* recalculate everything and update all the fields */
  217. X    redraw_screen(newcir);
  218. X    mm_newcir(0);
  219. X
  220. X    /* let searching functions change tminc and check for done */
  221. X    srchdone = srch_eval (mjd, &tminc) < 0;
  222. X    print_tminc(0); /* to show possibly new search increment */
  223. X
  224. X    /* update plot and listing files, now that all fields are up
  225. X     * to date and search function has been evaluated.
  226. X     */
  227. X    plot();
  228. X    listing();
  229. X
  230. X    /* stop loop to allow op to change parameters:
  231. X     * if a search evaluation converges (or errors out),
  232. X     * or if steps are done,
  233. X     * or if op hits any key.
  234. X     */
  235. X    newcir = 0;
  236. X    if (srchdone || nstep <= 0) {
  237. X
  238. X        /* update screen with the current stuff if stopped during
  239. X         * unattended plotting or listing since last redraw_screen()
  240. X         * didn't.
  241. X         */
  242. X        if ((plot_ison() || listing_ison()) && nstep > 0)
  243. X        redraw_screen (1);
  244. X
  245. X        /* return nstep to default of 1 */
  246. X        if (nstep <= 0) {
  247. X        nstep = 1;
  248. X        print_nstep (0);
  249. X        }
  250. X        print_idle();
  251. X    } else {
  252. X        mm_interval_id =
  253. X        XtAppAddTimeOut (xe_app, spause > 0 ? 1000 : 0, mm_timer_cb, 0);
  254. X    }
  255. }
  256. X
  257. /* a way for anyone to know what now is */
  258. Now *
  259. mm_get_now()
  260. {
  261. X    return (&now);
  262. }
  263. X
  264. /* draw all the stuff on the managed menus.
  265. X * if how_much == 0 then just update fields that need it;
  266. X * if how_much == 1 then redraw all fields;
  267. X */
  268. redraw_screen (how_much)
  269. int how_much;
  270. {
  271. X
  272. #define    ANYTHING_ISON    (plot_ison()        \
  273. X                || listing_ison()    \
  274. X                || jm_ison()    \
  275. X                || ss_ison()    \
  276. X                || sd_ison()    \
  277. X                || aa_ison()    \
  278. X                || m_ison()        \
  279. X            )
  280. X    /* print the single-step message if this is the last loop */
  281. X    if (nstep < 1)
  282. X        print_updating();
  283. X
  284. X    /* if just updating changed fields while plotting or listing
  285. X     * unattended then suppress most screen updates except
  286. X     * always show nstep to show plot loops to go and
  287. X     * always show tminc to show search convergence progress.
  288. X     */
  289. X    print_nstep(how_much);
  290. X    print_tminc(how_much);
  291. X    print_spause(how_much);
  292. X    if (how_much == 0 && nstep > 0 && spause == 0)
  293. X        f_off();
  294. X
  295. X    /* print all the time-related fields */
  296. X    mm_now (how_much);
  297. X
  298. X    mm_twilight (how_much);
  299. X
  300. X    /* print stuff on other menus */
  301. X    dm_update (&now, how_much);
  302. X    rm_update (&now, how_much);
  303. X    sm_update (&now, how_much);
  304. X    jm_update (&now, how_much);
  305. X    ss_update (&now, how_much);
  306. X    sd_update (&now, how_much);
  307. X    aa_update (&now, how_much);
  308. X    m_update (&now, how_much);
  309. X
  310. X    f_on();
  311. }
  312. X
  313. static
  314. print_tminc(force)
  315. int force;
  316. {
  317. X    static double last = -123.456;    /* anything unlikely */
  318. X
  319. X    if (force || tminc != last) {
  320. X        if (tminc == RTC)
  321. X        f_string (fw(R_STPSZ,C_STPSZV), " RT CLOCK");
  322. X        else if (fabs(tminc) >= 24.0)
  323. X        f_double (fw(R_STPSZ,C_STPSZV), "%6.4g dy", tminc/24.0);
  324. X        else
  325. X        f_signtime (fw(R_STPSZ,C_STPSZV), tminc);
  326. X        last = tminc;
  327. X    }
  328. }
  329. X
  330. static
  331. print_updating()
  332. {
  333. X    print_status ("Updating...");
  334. }
  335. X
  336. static
  337. print_idle()
  338. {
  339. X    print_status ("Make changes as desired or select Update to run.");
  340. X    f_string (go_w, "Update");
  341. }
  342. X
  343. static
  344. print_running()
  345. {
  346. X    print_status ("Running... select Stop to stop.");
  347. X    f_string (go_w, "Stop");
  348. }
  349. X
  350. static
  351. print_status (s)
  352. char *s;
  353. {
  354. X    static char *last_s;
  355. X
  356. X    if (s != last_s) {
  357. X        f_string (status_w, s);
  358. X        XFlush (XtD);
  359. X        last_s = s;
  360. X    }
  361. }
  362. X
  363. static
  364. print_nstep(force)
  365. int force;
  366. {
  367. X    static int last;
  368. X
  369. X    if (force || nstep != last) {
  370. X        char buf[16];
  371. X        (void) sprintf (buf, "%8d", nstep);
  372. X        f_string (fw(R_NSTEP,C_NSTEPV), buf);
  373. X        last = nstep;
  374. X    }
  375. }
  376. X
  377. static
  378. print_spause(force)
  379. int force;
  380. {
  381. X    static int last;
  382. X
  383. X    if (force || spause != last) {
  384. X        char buf[16];
  385. X        (void) sprintf (buf, "%8d", spause);
  386. X        f_string (fw(R_PAUSE,C_PAUSEV), buf);
  387. X        last = spause;
  388. X    }
  389. }
  390. X
  391. /* read in ephem's configuration file, if any.
  392. X * if errors in file, call usage() (which exits).
  393. X * if use -c, require it; else try $EPHEMCFG and ephem.cfg but don't
  394. X *   complain if can't find these since, after all, one is not required.
  395. X * skip all lines that doesn't begin with an alpha char.
  396. X */
  397. mm_readcfg()
  398. {
  399. X    char buf[128];
  400. X    FILE *fp;
  401. X    char *fn;
  402. X
  403. X    /* open the config file. 
  404. X     * only REQUIRED if used -c option.
  405. X     * if succcessful, fn points to file name.
  406. X     */
  407. X    if (cfgfile) {
  408. X        fn = cfgfile;
  409. X        fp = fopen (fn, "r");
  410. X        if (!fp) {
  411. X        (void) sprintf (buf, "Can not open %s", fn);
  412. X        usage (buf);    /* does not return */
  413. X        }
  414. X    } else {
  415. X        fn = getenv ("EPHEMCFG");
  416. X        if (!fn)
  417. X        fn = cfgdef;
  418. X    }
  419. X    fp = fopen (fn, "r");
  420. X    if (!fp)
  421. X        return;    /* oh well; after all, it's not required */
  422. X
  423. X    while (fgets (buf, sizeof(buf), fp)) {
  424. X        if (!isalpha(buf[0]))
  425. X        continue;
  426. X        buf[strlen(buf)-1] = '\0';        /* discard trailing \n */
  427. X        if (crack_fieldset (buf) < 0) {
  428. X        char why[NC];
  429. X        (void) sprintf (why, "Bad field spec in %s: %s\n", fn, buf);
  430. X        usage (why);
  431. X        }
  432. X    }
  433. X    (void) fclose (fp);
  434. }
  435. X
  436. /* process a field spec in buf, either from config file or argv.
  437. X * return 0 if recognized ok, else -1.
  438. X */
  439. static
  440. crack_fieldset (buf)
  441. char *buf;
  442. {
  443. #define    ARRAY_SIZ(a)    (sizeof(a)/sizeof((a)[0]))
  444. #define    MAXKW        6    /* longest keyword, not counting trailing 0 */
  445. X    /* N.B. index of item is its case value, below.
  446. X     * N.B. if add an item, keep it no longer than MAXKW chars.
  447. X     */
  448. X    static char keywords[][MAXKW+1] = {
  449. X        /*  0 */    "LAT",
  450. X        /*  1 */    "LONG",
  451. X        /*  2 */    "UT",
  452. X        /*  3 */    "UD",
  453. X        /*  4 */    "TZONE",
  454. X        /*  5 */    "TZNAME",
  455. X        /*  6 */    "HEIGHT",
  456. X        /*  7 */    "NSTEP",
  457. X        /*  8 */    "PAUSE",
  458. X        /*  9 */    "STPSZ",
  459. X        /* 10 */    "TEMP",
  460. X        /* 11 */    "PRES",
  461. X        /* 12 */    "EPOCH",
  462. X        /* 13 */    "JD",
  463. X        /* 14 */    "OBJX",
  464. X        /* 15 */    "OBJY",
  465. X        /* 16 */    "PROPTS",
  466. X        /* 17 */    "MENU"
  467. X    };
  468. X    int i;
  469. X    int l;
  470. X
  471. X    for (i = 0; i < ARRAY_SIZ(keywords); i++)
  472. X        if (strncmp (keywords[i], buf, l = strlen(keywords[i])) == 0) {
  473. X        buf += l+1;    /* skip keyword and its subsequent delimiter */
  474. X        break;
  475. X        }
  476. X
  477. X    switch (i) {
  478. X    case 0:  (void) chg_fld (buf, fm(R_LAT,C_LATV)); break;
  479. X    case 1:  (void) chg_fld (buf, fm(R_LONG,C_LONGV)); break;
  480. X    case 2:  (void) chg_fld (buf, fm(R_UT,C_UTV)); break;
  481. X    case 3:  (void) chg_fld (buf, fm(R_UD,C_UD)); break;
  482. X    case 4:  (void) chg_fld (buf, fm(R_TZONE,C_TZONEV)); break;
  483. X    case 5:  (void) chg_fld (buf, fm(R_TZN,C_TZN)); break;
  484. X    case 6:  (void) chg_fld (buf, fm(R_HEIGHT,C_HEIGHTV)); break;
  485. X    case 7:  (void) chg_fld (buf, fm(R_NSTEP,C_NSTEPV)); break;
  486. X    case 8:  (void) chg_fld (buf, fm(R_PAUSE,C_PAUSEV)); break;
  487. X    case 9:  (void) chg_fld (buf, fm(R_STPSZ,C_STPSZV)); break;
  488. X    case 10: (void) chg_fld (buf, fm(R_TEMP,C_TEMPV)); break;
  489. X    case 11: (void) chg_fld (buf, fm(R_PRES,C_PRESV)); break;
  490. X    case 12: (void) chg_fld (buf, fm(R_EPOCH,C_EPOCHV)); break;
  491. X    case 13: (void) chg_fld (buf, fm(R_JD,C_JDV)); break;
  492. X    case 14: (void) obj_filelookup (OBJX, buf); break;
  493. X    case 15: (void) obj_filelookup (OBJY, buf); break;
  494. X    case 16:
  495. X        if (buf[-1] != '+')
  496. X        oppl = 0;
  497. X        while (*buf)
  498. X        switch (*buf++) {
  499. X        case 'S': oppl |= (1<<SUN); break;
  500. X        case 'M': oppl |= (1<<MOON); break;
  501. X        case 'e': oppl |= (1<<MERCURY); break;
  502. X        case 'v': oppl |= (1<<VENUS); break;
  503. X        case 'm': oppl |= (1<<MARS); break;
  504. X        case 'j': case 'J': oppl |= (1<<JUPITER); break;
  505. X        case 's': oppl |= (1<<SATURN); break;
  506. X        case 'u': oppl |= (1<<URANUS); break;
  507. X        case 'n': oppl |= (1<<NEPTUNE); break;
  508. X        case 'p': oppl |= (1<<PLUTO); break;
  509. X        case 'x': oppl |= (1<<OBJX); break;
  510. X        case 'y': oppl |= (1<<OBJY); break;
  511. X        }
  512. X        break;
  513. X    case 17:
  514. X        do {
  515. X        if (strncmp (buf, "DATA", 4) == 0) {
  516. X            dm_manage();
  517. X            buf += 4;
  518. X        }
  519. X        else if (strncmp (buf, "RISET", 5) == 0) {
  520. X            rm_manage();
  521. X            buf += 5;
  522. X        }
  523. X        else if (strncmp (buf, "SEP", 3) == 0) {
  524. X            sm_manage();
  525. X            buf += 3;
  526. X        }
  527. X        else if (strncmp (buf, "JUP", 3) == 0) {
  528. X            jm_manage();
  529. X            buf += 3;
  530. X        }
  531. X        else if (strncmp (buf, "MOON", 4) == 0) {
  532. X            m_manage();
  533. X            buf += 4;
  534. X        }
  535. X        else if (strncmp (buf, "ALTAZ", 5) == 0) {
  536. X            aa_manage();
  537. X            buf += 5;
  538. X        }
  539. X        else if (strncmp (buf, "DOME", 4) == 0) {
  540. X            sd_manage();
  541. X            buf += 4;
  542. X        }
  543. X        else if (strncmp (buf, "SOLSYS", 6) == 0) {
  544. X            ss_manage();
  545. X            buf += 6;
  546. X        }
  547. X        else
  548. X            usage ("Bad MENU option"); /* exits */
  549. X
  550. X        } while (*buf++);    /* skip any delimiter */
  551. X        break;
  552. X    default:
  553. X        return (-1);
  554. X    }
  555. X    return (0);
  556. }
  557. X
  558. /* react to the field at *fp according to the string input at bp.
  559. X * crack the buffer and update the corresponding (global) variable(s)
  560. X * or do whatever a pick at that field should do.
  561. X * return 1 if we change a field that invalidates any of the times or
  562. X * to update all related fields.
  563. X */
  564. static
  565. chg_fld (bp, fp)
  566. char *bp;
  567. FieldMap *fp;
  568. {
  569. X    int deghrs = 0, mins = 0, secs = 0;
  570. X    int new = 0;
  571. X
  572. X    /* switch on just the row/col portion */
  573. X    switch (fp->id) {
  574. X    case mkid (R_JD, C_JDV):
  575. X        if (bp[0] == 'n' || bp[0] == 'N')
  576. X        time_fromsys (&now);
  577. X        else
  578. X        mjd = atof(bp) - 2415020L;
  579. X        set_t0 (&now);
  580. X        new = 1;
  581. X        break;
  582. X    case mkid (R_UD, C_UD):
  583. X        if (bp[0] == 'n' || bp[0] == 'N')
  584. X        time_fromsys (&now);
  585. X        else {
  586. X        if (decimal_year(bp)) {
  587. X            double y = atof (bp);
  588. X            year_mjd (y, &mjd);
  589. X        } else {
  590. X            double day, newmjd0;
  591. X            int month, year;
  592. X            mjd_cal (mjd, &month, &day, &year); /* init with now */
  593. X            f_sscandate (bp, &month, &day, &year);
  594. X            cal_mjd (month, day, year, &newmjd0);
  595. X            /* if don't give a fractional part to days
  596. X             * then retain current hours.
  597. X             */
  598. X            if ((long)day == day)
  599. X            mjd = newmjd0 + mjd_hr(mjd)/24.0;
  600. X            else
  601. X            mjd = newmjd0;
  602. X        }
  603. X        }
  604. X        set_t0 (&now);
  605. X        new = 1;
  606. X        break;
  607. X    case mkid (R_UT, C_UTV):
  608. X        if (bp[0] == 'n' || bp[0] == 'N')
  609. X        time_fromsys (&now);
  610. X        else {
  611. X        double newutc = (mjd-mjd_day(mjd)) * 24.0;
  612. X        f_dec_sexsign (newutc, °hrs, &mins, &secs);
  613. X        f_sscansex (bp, °hrs, &mins, &secs);
  614. X        sex_dec (deghrs, mins, secs, &newutc);
  615. X        mjd = mjd_day(mjd) + newutc/24.0;
  616. X        }
  617. X        set_t0 (&now);
  618. X        new = 1;
  619. X        break;
  620. X    case mkid (R_LD, C_LD):
  621. X        if (bp[0] == 'n' || bp[0] == 'N')
  622. X        time_fromsys (&now);
  623. X        else {
  624. X        if (decimal_year(bp)) {
  625. X            double y = atof (bp);
  626. X            year_mjd (y, &mjd);
  627. X            mjd += tz/24.0;
  628. X        } else {
  629. X            double day, newlmjd0;
  630. X            int month, year;
  631. X            mjd_cal (mjd-tz/24.0, &month, &day, &year); /* now */
  632. X            f_sscandate (bp, &month, &day, &year);
  633. X            cal_mjd (month, day, year, &newlmjd0);
  634. X            /* if don't give a fractional part to days
  635. X             * then retain current hours.
  636. X             */
  637. X            if ((long)day == day)
  638. X            mjd = newlmjd0 + mjd_hr(mjd-tz/24.0)/24.0;
  639. X            else
  640. X            mjd = newlmjd0;
  641. X            mjd += tz/24.0;
  642. X        }
  643. X        }
  644. X        set_t0 (&now);
  645. X        new = 1;
  646. X        break;
  647. X    case mkid (R_LT, C_LT):
  648. X        if (bp[0] == 'n' || bp[0] == 'N')
  649. X        time_fromsys (&now);
  650. X        else {
  651. X        double newlt = (mjd-mjd_day(mjd)) * 24.0 - tz;
  652. X        range (&newlt, 24.0);
  653. X        f_dec_sexsign (newlt, °hrs, &mins, &secs);
  654. X        f_sscansex (bp, °hrs, &mins, &secs);
  655. X        sex_dec (deghrs, mins, secs, &newlt);
  656. X        mjd = mjd_day(mjd-tz/24.0) + (newlt + tz)/24.0;
  657. X        }
  658. X        set_t0 (&now);
  659. X        new = 1;
  660. X        break;
  661. X    case mkid (R_LST, C_LSTV):
  662. X        if (bp[0] == 'n' || bp[0] == 'N')
  663. X        time_fromsys (&now);
  664. X        else {
  665. X        double lst, utc;
  666. X        now_lst (&now, &lst);
  667. X        f_dec_sexsign (lst, °hrs, &mins, &secs);
  668. X        f_sscansex (bp, °hrs, &mins, &secs);
  669. X        sex_dec (deghrs, mins, secs, &lst);
  670. X        lst -= radhr(lng); /* convert to gst */
  671. X        range (&lst, 24.0);
  672. X        gst_utc (mjd_day(mjd), lst, &utc);
  673. X        mjd = mjd_day(mjd) + utc/24.0;
  674. X        }
  675. X        set_t0 (&now);
  676. X        new = 1;
  677. X        break;
  678. X    case mkid (R_TZN, C_TZN):
  679. X        (void) strncpy (tznm, bp, sizeof(tznm)-1);
  680. X        new = 1;
  681. X        break;
  682. X    case mkid (R_TZONE, C_TZONEV):
  683. X        f_dec_sexsign (tz, °hrs, &mins, &secs);
  684. X        f_sscansex (bp, °hrs, &mins, &secs);
  685. X        sex_dec (deghrs, mins, secs, &tz);
  686. X        new = 1;
  687. X        break;
  688. X    case mkid (R_LONG, C_LONGV):
  689. X        f_dec_sexsign (-raddeg(lng), °hrs, &mins, &secs);
  690. X        f_sscansex (bp, °hrs, &mins, &secs);
  691. X        sex_dec (deghrs, mins, secs, &lng);
  692. X        lng = degrad (-lng);         /* want - radians west */
  693. X        new = 1;
  694. X        break;
  695. X    case mkid (R_LAT, C_LATV):
  696. X        f_dec_sexsign (raddeg(lat), °hrs, &mins, &secs);
  697. X        f_sscansex (bp, °hrs, &mins, &secs);
  698. X        sex_dec (deghrs, mins, secs, &lat);
  699. X        lat = degrad (lat);
  700. X        new = 1;
  701. X        break;
  702. X    case mkid (R_HEIGHT, C_HEIGHTV):
  703. X        if (sscanf (bp, "%lf", &height) == 1) {
  704. X        height /= 2.093e7; /*convert ft to earth radii above sea level*/
  705. X        new = 1;
  706. X        }
  707. X        break;
  708. X    case mkid (R_NSTEP, C_NSTEPV):
  709. X        (void) sscanf (bp, "%d", &nstep);
  710. X        print_nstep (0);
  711. X        break;
  712. X    case mkid (R_PAUSE, C_PAUSEV):
  713. X        (void) sscanf (bp, "%d", &spause);
  714. X        print_spause (0);
  715. X        break;
  716. X    case mkid (R_TEMP, C_TEMPV):
  717. X        if (sscanf (bp, "%lf", &temp) == 1) {
  718. X        temp = 5./9.*(temp - 32.0);    /* want degs C */
  719. X        new = 1;
  720. X        }
  721. X        break;
  722. X    case mkid (R_PRES, C_PRESV):
  723. X        if (sscanf (bp, "%lf", &pressure) == 1) {
  724. X        pressure *= 33.86;        /* want mBar */
  725. X        new = 1;
  726. X        }
  727. X        break;
  728. X    case mkid (R_EPOCH, C_EPOCHV):
  729. X        if (bp[0] == 'e' || bp[0] == 'E')
  730. X        epoch = EOD;
  731. X        else {
  732. X        double e;
  733. X        e = atof(bp);
  734. X        year_mjd (e, &epoch);
  735. X        }
  736. X        new = 1;
  737. X        break;
  738. X    case mkid (R_STPSZ, C_STPSZV):
  739. X        if (bp[0] == 'r' || bp[0] == 'R')
  740. X        tminc = RTC;
  741. X        else {
  742. X        char lastc = bp[strlen(bp)-1];
  743. X        if (lastc == 'd' || lastc == 'D') {
  744. X            /* ends in d so treat as a number of days */
  745. X            double x;
  746. X            if (sscanf (bp, "%lf", &x) == 1)
  747. X            tminc = x * 24.0;
  748. X        } else if (lastc == 's' || lastc == 'S') {
  749. X            /* ends in s so treat as a number of sidereal days */
  750. X            double x;
  751. X            if (sscanf (bp, "%lf", &x) == 1)
  752. X            tminc = x * 24.0 * SIDRATE;
  753. X        } else {
  754. X            if (tminc == RTC)
  755. X            deghrs = mins = secs = 0;
  756. X            else
  757. X            f_dec_sexsign (tminc, °hrs, &mins, &secs);
  758. X            f_sscansex (bp, °hrs, &mins, &secs);
  759. X            sex_dec (deghrs, mins, secs, &tminc);
  760. X        }
  761. X        }
  762. X        print_tminc(0);
  763. X        set_t0 (&now);
  764. X        break;
  765. X    default:
  766. X        printf ("chg_fld: unknown id: 0x%x\n", fp->id);
  767. X        exit (1);
  768. X    }
  769. X
  770. X    return (new);
  771. }
  772. X
  773. /* use typed OK to a prompt for fp. get his new value and use it */
  774. static void
  775. prompt_ok_cb (w, client, call)
  776. Widget w;
  777. caddr_t client;
  778. caddr_t call;
  779. {
  780. X    FieldMap *fp = (FieldMap *)client;
  781. X    char *text;
  782. X    
  783. X    get_xmstring(w, XmNtextString, &text);
  784. X    if (chg_fld (text, fp)) {
  785. X        mm_now (1);
  786. X        mm_newcir(1);
  787. X        newcir = 1;
  788. X    }
  789. X    XtDestroyWidget (w);
  790. X    XtFree (text);
  791. }
  792. X
  793. /* put up a prompt dialog to ask about fp */
  794. static
  795. prompt (fp)
  796. FieldMap *fp;
  797. {
  798. X    Widget w, sw;
  799. X    XmString str, title;
  800. X    Arg args[20];
  801. X    int n;
  802. X    
  803. X    str = XmStringCreateLtoR (fp->prompt, XmSTRING_DEFAULT_CHARSET);
  804. X    title = XmStringCreateSimple ("xephem Prompt");
  805. X    n = 0;
  806. X    XtSetArg(args[n], XmNselectionLabelString, str);  n++;
  807. X    XtSetArg(args[n], XmNdialogTitle, title);  n++;
  808. X    sw = XmCreatePromptDialog(toplevel_w, "MainPrompt", args, n);
  809. X    XmStringFree (str);
  810. X    XmStringFree (title);
  811. X
  812. X    w = XmSelectionBoxGetChild (sw, XmDIALOG_HELP_BUTTON);
  813. X    XtUnmanageChild (w);
  814. X
  815. X    XtAddCallback (sw, XmNokCallback, prompt_ok_cb, fp);
  816. X    XtManageChild (sw);
  817. X    w = XmSelectionBoxGetChild (sw, XmDIALOG_TEXT);
  818. X    XmProcessTraversal (w, XmTRAVERSE_CURRENT);
  819. X    XmProcessTraversal (w, XmTRAVERSE_CURRENT); /* yes, twice!! */
  820. }
  821. X
  822. /* print all the time/date/where related stuff: the Now structure.
  823. X * print in a nice order, based on the field locations, as much as possible.
  824. X */
  825. mm_now (all)
  826. int all;
  827. {
  828. X    char buf[32];
  829. X    double lmjd = mjd - tz/24.0;
  830. X    double jd = mjd + 2415020L;
  831. X    double tmp;
  832. X
  833. X    (void) sprintf (buf, "%-3.3s", tznm);
  834. X    f_string (fw(R_TZN,C_TZN), buf);
  835. X    f_time (fw(R_LT,C_LT), mjd_hr(lmjd));
  836. X    f_date (fw(R_LD,C_LD), lmjd);
  837. X
  838. X    f_time (fw(R_UT,C_UTV), mjd_hr(mjd));
  839. X    f_date (fw(R_UD,C_UD), mjd);
  840. X
  841. X    (void) sprintf (buf, "%14.5f", jd);
  842. X    (void) flog_log (fw(R_JD,C_JDV), jd, buf);
  843. X    f_string (fw(R_JD,C_JDV), buf);
  844. X
  845. X    now_lst (&now, &tmp);
  846. X    f_time (fw(R_LST,C_LSTV), tmp);
  847. X
  848. X    if (all) {
  849. X        f_gangle (fw(R_LAT,C_LATV), lat);
  850. X        f_gangle (fw(R_LONG,C_LONGV), -lng);    /* + west */
  851. X
  852. X        tmp = height * 2.093e7;    /* want to see ft, not earth radii */
  853. X        (void) sprintf (buf, "%5g ft", tmp);
  854. X        (void) flog_log (fw(R_HEIGHT,C_HEIGHTV), tmp, buf);
  855. X        f_string (fw(R_HEIGHT,C_HEIGHTV), buf);
  856. X
  857. X        tmp = 9./5.*temp + 32.0;     /* want to see degrees F, not C */
  858. X        (void) sprintf (buf, "%6g F", tmp);
  859. X        (void) flog_log (fw(R_TEMP,C_TEMPV), tmp, buf);
  860. X        f_string (fw(R_TEMP,C_TEMPV), buf);
  861. X
  862. X        tmp = pressure / 33.86;    /* want to see in. Hg, not mBar */
  863. X        (void) sprintf (buf, "%5.2f in", tmp);
  864. X        (void) flog_log (fw(R_PRES,C_PRESV), tmp, buf);
  865. X        f_string (fw(R_PRES,C_PRESV), buf);
  866. X
  867. X        f_signtime (fw(R_TZONE,C_TZONEV), tz);
  868. X
  869. X        if (epoch == EOD)
  870. X        f_string (fw(R_EPOCH,C_EPOCHV), "(OfDate)");
  871. X        else {
  872. X        mjd_year (epoch, &tmp);
  873. X        f_double (fw(R_EPOCH,C_EPOCHV), "%8.1f", tmp);
  874. X        }
  875. X    }
  876. X
  877. X    /* print the calendar for local day, if new month/year.  */
  878. X    mm_calendar (all);
  879. }
  880. X
  881. /* display dawn/dusk/length-of-night times.
  882. X */
  883. mm_twilight (force)
  884. int force;
  885. {
  886. X    double dusk, dawn;
  887. X    double tmp;
  888. X    int status;
  889. X
  890. X    if (!twilight_cir (&now, &dawn, &dusk, &status) && !force)
  891. X        return;
  892. X
  893. X    f_mtime (fw(R_DAWN,C_DAWNV), dawn);
  894. X    f_mtime (fw(R_DUSK,C_DUSKV), dusk);
  895. X    tmp = dawn - dusk; range (&tmp, 24.0);
  896. X    f_mtime (fw(R_LON,C_LONV), tmp);
  897. }
  898. X
  899. mm_newcir (y)
  900. int y;
  901. {
  902. X    static char ncmsg[] = "NEW CIRCUMSTANCES";
  903. X    static char nomsg[] = "                 ";
  904. X    static int last_y = -1;
  905. X
  906. X    if (y != last_y) {
  907. X        f_string (newcir_w, y ? ncmsg : nomsg);
  908. X        last_y = y;
  909. X    }
  910. }
  911. X
  912. static
  913. mm_calendar (force)
  914. int force;
  915. {
  916. X    static char *mnames[] = {
  917. X        "January", "February", "March", "April", "May", "June",
  918. X        "July", "August", "September", "October", "November", "December"
  919. X    };
  920. X    static int last_m, last_y;
  921. X    static double last_tz = -100;
  922. X    char cal[CAL_ROWS][CAL_COLS+1];
  923. X    int m, y;
  924. X    double d;
  925. X    int f, nd;
  926. X    int r;
  927. X    double jd0;
  928. X
  929. X    /* get local m/d/y. do nothing if still same month and not forced. */
  930. X    mjd_cal (mjd_day(mjd-tz/24.0), &m, &d, &y);
  931. X    if (m == last_m && y == last_y && tz == last_tz && !force || !f_ison())
  932. X        return;
  933. X    last_m = m;
  934. X    last_y = y;
  935. X    last_tz = tz;
  936. X
  937. X    /* find day of week of first day of month */
  938. X    cal_mjd (m, 1.0, y, &jd0);
  939. X    mjd_dow (jd0, &f);
  940. X    if (f < 0) {
  941. X        /* can't figure it out - too hard before Gregorian */
  942. X        for (r = CAL_ROWS; --r >= 0; )
  943. X        cal[r][0] = '\0';
  944. X    } else {
  945. X        /* print header */
  946. X        (void) sprintf (cal[0], "%s %4d", mnames[m-1], y); /* X centers */
  947. X        strcpy (cal[1], "Su Mo Tu We Th Fr Sa");
  948. X
  949. X        /* find number of days in this month */
  950. X        mjd_dpm (jd0, &nd);
  951. X
  952. X        /* print the calendar */
  953. X        for (r = 0; r < CAL_ROWS-2; r++) {
  954. X        char row[7*3+1], *rp = row;
  955. X        int c;
  956. X        for (c = 0; c < 7; c++) {
  957. X            int i = r*7+c;
  958. X            if (i < f || i >= f + nd)
  959. X            (void) sprintf (rp, "   ");
  960. X            else
  961. X            (void) sprintf (rp, "%2d ", i-f+1);
  962. X            rp += 3;
  963. X        }
  964. X        *--rp = '\0'; /* don't want last blank */
  965. X        strcpy (cal[r+2], row);
  966. X        }
  967. X    }
  968. X
  969. X    /* over print the new and full moons for this month.
  970. X     * TODO: don't really know which dates to use here (see moonnf())
  971. X     *   so try several to be fairly safe. have to go back to 4/29/1988
  972. X     *   to find the full moon on 5/1 for example.
  973. X     */
  974. X    mm_nfmoon (cal, jd0-3, tz, m, f);
  975. X    mm_nfmoon (cal, jd0+15, tz, m, f);
  976. X
  977. X    for (r = 0; r < CAL_ROWS; r++)
  978. X        f_string(cal_w[r], cal[r]);
  979. }
  980. X
  981. static
  982. mm_nfmoon (cal, jd, tzone, m, f)
  983. char cal[CAL_ROWS][CAL_COLS+1];
  984. double jd, tzone;
  985. int m, f;
  986. {
  987. X    static char nms[] = "NM", fms[] = "FM";
  988. X    double dm;
  989. X    int mm, ym;
  990. X    double jdn, jdf;
  991. X    int di;
  992. X
  993. X    moonnf (jd, &jdn, &jdf);
  994. X    mjd_cal (jdn-tzone/24.0, &mm, &dm, &ym);
  995. X    if (m == mm) {
  996. X        di = dm + f - 1;
  997. X        strncpy (&cal[2+di/7][3*(di%7)], nms, 2); /* don't add a '\0' */
  998. X    }
  999. X    mjd_cal (jdf-tzone/24.0, &mm, &dm, &ym);
  1000. X    if (m == mm) {
  1001. X        di = dm + f - 1;
  1002. X        strncpy (&cal[2+di/7][3*(di%7)], fms, 2); /* don't add a '\0' */
  1003. X    }
  1004. }
  1005. SHAR_EOF
  1006. echo 'File mainmenu.c is complete' &&
  1007. chmod 0644 mainmenu.c ||
  1008. echo 'restore of mainmenu.c failed'
  1009. Wc_c="`wc -c < 'mainmenu.c'`"
  1010. test 36543 -eq "$Wc_c" ||
  1011.     echo 'mainmenu.c: original size 36543, current size' "$Wc_c"
  1012. rm -f _shar_wnt_.tmp
  1013. fi
  1014. # ============= moon.c ==============
  1015. if test -f 'moon.c' -a X"$1" != X"-c"; then
  1016.     echo 'x - skipping moon.c (File already exists)'
  1017.     rm -f _shar_wnt_.tmp
  1018. else
  1019. > _shar_wnt_.tmp
  1020. echo 'x - extracting moon.c (Text)'
  1021. sed 's/^X//' << 'SHAR_EOF' > 'moon.c' &&
  1022. #include <stdio.h>
  1023. #include <math.h>
  1024. #include "astro.h"
  1025. X
  1026. /* given the mjd, find the geocentric ecliptic longitude, lam, and latitude,
  1027. X * bet, and horizontal parallax, hp for the moon.
  1028. X * N.B. series for long and lat are good to about 10 and 3 arcseconds. however,
  1029. X *   math errors cause up to 100 and 30 arcseconds error, even if use double.
  1030. X *   why?? suspect highly sensitive nature of difference used to get m1..6.
  1031. X * N.B. still need to correct for nutation. then for topocentric location
  1032. X *   further correct for parallax and refraction.
  1033. X */
  1034. moon (mjd, lam, bet, hp)
  1035. double mjd;
  1036. double *lam, *bet, *hp;
  1037. {
  1038. X    double t, t2;
  1039. X    double ld;
  1040. X    double ms;
  1041. X    double md;
  1042. X    double de;
  1043. X    double f;
  1044. X    double n;
  1045. X    double a, sa, sn, b, sb, c, sc, e, e2, l, g, w1, w2;
  1046. X    double m1, m2, m3, m4, m5, m6;
  1047. X
  1048. X    t = mjd/36525.;
  1049. X    t2 = t*t;
  1050. X
  1051. X    m1 = mjd/27.32158213;
  1052. X    m1 = 360.0*(m1-(long)m1);
  1053. X    m2 = mjd/365.2596407;
  1054. X    m2 = 360.0*(m2-(long)m2);
  1055. X    m3 = mjd/27.55455094;
  1056. X    m3 = 360.0*(m3-(long)m3);
  1057. X    m4 = mjd/29.53058868;
  1058. X    m4 = 360.0*(m4-(long)m4);
  1059. X    m5 = mjd/27.21222039;
  1060. X    m5 = 360.0*(m5-(long)m5);
  1061. X    m6 = mjd/6798.363307;
  1062. X    m6 = 360.0*(m6-(long)m6);
  1063. X
  1064. X    ld = 270.434164+m1-(.001133-.0000019*t)*t2;
  1065. X    ms = 358.475833+m2-(.00015+.0000033*t)*t2;
  1066. X    md = 296.104608+m3+(.009192+.0000144*t)*t2;
  1067. X    de = 350.737486+m4-(.001436-.0000019*t)*t2;
  1068. X    f = 11.250889+m5-(.003211+.0000003*t)*t2;
  1069. X    n = 259.183275-m6+(.002078+.000022*t)*t2;
  1070. X
  1071. X    a = degrad(51.2+20.2*t);
  1072. X    sa = sin(a);
  1073. X    sn = sin(degrad(n));
  1074. X    b = 346.56+(132.87-.0091731*t)*t;
  1075. X    sb = .003964*sin(degrad(b));
  1076. X    c = degrad(n+275.05-2.3*t);
  1077. X    sc = sin(c);
  1078. X    ld = ld+.000233*sa+sb+.001964*sn;
  1079. X    ms = ms-.001778*sa;
  1080. X    md = md+.000817*sa+sb+.002541*sn;
  1081. X    f = f+sb-.024691*sn-.004328*sc;
  1082. X    de = de+.002011*sa+sb+.001964*sn;
  1083. X    e = 1-(.002495+7.52e-06*t)*t;
  1084. X    e2 = e*e;
  1085. X
  1086. X    ld = degrad(ld);
  1087. X    ms = degrad(ms);
  1088. X    n = degrad(n);
  1089. X    de = degrad(de);
  1090. X    f = degrad(f);
  1091. X    md = degrad(md);
  1092. X
  1093. X    l = 6.28875*sin(md)+1.27402*sin(2*de-md)+.658309*sin(2*de)+
  1094. X        .213616*sin(2*md)-e*.185596*sin(ms)-.114336*sin(2*f)+
  1095. X        .058793*sin(2*(de-md))+.057212*e*sin(2*de-ms-md)+
  1096. X        .05332*sin(2*de+md)+.045874*e*sin(2*de-ms)+.041024*e*sin(md-ms);
  1097. X    l = l-.034718*sin(de)-e*.030465*sin(ms+md)+.015326*sin(2*(de-f))-
  1098. X        .012528*sin(2*f+md)-.01098*sin(2*f-md)+.010674*sin(4*de-md)+
  1099. X        .010034*sin(3*md)+.008548*sin(4*de-2*md)-e*.00791*sin(ms-md+2*de)-
  1100. X        e*.006783*sin(2*de+ms);
  1101. X    l = l+.005162*sin(md-de)+e*.005*sin(ms+de)+.003862*sin(4*de)+
  1102. X        e*.004049*sin(md-ms+2*de)+.003996*sin(2*(md+de))+
  1103. X        .003665*sin(2*de-3*md)+e*.002695*sin(2*md-ms)+
  1104. X        .002602*sin(md-2*(f+de))+e*.002396*sin(2*(de-md)-ms)-
  1105. X        .002349*sin(md+de);
  1106. X    l = l+e2*.002249*sin(2*(de-ms))-e*.002125*sin(2*md+ms)-
  1107. X        e2*.002079*sin(2*ms)+e2*.002059*sin(2*(de-ms)-md)-
  1108. X        .001773*sin(md+2*(de-f))-.001595*sin(2*(f+de))+
  1109. X        e*.00122*sin(4*de-ms-md)-.00111*sin(2*(md+f))+.000892*sin(md-3*de);
  1110. X    l = l-e*.000811*sin(ms+md+2*de)+e*.000761*sin(4*de-ms-2*md)+
  1111. X         e2*.000704*sin(md-2*(ms+de))+e*.000693*sin(ms-2*(md-de))+
  1112. X         e*.000598*sin(2*(de-f)-ms)+.00055*sin(md+4*de)+.000538*sin(4*md)+
  1113. X         e*.000521*sin(4*de-ms)+.000486*sin(2*md-de);
  1114. X    l = l+e2*.000717*sin(md-2*ms);
  1115. X    *lam = ld+degrad(l);
  1116. X    range (lam, 2*PI);
  1117. X
  1118. X    g = 5.12819*sin(f)+.280606*sin(md+f)+.277693*sin(md-f)+
  1119. X        .173238*sin(2*de-f)+.055413*sin(2*de+f-md)+.046272*sin(2*de-f-md)+
  1120. X        .032573*sin(2*de+f)+.017198*sin(2*md+f)+.009267*sin(2*de+md-f)+
  1121. X        .008823*sin(2*md-f)+e*.008247*sin(2*de-ms-f);
  1122. X    g = g+.004323*sin(2*(de-md)-f)+.0042*sin(2*de+f+md)+
  1123. X        e*.003372*sin(f-ms-2*de)+e*.002472*sin(2*de+f-ms-md)+
  1124. X        e*.002222*sin(2*de+f-ms)+e*.002072*sin(2*de-f-ms-md)+
  1125. X        e*.001877*sin(f-ms+md)+.001828*sin(4*de-f-md)-e*.001803*sin(f+ms)-
  1126. X        .00175*sin(3*f);
  1127. X    g = g+e*.00157*sin(md-ms-f)-.001487*sin(f+de)-e*.001481*sin(f+ms+md)+
  1128. X         e*.001417*sin(f-ms-md)+e*.00135*sin(f-ms)+.00133*sin(f-de)+
  1129. X         .001106*sin(f+3*md)+.00102*sin(4*de-f)+.000833*sin(f+4*de-md)+
  1130. X         .000781*sin(md-3*f)+.00067*sin(f+4*de-2*md);
  1131. X    g = g+.000606*sin(2*de-3*f)+.000597*sin(2*(de+md)-f)+
  1132. X        e*.000492*sin(2*de+md-ms-f)+.00045*sin(2*(md-de)-f)+
  1133. X        .000439*sin(3*md-f)+.000423*sin(f+2*(de+md))+
  1134. X        .000422*sin(2*de-f-3*md)-e*.000367*sin(ms+f+2*de-md)-
  1135. X        e*.000353*sin(ms+f+2*de)+.000331*sin(f+4*de);
  1136. X    g = g+e*.000317*sin(2*de+f-ms+md)+e2*.000306*sin(2*(de-ms)-f)-
  1137. X        .000283*sin(md+3*f);
  1138. X    w1 = .0004664*cos(n);
  1139. X    w2 = .0000754*cos(c);
  1140. X    *bet = degrad(g)*(1-w1-w2);
  1141. X
  1142. X    *hp = .950724+.051818*cos(md)+.009531*cos(2*de-md)+.007843*cos(2*de)+
  1143. X          .002824*cos(2*md)+.000857*cos(2*de+md)+e*.000533*cos(2*de-ms)+
  1144. X          e*.000401*cos(2*de-md-ms)+e*.00032*cos(md-ms)-.000271*cos(de)-
  1145. X          e*.000264*cos(ms+md)-.000198*cos(2*f-md);
  1146. X    *hp = *hp+.000173*cos(3*md)+.000167*cos(4*de-md)-e*.000111*cos(ms)+
  1147. X         .000103*cos(4*de-2*md)-.000084*cos(2*md-2*de)-
  1148. X         e*.000083*cos(2*de+ms)+.000079*cos(2*de+2*md)+.000072*cos(4*de)+
  1149. X         e*.000064*cos(2*de-ms+md)-e*.000063*cos(2*de+ms-md)+
  1150. X         e*.000041*cos(ms+de);
  1151. X    *hp = *hp+e*.000035*cos(2*md-ms)-.000033*cos(3*md-2*de)-
  1152. X         .00003*cos(md+de)-.000029*cos(2*(f-de))-e*.000029*cos(2*md+ms)+
  1153. X         e2*.000026*cos(2*(de-ms))-.000023*cos(2*(f-de)+md)+
  1154. X         e*.000019*cos(4*de-ms-md);
  1155. X    *hp = degrad(*hp);
  1156. }
  1157. SHAR_EOF
  1158. chmod 0644 moon.c ||
  1159. echo 'restore of moon.c failed'
  1160. Wc_c="`wc -c < 'moon.c'`"
  1161. test 5143 -eq "$Wc_c" ||
  1162.     echo 'moon.c: original size 5143, current size' "$Wc_c"
  1163. rm -f _shar_wnt_.tmp
  1164. fi
  1165. # ============= moonmenu.c ==============
  1166. if test -f 'moonmenu.c' -a X"$1" != X"-c"; then
  1167.     echo 'x - skipping moonmenu.c (File already exists)'
  1168.     rm -f _shar_wnt_.tmp
  1169. else
  1170. > _shar_wnt_.tmp
  1171. echo 'x - extracting moonmenu.c (Text)'
  1172. sed 's/^X//' << 'SHAR_EOF' > 'moonmenu.c' &&
  1173. /* code to manage the stuff on the moon display.
  1174. X */
  1175. X
  1176. #include <stdio.h>
  1177. #include <ctype.h>
  1178. #include <math.h>
  1179. #ifdef VMS
  1180. #include <stdlib.h>
  1181. #endif
  1182. #include <X11/Xlib.h>
  1183. #include <Xm/Xm.h>
  1184. #include <Xm/Form.h>
  1185. #include <Xm/Frame.h>
  1186. #include <Xm/DrawingA.h>
  1187. #include <Xm/LabelG.h>
  1188. #include <Xm/PushBG.h>
  1189. #include <Xm/ToggleBG.h>
  1190. #include <Xm/Text.h>
  1191. #include "astro.h"
  1192. #include "circum.h"
  1193. #include "moreobjs.h"
  1194. X
  1195. /* get the small moonbit map and its dimension defines.
  1196. X * moon is roughly centered within the map, with a radius of some 200 pixels.
  1197. X * exact values set by trial and error.
  1198. X */
  1199. #include "smallfm.xbm"
  1200. #define    MRAD    191                /* radius of moon image */
  1201. #define    TOPMAR    (smallfm_height/2 - MRAD + 2)    /* top margin */
  1202. #define    LEFTMAR    (smallfm_width/2 - MRAD)    /* left margin */
  1203. X
  1204. #define    NSTARS    100        /* number background stars in graphical view */
  1205. X
  1206. extern Now *mm_get_now();
  1207. extern Widget toplevel_w;
  1208. X
  1209. static Widget mform_w;        /* main moon form dialog */
  1210. static Widget mda_w;        /* moon drawring area */
  1211. static Widget eshine_w;        /* whether we want to show earthshine */
  1212. static Widget mapvw_w;        /* toggle button that selects which view */
  1213. X
  1214. #define    MAPVW_W    (smallfm_width+20)
  1215. #define    MAPVW_H    (smallfm_height+40)
  1216. X
  1217. /* called when the moon view is activated via the main menu pulldown.
  1218. X * if never called before, create and manage all the widgets as a child of a
  1219. X * form. otherwise, just toggle whether the form is managed.
  1220. X */
  1221. m_manage ()
  1222. {
  1223. X    if (!mform_w) {
  1224. X        void m_eshine_cb();
  1225. X        void m_mapvw_cb();
  1226. X        void m_close_cb();
  1227. X        void m_da_exp_cb();
  1228. X        Widget w;
  1229. X        Widget frame_w;
  1230. X        Widget close_w;
  1231. X        XmString str;
  1232. X        Arg args[20];
  1233. X        int n;
  1234. X
  1235. X        /* create and set size of form */
  1236. X        n = 0;
  1237. X        XtSetArg (args[n], XmNunitType, XmPIXELS); n++;
  1238. X        XtSetArg (args[n], XmNheight, MAPVW_W); n++;
  1239. X        XtSetArg (args[n], XmNwidth, MAPVW_H); n++;
  1240. X        XtSetArg (args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
  1241. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  1242. X        XtSetArg (args[n], XmNhorizontalSpacing, 5); n++;
  1243. X        XtSetArg (args[n], XmNverticalSpacing, 5); n++;
  1244. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  1245. X        mform_w = XmCreateFormDialog (toplevel_w, "MoonForm", args, n);
  1246. X
  1247. X        /* set some stuff in the parent DialogShell.
  1248. X         * setting XmNdialogTitle in the Form didn't work..
  1249. X         */
  1250. X        n = 0;
  1251. X        XtSetArg (args[n], XmNtitle, "xephem Moon View"); n++;
  1252. X        XtSetValues (XtParent(mform_w), args, n);
  1253. X
  1254. X        /* make the earthshine toggle button */
  1255. X
  1256. X        n = 0;
  1257. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1258. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1259. X        XtSetArg (args[n], XmNleftPosition, 35); n++;
  1260. X        eshine_w = XmCreateToggleButtonGadget(mform_w, "MEShine", args, n);
  1261. X        set_xmstring (eshine_w, XmNlabelString, "Earthshine");
  1262. X        XtAddCallback (eshine_w, XmNvalueChangedCallback, m_eshine_cb, 0);
  1263. X        XtManageChild (eshine_w);
  1264. X        XmToggleButtonGadgetSetState (eshine_w, True, False);
  1265. X
  1266. X        /* make the view option toggle button */
  1267. X
  1268. X        n = 0;
  1269. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1270. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1271. X        mapvw_w = XmCreateToggleButtonGadget(mform_w, "MMapView", args, n);
  1272. X        set_xmstring (mapvw_w, XmNlabelString, "Bitmap View");
  1273. X        XtAddCallback (mapvw_w, XmNvalueChangedCallback, m_mapvw_cb, 0);
  1274. X        XtManageChild (mapvw_w);
  1275. X        XmToggleButtonGadgetSetState (mapvw_w, True, False);
  1276. X
  1277. X        /* make the close button */
  1278. X
  1279. X        str = XmStringCreate("Close", XmSTRING_DEFAULT_CHARSET);
  1280. X        n = 0;
  1281. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1282. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1283. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1284. X        close_w = XmCreatePushButtonGadget (mform_w, "MClose", args, n);
  1285. X        XtAddCallback (close_w, XmNactivateCallback, m_close_cb, 0);
  1286. X        XtManageChild (close_w);
  1287. X        XmStringFree (str);
  1288. X
  1289. X        /* make a frame for the drawing area */
  1290. X
  1291. X        n = 0;
  1292. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  1293. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  1294. X        XtSetArg (args[n], XmNbottomWidget, close_w); n++;
  1295. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1296. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1297. X        XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_OUT); n++;
  1298. X        frame_w = XmCreateFrame (mform_w, "MoonFrame", args, n);
  1299. X        XtManageChild (frame_w);
  1300. X
  1301. X        /* make a drawing area in the frame for the sky */
  1302. X        n = 0;
  1303. X        XtSetArg (args[n], XmNmarginWidth, 0); n++;
  1304. X        XtSetArg (args[n], XmNmarginHeight, 0); n++;
  1305. X        mda_w = XmCreateDrawingArea (frame_w, "MoonDA", args, n);
  1306. X        XtManageChild (mda_w);
  1307. X        XtAddCallback (mda_w, XmNexposeCallback, m_da_exp_cb, 0);
  1308. X        XtAddCallback (mda_w, XmNresizeCallback, m_da_exp_cb, 0);
  1309. X    }
  1310. X    
  1311. X    if (XtIsManaged(mform_w))
  1312. X        XtUnmanageChild (mform_w);
  1313. X    else {
  1314. X        XtManageChild (mform_w);
  1315. X        /* let the initial expose do the drawing */
  1316. X    }
  1317. }
  1318. X
  1319. m_ison()
  1320. {
  1321. X    return (mform_w && XtIsManaged(mform_w));
  1322. }
  1323. X
  1324. m_update (np, how_much)
  1325. Now *np;
  1326. int how_much;
  1327. {
  1328. X    if (!mform_w || !XtIsManaged(mform_w))
  1329. X        return;
  1330. X
  1331. X    m_draw (how_much);
  1332. X        
  1333. }
  1334. X
  1335. /* callback from the Close button.
  1336. X */
  1337. static void
  1338. m_close_cb (w, client, call)
  1339. Widget w;
  1340. caddr_t client;
  1341. caddr_t call;
  1342. {
  1343. X    XtUnmanageChild (mform_w);
  1344. }
  1345. X
  1346. /* callback from the Map view toggle button.
  1347. X */
  1348. static void
  1349. m_mapvw_cb (w, client, call)
  1350. Widget w;
  1351. caddr_t client;
  1352. caddr_t call;
  1353. {
  1354. X    if (XmToggleButtonGadgetGetState(mapvw_w)) {
  1355. X        /* turning on map so insure a good initial size at least */
  1356. X        Arg args[20];
  1357. X        int n;
  1358. X
  1359. X        n = 0;
  1360. X        XtSetArg (args[n], XmNwidth, MAPVW_W); n++;
  1361. X        XtSetArg (args[n], XmNheight, MAPVW_H); n++;
  1362. X        XtSetValues (mform_w, args, n);
  1363. X    }
  1364. X
  1365. X    m_draw (1);
  1366. }
  1367. X
  1368. /* callback from the earthshine toggle button.
  1369. X */
  1370. static void
  1371. m_eshine_cb (w, client, call)
  1372. Widget w;
  1373. caddr_t client;
  1374. caddr_t call;
  1375. {
  1376. X    m_draw (1);
  1377. }
  1378. X
  1379. /* expose (or reconfig) of moon drawing area.
  1380. X * just redraw the scene to the current window size.
  1381. X */
  1382. static void
  1383. m_da_exp_cb (w, client, call)
  1384. Widget w;
  1385. caddr_t client;
  1386. caddr_t call;
  1387. {
  1388. X    XmDrawingAreaCallbackStruct *c = (XmDrawingAreaCallbackStruct *)call;
  1389. X
  1390. X    switch (c->reason) {
  1391. X    case XmCR_RESIZE:
  1392. X        /* seems we can get one resize before the first expose.
  1393. X         * hence, we don't have a good window to use yet. just let it
  1394. X         * go; we'll get the expose soon.
  1395. X         */
  1396. X        if (!XtWindow(w))
  1397. X        return;
  1398. X        break;
  1399. X    case XmCR_EXPOSE: {
  1400. X        XExposeEvent *e = &c->event->xexpose;
  1401. X        /* wait for the last in the series */
  1402. X        if (e->count != 0)
  1403. X        return;
  1404. X        break;
  1405. X        }
  1406. X    default:
  1407. X        printf ("Unexpected mda_w event. type=%d\n", c->reason);
  1408. X        return;
  1409. X    }
  1410. X
  1411. X    m_draw (1);
  1412. }
  1413. X
  1414. /* draw moon, always if force or scene has changed.
  1415. X */
  1416. static
  1417. m_draw (force)
  1418. int force;
  1419. {
  1420. X    static double last_el;
  1421. X    Now *np;
  1422. X    Sky sky;
  1423. X    double el;
  1424. X
  1425. X    /* get new elongation */
  1426. X    np = mm_get_now();
  1427. X    (void) body_cir (MOON, 3600.0, np, &sky);
  1428. X    el = degrad(sky.s_elong);
  1429. X
  1430. X    /* don't bother if not forcing and hasn't changed 1 degree */
  1431. X    if (!force && fabs (el - last_el) < degrad(1))
  1432. X        return;
  1433. X    last_el = el;
  1434. X
  1435. X    if (XmToggleButtonGadgetGetState(mapvw_w)) {
  1436. X        /* want map view */
  1437. X        XtManageChild (eshine_w);
  1438. X        m_draw_mapview (el);
  1439. X    } else {
  1440. X        /* want graphical view */
  1441. X        XtUnmanageChild (eshine_w);
  1442. X        m_draw_grview (el);
  1443. X    }
  1444. }
  1445. X
  1446. /* version that draws moon using genuine bitmap image. */
  1447. static
  1448. m_draw_mapview (el)
  1449. double el;
  1450. {
  1451. X    static GC m_fgc;
  1452. X    Display *dsp = XtDisplay (mda_w);
  1453. X    Window win = XtWindow (mda_w);
  1454. X    double cosel;
  1455. X    XImage *xim;
  1456. X    unsigned char *m;
  1457. X    int y;    /* y coord: 0 is center, up is + */
  1458. X    int earthshine = XmToggleButtonGadgetGetState(eshine_w);
  1459. X
  1460. X    if (!m_fgc) {
  1461. X        /* make gc from MoonDA colors
  1462. X         */
  1463. X        XGCValues gcv;
  1464. X        unsigned int gcm;
  1465. X
  1466. X        gcm = GCForeground | GCBackground;
  1467. X        get_something (mda_w, XmNforeground, (char *)&gcv.background);
  1468. X        get_something (mda_w, XmNbackground, (char *)&gcv.foreground);
  1469. X
  1470. X        m_fgc = XCreateGC (dsp, win, gcm, &gcv);
  1471. X    }
  1472. X
  1473. X    /* make a copy so we can darken some of it */
  1474. X    m = (unsigned char *)XtMalloc(smallfm_width*smallfm_height/8);
  1475. X    memcpy (m, smallfm_bits, smallfm_width*smallfm_height/8);
  1476. X
  1477. X    cosel = cos(el);
  1478. X    for (y = MRAD; y > -MRAD; y--) {
  1479. X        int lx, rx;    /* left and right edge of scan line to darken */
  1480. X        int r, c;    /* X row/col coords */
  1481. X        lx = -sqrt((double)(MRAD*MRAD - y*y));
  1482. X        rx = -lx * cosel;
  1483. X        if (el < 0) {
  1484. X        int tmp = rx;
  1485. X        rx = -lx;
  1486. X        lx = -tmp;
  1487. X        }
  1488. X        r = TOPMAR + MRAD - y;
  1489. X        for (c = LEFTMAR + MRAD + lx; c < LEFTMAR + MRAD + rx; c++)
  1490. X        if (!earthshine || (c & 3) != 3 || (y & 3) != 3)
  1491. X            m[r*smallfm_width/8 + c/8] |= (1 << (c%8)); /* 1 is bkgnd */
  1492. X    }
  1493. X
  1494. X    xim = XCreateImage (dsp, XDefaultVisual (dsp, 0),
  1495. X        /* depth */        1,
  1496. X        /* format */    XYBitmap, 
  1497. X        /* offset */    0,
  1498. X        /* data */        m,
  1499. X        /* width */        smallfm_width, 
  1500. X        /* height */    smallfm_height,
  1501. X        /* pad */        8,
  1502. X        /* bpl */        0);
  1503. X
  1504. X
  1505. X    XPutImage (dsp, win, m_fgc, xim, 0, 0, 0, 0,
  1506. X                        smallfm_width, smallfm_height);
  1507. X    XDestroyImage (xim);    /* also frees m */
  1508. }
  1509. X
  1510. /* version that draws moon using just simple graphics */
  1511. static
  1512. m_draw_grview (el)
  1513. double el;
  1514. {
  1515. X    static GC m_fgc, m_bgc;
  1516. X    static XPoint *stars;
  1517. X    static int last_w, last_h;
  1518. X    Display *dsp = XtDisplay (mda_w);
  1519. X    Window win = XtWindow (mda_w);
  1520. X    Window root;
  1521. X    int x, y;
  1522. X    unsigned int bw, d;
  1523. X    unsigned w, h;        /* actual size of drawing area window */
  1524. X    unsigned nx, ny;    /* width and height of moon ellipse */
  1525. X    int la1, la2, ta1, ta2; /* limb and terminator start and extent */
  1526. X    int wid;        /* distance from meridian to terminator */
  1527. X    int xb, yb;        /* x and y borders, eg, (w-nx)/2 */
  1528. X    Pixmap pm;
  1529. X
  1530. X    if (!m_fgc) {
  1531. X        /* make gcs from MoonDA colors
  1532. X         */
  1533. X        XGCValues gcv;
  1534. X        unsigned int gcm;
  1535. X
  1536. X        gcm = GCForeground | GCBackground;
  1537. X        get_something (mda_w, XmNforeground, (char *)&gcv.foreground);
  1538. X        get_something (mda_w, XmNbackground, (char *)&gcv.background);
  1539. X        m_fgc = XCreateGC (dsp, win, gcm, &gcv);
  1540. X
  1541. X        get_something (mda_w, XmNbackground, (char *)&gcv.foreground);
  1542. X        get_something (mda_w, XmNforeground, (char *)&gcv.background);
  1543. X        m_bgc = XCreateGC (dsp, win, gcm, &gcv);
  1544. X    }
  1545. X
  1546. X
  1547. X    /* get size of window now and make a fresh pixmap to match.
  1548. X     * we draw the scene in the pixmap then copy it to the window.
  1549. X     * otherwise, you can see it drawing and it flashes and looks ugly.
  1550. X     */
  1551. X    XGetGeometry (dsp, win, &root, &x, &y, &w, &h, &bw, &d);
  1552. X    pm = XCreatePixmap (dsp, win, w, h, d);
  1553. X    XFillRectangle (dsp, pm, m_bgc, 0, 0, w, h);
  1554. X
  1555. X    /* set moon ellipse portion within drawing window here as desired.
  1556. X     * this code sets it to match the map view.
  1557. X     */
  1558. X    nx = MRAD*w/(MRAD+LEFTMAR);
  1559. X    ny = MRAD*h/(MRAD+TOPMAR);
  1560. X
  1561. X    xb = (w - nx)/2;
  1562. X    yb = (h - ny)/2;
  1563. X
  1564. X    la1 = el >= 0.0 ? -90*64 : 90*64;
  1565. X    la2 = 180*64;
  1566. X    wid = fabs(nx/2*cos(el))+0.5;
  1567. X    ta1 = el >= PI/2 || (el <= 0 && el >= -PI/2) ? 90*64 : -90*64;
  1568. X    ta2 = 180*64;
  1569. X
  1570. X    /* dsp, win, gc, x, y, w, h, start_ang, ang_extent */
  1571. X    /* draw the lit hemisphere to the limb */
  1572. X    XFillArc (dsp, pm, m_fgc, xb, yb, nx, ny, la1, la2);
  1573. X
  1574. X    /* draw the portion from the terminator to the meridian */
  1575. X    if (la1 < 0 && ta1 < 0 || la1 > 0 && ta1 > 0) {
  1576. X        /* crescent, so draw in background color */
  1577. X        XFillArc (dsp, pm, m_bgc, nx/2-wid+xb, yb, 2*wid, ny, ta1, ta2);
  1578. X    } else {
  1579. X        /* gibbous, so draw in foreground color */
  1580. X        XFillArc (dsp, pm, m_fgc, nx/2-wid+xb, yb, 2*wid, ny, ta1, ta2);
  1581. X    }
  1582. X
  1583. X    /* add in the background stars */
  1584. X    if (!stars || last_w != w || last_h != h) {
  1585. X        /* sprinkle NSTARS stars outside the moon's ellipse.
  1586. X         */
  1587. X        int i;
  1588. X        if (stars)
  1589. X        XtFree ((char *)stars);
  1590. X        stars = (XPoint *) XtMalloc (NSTARS * sizeof(XPoint));
  1591. X        for (i = 0; i < NSTARS; ) {
  1592. X        double hh = ny/2;
  1593. X        double hw = nx/2;
  1594. X        x = ((rand() >> 2) & 0xfff) * (w-1) / 0xfff;
  1595. X        y = ((rand() >> 2) & 0xfff) * (h-1) / 0xfff;
  1596. X        /* compare the candidate y with the y on the ellipse at the
  1597. X         * candidate x to decide whether to draw the point.
  1598. X         */
  1599. #            define SQR(x)    ((x)*(x))
  1600. X        if (SQR(y-h/2) > SQR(hh) - SQR(hh)*SQR(x-w/2)/SQR(hw)) {
  1601. X            stars[i].x = x;
  1602. X            stars[i].y = y;
  1603. X            i++;
  1604. X        }
  1605. X        }
  1606. X    }
  1607. X    XDrawPoints (dsp, pm, m_fgc, stars, NSTARS, CoordModeOrigin);
  1608. X
  1609. X    XCopyArea (dsp, pm, win, m_fgc, 0, 0, w, h, 0, 0);
  1610. X    XFreePixmap (dsp, pm);
  1611. X
  1612. X    last_w = w;
  1613. X    last_h = h;
  1614. }
  1615. SHAR_EOF
  1616. chmod 0644 moonmenu.c ||
  1617. echo 'restore of moonmenu.c failed'
  1618. Wc_c="`wc -c < 'moonmenu.c'`"
  1619. test 12318 -eq "$Wc_c" ||
  1620.     echo 'moonmenu.c: original size 12318, current size' "$Wc_c"
  1621. rm -f _shar_wnt_.tmp
  1622. fi
  1623. # ============= moonnf.c ==============
  1624. if test -f 'moonnf.c' -a X"$1" != X"-c"; then
  1625.     echo 'x - skipping moonnf.c (File already exists)'
  1626.     rm -f _shar_wnt_.tmp
  1627. else
  1628. > _shar_wnt_.tmp
  1629. echo 'x - extracting moonnf.c (Text)'
  1630. sed 's/^X//' << 'SHAR_EOF' > 'moonnf.c' &&
  1631. #include <stdio.h>
  1632. #include <math.h>
  1633. #include "astro.h"
  1634. X
  1635. #define    unw(w,z)    ((w)-floor((w)/(z))*(z))
  1636. X
  1637. /* given a modified Julian date, mjd, return the mjd of the new
  1638. X * and full moons about then, mjdn and mjdf.
  1639. X * TODO: exactly which ones does it find? eg:
  1640. X *   5/28/1988 yields 5/15 and 5/31
  1641. X *   5/29             6/14     6/29
  1642. X */
  1643. moonnf (mjd, mjdn, mjdf)
  1644. double mjd;
  1645. double *mjdn, *mjdf;
  1646. {
  1647. X    int mo, yr;
  1648. X    double dy;
  1649. X    double mjd0;
  1650. X    double k, tn, tf, t;
  1651. X
  1652. X    mjd_cal (mjd, &mo, &dy, &yr);
  1653. X    cal_mjd (1, 0., yr, &mjd0);
  1654. X    k = (yr-1900+((mjd-mjd0)/365))*12.3685;
  1655. X    k = floor(k+0.5);
  1656. X    tn = k/1236.85;
  1657. X    tf = (k+0.5)/1236.85;
  1658. X    t = tn;
  1659. X    m (t, k, mjdn);
  1660. X    t = tf;
  1661. X    k += 0.5;
  1662. X    m (t, k, mjdf);
  1663. }
  1664. X
  1665. static
  1666. m (t, k, mjd)
  1667. double t, k;
  1668. double *mjd;
  1669. {
  1670. X    double t2, a, a1, b, b1, c, ms, mm, f, ddjd;
  1671. X
  1672. X    t2 = t*t;
  1673. X    a = 29.53*k;
  1674. X    c = degrad(166.56+(132.87-9.173e-3*t)*t);
  1675. X    b = 5.8868e-4*k+(1.178e-4-1.55e-7*t)*t2+3.3e-4*sin(c)+7.5933E-1;
  1676. X    ms = 359.2242+360*unw(k/1.236886e1,1)-(3.33e-5+3.47e-6*t)*t2;
  1677. X    mm = 306.0253+360*unw(k/9.330851e-1,1)+(1.07306e-2+1.236e-5*t)*t2;
  1678. X    f = 21.2964+360*unw(k/9.214926e-1,1)-(1.6528e-3+2.39e-6*t)*t2;
  1679. X    ms = unw(ms,360);
  1680. X    mm = unw(mm,360);
  1681. X    f = unw(f,360);
  1682. X    ms = degrad(ms);
  1683. X    mm = degrad(mm);
  1684. X    f = degrad(f);
  1685. X    ddjd = (1.734e-1-3.93e-4*t)*sin(ms)+2.1e-3*sin(2*ms)
  1686. X        -4.068e-1*sin(mm)+1.61e-2*sin(2*mm)-4e-4*sin(3*mm)
  1687. X        +1.04e-2*sin(2*f)-5.1e-3*sin(ms+mm)-7.4e-3*sin(ms-mm)
  1688. X        +4e-4*sin(2*f+ms)-4e-4*sin(2*f-ms)-6e-4*sin(2*f+mm)
  1689. X        +1e-3*sin(2*f-mm)+5e-4*sin(ms+2*mm);
  1690. X    a1 = (long)a;
  1691. X    b = b+ddjd+(a-a1);
  1692. X    b1 = (long)b;
  1693. X    a = a1+b1;
  1694. X    b = b-b1;
  1695. X    *mjd = a + b;
  1696. }
  1697. SHAR_EOF
  1698. chmod 0644 moonnf.c ||
  1699. echo 'restore of moonnf.c failed'
  1700. Wc_c="`wc -c < 'moonnf.c'`"
  1701. test 1557 -eq "$Wc_c" ||
  1702.     echo 'moonnf.c: original size 1557, current size' "$Wc_c"
  1703. rm -f _shar_wnt_.tmp
  1704. fi
  1705. # ============= nutation.c ==============
  1706. if test -f 'nutation.c' -a X"$1" != X"-c"; then
  1707.     echo 'x - skipping nutation.c (File already exists)'
  1708.     rm -f _shar_wnt_.tmp
  1709. else
  1710. > _shar_wnt_.tmp
  1711. echo 'x - extracting nutation.c (Text)'
  1712. sed 's/^X//' << 'SHAR_EOF' > 'nutation.c' &&
  1713. #include <stdio.h>
  1714. #include <math.h>
  1715. #include "astro.h"
  1716. X
  1717. /* given the modified JD, mjd, find the nutation in obliquity, *deps, and
  1718. X * the nutation in longitude, *dpsi, each in radians.
  1719. X */
  1720. nutation (mjd, deps, dpsi)
  1721. double mjd;
  1722. double *deps, *dpsi;
  1723. {
  1724. X    static double lastmjd = -10000, lastdeps, lastdpsi;
  1725. X    double ls, ld;    /* sun's mean longitude, moon's mean longitude */
  1726. X    double ms, md;    /* sun's mean anomaly, moon's mean anomaly */
  1727. X    double nm;    /* longitude of moon's ascending node */
  1728. X    double t, t2;    /* number of Julian centuries of 36525 days since
  1729. X             * Jan 0.5 1900.
  1730. X             */
  1731. X    double tls, tnm, tld;    /* twice above */
  1732. X    double a, b;    /* temps */
  1733. X
  1734. X    if (mjd == lastmjd) {
  1735. X        *deps = lastdeps;
  1736. X        *dpsi = lastdpsi;
  1737. X        return;
  1738. X    }
  1739. X        
  1740. X    t = mjd/36525.;
  1741. X    t2 = t*t;
  1742. X
  1743. X    a = 100.0021358*t;
  1744. X    b = 360.*(a-(long)a);
  1745. X    ls = 279.697+.000303*t2+b;
  1746. X
  1747. X    a = 1336.855231*t;
  1748. X    b = 360.*(a-(long)a);
  1749. X    ld = 270.434-.001133*t2+b;
  1750. X
  1751. X    a = 99.99736056000026*t;
  1752. X    b = 360.*(a-(long)a);
  1753. X    ms = 358.476-.00015*t2+b;
  1754. X
  1755. X    a = 13255523.59*t;
  1756. X    b = 360.*(a-(long)a);
  1757. X    md = 296.105+.009192*t2+b;
  1758. X
  1759. X    a = 5.372616667*t;
  1760. X    b = 360.*(a-(long)a);
  1761. X    nm = 259.183+.002078*t2-b;
  1762. X
  1763. X    /* convert to radian forms for use with trig functions.
  1764. X     */
  1765. X    tls = 2*degrad(ls);
  1766. X    nm = degrad(nm);
  1767. X    tnm = 2*nm;
  1768. X    ms = degrad(ms);
  1769. X    tld = 2*degrad(ld);
  1770. X    md = degrad(md);
  1771. X
  1772. X    /* find delta psi and eps, in arcseconds.
  1773. X     */
  1774. X    lastdpsi = (-17.2327-.01737*t)*sin(nm)+(-1.2729-.00013*t)*sin(tls)
  1775. X           +.2088*sin(tnm)-.2037*sin(tld)+(.1261-.00031*t)*sin(ms)
  1776. X           +.0675*sin(md)-(.0497-.00012*t)*sin(tls+ms)
  1777. X           -.0342*sin(tld-nm)-.0261*sin(tld+md)+.0214*sin(tls-ms)
  1778. X           -.0149*sin(tls-tld+md)+.0124*sin(tls-nm)+.0114*sin(tld-md);
  1779. X    lastdeps = (9.21+.00091*t)*cos(nm)+(.5522-.00029*t)*cos(tls)
  1780. X           -.0904*cos(tnm)+.0884*cos(tld)+.0216*cos(tls+ms)
  1781. X           +.0183*cos(tld-nm)+.0113*cos(tld+md)-.0093*cos(tls-ms)
  1782. X           -.0066*cos(tls-nm);
  1783. X
  1784. X    /* convert to radians.
  1785. X     */
  1786. X    lastdpsi = degrad(lastdpsi/3600);
  1787. X    lastdeps = degrad(lastdeps/3600);
  1788. X
  1789. X    lastmjd = mjd;
  1790. X    *deps = lastdeps;
  1791. X    *dpsi = lastdpsi;
  1792. }
  1793. SHAR_EOF
  1794. chmod 0644 nutation.c ||
  1795. echo 'restore of nutation.c failed'
  1796. Wc_c="`wc -c < 'nutation.c'`"
  1797. test 2011 -eq "$Wc_c" ||
  1798.     echo 'nutation.c: original size 2011, current size' "$Wc_c"
  1799. rm -f _shar_wnt_.tmp
  1800. fi
  1801. # ============= obj.c ==============
  1802. if test -f 'obj.c' -a X"$1" != X"-c"; then
  1803.     echo 'x - skipping obj.c (File already exists)'
  1804.     rm -f _shar_wnt_.tmp
  1805. else
  1806. > _shar_wnt_.tmp
  1807. echo 'x - extracting obj.c (Text)'
  1808. sed 's/^X//' << 'SHAR_EOF' > 'obj.c' &&
  1809. /* code to manage the stuff on the "objx/y" menu.
  1810. X */
  1811. X
  1812. #include <stdio.h>
  1813. #include <ctype.h>
  1814. #include <math.h>
  1815. #ifdef VMS
  1816. #include <stdlib.h>
  1817. #endif
  1818. #include <X11/Xlib.h>
  1819. #include <X11/cursorfont.h>
  1820. #include <Xm/Xm.h>
  1821. #include <Xm/Form.h>
  1822. #include <Xm/LabelG.h>
  1823. #include <Xm/List.h>
  1824. #include <Xm/PushBG.h>
  1825. #include <Xm/SelectioB.h>
  1826. #include <Xm/ToggleBG.h>
  1827. #include <Xm/SeparatoG.h>
  1828. #include <Xm/RowColumn.h>
  1829. #include "fieldmap.h"
  1830. #include "astro.h"
  1831. #include "circum.h"
  1832. #include "moreobjs.h"
  1833. X
  1834. extern char *getenv();
  1835. extern Widget toplevel_w;
  1836. extern Now *mm_get_now();
  1837. X
  1838. #define    MAXDBLINE    256    /* longest allowable database file line */
  1839. X
  1840. /* locations of each field.
  1841. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  1842. X * historical reasons.
  1843. X */
  1844. #define    NR    23    /* initial number of rows */
  1845. #define    NC    60    /* initial number of columns */
  1846. #define    TBLW    30    /* fixed width of left tabular section */
  1847. X
  1848. /* first row of the object-specific fields */
  1849. #define    FIRST_ROW    7
  1850. X
  1851. /* define a code for each member in each object type struct.
  1852. X * making them globally unique avoids a nested switch on fp->type.
  1853. X * making them sequencial might encourage the compiler to make a jmp table.
  1854. X */
  1855. #define    F_NAME        1
  1856. #define    F_RA        2
  1857. #define    F_DEC        3
  1858. #define    F_MAG        4
  1859. #define    F_EPOCH        5
  1860. #define    F_SIZE        6
  1861. X
  1862. #define    E_NAME        7
  1863. #define    E_INC        8
  1864. #define    E_LAN        9
  1865. #define    E_AOP        10
  1866. #define    E_A        11
  1867. #define    E_N        12
  1868. #define    E_E        13
  1869. #define    E_M        14
  1870. #define    E_CEPOCH    15
  1871. #define    E_EPOCH        16
  1872. #define    E_M1        17
  1873. SHAR_EOF
  1874. true || echo 'restore of obj.c failed'
  1875. fi
  1876. echo 'End of  part 5'
  1877. echo 'File obj.c is continued in part 6'
  1878. echo 6 > _shar_seq_.tmp
  1879. exit 0
  1880. -- 
  1881. --
  1882. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1883. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1884. Sunnyvale, California 94086            at&t: 408/522-9236
  1885.