home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / xephem / part10 < prev    next >
Encoding:
Text File  |  1992-03-05  |  50.1 KB  |  1,700 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: v16i121: xephem - astronomical ephemeris program., Part10/24
  5. Message-ID: <1992Mar6.135424.2409@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:54:24 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 121
  15. Archive-name: xephem/part10
  16.  
  17. # this is part.10 (part 10 of a multipart archive)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file skydome.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" != 10; 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 skydome.c'
  35. else
  36. echo 'x - continuing file skydome.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'skydome.c' &&
  38. X        XFillArc (dsp, win, sd_bgc, 1, 1, nx-2, ny-2, 0, 360*64);
  39. X        XDrawArc (dsp, win, sd_fgc, 0, 0, nx-1, ny-1, 0, 360*64);
  40. X    }
  41. X
  42. X    /* display each point */
  43. X    for (i = 0; i < npoints; i++)
  44. X        if (propts & (1<<points[i].p))
  45. X        sky_dome(dsp, win, sd_fgc, i, nx, ny);
  46. }
  47. X
  48. /* draw points[i] on screen of size [nx,ny]. */
  49. static
  50. sky_dome (dsp, win, gc, i, nx, ny)
  51. Display *dsp;
  52. Window win;
  53. GC gc;
  54. int i;        /* points[] index */
  55. int nx, ny;    /* size of drawing area, in pixels */
  56. {
  57. X    int sx, sy;
  58. X    double az = points[i].az;
  59. X    double r = 1.0 - points[i].alt/(PI/2);
  60. X
  61. X    points[i].sx = sx = nx/2*(1.0 - r*sin(az));
  62. X    points[i].sy = sy = ny/2*(1.0 - r*cos(az));
  63. X
  64. X    if (bigdots) {
  65. X        XDrawPoint (dsp, win, gc, sx, sy);
  66. X        XDrawPoint (dsp, win, gc, sx+1, sy);
  67. X        XDrawPoint (dsp, win, gc, sx, sy+1);
  68. X        XDrawPoint (dsp, win, gc, sx+1, sy+1);
  69. X    } else
  70. X        XDrawPoint (dsp, win, gc, sx, sy);
  71. }
  72. SHAR_EOF
  73. echo 'File skydome.c is complete' &&
  74. chmod 0644 skydome.c ||
  75. echo 'restore of skydome.c failed'
  76. Wc_c="`wc -c < 'skydome.c'`"
  77. test 15221 -eq "$Wc_c" ||
  78.     echo 'skydome.c: original size 15221, current size' "$Wc_c"
  79. rm -f _shar_wnt_.tmp
  80. fi
  81. # ============= solarsys.c ==============
  82. if test -f 'solarsys.c' -a X"$1" != X"-c"; then
  83.     echo 'x - skipping solarsys.c (File already exists)'
  84.     rm -f _shar_wnt_.tmp
  85. else
  86. > _shar_wnt_.tmp
  87. echo 'x - extracting solarsys.c (Text)'
  88. sed 's/^X//' << 'SHAR_EOF' > 'solarsys.c' &&
  89. /* code to manage the stuff on the solar system display.
  90. X */
  91. X
  92. #include <stdio.h>
  93. #include <ctype.h>
  94. #include <math.h>
  95. #ifdef VMS
  96. #include <stdlib.h>
  97. #endif
  98. #include <X11/Xlib.h>
  99. #include <Xm/Xm.h>
  100. #include <Xm/Form.h>
  101. #include <Xm/Frame.h>
  102. #include <Xm/DrawingA.h>
  103. #include <Xm/LabelG.h>
  104. #include <Xm/PushBG.h>
  105. #include <Xm/ToggleBG.h>
  106. #include <Xm/Text.h>
  107. #include <Xm/Scale.h>
  108. #include "astro.h"
  109. #include "circum.h"
  110. #include "moreobjs.h"
  111. X
  112. extern Now *mm_get_now();
  113. extern Widget toplevel_w;
  114. #define    XtD    XtDisplay(toplevel_w)
  115. X
  116. static Widget ssform_w;        /* main solar system form dialog */
  117. static Widget hr_w, hlng_w, hlat_w; /* scales for heliocentric R, long, lat */
  118. static Widget ssda_w;        /* solar system drawring area */
  119. static Widget picked_name_w;    /* display name of object if picked */
  120. static Widget objs_w[NOBJ];     /* object selection toggle buttons */
  121. X
  122. #define    TRAILS    1
  123. #define    BIGDOTS    2
  124. #define    NR    15
  125. #define    NC    36
  126. X
  127. static int trails;
  128. static int bigdots = 1;
  129. X
  130. /* use this string to make a label gadget appear empty.
  131. X * using "" seems to act like unmanaging it altogether!
  132. X */
  133. static char no_name[] = " ";
  134. X
  135. static unsigned int propts;    /* mask of (1<<p) for object on */
  136. X
  137. /* heliocentric coordinates, and enough info to locate it on screen */
  138. typedef struct {
  139. X    double x, y, z;    /* helio cartesian coords */
  140. X    int p;        /* object code */
  141. X    int sx, sy;        /* screen (window) coords */
  142. } HLoc;
  143. X
  144. static HLoc *points;    /* malloc'd set of points on screen now */
  145. static int npoints;    /* number of points */
  146. X
  147. static char *onames[NOBJ] = {
  148. X    /* NB: these must correspond to the astro/morobj defines */
  149. X    "Mercury", "Venus", "Mars", "Jupiter", "Saturn",
  150. X    "Uranus", "Neptune", "Pluto", "Sun",
  151. X    "Earth",    /* NB: earth for MOON */
  152. X    "X", "Y"
  153. };
  154. X
  155. X
  156. /* called when the solar system view is activated via the main menu pulldown.
  157. X * if never called before, create and manage all the widgets as a child of a
  158. X * form. otherwise, just toggle whether the form is managed.
  159. X */
  160. ss_manage ()
  161. {
  162. X    if (!ssform_w) {
  163. X        void ss_activate_cb();
  164. X        void ss_close_cb();
  165. X        void ss_help_cb();
  166. X        void ss_changed_cb();
  167. X        void ss_da_exp_cb();
  168. X        void ss_propts_cb();
  169. X        void ss_toggle_cb();
  170. X        Widget close_w;
  171. X        Widget trails_w;
  172. X        Widget toggle_w;
  173. X        Widget w, pw, frame_w;
  174. X        Widget help_w;
  175. X        Widget big_w;
  176. X        XmString str;
  177. X        Arg args[20];
  178. X        int n;
  179. X        int i, p;
  180. X
  181. X        /* create form */
  182. X        n = 0;
  183. X        XtSetArg (args[n], XmNheight, NR*char_height()); n++;
  184. X        XtSetArg (args[n], XmNwidth, NC*char_width()); n++;
  185. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  186. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  187. X        XtSetArg (args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
  188. X        ssform_w = XmCreateFormDialog (toplevel_w, "SolarSystem", args, n);
  189. X
  190. X        /* set some stuff in the parent DialogShell.
  191. X         * setting XmNdialogTitle in the Form didn't work..
  192. X         */
  193. X        n = 0;
  194. X        XtSetArg (args[n], XmNtitle, "xephem Solar System"); n++;
  195. X        XtSetValues (XtParent(ssform_w), args, n);
  196. X
  197. X        /* make the "close" push button */
  198. X
  199. X        str = XmStringCreate("Close", XmSTRING_DEFAULT_CHARSET);
  200. X        n = 0;
  201. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  202. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  203. X        XtSetArg (args[n], XmNlabelString, str); n++;
  204. X        close_w = XmCreatePushButtonGadget (ssform_w, "SSClose", args, n);
  205. X        XtAddCallback (close_w, XmNactivateCallback, ss_close_cb, 0);
  206. X        XtManageChild (close_w);
  207. X        XmStringFree (str);
  208. X
  209. X        /* make the "help" push button */
  210. X
  211. X        str = XmStringCreate("Help", XmSTRING_DEFAULT_CHARSET);
  212. X        n = 0;
  213. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  214. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  215. X        XtSetArg (args[n], XmNlabelString, str); n++;
  216. X        help_w = XmCreatePushButtonGadget (ssform_w, "SSHelp", args, n);
  217. X        XtAddCallback (help_w, XmNactivateCallback, ss_help_cb, 0);
  218. X        XtManageChild (help_w);
  219. X        XmStringFree (str);
  220. X
  221. X        /* "toggle on/off" push button */
  222. X
  223. X        str = XmStringCreate("Toggle On/off", XmSTRING_DEFAULT_CHARSET);
  224. X        n = 0;
  225. X        XtSetArg (args[n], XmNlabelString, str); n++;
  226. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  227. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  228. X        XtSetArg (args[n], XmNleftPosition, 35); n++;
  229. X        toggle_w = XmCreatePushButtonGadget (ssform_w, "SSToggle", args, n);
  230. X        XtAddCallback (toggle_w, XmNactivateCallback, ss_toggle_cb, 0);
  231. X        XtManageChild (toggle_w);
  232. X        XmStringFree (str);
  233. X
  234. X        /* make the "big dots" toggle button */
  235. X
  236. X        str = XmStringCreate("Big dots", XmSTRING_DEFAULT_CHARSET);
  237. X        n = 0;
  238. X        XtSetArg (args[n], XmNset, bigdots); n++;
  239. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  240. X        XtSetArg (args[n], XmNbottomWidget, close_w); n++;
  241. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  242. X        XtSetArg (args[n], XmNlabelString, str); n++;
  243. X        big_w = XmCreateToggleButtonGadget(ssform_w, "SSBigDots",
  244. X                                    args, n);
  245. X        XmStringFree (str);
  246. X        XtManageChild (big_w);
  247. X        XtAddCallback(big_w, XmNvalueChangedCallback, ss_activate_cb,
  248. X                                    BIGDOTS);
  249. X
  250. X        /* make the "leave trail" toggle button */
  251. X
  252. X        str = XmStringCreate("Leave trails", XmSTRING_DEFAULT_CHARSET);
  253. X        n = 0;
  254. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  255. X        XtSetArg (args[n], XmNbottomWidget, close_w); n++;
  256. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  257. X        XtSetArg (args[n], XmNlabelString, str); n++;
  258. X        trails_w = XmCreateToggleButtonGadget(ssform_w, "SSTrails",
  259. X                                    args, n);
  260. X        XmStringFree (str);
  261. X        XtManageChild (trails_w);
  262. X        XtAddCallback(trails_w, XmNvalueChangedCallback, ss_activate_cb,
  263. X                                    TRAILS);
  264. X
  265. X        /* make the object selection buttons */
  266. X
  267. X        for (i = 0, p = nxtbody(-1); p != -1; i++, p = nxtbody(p)) {
  268. X        char buf[3];
  269. X        strncpy (buf, onames[p], 2);
  270. X        buf[2] = '\0';
  271. X        str = XmStringCreate (buf, XmSTRING_DEFAULT_CHARSET);
  272. X        n = 0;
  273. X        XtSetArg (args[n], XmNlabelString, str); n++;
  274. X        /* always turn on Earth (alias MOON) */
  275. X        XtSetArg (args[n], XmNset,
  276. X            (p == MOON) || (propts & (1<<p)) ? True : False); n++;
  277. X        XtSetArg (args[n], XmNindicatorOn, False); n++;
  278. X        XtSetArg (args[n], XmNshadowThickness, 2); n++;
  279. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  280. X        XtSetArg (args[n], XmNbottomWidget, big_w); n++;
  281. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  282. X        XtSetArg (args[n], XmNleftPosition, i*100/NOBJ); n++;
  283. X        pw = XmCreateToggleButtonGadget (ssform_w, "SSPropts", args, n);
  284. X        XtAddCallback(pw, XmNvalueChangedCallback, ss_propts_cb, p);
  285. X        XtManageChild (pw);
  286. X        objs_w[p] = pw;
  287. X        XmStringFree (str);
  288. X        }
  289. X
  290. X        /* make the picked object label */
  291. X
  292. X        str = XmStringCreate(no_name, XmSTRING_DEFAULT_CHARSET);
  293. X        n = 0;
  294. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  295. X        XtSetArg (args[n], XmNbottomWidget, pw); n++;
  296. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  297. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  298. X        XtSetArg (args[n], XmNlabelString, str); n++;
  299. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_CENTER); n++;
  300. X        picked_name_w = XmCreateLabelGadget (ssform_w, "SSPickedName",
  301. X                                    args, n);
  302. X        XtManageChild (picked_name_w);
  303. X        XmStringFree (str);
  304. X
  305. X        /* make the three scales on the edges */
  306. X
  307. X        n = 0;
  308. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  309. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  310. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  311. X        XtSetArg (args[n], XmNbottomWidget, picked_name_w); n++;
  312. X        XtSetArg (args[n], XmNmaximum, 359); n++;
  313. X        XtSetArg (args[n], XmNminimum, 0); n++;
  314. X        XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  315. X        XtSetArg (args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
  316. X        XtSetArg (args[n], XmNshowValue, True); n++;
  317. X        XtSetArg (args[n], XmNvalue, 0); n++;
  318. X        hlng_w = XmCreateScale (ssform_w, "HLongScale", args, n);
  319. X        XtAddCallback (hlng_w, XmNvalueChangedCallback, ss_changed_cb, 0);
  320. X        XtManageChild (hlng_w);
  321. X
  322. X        n = 0;
  323. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  324. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  325. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  326. X        XtSetArg (args[n], XmNbottomWidget, hlng_w); n++;
  327. X        XtSetArg (args[n], XmNdecimalPoints, 1); n++;
  328. X        XtSetArg (args[n], XmNmaximum, 100); n++;
  329. X        XtSetArg (args[n], XmNminimum, 0); n++;
  330. X        XtSetArg (args[n], XmNvalue, 50); n++;
  331. X        XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  332. X        XtSetArg (args[n], XmNprocessingDirection, XmMAX_ON_TOP); n++;
  333. X        /* XtSetArg (args[n], XmNshowValue, True); n++; */
  334. X        hr_w = XmCreateScale (ssform_w, "SSScale", args, n);
  335. X        XtAddCallback (hr_w, XmNvalueChangedCallback, ss_changed_cb, 0);
  336. X        XtManageChild (hr_w);
  337. X
  338. X        n = 0;
  339. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  340. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  341. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  342. X        XtSetArg (args[n], XmNbottomWidget, hlng_w); n++;
  343. X        XtSetArg (args[n], XmNmaximum, 90); n++;
  344. X        XtSetArg (args[n], XmNminimum, -90); n++;
  345. X        XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  346. X        XtSetArg (args[n], XmNprocessingDirection, XmMAX_ON_TOP); n++;
  347. X        XtSetArg (args[n], XmNshowValue, True); n++;
  348. X        XtSetArg (args[n], XmNvalue, 90); n++;
  349. X        hlat_w = XmCreateScale (ssform_w, "HLatScale", args, n);
  350. X        XtAddCallback (hlat_w, XmNvalueChangedCallback, ss_changed_cb, 0);
  351. X        XtManageChild (hlat_w);
  352. X
  353. X        /* make a frame for the drawing area */
  354. X
  355. X        n = 0;
  356. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  357. X        XtSetArg (args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
  358. X        XtSetArg (args[n], XmNbottomWidget, hlng_w); n++;
  359. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  360. X        XtSetArg (args[n], XmNleftWidget, hr_w); n++;
  361. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  362. X        XtSetArg (args[n], XmNrightWidget, hlat_w); n++;
  363. X        XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_OUT); n++;
  364. X        frame_w = XmCreateFrame (ssform_w, "SolarFrame", args, n);
  365. X        XtManageChild (frame_w);
  366. X
  367. X        /* make a drawing area for drawing the solar system */
  368. X
  369. X        n = 0;
  370. X        ssda_w = XmCreateDrawingArea (frame_w, "SolarMap", args, n);
  371. X        XtAddCallback (ssda_w, XmNexposeCallback, ss_da_exp_cb, 0);
  372. X        XtAddCallback (ssda_w, XmNresizeCallback, ss_da_exp_cb, 0);
  373. X        XtAddCallback (ssda_w, XmNinputCallback, ss_da_exp_cb, 0);
  374. X        XtManageChild (ssda_w);
  375. X    }
  376. X    
  377. X    if (XtIsManaged(ssform_w))
  378. X        XtUnmanageChild (ssform_w);
  379. X    else {
  380. X        XtManageChild (ssform_w);
  381. X        ss_update (mm_get_now(), 1);
  382. X    }
  383. }
  384. X
  385. ss_set_objs_on(mask)
  386. int mask;
  387. {
  388. X    propts = mask;
  389. }
  390. X
  391. ss_ison()
  392. {
  393. X    return (ssform_w && XtIsManaged(ssform_w));
  394. }
  395. X
  396. /* called when we are to update our view.
  397. X * don't bother if we are unmanaged unless trails is on - in that case,
  398. X * compute the new locations but don't display them.
  399. X */
  400. ss_update (np, how_much)
  401. Now *np;
  402. int how_much;
  403. {
  404. X    double as = how_much ? 0.0 : 3600.0;
  405. X    Sky sky;
  406. X    HLoc *lp;
  407. X    int up;
  408. X    int p;
  409. X
  410. X    up = ssform_w && XtIsManaged(ssform_w);
  411. X    if (!up && !trails)
  412. X        return;
  413. X
  414. X    if (!trails) {
  415. X        if (points)
  416. X        XtFree ((char*)points);
  417. X        points = 0;
  418. X        npoints = 0;
  419. X    }
  420. X
  421. X    /* always make one entry for the sun */
  422. X    if (npoints == 0) {
  423. X        points = (HLoc *) XtMalloc (sizeof(HLoc));
  424. X        points->x = 0.0;
  425. X        points->y = 0.0;
  426. X        points->z = 0.0;
  427. X        points->p = SUN;
  428. X        npoints = 1;
  429. X    }
  430. X
  431. X    /* tag earth's data (from SUN object) as object MOON */
  432. X    for (p = nxtbody(-1); p != -1; p = nxtbody(p)) {
  433. X        double sd;
  434. X        if (p==MOON || ((p==OBJX || p==OBJY) && !obj_ison(p)))
  435. X        continue;
  436. X        (void) body_cir (p, as, np, &sky);
  437. X        if (sky.s_hlong == NOHELIO)
  438. X        continue;
  439. X        npoints++;
  440. X        points = (HLoc *) XtRealloc ((char *)points, npoints*sizeof(HLoc));
  441. X        lp = &points[npoints-1];
  442. X        sd = (p == SUN) ? sky.s_edist : sky.s_sdist;
  443. X        lp->x = sd*cos(sky.s_hlat)*cos(sky.s_hlong);
  444. X        lp->y = sd*cos(sky.s_hlat)*sin(sky.s_hlong);
  445. X        lp->z = sd*sin(sky.s_hlat);
  446. X        lp->p = p == SUN ? MOON : p;
  447. X    }
  448. X
  449. X    if (up)
  450. X        ss_all(!trails);
  451. X        
  452. }
  453. X
  454. /* callback from the toggle buttons
  455. X */
  456. void
  457. ss_activate_cb (w, client, call)
  458. Widget w;
  459. caddr_t client;
  460. caddr_t call;
  461. {
  462. X    int what = (int) client;
  463. X
  464. X    switch (what) {
  465. X    case TRAILS:
  466. X        trails = XmToggleButtonGadgetGetState(w);
  467. X        break;
  468. X    case BIGDOTS:
  469. X        bigdots = XmToggleButtonGadgetGetState(w);
  470. X        ss_all (1);
  471. X        break;
  472. X    default:
  473. X        printf ("unknown toggle button\n");
  474. X        break;
  475. X    }
  476. }
  477. X
  478. /* callback from the toggle on/off button
  479. X */
  480. void
  481. ss_toggle_cb (w, client, call)
  482. Widget w;
  483. caddr_t client;
  484. caddr_t call;
  485. {
  486. X    int p;
  487. X
  488. X    for (p = nxtbody(-1); p != -1; p = nxtbody(p)) {
  489. X        int s = XmToggleButtonGadgetGetState(objs_w[p]);
  490. X        if (s) propts &= ~(1<<p);
  491. X        else   propts |= 1<<p;
  492. X        XmToggleButtonGadgetSetState(objs_w[p], !s, False /*don't invoke*/);
  493. X    }
  494. X    ss_all (1);
  495. X        
  496. }
  497. X
  498. /* callback from the toggle buttons for each object.
  499. X * set the onoff flag in the points array for the planet whose code is in
  500. X * client, then redraw.
  501. X */
  502. void
  503. ss_propts_cb (w, client, call)
  504. Widget w;
  505. caddr_t client;
  506. caddr_t call;
  507. {
  508. X    int p = (int) client;
  509. X
  510. X    if (XmToggleButtonGadgetGetState(w))    propts |= 1<<p;
  511. X    else                        propts &= ~(1<<p);
  512. X    ss_all (1);
  513. }
  514. X
  515. /* callback when any of the scales change value.
  516. X */
  517. void
  518. ss_changed_cb (w, client, call)
  519. Widget w;
  520. caddr_t client;
  521. caddr_t call;
  522. {
  523. X    /*
  524. X    XmScaleCallbackStruct *s = (XmScaleCallbackStruct *) call;
  525. X    */
  526. X
  527. X    if (w != hr_w && w != hlng_w && w != hlat_w) {
  528. X        printf ("Unknown scaled callback\n");
  529. X        return;
  530. X    }
  531. X
  532. X    ss_all(1);
  533. }
  534. X
  535. /* callback from the Close button.
  536. X */
  537. void
  538. ss_close_cb (w, client, call)
  539. Widget w;
  540. caddr_t client;
  541. caddr_t call;
  542. {
  543. X    XtUnmanageChild (ssform_w);
  544. }
  545. X
  546. /* callback from the Help button.
  547. X */
  548. void
  549. ss_help_cb (w, client, call)
  550. Widget w;
  551. caddr_t client;
  552. caddr_t call;
  553. {
  554. X    static char *msg[] = {
  555. "This displays the solar system. The sun is always at the center. The left",
  556. "slider controls your distance from the sun - further up is closer. The",
  557. "bottom slider controls your heliocentric longitude. The right slider controls",
  558. "your heliocentric latitude - your angle above the ecliptic."
  559. };
  560. X
  561. X    hlp_dialog ("Solar System View", msg, sizeof(msg)/sizeof(msg[0]));
  562. }
  563. X
  564. /* expose (or reconfig) of solar system drawing area.
  565. X * redraw the scene to the (new?) size.
  566. X * also, input callback when picking a dot for identification.
  567. X */
  568. static void
  569. ss_da_exp_cb (w, client, call)
  570. Widget w;
  571. caddr_t client;
  572. caddr_t call;
  573. {
  574. X    XmDrawingAreaCallbackStruct *c = (XmDrawingAreaCallbackStruct *)call;
  575. X
  576. X    switch (c->reason) {
  577. X    case XmCR_RESIZE:
  578. X        /* seems we can get one resize before the first expose.
  579. X         * hence, we don't have a good window to use yet. just let it
  580. X         * go; we'll get the expose soon.
  581. X         */
  582. X        if (!XtWindow(w))
  583. X        return;
  584. X        break;
  585. X    case XmCR_EXPOSE: {
  586. X        XExposeEvent *e = &c->event->xexpose;
  587. X        /* wait for the last in the series */
  588. X        if (e->count != 0)
  589. X        return;
  590. X        break;
  591. X        }
  592. X    case XmCR_INPUT:
  593. X        ss_identify (c->event);
  594. X        return;
  595. X    default:
  596. X        printf ("Unexpected ssda_w event. type=%d\n", c->reason);
  597. X        return;
  598. X    }
  599. X
  600. X    ss_update (mm_get_now(), 1);
  601. }
  602. X
  603. /* a dot has been picked: find what it is and report it. */
  604. static
  605. ss_identify (ev)
  606. XXEvent *ev;
  607. {
  608. #define    PICKRANGE    36    /* sqr of dist allowed from pointer */
  609. X    int x, y, mind, mini;
  610. X    int i;
  611. X    char *name;
  612. X
  613. X    switch (ev->type) {
  614. X    case ButtonPress:
  615. X        x = ((XButtonPressedEvent *)ev)->x;
  616. X        y = ((XButtonPressedEvent *)ev)->y;
  617. X        mini = -1;
  618. X        for (i = 0; i < npoints; i++) {
  619. X            if (propts & (1<<points[i].p)) {
  620. X            int d = (x-points[i].sx)*(x-points[i].sx) +
  621. X                        (y-points[i].sy)*(y-points[i].sy);
  622. X            if (mini < 0 || d < mind) {
  623. X            mini = i;
  624. X            mind = d;
  625. X            }
  626. X        }
  627. X        }
  628. X        if (mini >= 0 && mind <= PICKRANGE) {
  629. X        extern char *obj_getname();
  630. X        int p = points[mini].p;
  631. X        if (p >= MERCURY && p <= MOON)
  632. X            name = onames[p];
  633. X        else if (p == OBJX || p == OBJY)
  634. X            name = obj_getname(p);
  635. X        else
  636. X            name = "?";
  637. X        } else
  638. X        name = no_name;
  639. X        f_string (picked_name_w, name);
  640. X        break;
  641. X    }
  642. }
  643. X
  644. /* draw everything in the points array from the current vantage to the
  645. X * current screen size.
  646. X */
  647. static
  648. ss_all(preclr)
  649. int preclr;
  650. {
  651. X    static GC ss_fgc;
  652. X    unsigned int nx, ny;
  653. X    Window root;
  654. X    int x, y;
  655. X    unsigned int bw, d;
  656. X    Display *dsp = XtDisplay(ssda_w);
  657. X    Window win = XtWindow(ssda_w);
  658. X    int i;
  659. X
  660. X    if (!ss_fgc) {
  661. X        XGCValues gcv;
  662. X        unsigned int gcm;
  663. X        gcm = GCForeground;
  664. X        get_something (ssda_w, XmNforeground, (char *)&gcv.foreground);
  665. X        ss_fgc = XCreateGC (dsp, win, gcm, &gcv);
  666. X    }
  667. X
  668. X    XGetGeometry(dsp, win, &root, &x, &y, &nx, &ny, &bw, &d);
  669. X
  670. X    if (preclr) {
  671. X        XClearWindow (dsp, win);
  672. X        /* make a cross for the sun */
  673. X        if (propts & (1<<SUN)) {
  674. X        XDrawLine (dsp, win, ss_fgc, nx/2, ny/2-2, nx/2, ny/2+2);
  675. X        XDrawLine (dsp, win, ss_fgc, nx/2-2, ny/2, nx/2+2, ny/2);
  676. X        }
  677. X    }
  678. X
  679. X    /* display each point */
  680. X    for (i = 0; i < npoints; i++)
  681. X        if (propts & (1<<points[i].p))
  682. X        solar_system(dsp, win, ss_fgc, i, nx, ny);
  683. }
  684. X
  685. /* draw points[i] on screen of size [nx,ny]. */
  686. static
  687. solar_system(dsp, win, gc, i, nx, ny)
  688. Display *dsp;
  689. Window win;
  690. GC gc;
  691. int i;        /* points[] index */
  692. int nx, ny;    /* size of drawing area, in pixels */
  693. {
  694. X    int sv;        /* ScaleValue tmp */
  695. X    double scale;
  696. X    double elt;    /* heliocentric lat of eye, rads */
  697. X    double elg;    /* heliocentric lng of eye, rads */
  698. X    double x, y, z;    /* progressive transform values... */
  699. X    double xp, yp, zp;
  700. X    double xpp, ypp;
  701. X    double tmp;
  702. X    int sx, sy;
  703. X
  704. X    XmScaleGetValue (hr_w, &sv);
  705. X    scale = 3. * pow (50./3., sv/100.); /* 3 to 50x, geometricly */
  706. X    XmScaleGetValue (hlat_w, &sv);
  707. X    elt = degrad(sv);
  708. X    XmScaleGetValue (hlng_w, &sv);
  709. X    elg = degrad(sv);
  710. X
  711. X    /* initial loc of points[i] */
  712. X    x = points[i].x;
  713. X    y = points[i].y;
  714. X    z = points[i].z;
  715. X
  716. X    /* rotate by -elg about z axis to get to -yz plane.
  717. X     * once we rotate up about x to the z axis (next step) that will put
  718. X     * +x to the right and +y up.
  719. X     */
  720. X    tmp = -elg;
  721. X    xp = x*cos(tmp) - y*sin(tmp);
  722. X    yp = x*sin(tmp) + y*cos(tmp);
  723. X    zp = z;
  724. X
  725. X    /* rotate by -(PI/2-elt) about x axis to get to z axis */
  726. X    tmp = -(PI/2-elt);
  727. X    xpp = xp;
  728. X    ypp = yp*cos(tmp) - zp*sin(tmp);
  729. X    /* NOT USED: zpp = yp*sin(tmp) + zp*cos(tmp); */
  730. X
  731. X    /* now, straight ortho projection */
  732. X    sx = nx/2 + xpp*scale;
  733. X    sy = ny/2 - ypp*scale;
  734. X
  735. X    if (bigdots) {
  736. X        XDrawPoint (dsp, win, gc, sx, sy);
  737. X        XDrawPoint (dsp, win, gc, sx+1, sy);
  738. X        XDrawPoint (dsp, win, gc, sx, sy+1);
  739. X        XDrawPoint (dsp, win, gc, sx+1, sy+1);
  740. X    } else
  741. X        XDrawPoint (dsp, win, gc, sx, sy);
  742. X
  743. X    points[i].sx = sx;
  744. X    points[i].sy = sy;
  745. }
  746. SHAR_EOF
  747. chmod 0644 solarsys.c ||
  748. echo 'restore of solarsys.c failed'
  749. Wc_c="`wc -c < 'solarsys.c'`"
  750. test 18782 -eq "$Wc_c" ||
  751.     echo 'solarsys.c: original size 18782, current size' "$Wc_c"
  752. rm -f _shar_wnt_.tmp
  753. fi
  754. # ============= srch.c ==============
  755. if test -f 'srch.c' -a X"$1" != X"-c"; then
  756.     echo 'x - skipping srch.c (File already exists)'
  757.     rm -f _shar_wnt_.tmp
  758. else
  759. > _shar_wnt_.tmp
  760. echo 'x - extracting srch.c (Text)'
  761. sed 's/^X//' << 'SHAR_EOF' > 'srch.c' &&
  762. /* this file contains functions to support iterative xephem searches.
  763. X * we support several kinds of searching and solving algorithms.
  764. X * values used in the evaluations come from the field logging flog.c system.
  765. X * the expressions being evaluated are compiled and executed from compiler.c.
  766. X */
  767. X
  768. #include <stdio.h>
  769. #include <ctype.h>
  770. #include <math.h>
  771. #ifdef VMS
  772. #include <stdlib.h>
  773. #endif
  774. #include <X11/Xlib.h>
  775. #include <Xm/Xm.h>
  776. #include <Xm/Form.h>
  777. #include <Xm/Frame.h>
  778. #include <Xm/LabelG.h>
  779. #include <Xm/PushBG.h>
  780. #include <Xm/RowColumn.h>
  781. #include <Xm/SeparatoG.h>
  782. #include <Xm/SelectioB.h>
  783. #include <Xm/ToggleBG.h>
  784. #include <Xm/Text.h>
  785. #include "fieldmap.h"
  786. /* N.B. if you need circum.h for something, beware of the height #define - it
  787. X * interferes with the height member of the XResizeRequestEvent structure.
  788. X */
  789. X
  790. extern Widget toplevel_w;
  791. #define    XtD    XtDisplay(toplevel_w)
  792. X
  793. /* locations of each field.
  794. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  795. X * historical reasons.
  796. X */
  797. #define    NR        13
  798. #define    NC        35
  799. X
  800. #define    R_ON        1
  801. #define    C_ON        1
  802. #define    R_GOALBOX    1
  803. #define    C_GOALBOX    20
  804. X
  805. #define    R_SEP1        4
  806. X
  807. #define    R_ACCULABEL    5
  808. #define    C_ACCULABEL    1
  809. #define    R_ACCU        5
  810. #define    C_ACCU        25
  811. X
  812. #define    R_SEP2        6
  813. X
  814. #define    R_FIELDS    7
  815. #define    C_FIELDS    1
  816. #define    R_COMPILE    7
  817. #define    C_COMPILE    26
  818. #define    R_FUNC        8
  819. #define    C_FUNC        1
  820. #define    R_ERRS        9
  821. #define    C_ERRS        1
  822. #define    R_USE        10
  823. #define    R_VALUE        11
  824. #define    C_VALUE        17
  825. X
  826. #define    R_SEP3        12
  827. X
  828. #define    R_HELP        13
  829. #define    R_CLOSE        13
  830. X
  831. /* the widgets we need direct access to */
  832. static Widget srchform_w;
  833. static Widget help_w;
  834. static Widget acc_w;
  835. static Widget field_w;
  836. static Widget func_w;    /* contains the search function [to be] compiled */
  837. static Widget err_w;
  838. static Widget valu_w;    /* used to display most recent calulated value */
  839. static Widget use_w;    /* use to select srch value for use in plotting */
  840. static Widget on_w;    /* whether searching is active comes directly from this
  841. X             * widget's XmToggleButtonGadgetGetState()
  842. X             */
  843. X
  844. static int srch_minmax(), srch_solve0(), srch_binary();
  845. X
  846. static int (*srch_f)();        /* 0 or pointer to one of the search functions*/
  847. static int srch_tmscalled;    /* number of iterations so far */
  848. static double tmlimit = 1./60.;    /* search accuracy, in hrs; def is one minute */
  849. X
  850. static int srch_selecting;    /* whether our value is currently selectable */
  851. X
  852. /* called when the search menu is activated via the main menu pulldown.
  853. X * if never called before, create and manage all the widgets as a child of a
  854. X * form. otherwise, just toggle whether the form is managed.
  855. X */
  856. srch_manage ()
  857. {
  858. X    if (!srchform_w) {
  859. X        void srch_help_cb();
  860. X        void srch_goal_cb();
  861. X        void srch_compile_cb();
  862. X        void srch_on_off_cb();
  863. X        void srch_close_cb();
  864. X        void srch_acc_cb();
  865. X        void srch_use_cb();
  866. X        void srch_fields_cb();
  867. X        XmString str;
  868. X        Widget w, rb_w;
  869. X        Arg args[20];
  870. X        int x, y;
  871. X        int i, n;
  872. X
  873. X        /* get location of our main app menu and place nearby */
  874. X        n = 0;
  875. X        XtSetArg (args[n], XmNx, &x); n++;
  876. X        XtSetArg (args[n], XmNy, &y); n++;
  877. X        XtGetValues (toplevel_w, args, n);
  878. X
  879. X        /* create and set size of form to hold NR and NC */
  880. X        n = 0;
  881. X        XtSetArg (args[n], XmNfractionBase, 1000); n++;
  882. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  883. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  884. X        XtSetArg (args[n], XmNresizePolicy, XmRESIZE_NONE); n++;
  885. X        srchform_w = XmCreateFormDialog (toplevel_w, "Srch", args, n);
  886. X
  887. X        /* set some stuff in the parent DialogShell.
  888. X         * setting XmNdialogTitle in the Form didn't work..
  889. X         */
  890. X        n = 0;
  891. X        XtSetArg (args[n], XmNtitle, "xephem Search Control"); n++;
  892. X        XtSetValues (XtParent(srchform_w), args, n);
  893. X
  894. X        /* first separator */
  895. X
  896. X        n = 0;
  897. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  898. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_SEP1)); n++;
  899. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  900. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  901. X        XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  902. X        (void) XtCreateManagedWidget ("SrchSep1",
  903. X                    xmSeparatorGadgetClass, srchform_w, args, n);
  904. X
  905. X        /* searching on/off toggle button */
  906. X
  907. X        n = 0;
  908. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  909. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_ON)); n++;
  910. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  911. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_ON)); n++;
  912. X        on_w = XmCreateToggleButtonGadget (srchform_w, "On", args, n);
  913. X        XtAddCallback (on_w, XmNvalueChangedCallback, srch_on_off_cb, 0);
  914. X        XtManageChild (on_w);
  915. X
  916. X        /* create goal radio box and its toggle buttons in a frame */
  917. X
  918. X        n = 0;
  919. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  920. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_GOALBOX)); n++;
  921. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  922. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_GOALBOX)); n++;
  923. X        w = XmCreateFrame (srchform_w, "SrchGoalRadioBoxFrame", args, n);
  924. X        XtManageChild (w);
  925. X
  926. X        n = 0;
  927. X        XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  928. X        rb_w = XmCreateRadioBox (w, "SrchGoalRadioBox", args, n);
  929. X        XtManageChild (rb_w);
  930. X
  931. X        n = 0;
  932. X        /* XtSetArg (args[n], XmNset, True); n++; NO DEFAULT */
  933. X        str = XmStringCreate("Find Extreme", XmSTRING_DEFAULT_CHARSET);
  934. X        XtSetArg (args[n], XmNlabelString, str); n++;
  935. X        w = XmCreateToggleButtonGadget (rb_w, "SrchExtreme", args, n);
  936. X        XtAddCallback (w, XmNvalueChangedCallback, srch_goal_cb,
  937. X                            (int)srch_minmax);
  938. X        XtManageChild (w);
  939. X        XmStringFree(str);
  940. X
  941. X        n = 0;
  942. X        str = XmStringCreate("Find 0", XmSTRING_DEFAULT_CHARSET);
  943. X        XtSetArg (args[n], XmNlabelString, str); n++;
  944. X        w = XmCreateToggleButtonGadget (rb_w, "Srch0", args, n);
  945. X        XtAddCallback (w, XmNvalueChangedCallback, srch_goal_cb,    
  946. X                            (int)srch_solve0);
  947. X        XtManageChild (w);
  948. X        XmStringFree(str);
  949. X
  950. X        n = 0;
  951. X        str = XmStringCreate("Binary", XmSTRING_DEFAULT_CHARSET);
  952. X        XtSetArg (args[n], XmNlabelString, str); n++;
  953. X        w = XmCreateToggleButtonGadget (rb_w, "SrchBinary", args, n);
  954. X        XtAddCallback (w, XmNvalueChangedCallback, srch_goal_cb,
  955. X                            (int)srch_binary);
  956. X        XtManageChild (w);
  957. X        XmStringFree(str);
  958. X
  959. X        /* center separator */
  960. X
  961. X        n = 0;
  962. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  963. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_SEP2)); n++;
  964. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  965. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  966. X        XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  967. X        (void) XtCreateManagedWidget ("SrchSep2",
  968. X                xmSeparatorGadgetClass, srchform_w, args, n);
  969. X
  970. X        /* Accuracy label and its push button */
  971. X
  972. X        n = 0;
  973. X        str = XmStringCreate("Accuracy:", XmSTRING_DEFAULT_CHARSET);
  974. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  975. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_ACCULABEL)); n++;
  976. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  977. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_ACCULABEL)); n++;
  978. X        XtSetArg (args[n], XmNlabelString, str); n++;
  979. X        w = XmCreateLabelGadget (srchform_w, "SrchAccL", args, n);
  980. X        XmStringFree (str);
  981. X        XtManageChild (w);
  982. X
  983. X        n = 0;
  984. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  985. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_ACCU)); n++;
  986. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  987. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_ACCU)); n++;
  988. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  989. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  990. X        acc_w = XmCreatePushButtonGadget (srchform_w, "SrchAcc", args, n);
  991. X        XtAddCallback (acc_w, XmNactivateCallback, srch_acc_cb, 0);
  992. X        f_time (acc_w, tmlimit);
  993. X        XtManageChild (acc_w);
  994. X
  995. X        /* bottom separator */
  996. X
  997. X        n = 0;
  998. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  999. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_SEP3)); n++;
  1000. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1001. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1002. X        XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  1003. X        (void) XtCreateManagedWidget ("SrchSep3",
  1004. X                    xmSeparatorGadgetClass, srchform_w, args, n);
  1005. X
  1006. X        /* use fields button */
  1007. X
  1008. X        n = 0;
  1009. X        str = XmStringCreate("Enable field buttons",
  1010. X                            XmSTRING_DEFAULT_CHARSET);
  1011. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1012. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1013. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_FIELDS)); n++;
  1014. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1015. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_FIELDS)); n++;
  1016. X        field_w = XmCreateToggleButtonGadget (srchform_w,
  1017. X                            "SrchField", args, n);
  1018. X        XtAddCallback (field_w, XmNvalueChangedCallback, srch_fields_cb, 0);
  1019. X        XtManageChild (field_w);
  1020. X        XmStringFree(str);
  1021. X
  1022. X        /* COMPILE push button */
  1023. X
  1024. X        n = 0;
  1025. X        str = XmStringCreate ("Compile", XmSTRING_DEFAULT_CHARSET);
  1026. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1027. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1028. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_COMPILE)); n++;
  1029. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1030. X        XtSetArg (args[n], XmNshowAsDefault, True); n++;
  1031. X        w = XmCreatePushButtonGadget (srchform_w, "SrchCompile", args, n);
  1032. X        XtAddCallback (w, XmNactivateCallback, srch_compile_cb, 0);
  1033. X        XtManageChild (w);
  1034. X        XmStringFree (str);
  1035. X        set_something (srchform_w, XmNdefaultButton, w);
  1036. X
  1037. X        /* function text */
  1038. X
  1039. X        n = 0;
  1040. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1041. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_FUNC)); n++;
  1042. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1043. X        XtSetArg (args[n], XmNleftPosition, 50); n++;
  1044. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1045. X        XtSetArg (args[n], XmNrightPosition, 950); n++;
  1046. X        func_w = XmCreateText (srchform_w, "SrchFunction", args, n);
  1047. X        XtManageChild (func_w);
  1048. X        XmTextSetString (func_w, "");
  1049. X
  1050. X        /* compiler message label */
  1051. X
  1052. X        str = XmStringCreate ("", XmSTRING_DEFAULT_CHARSET);
  1053. X        n = 0;
  1054. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1055. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_ERRS)); n++;
  1056. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1057. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1058. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
  1059. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1060. X        err_w = XmCreateLabelGadget (srchform_w, "SrchErrsL", args, n);
  1061. X        XtManageChild (err_w);
  1062. X        XmStringFree (str);
  1063. X
  1064. X        /* button to select using for plotting. 
  1065. X         * ONLY MANAGED WHEN WE ARE TOLD TO SELECT FOR PLOTTING.
  1066. X         */
  1067. X
  1068. X        n = 0;
  1069. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1070. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_USE)); n++;
  1071. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1072. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1073. X        use_w = XmCreatePushButtonGadget (srchform_w, "SrchUse",
  1074. X                                    args, n);
  1075. X        XtAddCallback (use_w, XmNactivateCallback, srch_use_cb, 0);
  1076. X        set_xmstring (use_w, XmNlabelString, "Use for plotting");
  1077. X
  1078. X        /* current search function evaluation labels */
  1079. X
  1080. X        str = XmStringCreate ("Current value: ", XmSTRING_DEFAULT_CHARSET);
  1081. X        n = 0;
  1082. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1083. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_VALUE)); n++;
  1084. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1085. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1086. X        w = XmCreateLabelGadget (srchform_w, "SrchValuL", args, n);
  1087. X        XtManageChild (w);
  1088. X        XmStringFree (str);
  1089. X
  1090. X        str = XmStringCreate ("", XmSTRING_DEFAULT_CHARSET);
  1091. X        n = 0;
  1092. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1093. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_VALUE)); n++;
  1094. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1095. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_VALUE)); n++;
  1096. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1097. X        XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  1098. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1099. X        valu_w = XmCreateLabelGadget (srchform_w, "SrchValu", args, n);
  1100. X        XtManageChild (valu_w);
  1101. X        XmStringFree (str);
  1102. X
  1103. X        /* make the HELP control */
  1104. X
  1105. X        str = XmStringCreate("Help", XmSTRING_DEFAULT_CHARSET);
  1106. X        n = 0;
  1107. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1108. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_HELP)); n++;
  1109. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  1110. X        XtSetArg (args[n], XmNrightPosition, 1000); n++;
  1111. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1112. X        help_w = XmCreatePushButtonGadget(srchform_w, "SrchHelp", args, n);
  1113. X        XmStringFree (str);
  1114. X        XtManageChild (help_w);
  1115. X        XtAddCallback(help_w, XmNactivateCallback, srch_help_cb, 0);
  1116. X
  1117. X        /* make the CLOSE control */
  1118. X
  1119. X        str = XmStringCreate("Close", XmSTRING_DEFAULT_CHARSET);
  1120. X        n = 0;
  1121. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  1122. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CLOSE)); n++;
  1123. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  1124. X        XtSetArg (args[n], XmNleftPosition, 0); n++;
  1125. X        XtSetArg (args[n], XmNlabelString, str); n++;
  1126. X        w = XmCreatePushButtonGadget(srchform_w, "SrchClose", args,n);
  1127. X        XmStringFree (str);
  1128. X        XtManageChild (w);
  1129. X        XtAddCallback(w, XmNactivateCallback, srch_close_cb, 0);
  1130. X    }
  1131. X    
  1132. X    if (XtIsManaged(srchform_w))
  1133. X        XtUnmanageChild (srchform_w);
  1134. X    else {
  1135. X        XtManageChild (srchform_w);
  1136. X        srch_set_buttons(srch_selecting);
  1137. X    }
  1138. }
  1139. X
  1140. /* called by other menus as they want to hear from our buttons or not.
  1141. X * the "on"s and "off"s stack - only really redo the buttons if it's the
  1142. X * first on or the last off.
  1143. X */
  1144. srch_selection_mode (whether)
  1145. int whether;    /* whether setting up for plotting or for not plotting */
  1146. {
  1147. X    srch_selecting += whether ? 1 : -1;
  1148. X
  1149. X    if (srchform_w && XtIsManaged(srchform_w))
  1150. X        if (whether && srch_selecting == 1     /* first one to want on */
  1151. X        || !whether && srch_selecting == 0 /* last one to want off */)
  1152. X        srch_set_buttons (whether);
  1153. }
  1154. X
  1155. /* go through all the buttons pickable for plotting and set whether they
  1156. X * should appear to look like buttons.
  1157. X */
  1158. static
  1159. srch_set_buttons (whether)
  1160. int whether;    /* whether setting up for plotting or for not plotting */
  1161. {
  1162. X    if (whether)
  1163. X        XtManageChild (use_w);
  1164. X    else
  1165. X        XtUnmanageChild (use_w);
  1166. }
  1167. X
  1168. /* called when other modules, such as data or riset menu, have a button pushed
  1169. X * and we have asked (by enabling field buttons) that they inform us that
  1170. X * that button is to be included in the search function.
  1171. X * other modules that use buttons, such as plotting and listing, might ask
  1172. X * too so it might not really be us that wants to use it.
  1173. X */
  1174. srch_selection (fp)
  1175. FieldMap *fp;
  1176. {
  1177. X    int ins;
  1178. X
  1179. X    if (!srchform_w
  1180. X        || !XtIsManaged(srchform_w)
  1181. X        || !XmToggleButtonGadgetGetState(field_w))
  1182. X        return;
  1183. X
  1184. X    ins = XmTextGetInsertionPosition (func_w);
  1185. X    XmTextReplace (func_w, /* from */ ins, /* to */ ins, fp->name);
  1186. X
  1187. X    /* move the focus right back to the search menu so the insertion point
  1188. X     * remains visible.
  1189. X     */
  1190. X    XSetInputFocus (XtDisplay(srchform_w), XtWindow(srchform_w),
  1191. X                        RevertToParent, CurrentTime);
  1192. }
  1193. X
  1194. /* if searching is in effect call the search type function.
  1195. X * it might modify *tmincp according to where it next wants to eval.
  1196. X * (remember tminc is in hours, not days).
  1197. X * if searching ends for any reason it is also turned off.
  1198. X * flog the new value.
  1199. X * if we are not searching but are plotting or listing we still execute the
  1200. X *   search function (if it is ok) and flog and display it.
  1201. X * return 0 if caller can continue or -1 if it is time to stop.
  1202. X */
  1203. srch_eval(mjd, tmincp)
  1204. double mjd;
  1205. double *tmincp;
  1206. {
  1207. X    int s;
  1208. X
  1209. X    if (prog_isgood() && (srch_ison() || plot_ison() || listing_ison())) {
  1210. X        char errbuf[128];
  1211. X        double v;
  1212. X        s = execute_expr (&v, errbuf);
  1213. X        if (s == 0) {
  1214. X        f_double (valu_w, "%g", v);
  1215. X        if (srch_ison()) {
  1216. X            s = (*srch_f)(mjd, v, tmincp);
  1217. X            srch_tmscalled++;
  1218. X        }
  1219. X        } else {
  1220. X        char srchmsg[256];
  1221. X        sprintf (srchmsg, "Search evaluation error: %s", errbuf);
  1222. X        f_msg (srchmsg, 0);
  1223. X        }
  1224. X    } else
  1225. X        s = 0;
  1226. X
  1227. X    if (s < 0)
  1228. X        XmToggleButtonGadgetSetState(on_w, False, /*invoke cb*/True);
  1229. X
  1230. X    return (s);
  1231. }
  1232. X
  1233. /* return 0 if searching in presently off, else something else.  */
  1234. srch_ison()
  1235. {
  1236. X    return (on_w && XmToggleButtonGadgetGetState(on_w));
  1237. }
  1238. X
  1239. /* callback from the "use" button.
  1240. X * if plotting or listing has put us in selecting mode, we look like a button
  1241. X * and we should inform them we have been picked.
  1242. X * otherwise, we do nothing (we didn't look like a button anyway).
  1243. X */
  1244. static void
  1245. srch_use_cb (w, client, call)
  1246. Widget w;
  1247. caddr_t client;
  1248. caddr_t call;
  1249. {
  1250. X    static char msg[] =
  1251. X        "You must first successfully compile a search\nfunction before value may be selected.";
  1252. X    static FieldMap vfm = {
  1253. X        mkid (R_VALUE, 1),
  1254. X        PLT,
  1255. X        0,
  1256. X        0,
  1257. X        "SrchValue",
  1258. X        0
  1259. X    };
  1260. X
  1261. X    if (srch_selecting) {
  1262. X        if (prog_isgood()) {
  1263. X        vfm.w = valu_w;
  1264. X        plt_selection (&vfm);
  1265. X        lst_selection (&vfm);
  1266. X        } else
  1267. X        f_msg (msg, 1);
  1268. X    }
  1269. }
  1270. X
  1271. /* callback from the compile button.
  1272. X */
  1273. static void
  1274. srch_compile_cb (w, client, call)
  1275. Widget w;
  1276. caddr_t client;
  1277. caddr_t call;
  1278. {
  1279. X    char *newexp;
  1280. X    char errbuf[256];
  1281. X
  1282. X    newexp = XmTextGetString (func_w);
  1283. X    if (compile_expr (newexp, errbuf) < 0) {
  1284. X        set_xmstring (err_w, XmNlabelString, errbuf);
  1285. X    } else {
  1286. X        set_xmstring (err_w, XmNlabelString, "<no compile errors>");
  1287. X    }
  1288. X    XtFree (newexp);
  1289. X
  1290. X    /* as a courtesy, turn off searching if it's currently active */
  1291. X    if (XmToggleButtonGadgetGetState(on_w))
  1292. X        XmToggleButtonGadgetSetState(on_w, False, True/*invoke cb*/);
  1293. }
  1294. X
  1295. /* callback from the help button.
  1296. X */
  1297. static void
  1298. srch_help_cb (w, client, call)
  1299. Widget w;
  1300. caddr_t client;
  1301. caddr_t call;
  1302. {
  1303. static char *help_msg[] = {
  1304. "This menu controls the automatic searching facility. You define an arithmetic",
  1305. "or boolean function, using most of the fields xephem displays, then xephem",
  1306. "will automatically evaluate the function and adjust the time on each",
  1307. "iteration to search for the goal.",
  1308. "",
  1309. "To perform a search:",
  1310. "   enter a function,",
  1311. "   compile it,",
  1312. "   select a goal,",
  1313. "   set the desired accuracy,",
  1314. "   enable searching,",
  1315. "   perform the search by stepping xephem."
  1316. };
  1317. X
  1318. X    hlp_dialog ("Search", help_msg, sizeof(help_msg)/sizeof(help_msg[0]));
  1319. }
  1320. X
  1321. /* callback from the "field enable" push button.
  1322. X * inform the other menues whether we are setting up for them to tell us
  1323. X * what fields to plot.
  1324. X */
  1325. static void
  1326. srch_fields_cb (w, client, call)
  1327. Widget w;
  1328. caddr_t client;
  1329. caddr_t call;
  1330. {
  1331. X    int whether = XmToggleButtonGadgetGetState(w);;
  1332. X
  1333. X    dm_selection_mode(whether);
  1334. X    mm_selection_mode(whether);
  1335. X    rm_selection_mode(whether);
  1336. X    sm_selection_mode(whether);
  1337. X    jm_selection_mode(whether);
  1338. }
  1339. X
  1340. /* callback from the Close button.
  1341. X */
  1342. static void
  1343. srch_close_cb (w, client, call)
  1344. Widget w;
  1345. caddr_t client;
  1346. caddr_t call;
  1347. {
  1348. X    XtUnmanageChild (srchform_w);
  1349. }
  1350. X
  1351. /* user typed OK to the accuracy prompt. get his new value and use it */
  1352. static void
  1353. srch_acc_ok_cb (w, client, call)
  1354. Widget w;
  1355. caddr_t client;
  1356. caddr_t call;
  1357. {
  1358. X    int hrs, mins, secs;
  1359. X    char *text;
  1360. X    
  1361. X    f_dec_sexsign (tmlimit, &hrs, &mins, &secs);
  1362. X    get_xmstring(w, XmNtextString, &text);
  1363. X    f_sscansex (text, &hrs, &mins, &secs);
  1364. X    XtFree (text);
  1365. X    sex_dec (hrs, mins, secs, &tmlimit);
  1366. X    f_time (acc_w, tmlimit);
  1367. X    XtDestroyWidget (w);
  1368. }
  1369. X
  1370. /* callback from the accuracy-change-request pushbutton.
  1371. X * put up a prompt dialog to ask for a new value.
  1372. X */
  1373. static void
  1374. srch_acc_cb (w, client, call)
  1375. Widget w;
  1376. caddr_t client;
  1377. caddr_t call;
  1378. {
  1379. X    Widget w, dw;
  1380. X    XmString str;
  1381. X    Arg args[20];
  1382. X    int n;
  1383. X    
  1384. X    str = XmStringCreate ("search accuracy (h:m:s):",
  1385. X                            XmSTRING_DEFAULT_CHARSET);
  1386. X    n = 0;
  1387. X    XtSetArg(args[n], XmNselectionLabelString, str);  n++;
  1388. X    dw = XmCreatePromptDialog(toplevel_w, "xephem Accuracy", args, n);
  1389. X    w = XmSelectionBoxGetChild (dw, XmDIALOG_HELP_BUTTON);
  1390. X    XtUnmanageChild (w);
  1391. X    XmStringFree (str);
  1392. X    XtAddCallback (dw, XmNokCallback, srch_acc_ok_cb, 0);
  1393. X    XtManageChild (dw);
  1394. X    w = XmSelectionBoxGetChild (dw, XmDIALOG_TEXT);
  1395. X    XmProcessTraversal (w, XmTRAVERSE_CURRENT);
  1396. X    XmProcessTraversal (w, XmTRAVERSE_CURRENT); /* yes, twice!! */
  1397. }
  1398. X
  1399. /* callback from the search goal selection radio buttons.
  1400. X * same callback used for all of them.
  1401. X * client is pointer to desired search function.
  1402. X */
  1403. static void
  1404. srch_goal_cb(w, client, call)
  1405. Widget w;
  1406. caddr_t client;
  1407. caddr_t call;
  1408. {
  1409. X    int (*sfp)()= (int (*)())client;
  1410. X
  1411. X    if (XmToggleButtonGadgetGetState(w)) {
  1412. X        /* better turn off searching if changing the search function! */
  1413. X        if (srch_f != sfp && srch_ison())
  1414. X        XmToggleButtonGadgetSetState(on_w, False, True /* invoke cb */);
  1415. X        srch_f = sfp;
  1416. X    }
  1417. }
  1418. X
  1419. /* callback from the on/off toggle button activate.
  1420. X */
  1421. static void
  1422. srch_on_off_cb(w, client, call)
  1423. Widget w;
  1424. caddr_t client;
  1425. caddr_t call;
  1426. {
  1427. X    static char *msg =
  1428. X        "You must first successfully compile a search function and\n select a goal algorithm before searching may be enabled.";
  1429. X
  1430. X    if (XmToggleButtonGadgetGetState(w)) {
  1431. X        /* insure there is a valid function and goal algorithm selected
  1432. X         * if turning searching on.
  1433. X         */
  1434. X        if (!prog_isgood()) {
  1435. X        XmToggleButtonGadgetSetState(on_w, False, True/* invoke cb */);
  1436. X        f_msg (msg, 1);
  1437. X         
  1438. X        } else if (srch_f == 0) {
  1439. X        XmToggleButtonGadgetSetState(on_w, False, True/* invoke cb */);
  1440. X        f_msg (msg, 1);
  1441. X        } else {
  1442. X        srch_tmscalled = 0;
  1443. X        /* turning on searhing so as a courtesy turn off the
  1444. X         * field selection mechanism if it's on now.
  1445. X         */
  1446. X        if (XmToggleButtonGadgetGetState(field_w))
  1447. X            XmToggleButtonGadgetSetState(field_w, False, True);
  1448. X        }
  1449. X    }
  1450. }
  1451. X
  1452. /* use successive paraboloidal fits to find when expression is at a
  1453. X * local minimum or maximum.
  1454. X */
  1455. static
  1456. srch_minmax(mjd, v, tmincp)
  1457. double mjd;
  1458. double v;
  1459. double *tmincp;
  1460. {
  1461. X    static double base;        /* for better stability */
  1462. X    static double x_1, x_2, x_3;    /* keep in increasing order */
  1463. X    static double y_1, y_2, y_3;
  1464. X    double xm, a, b;
  1465. X
  1466. X    if (srch_tmscalled == 0) {
  1467. X        base = mjd;
  1468. X        x_1 = 0.0;
  1469. X        y_1 = v;
  1470. X        return (0);
  1471. X    }
  1472. X    mjd -= base;
  1473. X    if (srch_tmscalled == 1) {
  1474. X        /* put in one of first two slots */
  1475. X        if (mjd < x_1) {
  1476. X            x_2 = x_1;  y_2 = y_1;
  1477. X        x_1 = mjd; y_1 = v;
  1478. X        } else {
  1479. X        x_2 = mjd; y_2 = v;
  1480. X        }
  1481. X        return (0);
  1482. X    }
  1483. X    if (srch_tmscalled == 2 || fabs(mjd - x_1) < fabs(mjd - x_3)) {
  1484. X        /* closer to x_1 so discard x_3.
  1485. X         * or if it's our third value we know to "discard" x_3.
  1486. X         */
  1487. X        if (mjd > x_2) {
  1488. X        x_3 = mjd; y_3 = v;
  1489. X        } else {
  1490. X        x_3 = x_2;  y_3 = y_2;
  1491. X        if (mjd > x_1) {
  1492. X            x_2 = mjd; y_2 = v;
  1493. X        } else {
  1494. X            x_2 = x_1;  y_2 = y_1;
  1495. X            x_1 = mjd; y_1 = v;
  1496. X        }
  1497. X        }
  1498. X        if (srch_tmscalled == 2)
  1499. X        return (0);
  1500. X    } else {
  1501. X        /* closer to x_3 so discard x_1 */
  1502. X        if (mjd < x_2) {
  1503. X        x_1 = mjd;  y_1 = v;
  1504. X        } else {
  1505. X        x_1 =  x_2;  y_1 = y_2;
  1506. X        if (mjd < x_3) {
  1507. X            x_2 = mjd; y_2 = v;
  1508. X        } else {
  1509. X            x_2 =  x_3; y_2 = y_3;
  1510. X            x_3 = mjd; y_3 = v;
  1511. X        }
  1512. X        }
  1513. X    }
  1514. X
  1515. #ifdef TRACEMM
  1516. X    { char buf[NC];
  1517. X      sprintf (buf, "x_1=%g y_1=%g x_2=%g y_2=%g x_3=%g y_3=%g",
  1518. X                        x_1, y_1, x_2, y_2, x_3, y_3);
  1519. X      f_msg (buf, 0);
  1520. X    }
  1521. #endif
  1522. X    a = y_1*(x_2-x_3) - y_2*(x_1-x_3) + y_3*(x_1-x_2);
  1523. X    if (fabs(a) < 1e-10) {
  1524. X        /* near-0 zero denominator, ie, curve is pretty flat here,
  1525. X         * so assume we are done enough.
  1526. X         * signal this by forcing a 0 tminc.
  1527. X         */
  1528. X        *tmincp = 0.0;
  1529. X        return (-1);
  1530. X    }
  1531. X    b = (x_1*x_1)*(y_2-y_3) - (x_2*x_2)*(y_1-y_3) + (x_3*x_3)*(y_1-y_2);
  1532. X    xm = -b/(2.0*a);
  1533. X    *tmincp = (xm - mjd)*24.0;
  1534. X    return (fabs (*tmincp) < tmlimit ? -1 : 0);
  1535. }
  1536. X
  1537. /* use secant method to solve for time when expression passes through 0.
  1538. X */
  1539. static
  1540. srch_solve0(mjd, v, tmincp)
  1541. double mjd;
  1542. double v;
  1543. double *tmincp;
  1544. {
  1545. X    static double x0, x_1;    /* x(n-1) and x(n) */
  1546. X    static double y_0, y_1;    /* y(n-1) and y(n) */
  1547. X    double x_2;        /* x(n+1) */
  1548. X    double df;        /* y(n) - y(n-1) */
  1549. X
  1550. X    switch (srch_tmscalled) {
  1551. X    case 0: x0 = mjd; y_0 = v; return(0);
  1552. X    case 1: x_1 = mjd; y_1 = v; break;
  1553. X    default: x0 = x_1; y_0 = y_1; x_1 = mjd; y_1 = v; break;
  1554. X    }
  1555. X
  1556. X    df = y_1 - y_0;
  1557. X    if (fabs(df) < 1e-10) {
  1558. X        /* near-0 zero denominator, ie, curve is pretty flat here,
  1559. X         * so assume we are done enough.
  1560. X         * signal this by forcing a 0 tminc.
  1561. X         */
  1562. X        *tmincp = 0.0;
  1563. X        return (-1);
  1564. X    }
  1565. X    x_2 = x_1 - y_1*(x_1-x0)/df;
  1566. X    *tmincp = (x_2 - mjd)*24.0;
  1567. X    return (fabs (*tmincp) < tmlimit ? -1 : 0);
  1568. }
  1569. X
  1570. /* binary search for time when expression changes from its initial state.
  1571. X * if the change is outside the initial tminc range, then keep searching in that
  1572. X *    direction by tminc first before starting to divide down.
  1573. X */
  1574. static
  1575. srch_binary(mjd, v, tmincp)
  1576. double mjd;
  1577. double v;
  1578. double *tmincp;
  1579. {
  1580. X    static double lb, ub;        /* lower and upper bound */
  1581. X    static int initial_state;
  1582. X    int this_state = v >= 0.5;
  1583. X
  1584. #define    FLUNDEF    -9e10
  1585. X
  1586. X    if (srch_tmscalled == 0) {
  1587. X        if (*tmincp >= 0.0) {
  1588. X        /* going forwards in time so first mjd is lb and no ub yet */
  1589. X        lb = mjd;
  1590. X        ub = FLUNDEF;
  1591. X        } else {
  1592. X        /* going backwards in time so first mjd is ub and no lb yet */
  1593. X        ub = mjd;
  1594. X        lb = FLUNDEF;
  1595. X        }
  1596. X        initial_state = this_state;
  1597. X        return (0);
  1598. X    }
  1599. X
  1600. X    if (ub != FLUNDEF && lb != FLUNDEF) {
  1601. X        if (this_state == initial_state)
  1602. X        lb = mjd;
  1603. X        else
  1604. X        ub = mjd;
  1605. X        *tmincp = ((lb + ub)/2.0 - mjd)*24.0;
  1606. #ifdef TRACEBIN
  1607. X        { char buf[NC];
  1608. X          sprintf (buf, "lb=%g ub=%g tminc=%g mjd=%g is=%d ts=%d",
  1609. X                lb, ub, *tmincp, mjd, initial_state, this_state);
  1610. X          f_msg (buf, 0);
  1611. X        }
  1612. #endif
  1613. X        /* signal to stop if asking for time change less than TMLIMIT */
  1614. X        return (fabs (*tmincp) < tmlimit ? -1 : 0);
  1615. X    } else if (this_state != initial_state) {
  1616. X        /* gone past; turn around half way */
  1617. X        if (*tmincp >= 0.0)
  1618. X        ub = mjd;
  1619. X        else
  1620. X        lb = mjd;
  1621. X        *tmincp /= -2.0;
  1622. X        return (0);
  1623. X    } else {
  1624. X        /* just keep going, looking for first state change but we keep
  1625. X         * learning the lower (or upper, if going backwards) bound.
  1626. X         */
  1627. X        if (*tmincp >= 0.0)
  1628. X        lb = mjd;
  1629. X        else
  1630. X        ub = mjd;
  1631. X        return (0);
  1632. X    }
  1633. }
  1634. SHAR_EOF
  1635. chmod 0644 srch.c ||
  1636. echo 'restore of srch.c failed'
  1637. Wc_c="`wc -c < 'srch.c'`"
  1638. test 26324 -eq "$Wc_c" ||
  1639.     echo 'srch.c: original size 26324, current size' "$Wc_c"
  1640. rm -f _shar_wnt_.tmp
  1641. fi
  1642. # ============= sun.c ==============
  1643. if test -f 'sun.c' -a X"$1" != X"-c"; then
  1644.     echo 'x - skipping sun.c (File already exists)'
  1645.     rm -f _shar_wnt_.tmp
  1646. else
  1647. > _shar_wnt_.tmp
  1648. echo 'x - extracting sun.c (Text)'
  1649. sed 's/^X//' << 'SHAR_EOF' > 'sun.c' &&
  1650. #include <stdio.h>
  1651. #include <math.h>
  1652. #include "astro.h"
  1653. X
  1654. /* given the modified JD, mjd, return the true geocentric ecliptic longitude
  1655. X *   of the sun for the mean equinox of the date, *lsn, in radians, and the
  1656. X *   sun-earth distance, *rsn, in AU. (the true ecliptic latitude is never more
  1657. X *   than 1.2 arc seconds and so may be taken to be a constant 0.)
  1658. X * if the APPARENT ecliptic longitude is required, correct the longitude for
  1659. X *   nutation to the true equinox of date and for aberration (light travel time,
  1660. X *   approximately  -9.27e7/186000/(3600*24*365)*2*pi = -9.93e-5 radians).
  1661. X */
  1662. sunpos (mjd, lsn, rsn)
  1663. double mjd;
  1664. double *lsn, *rsn;
  1665. {
  1666. X    double t, t2;
  1667. X    double ls, ms;    /* mean longitude and mean anomoay */
  1668. X    double s, nu, ea; /* eccentricity, true anomaly, eccentric anomaly */
  1669. X    double a, b, a1, b1, c1, d1, e1, h1, dl, dr;
  1670. X
  1671. X    t = mjd/36525.;
  1672. X    t2 = t*t;
  1673. X    a = 100.0021359*t;
  1674. X    b = 360.*(a-(long)a);
  1675. X    ls = 279.69668+.0003025*t2+b;
  1676. X    a = 99.99736042000039*t;
  1677. X    b = 360*(a-(long)a);
  1678. X    ms = 358.47583-(.00015+.0000033*t)*t2+b;
  1679. X    s = .016751-.0000418*t-1.26e-07*t2;
  1680. X    anomaly (degrad(ms), s, &nu, &ea);
  1681. X    a = 62.55209472000015*t;
  1682. X    b = 360*(a-(long)a);
  1683. X    a1 = degrad(153.23+b);
  1684. X    a = 125.1041894*t;
  1685. X    b = 360*(a-(long)a);
  1686. X    b1 = degrad(216.57+b);
  1687. X    a = 91.56766028*t;
  1688. SHAR_EOF
  1689. true || echo 'restore of sun.c failed'
  1690. fi
  1691. echo 'End of  part 10'
  1692. echo 'File sun.c is continued in part 11'
  1693. echo 11 > _shar_seq_.tmp
  1694. exit 0
  1695. -- 
  1696. --
  1697. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1698. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1699. Sunnyvale, California 94086            at&t: 408/522-9236
  1700.