home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / xephem / part03 < prev    next >
Encoding:
Text File  |  1992-03-05  |  50.2 KB  |  1,649 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: v16i114: xephem - astronomical ephemeris program., Part03/24
  5. Message-ID: <1992Mar6.135226.1992@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:52:26 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 114
  15. Archive-name: xephem/part03
  16.  
  17. # this is part.03 (part 3 of a multipart archive)
  18. # do not concatenate these parts, unpack them in order with /bin/sh
  19. # file constel.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" != 3; 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 constel.c'
  35. else
  36. echo 'x - continuing file constel.c'
  37. sed 's/^X//' << 'SHAR_EOF' >> 'constel.c' &&
  38. X    {12.8333, 14.2500, -22.0000, Vir},
  39. X    {9.0833, 9.7500, -24.0000, Hya},
  40. X    {1.6667, 2.6500, -24.3833, Cet},
  41. X    {2.6500, 3.7500, -24.3833, Eri},
  42. X    {10.8333, 11.8333, -24.5000, Crt},
  43. X    {11.8333, 12.5833, -24.5000, Crv},
  44. X    {14.2500, 14.9167, -24.5000, Lib},
  45. X    {16.2667, 16.7500, -24.5833, Oph},
  46. X    {0.0000, 1.6667, -25.5000, Cet},
  47. X    {21.3333, 21.8667, -25.5000, Cap},
  48. X    {21.8667, 23.8333, -25.5000, Aqr},
  49. X    {23.8333, 24.0000, -25.5000, Cet},
  50. X    {9.7500, 10.2500, -26.5000, Hya},
  51. X    {4.7000, 4.8333, -27.2500, Eri},
  52. X    {4.8333, 6.1167, -27.2500, Lep},
  53. X    {20.0000, 21.3333, -28.0000, Cap},
  54. X    {10.2500, 10.5833, -29.1667, Hya},
  55. X    {12.5833, 14.9167, -29.5000, Hya},
  56. X    {14.9167, 15.6667, -29.5000, Lib},
  57. X    {15.6667, 16.0000, -29.5000, Sco},
  58. X    {4.5833, 4.7000, -30.0000, Eri},
  59. X    {16.7500, 17.6000, -30.0000, Oph},
  60. X    {17.6000, 17.8333, -30.0000, Sgr},
  61. X    {10.5833, 10.8333, -31.1667, Hya},
  62. X    {6.1167, 7.3667, -33.0000, CMa},
  63. X    {12.2500, 12.5833, -33.0000, Hya},
  64. X    {10.8333, 12.2500, -35.0000, Hya},
  65. X    {3.5000, 3.7500, -36.0000, For},
  66. X    {8.3667, 9.3667, -36.7500, Pyx},
  67. X    {4.2667, 4.5833, -37.0000, Eri},
  68. X    {17.8333, 19.1667, -37.0000, Sgr},
  69. X    {21.3333, 23.0000, -37.0000, PsA},
  70. X    {23.0000, 23.3333, -37.0000, Scl},
  71. X    {3.0000, 3.5000, -39.5833, For},
  72. X    {9.3667, 11.0000, -39.7500, Ant},
  73. X    {0.0000, 1.6667, -40.0000, Scl},
  74. X    {1.6667, 3.0000, -40.0000, For},
  75. X    {3.8667, 4.2667, -40.0000, Eri},
  76. X    {23.3333, 24.0000, -40.0000, Scl},
  77. X    {14.1667, 14.9167, -42.0000, Cen},
  78. X    {15.6667, 16.0000, -42.0000, Lup},
  79. X    {16.0000, 16.4208, -42.0000, Sco},
  80. X    {4.8333, 5.0000, -43.0000, Cae},
  81. X    {5.0000, 6.5833, -43.0000, Col},
  82. X    {8.0000, 8.3667, -43.0000, Pup},
  83. X    {3.4167, 3.8667, -44.0000, Eri},
  84. X    {16.4208, 17.8333, -45.5000, Sco},
  85. X    {17.8333, 19.1667, -45.5000, CrA},
  86. X    {19.1667, 20.3333, -45.5000, Sgr},
  87. X    {20.3333, 21.3333, -45.5000, Mic},
  88. X    {3.0000, 3.4167, -46.0000, Eri},
  89. X    {4.5000, 4.8333, -46.5000, Cae},
  90. X    {15.3333, 15.6667, -48.0000, Lup},
  91. X    {0.0000, 2.3333, -48.1667, Phe},
  92. X    {2.6667, 3.0000, -49.0000, Eri},
  93. X    {4.0833, 4.2667, -49.0000, Hor},
  94. X    {4.2667, 4.5000, -49.0000, Cae},
  95. X    {21.3333, 22.0000, -50.0000, Gru},
  96. X    {6.0000, 8.0000, -50.7500, Pup},
  97. X    {8.0000, 8.1667, -50.7500, Vel},
  98. X    {2.4167, 2.6667, -51.0000, Eri},
  99. X    {3.8333, 4.0833, -51.0000, Hor},
  100. X    {0.0000, 1.8333, -51.5000, Phe},
  101. X    {6.0000, 6.1667, -52.5000, Car},
  102. X    {8.1667, 8.4500, -53.0000, Vel},
  103. X    {3.5000, 3.8333, -53.1667, Hor},
  104. X    {3.8333, 4.0000, -53.1667, Dor},
  105. X    {0.0000, 1.5833, -53.5000, Phe},
  106. X    {2.1667, 2.4167, -54.0000, Eri},
  107. X    {4.5000, 5.0000, -54.0000, Pic},
  108. X    {15.0500, 15.3333, -54.0000, Lup},
  109. X    {8.4500, 8.8333, -54.5000, Vel},
  110. X    {6.1667, 6.5000, -55.0000, Car},
  111. X    {11.8333, 12.8333, -55.0000, Cen},
  112. X    {14.1667, 15.0500, -55.0000, Lup},
  113. X    {15.0500, 15.3333, -55.0000, Nor},
  114. X    {4.0000, 4.3333, -56.5000, Dor},
  115. X    {8.8333, 11.0000, -56.5000, Vel},
  116. X    {11.0000, 11.2500, -56.5000, Cen},
  117. X    {17.5000, 18.0000, -57.0000, Ara},
  118. X    {18.0000, 20.3333, -57.0000, Tel},
  119. X    {22.0000, 23.3333, -57.0000, Gru},
  120. X    {3.2000, 3.5000, -57.5000, Hor},
  121. X    {5.0000, 5.5000, -57.5000, Pic},
  122. X    {6.5000, 6.8333, -58.0000, Car},
  123. X    {0.0000, 1.3333, -58.5000, Phe},
  124. X    {1.3333, 2.1667, -58.5000, Eri},
  125. X    {23.3333, 24.0000, -58.5000, Phe},
  126. X    {4.3333, 4.5833, -59.0000, Dor},
  127. X    {15.3333, 16.4208, -60.0000, Nor},
  128. X    {20.3333, 21.3333, -60.0000, Ind},
  129. X    {5.5000, 6.0000, -61.0000, Pic},
  130. X    {15.1667, 15.3333, -61.0000, Cir},
  131. X    {16.4208, 16.5833, -61.0000, Ara},
  132. X    {14.9167, 15.1667, -63.5833, Cir},
  133. X    {16.5833, 16.7500, -63.5833, Ara},
  134. X    {6.0000, 6.8333, -64.0000, Pic},
  135. X    {6.8333, 9.0333, -64.0000, Car},
  136. X    {11.2500, 11.8333, -64.0000, Cen},
  137. X    {11.8333, 12.8333, -64.0000, Cru},
  138. X    {12.8333, 14.5333, -64.0000, Cen},
  139. X    {13.5000, 13.6667, -65.0000, Cir},
  140. X    {16.7500, 16.8333, -65.0000, Ara},
  141. X    {2.1667, 3.2000, -67.5000, Hor},
  142. X    {3.2000, 4.5833, -67.5000, Ret},
  143. X    {14.7500, 14.9167, -67.5000, Cir},
  144. X    {16.8333, 17.5000, -67.5000, Ara},
  145. X    {17.5000, 18.0000, -67.5000, Pav},
  146. X    {22.0000, 23.3333, -67.5000, Tuc},
  147. X    {4.5833, 6.5833, -70.0000, Dor},
  148. X    {13.6667, 14.7500, -70.0000, Cir},
  149. X    {14.7500, 17.0000, -70.0000, TrA},
  150. X    {0.0000, 1.3333, -75.0000, Tuc},
  151. X    {3.5000, 4.5833, -75.0000, Hyi},
  152. X    {6.5833, 9.0333, -75.0000, Vol},
  153. X    {9.0333, 11.2500, -75.0000, Car},
  154. X    {11.2500, 13.6667, -75.0000, Mus},
  155. X    {18.0000, 21.3333, -75.0000, Pav},
  156. X    {21.3333, 23.3333, -75.0000, Ind},
  157. X    {23.3333, 24.0000, -75.0000, Tuc},
  158. X    {0.7500, 1.3333, -76.0000, Tuc},
  159. X    {0.0000, 3.5000, -82.5000, Hyi},
  160. X    {7.6667, 13.6667, -82.5000, Cha},
  161. X    {13.6667, 18.0000, -82.5000, Aps},
  162. X    {3.5000, 7.6667, -85.0000, Men},
  163. X    {0.0000, 24.0000, -90.0000, Oct},
  164. X    {0.0000, 24.0000, -90.0000, ""}
  165. };
  166. X
  167. /* given ra and dec (in rads) precessed to epoch e (an mjd)
  168. X * point *name to a string naming the constellation at that location.
  169. X */
  170. confnd(r, d, e, name)
  171. double r, d, e;
  172. char **name;
  173. {
  174. X    double ra1875, de1875, mjd1875;
  175. X    int i;
  176. X
  177. X    cal_mjd (1, 1.0, 1875, &mjd1875);
  178. X    precess (e, mjd1875, &r, &d);
  179. X        
  180. X    /* find constellation such that the declination entered is higher than
  181. X     * the lower boundary of the constellation when the upper and lower
  182. X     * right ascensions for the constellation bound the entered right
  183. X     * ascension
  184. X     */
  185. X    i = 0;
  186. X    ra1875 = radhr (r);
  187. X    de1875 = raddeg (d);
  188. X    while ((con_data[i].l_dec > de1875 || con_data[i].u_ra <= ra1875
  189. X             || con_data[i].l_ra > ra1875) && con_data[i].cons[0])
  190. X         i++;
  191. X
  192. X    *name = con_data[i].cons[0] ? con_data[i].cons : "<No constellation?!>";
  193. }
  194. SHAR_EOF
  195. echo 'File constel.c is complete' &&
  196. chmod 0644 constel.c ||
  197. echo 'restore of constel.c failed'
  198. Wc_c="`wc -c < 'constel.c'`"
  199. test 20026 -eq "$Wc_c" ||
  200.     echo 'constel.c: original size 20026, current size' "$Wc_c"
  201. rm -f _shar_wnt_.tmp
  202. fi
  203. # ============= datamenu.c ==============
  204. if test -f 'datamenu.c' -a X"$1" != X"-c"; then
  205.     echo 'x - skipping datamenu.c (File already exists)'
  206.     rm -f _shar_wnt_.tmp
  207. else
  208. > _shar_wnt_.tmp
  209. echo 'x - extracting datamenu.c (Text)'
  210. sed 's/^X//' << 'SHAR_EOF' > 'datamenu.c' &&
  211. /* code to manage the stuff on the "data" menu.
  212. X */
  213. X
  214. #include <stdio.h>
  215. #include <ctype.h>
  216. #include <math.h>
  217. #ifdef VMS
  218. #include <stdlib.h>
  219. #endif
  220. #include <Xm/Xm.h>
  221. #include <Xm/Form.h>
  222. #include <Xm/LabelG.h>
  223. #include <Xm/PushBG.h>
  224. #include <Xm/PushB.h>
  225. #include <Xm/ToggleBG.h>
  226. #include "fieldmap.h"
  227. #include "astro.h"
  228. #include "circum.h"
  229. #include "moreobjs.h"
  230. X
  231. extern char *strncpy();
  232. extern char *getenv();
  233. extern Widget toplevel_w;
  234. extern XmString str_width();
  235. extern Now *mm_get_now();
  236. extern char *objname[];
  237. #define    XtD    XtDisplay(toplevel_w)
  238. X
  239. /* locations of each field.
  240. X * these are in terms of a 1-based row/col on a 24x80 alpha screen, for
  241. X * historical reasons.
  242. X */
  243. #define    NR    14
  244. #define    NC    86
  245. X
  246. #define    C_OBJ        1
  247. #define    C_CONSTEL    4
  248. #define    C_XTRA        3
  249. X
  250. /* menu 1 info table */
  251. #define    C_RA        8
  252. #define    C_DEC        16
  253. #define    C_AZ        23
  254. #define    C_ALT        30
  255. #define    C_HLONG        37
  256. #define    C_HLAT        44
  257. #define    C_EDIST        51
  258. #define C_SDIST     58
  259. #define    C_ELONG        65
  260. #define    C_SIZE        72
  261. #define    C_MAG        77
  262. #define    C_PHASE        83
  263. X
  264. /* planet rows */
  265. #define    R_PLANTAB    (1)
  266. #define    R_SUN        (R_PLANTAB+1)
  267. #define    R_MOON        (R_PLANTAB+2)
  268. #define    R_MERCURY    (R_PLANTAB+3)
  269. #define    R_VENUS        (R_PLANTAB+4)
  270. #define    R_MARS        (R_PLANTAB+5)
  271. #define    R_JUPITER    (R_PLANTAB+6)
  272. #define    R_SATURN    (R_PLANTAB+7)
  273. #define    R_URANUS    (R_PLANTAB+8)
  274. #define    R_NEPTUNE    (R_PLANTAB+9)
  275. #define    R_PLUTO        (R_PLANTAB+10)
  276. #define    R_OBJX        (R_PLANTAB+11)
  277. #define    R_OBJY        (R_PLANTAB+12)
  278. #define    R_CONTROL    (R_PLANTAB+13)
  279. X
  280. static FieldMap dm_field_map[] = {
  281. X    {mkid(R_JUPITER,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Jup.Alt"}, 
  282. X    {mkid(R_JUPITER,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Jup.Az"}, 
  283. X    {mkid(R_JUPITER,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  284. X    {mkid(R_JUPITER,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Jup.Dec"}, 
  285. X    {mkid(R_JUPITER,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Jup.EDist"}, 
  286. X    {mkid(R_JUPITER,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Jup.ELong"}, 
  287. X    {mkid(R_JUPITER,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Jup.HLat"}, 
  288. X    {mkid(R_JUPITER,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Jup.HLong"}, 
  289. X    {mkid(R_JUPITER,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Jup.Mag"}, 
  290. X    {mkid(R_JUPITER,C_PHASE), PLT, NC-C_PHASE, 0, "Jup.Phase"}, 
  291. X    {mkid(R_JUPITER,C_RA), PLT, C_DEC-C_RA-1, 0, "Jup.RA"}, 
  292. X    {mkid(R_JUPITER,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Jup.SDist"}, 
  293. X    {mkid(R_JUPITER,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Jup.Size"}, 
  294. X    {mkid(R_MARS,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Mars.Alt"}, 
  295. X    {mkid(R_MARS,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Mars.Az"}, 
  296. X    {mkid(R_MARS,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  297. X    {mkid(R_MARS,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Mars.Dec"}, 
  298. X    {mkid(R_MARS,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Mars.EDist"}, 
  299. X    {mkid(R_MARS,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Mars.ELong"}, 
  300. X    {mkid(R_MARS,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Mars.HLat"}, 
  301. X    {mkid(R_MARS,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Mars.HLong"}, 
  302. X    {mkid(R_MARS,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Mars.Mag"}, 
  303. X    {mkid(R_MARS,C_PHASE), PLT, NC-C_PHASE, 0, "Mars.Phase"}, 
  304. X    {mkid(R_MARS,C_RA), PLT, C_DEC-C_RA-1, 0, "Mars.RA"}, 
  305. X    {mkid(R_MARS,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Mars.SDist"}, 
  306. X    {mkid(R_MARS,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Mars.Size"}, 
  307. X    {mkid(R_MERCURY,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Merc.Alt"}, 
  308. X    {mkid(R_MERCURY,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Merc.Az"}, 
  309. X    {mkid(R_MERCURY,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  310. X    {mkid(R_MERCURY,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Merc.Dec"}, 
  311. X    {mkid(R_MERCURY,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Merc.EDist"}, 
  312. X    {mkid(R_MERCURY,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Merc.ELong"}, 
  313. X    {mkid(R_MERCURY,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Merc.HLat"}, 
  314. X    {mkid(R_MERCURY,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Merc.HLong"}, 
  315. X    {mkid(R_MERCURY,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Merc.Mag"}, 
  316. X    {mkid(R_MERCURY,C_PHASE), PLT, NC-C_PHASE, 0, "Merc.Phase"}, 
  317. X    {mkid(R_MERCURY,C_RA), PLT, C_DEC-C_RA-1, 0, "Merc.RA"}, 
  318. X    {mkid(R_MERCURY,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Merc.SDist"}, 
  319. X    {mkid(R_MERCURY,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Merc.Size"}, 
  320. X    {mkid(R_MOON,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Moon.Alt"}, 
  321. X    {mkid(R_MOON,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Moon.Az"}, 
  322. X    {mkid(R_MOON,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  323. X    {mkid(R_MOON,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Moon.Dec"}, 
  324. X    {mkid(R_MOON,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Moon.EDist"}, 
  325. X    {mkid(R_MOON,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Moon.ELong"}, 
  326. X    {mkid(R_MOON,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Moon.HLat"}, 
  327. X    {mkid(R_MOON,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Moon.HLong"}, 
  328. X    {mkid(R_MOON,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Moon.Mag"}, 
  329. X    {mkid(R_MOON,C_PHASE), PLT, NC-C_PHASE, 0, "Moon.Phase"}, 
  330. X    {mkid(R_MOON,C_RA), PLT, C_DEC-C_RA-1, 0, "Moon.RA"}, 
  331. X    {mkid(R_MOON,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Moon.SDist"}, 
  332. X    {mkid(R_MOON,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Moon.Size"}, 
  333. X    {mkid(R_NEPTUNE,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Nep.Alt"}, 
  334. X    {mkid(R_NEPTUNE,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Nep.Az"}, 
  335. X    {mkid(R_NEPTUNE,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  336. X    {mkid(R_NEPTUNE,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Nep.Dec"}, 
  337. X    {mkid(R_NEPTUNE,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Nep.EDist"}, 
  338. X    {mkid(R_NEPTUNE,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Nep.ELong"}, 
  339. X    {mkid(R_NEPTUNE,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Nep.HLat"}, 
  340. X    {mkid(R_NEPTUNE,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Nep.HLong"}, 
  341. X    {mkid(R_NEPTUNE,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Nep.Mag"}, 
  342. X    {mkid(R_NEPTUNE,C_PHASE), PLT, NC-C_PHASE, 0, "Nep.Phase"}, 
  343. X    {mkid(R_NEPTUNE,C_RA), PLT, C_DEC-C_RA-1, 0, "Nep.RA"}, 
  344. X    {mkid(R_NEPTUNE,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Nep.SDist"}, 
  345. X    {mkid(R_NEPTUNE,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Nep.Size"}, 
  346. X    {mkid(R_OBJX,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "ObjX.Alt"}, 
  347. X    {mkid(R_OBJX,C_AZ), PLT, C_ALT-C_AZ-1, 0, "ObjX.Az"}, 
  348. X    {mkid(R_OBJX,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  349. X    {mkid(R_OBJX,C_DEC), PLT, C_AZ-C_DEC-1, 0, "ObjX.Dec"}, 
  350. X    {mkid(R_OBJX,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "ObjX.EDist"}, 
  351. X    {mkid(R_OBJX,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "ObjX.ELong"}, 
  352. X    {mkid(R_OBJX,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "ObjX.HLat"}, 
  353. X    {mkid(R_OBJX,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "ObjX.HLong"}, 
  354. X    {mkid(R_OBJX,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "ObjX.Mag"}, 
  355. X    {mkid(R_OBJX,C_PHASE), PLT, NC-C_PHASE, 0, "ObjX.Phase"}, 
  356. X    {mkid(R_OBJX,C_RA), PLT, C_DEC-C_RA-1, 0, "ObjX.RA"}, 
  357. X    {mkid(R_OBJX,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "ObjX.SDist"}, 
  358. X    {mkid(R_OBJX,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "ObjX.Size"}, 
  359. X    {mkid(R_OBJY,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "ObjY.Alt"}, 
  360. X    {mkid(R_OBJY,C_AZ), PLT, C_ALT-C_AZ-1, 0, "ObjY.Az"}, 
  361. X    {mkid(R_OBJY,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  362. X    {mkid(R_OBJY,C_DEC), PLT, C_AZ-C_DEC-1, 0, "ObjY.Dec"}, 
  363. X    {mkid(R_OBJY,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "ObjY.EDist"}, 
  364. X    {mkid(R_OBJY,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "ObjY.ELong"}, 
  365. X    {mkid(R_OBJY,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "ObjY.HLat"}, 
  366. X    {mkid(R_OBJY,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "ObjY.HLong"}, 
  367. X    {mkid(R_OBJY,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "ObjY.Mag"}, 
  368. X    {mkid(R_OBJY,C_PHASE), PLT, NC-C_PHASE, 0, "ObjY.Phase"}, 
  369. X    {mkid(R_OBJY,C_RA), PLT, C_DEC-C_RA-1, 0, "ObjY.RA"}, 
  370. X    {mkid(R_OBJY,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "ObjY.SDist"}, 
  371. X    {mkid(R_OBJY,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "ObjY.Size"}, 
  372. X    {mkid(R_PLUTO,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Pluto.Alt"}, 
  373. X    {mkid(R_PLUTO,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Pluto.Az"}, 
  374. X    {mkid(R_PLUTO,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  375. X    {mkid(R_PLUTO,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Pluto.Dec"}, 
  376. X    {mkid(R_PLUTO,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Pluto.EDist"}, 
  377. X    {mkid(R_PLUTO,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Pluto.ELong"}, 
  378. X    {mkid(R_PLUTO,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Pluto.HLat"}, 
  379. X    {mkid(R_PLUTO,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Pluto.HLong"}, 
  380. X    {mkid(R_PLUTO,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Pluto.Mag"}, 
  381. X    {mkid(R_PLUTO,C_PHASE), PLT, NC-C_PHASE, 0, "Pluto.Phase"}, 
  382. X    {mkid(R_PLUTO,C_RA), PLT, C_DEC-C_RA-1, 0, "Pluto.RA"}, 
  383. X    {mkid(R_PLUTO,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Pluto.SDist"}, 
  384. X    {mkid(R_PLUTO,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Pluto.Size"}, 
  385. X    {mkid(R_SATURN,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Sat.Alt"}, 
  386. X    {mkid(R_SATURN,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Sat.Az"}, 
  387. X    {mkid(R_SATURN,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  388. X    {mkid(R_SATURN,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Sat.Dec"}, 
  389. X    {mkid(R_SATURN,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Sat.EDist"}, 
  390. X    {mkid(R_SATURN,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Sat.ELong"}, 
  391. X    {mkid(R_SATURN,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Sat.HLat"}, 
  392. X    {mkid(R_SATURN,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Sat.HLong"}, 
  393. X    {mkid(R_SATURN,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Sat.Mag"}, 
  394. X    {mkid(R_SATURN,C_PHASE), PLT, NC-C_PHASE, 0, "Sat.Phase"}, 
  395. X    {mkid(R_SATURN,C_RA), PLT, C_DEC-C_RA-1, 0, "Sat.RA"}, 
  396. X    {mkid(R_SATURN,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Sat.SDist"}, 
  397. X    {mkid(R_SATURN,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Sat.Size"}, 
  398. X    {mkid(R_SUN,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Sun.Alt"}, 
  399. X    {mkid(R_SUN,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Sun.Az"}, 
  400. X    {mkid(R_SUN,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  401. X    {mkid(R_SUN,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Sun.Dec"}, 
  402. X    {mkid(R_SUN,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Sun.EDist"}, 
  403. X    {mkid(R_SUN,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Sun.HLong"}, 
  404. X    {mkid(R_SUN,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Sun.Mag"}, 
  405. X    {mkid(R_SUN,C_RA), PLT, C_DEC-C_RA-1, 0, "Sun.RA"}, 
  406. X    {mkid(R_SUN,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Sun.Size"}, 
  407. X    {mkid(R_URANUS,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Uranus.Alt"}, 
  408. X    {mkid(R_URANUS,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Uranus.Az"}, 
  409. X    {mkid(R_URANUS,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  410. X    {mkid(R_URANUS,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Uranus.Dec"}, 
  411. X    {mkid(R_URANUS,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Uranus.EDist"}, 
  412. X    {mkid(R_URANUS,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Uranus.ELong"}, 
  413. X    {mkid(R_URANUS,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Uranus.HLat"}, 
  414. X    {mkid(R_URANUS,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Uranus.HLong"}, 
  415. X    {mkid(R_URANUS,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Uranus.Mag"}, 
  416. X    {mkid(R_URANUS,C_PHASE), PLT, NC-C_PHASE, 0, "Uranus.Phase"}, 
  417. X    {mkid(R_URANUS,C_RA), PLT, C_DEC-C_RA-1, 0, "Uranus.RA"}, 
  418. X    {mkid(R_URANUS,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Uranus.SDist"}, 
  419. X    {mkid(R_URANUS,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Uranus.Size"}, 
  420. X    {mkid(R_VENUS,C_ALT), PLT, C_HLONG-C_ALT-1, 0, "Ven.Alt"}, 
  421. X    {mkid(R_VENUS,C_AZ), PLT, C_ALT-C_AZ-1, 0, "Ven.Az"}, 
  422. X    {mkid(R_VENUS,C_CONSTEL), 0, C_RA-C_CONSTEL-1}, 
  423. X    {mkid(R_VENUS,C_DEC), PLT, C_AZ-C_DEC-1, 0, "Ven.Dec"}, 
  424. X    {mkid(R_VENUS,C_EDIST), PLT, C_SDIST-C_EDIST-1, 0, "Ven.EDist"}, 
  425. X    {mkid(R_VENUS,C_ELONG), PLT, C_SIZE-C_ELONG-1, 0, "Ven.ELong"}, 
  426. X    {mkid(R_VENUS,C_HLAT), PLT, C_EDIST-C_HLAT-1, 0, "Ven.HLat"}, 
  427. X    {mkid(R_VENUS,C_HLONG), PLT, C_HLAT-C_HLONG-1, 0, "Ven.HLong"}, 
  428. X    {mkid(R_VENUS,C_MAG), PLT, C_PHASE-C_MAG-1, 0, "Ven.Mag"}, 
  429. X    {mkid(R_VENUS,C_PHASE), PLT, NC-C_PHASE, 0, "Ven.Phase"}, 
  430. X    {mkid(R_VENUS,C_RA), PLT, C_DEC-C_RA-1, 0, "Ven.RA"}, 
  431. X    {mkid(R_VENUS,C_SDIST), PLT, C_ELONG-C_SDIST-1, 0, "Ven.SDist"}, 
  432. X    {mkid(R_VENUS,C_SIZE), PLT, C_MAG-C_SIZE-1, 0, "Ven.Size"}, 
  433. X
  434. X    {mkid(R_PLANTAB,C_OBJ), 0, 0, "Ob"},
  435. X    {mkid(R_PLANTAB,C_CONSTEL), 0, 0, "Cns"},
  436. X    {mkid(R_PLANTAB,C_RA+2), 0,    0, "R.A."},
  437. X    {mkid(R_PLANTAB,C_DEC+2), 0, 0, "Dec"},
  438. X    {mkid(R_PLANTAB,C_AZ+2), 0,     0, "Az"},
  439. X    {mkid(R_PLANTAB,C_ALT+2), 0, 0, "Alt"},
  440. X    {mkid(R_PLANTAB,C_HLONG), 0, 0, "H Long"},
  441. X    {mkid(R_PLANTAB,C_HLAT), 0, 0, "H Lat"},
  442. X    {mkid(R_PLANTAB,C_EDIST), 0, 0, "Ea Dst"},
  443. X    {mkid(R_PLANTAB,C_SDIST), 0, 0, "Sn Dst"},
  444. X    {mkid(R_PLANTAB,C_ELONG), 0, 0, "Elong"},
  445. X    {mkid(R_PLANTAB,C_SIZE), 0, 0, "Size"},
  446. X    {mkid(R_PLANTAB,C_MAG), 0, 0, "VMag"},
  447. X    {mkid(R_PLANTAB,C_PHASE), 0, 0, "Phs"},
  448. };
  449. #define    NFM    (sizeof(dm_field_map)/sizeof(dm_field_map[0]))
  450. #define    LFM    (&dm_field_map[NFM])
  451. #define    fw(r,c)    (fm(r,c)->w)
  452. X
  453. static Widget dataform_w;
  454. static Widget objs_w[NOBJ];    /* object selector toggle buttons */
  455. static unsigned objs_on;    /* (1<<<OBJ>) when object is active */
  456. static int dm_selecting;    /* set while our fields are being selected */
  457. X
  458. static short bodyrow[NOBJ] = {
  459. X    R_MERCURY, R_VENUS, R_MARS, R_JUPITER, R_SATURN,
  460. X    R_URANUS, R_NEPTUNE, R_PLUTO, R_SUN, R_MOON, R_OBJX, R_OBJY
  461. };
  462. X
  463. static FieldMap *
  464. fm(r,c)
  465. int r, c;
  466. {
  467. X    FieldMap *fp;
  468. X    int id = mkid(r,c);
  469. X
  470. X    for (fp = dm_field_map; fp < LFM; fp++)
  471. X        if (fp->id == id)
  472. X        return (fp);
  473. X    printf ("fm: can't find id 0x%x (%d,%d)\n", id, r, c);
  474. X    exit (1);
  475. X    return(0);    /* for lint */
  476. }
  477. X
  478. /* method by which another module can access our field map.
  479. X * this is used by the search compiler.
  480. X */
  481. dm_getfieldmap (fmpp)
  482. FieldMap **fmpp;
  483. {
  484. X    *fmpp = dm_field_map;
  485. X    return (NFM);
  486. }
  487. X
  488. /* called when the data menu is activated via the main menu pulldown.
  489. X * if never called before, create and manage all the widgets as a child of a
  490. X * form. otherwise, just toggle whether the form is managed.
  491. X */
  492. dm_manage ()
  493. {
  494. X    if (!dataform_w) {
  495. X        void dm_activate_cb();
  496. X        void dm_obj_cb();
  497. X        void dm_toggle_cb();
  498. X        void dm_close_cb();
  499. X        void dm_help_cb();
  500. X        FieldMap *fp;
  501. X        Widget w;
  502. X        XmString str;
  503. X        Arg args[20];
  504. X        int i, n;
  505. X
  506. X        /* create the form */
  507. X        n = 0;
  508. X        XtSetArg (args[n], XmNautoUnmanage, False); n++;
  509. X        XtSetArg (args[n], XmNdefaultPosition, False); n++;
  510. X        XtSetArg (args[n], XmNfractionBase, 1000); n++;
  511. X        XtSetArg (args[n], XmNallowOverlap, False); n++;
  512. X        XtSetArg (args[n], XmNwidth, NC*char_width()); n++;
  513. X        dataform_w = XmCreateFormDialog (toplevel_w, "Data", args, n);
  514. X
  515. X        /* set some stuff in the parent DialogShell.
  516. X         * setting XmNdialogTitle in the Form didn't work..
  517. X         */
  518. X        n = 0;
  519. X        XtSetArg (args[n], XmNtitle, "xephem General Data Table"); n++;
  520. X        XtSetValues (XtParent(dataform_w), args, n);
  521. X
  522. X        /* establish the buttons and labels */
  523. X        for (fp = dm_field_map; fp < LFM; fp++) {
  524. X        int free_str;
  525. X        n = 0;
  526. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  527. X        XtSetArg (args[n], XmNtopPosition, ypos(fp->id)); n++;
  528. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  529. X        XtSetArg (args[n], XmNleftPosition, xpos(fp->id)); n++;
  530. X        free_str = 0;
  531. X        if (fp->prompt) {
  532. X            str = XmStringCreate (fp->prompt,XmSTRING_DEFAULT_CHARSET);
  533. X            free_str = 1;
  534. X        } else if (fp->width) {
  535. X            str = str_width (fp->width);
  536. X            XtSetArg(args[n], XmNrecomputeSize, False); n++;
  537. X        } else {
  538. X            str = XmStringCreate("?",XmSTRING_DEFAULT_CHARSET);
  539. X            free_str = 1;
  540. X        }
  541. X        XtSetArg (args[n], XmNlabelString, str); n++;
  542. X        if (fp->how) {
  543. X            /* pushbutton */
  544. X            XtSetArg (args[n], XmNalignment, XmALIGNMENT_END); n++;
  545. X            fp->w = XtCreateManagedWidget ("DataButton",
  546. X                xmPushButtonWidgetClass, dataform_w, args, n);
  547. X            XtAddCallback (fp->w, XmNactivateCallback, dm_activate_cb,
  548. X                                    fp);
  549. X        } else {
  550. X            /* label */
  551. X            fp->w = XtCreateManagedWidget ("DataLabel",
  552. X                    xmLabelGadgetClass, dataform_w, args, n);
  553. X        }
  554. X        if (free_str)
  555. X            XmStringFree(str);
  556. X        }
  557. X
  558. X        /* make the object control toggle buttons */
  559. X        for (i = 0; i < NOBJ; i++) {
  560. X        str = XmStringCreate (objname[i], XmSTRING_DEFAULT_CHARSET);
  561. X        n = 0;
  562. X        XtSetArg (args[n], XmNlabelString, str); n++;
  563. X        XtSetArg (args[n], XmNset, objs_on&(1<<i) ? True : False);n++;
  564. X        XtSetArg (args[n], XmNindicatorOn, False); n++;
  565. X        XtSetArg (args[n], XmNshadowThickness, 2); n++;
  566. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  567. X        XtSetArg (args[n], XmNtopPosition, r2ypos(bodyrow[i])); n++;
  568. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  569. X        XtSetArg (args[n], XmNleftPosition, c2xpos(C_OBJ)); n++;
  570. X        objs_w[i] = XmCreateToggleButtonGadget (dataform_w, "DmObjs",
  571. X                                    args, n);
  572. X        XtAddCallback(objs_w[i], XmNvalueChangedCallback,dm_obj_cb,i);
  573. X        XtManageChild (objs_w[i]);
  574. X        XmStringFree (str);
  575. X        }
  576. X
  577. X        /* make the close button */
  578. X        str = XmStringCreate ("Close", XmSTRING_DEFAULT_CHARSET);
  579. X        n = 0;
  580. X        XtSetArg (args[n], XmNlabelString, str); n++;
  581. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  582. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  583. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  584. X        XtSetArg (args[n], XmNleftPosition, c2xpos(1)); n++;
  585. X        w = XmCreatePushButtonGadget (dataform_w, "DataClose", args, n);
  586. X        XtAddCallback (w, XmNactivateCallback, dm_close_cb, 0);
  587. X        XtManageChild (w);
  588. X        XmStringFree (str);
  589. X
  590. X        /* make the toggle on/off pushbutton */
  591. X
  592. X        str = XmStringCreate ("Toggle On/off", XmSTRING_DEFAULT_CHARSET);
  593. X        n = 0;
  594. X        XtSetArg (args[n], XmNlabelString, str); n++;
  595. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  596. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  597. X        XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  598. X        XtSetArg (args[n], XmNleftPosition, 450); n++;
  599. X        XtSetArg(args[n], XmNrecomputeSize, False); n++;
  600. X        w = XmCreatePushButtonGadget (dataform_w, "DataToggle", args, n);
  601. X        XtAddCallback (w, XmNactivateCallback, dm_toggle_cb, 0);
  602. X        XtManageChild (w);
  603. X        XmStringFree (str);
  604. X
  605. X        /* make the help pushbutton */
  606. X
  607. X        str = XmStringCreate ("Help", XmSTRING_DEFAULT_CHARSET);
  608. X        n = 0;
  609. X        XtSetArg (args[n], XmNlabelString, str); n++;
  610. X        XtSetArg (args[n], XmNtopAttachment, XmATTACH_POSITION); n++;
  611. X        XtSetArg (args[n], XmNtopPosition, r2ypos(R_CONTROL)); n++;
  612. X        XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  613. X        XtSetArg (args[n], XmNrightPosition, 1000); n++;
  614. X        w = XmCreatePushButtonGadget (dataform_w, "DataHelp", args, n);
  615. X        XtAddCallback (w, XmNactivateCallback, dm_help_cb, 0);
  616. X        XtManageChild (w);
  617. X        XmStringFree (str);
  618. X    }
  619. X    
  620. X    if (XtIsManaged(dataform_w))
  621. X        XtUnmanageChild (dataform_w);
  622. X    else {
  623. X        XtManageChild (dataform_w);
  624. X        dm_update (mm_get_now(), 1);
  625. X        dm_set_buttons (dm_selecting);
  626. X    }
  627. }
  628. X
  629. /* used by main to set the initial state of the objects to be on. */
  630. dm_set_objs_on (mask)
  631. int mask;
  632. {
  633. X    objs_on = mask;
  634. }
  635. X
  636. /* called by other menus as they want to hear from our buttons or not.
  637. X * the "on"s and "off"s stack - only really redo the buttons if it's the
  638. X * first on or the last off.
  639. X */
  640. dm_selection_mode (whether)
  641. int whether;    /* whether setting up for plotting or for not plotting */
  642. {
  643. X    dm_selecting += whether ? 1 : -1;
  644. X
  645. X    if (dataform_w && XtIsManaged(dataform_w))
  646. X        if (whether && dm_selecting == 1     /* first one to want on */
  647. X        || !whether && dm_selecting == 0 /* last one to want off */)
  648. X        dm_set_buttons (whether);
  649. }
  650. X
  651. /* go through all the buttons pickable for plotting and set whether they
  652. X * should appear to look like buttons or just flat labels.
  653. X */
  654. static
  655. dm_set_buttons (whether)
  656. int whether;    /* whether setting up for plotting or for not plotting */
  657. {
  658. X    static Arg look_like_button[] = {
  659. X        {XmNbottomShadowColor, (XtArgVal) 0},
  660. X        {XmNtopShadowColor, (XtArgVal) 0},
  661. X        {XmNfillOnArm, (XtArgVal) True},
  662. X    };
  663. X    static Arg look_like_label[] = {
  664. X        {XmNbottomShadowColor, (XtArgVal) 0},
  665. X        {XmNtopShadowColor, (XtArgVal) 0},
  666. X        {XmNfillOnArm, (XtArgVal) False},
  667. X    };
  668. X    static int called;
  669. X    FieldMap *fp;
  670. X
  671. X    if (!called) {
  672. X        Widget w;
  673. X        Pixel pixel;
  674. X
  675. X        w = dm_field_map[0].w;
  676. X        if (!w) {
  677. X        printf ("called dm_set_buttons() before widgets defined\n");
  678. X        exit (1);
  679. X        }
  680. X        get_something (w, XmNbottomShadowColor, &pixel);
  681. X        look_like_button[0].value = pixel;
  682. X        get_something (w, XmNtopShadowColor, &pixel);
  683. X        look_like_button[1].value = pixel;
  684. X        get_something (w, XmNbackground, &pixel);
  685. X        look_like_label[0].value = pixel;
  686. X        look_like_label[1].value = pixel;
  687. X        called = 1;
  688. X    }
  689. X
  690. X    for (fp = dm_field_map; fp < LFM; fp++)
  691. X        if (whether && (fp->how & PLT))
  692. X        XtSetValues (fp->w,look_like_button,XtNumber(look_like_button));
  693. X        else
  694. X        XtSetValues (fp->w,look_like_label,XtNumber(look_like_label));
  695. }
  696. X
  697. /* callback from any of the data menu buttons being activated.
  698. X */
  699. void
  700. dm_activate_cb (w, client, call)
  701. Widget w;
  702. caddr_t client;
  703. caddr_t call;
  704. {
  705. X    FieldMap *fp = (FieldMap *)client;
  706. X    if (dm_selecting) {
  707. X        plt_selection (fp);
  708. X        lst_selection (fp);
  709. X        srch_selection (fp);
  710. X    }
  711. }
  712. X
  713. /* callback from the Close button
  714. X */
  715. void
  716. dm_close_cb (w, client, call)
  717. Widget w;
  718. caddr_t client;
  719. caddr_t call;
  720. {
  721. X    XtUnmanageChild (dataform_w);
  722. }
  723. X
  724. /* callback from the Help button
  725. X */
  726. void
  727. dm_help_cb (w, client, call)
  728. Widget w;
  729. caddr_t client;
  730. caddr_t call;
  731. {
  732. X    static char *msg[] = {
  733. "This table displays various information about the planets and objects.",
  734. "To reduce computation, each may be individually turned off or on."
  735. };
  736. X
  737. X    hlp_dialog ("Data Table", msg, sizeof(msg)/sizeof(msg[0]));
  738. }
  739. X
  740. /* callback from the "toggle on/off" push button.
  741. X * toggle each object on or off.
  742. X * basically we just force set all the planet buttons and let their callbacks
  743. X *   do the real work.
  744. X */
  745. static void
  746. dm_toggle_cb (w, client, call)
  747. Widget w;
  748. caddr_t client;
  749. caddr_t call;
  750. {
  751. X    int p;
  752. X
  753. X    for (p = nxtbody(-1); p != -1; p = nxtbody(p)) {
  754. X        int state = XmToggleButtonGadgetGetState (objs_w[p]);
  755. X        XmToggleButtonGadgetSetState (objs_w[p], !state, True/*invoke cb*/);
  756. X    }
  757. }
  758. X
  759. /* callback for each of the object on/off toggle buttons.
  760. X */
  761. void
  762. dm_obj_cb (w, client, call)
  763. Widget w;
  764. caddr_t client;
  765. caddr_t call;
  766. {
  767. X    XmToggleButtonCallbackStruct *t = (XmToggleButtonCallbackStruct *) call;
  768. X    int p = (int)client;
  769. X
  770. X    if (t->set && !(objs_on & (1<<p))) {
  771. X        objs_on |= 1<<p;
  772. X        dm_compute (p, 1, mm_get_now());
  773. X    } else if (!t->set && (objs_on & (1<<p))) {
  774. X        objs_on &= ~(1<<p);
  775. X        dm_erase_obj (p);
  776. X    }
  777. }
  778. X
  779. /* erase all the buttons in the row corresponding to object p */
  780. dm_erase_obj (p)
  781. int p;
  782. {
  783. X    FieldMap *fp;
  784. X    int r = bodyrow[p];
  785. X
  786. X    for (fp = dm_field_map; fp < LFM; fp++)
  787. X        if (f2r(fp->id) == r)
  788. X        f_string (fp->w, "");
  789. }
  790. X
  791. /* called to recompute and fill in values for the data menu.
  792. X * don't bother if it doesn't exist or is unmanaged now.
  793. X */
  794. dm_update (np, how_much)
  795. Now *np;
  796. int how_much;
  797. {
  798. X    int p;
  799. X    if (dataform_w && (how_much || XtIsManaged(dataform_w)))
  800. X        for (p = nxtbody(-1); p != -1; p = nxtbody(p))
  801. X        if (objs_on & 1<<p) {
  802. X            /* if object type changes to, say fixed, some fields may
  803. X             * no longer be used and be left dirty.
  804. X             */
  805. X            if (p == OBJX || p == OBJY)
  806. X            dm_erase_obj (p);
  807. X            dm_compute (p, how_much, np);
  808. X        }
  809. }
  810. X
  811. X
  812. /* compute and print body info in data menu format */
  813. static
  814. dm_compute (p, force, np)
  815. int p;        /* which body, as in astro.h/moreobjs.h defines */
  816. int force;    /* whether to print for sure or only if things have changed */
  817. Now *np;
  818. {
  819. X    Sky sky;
  820. X    double as = plot_ison() || srch_ison() ? 0.0 : 60.0;
  821. X    int row = bodyrow[p];
  822. X
  823. X    if (body_cir (p, as, np, &sky) || force) {
  824. X        show_constellation (np, row, &sky);
  825. X        f_ra (fw(row,C_RA), sky.s_ra);
  826. X        f_angle (fw(row,C_DEC), sky.s_dec);
  827. X        if (sky.s_hlong != NOHELIO) {
  828. X        f_angle (fw(row,C_HLONG), sky.s_hlong);
  829. X        if (p != SUN)
  830. X            f_angle (fw(row,C_HLAT), sky.s_hlat);
  831. X        }
  832. X
  833. X        if (p == MOON) {
  834. X        /* distance is on km, show in miles */
  835. X        f_double (fw(R_MOON,C_EDIST), "%6.0f", sky.s_edist/1.609344);
  836. X        } else if (sky.s_edist > 0.0) {
  837. X        /* show distance in au */
  838. X        f_double (fw(row,C_EDIST),(sky.s_edist>=10.0)?"%6.3f":"%6.4f",
  839. X                                sky.s_edist);
  840. X        }
  841. X        if (sky.s_sdist > 0.0)
  842. X        f_double (fw(row,C_SDIST),
  843. X            (sky.s_sdist>=9.99995)?"%6.3f":"%6.4f", sky.s_sdist);
  844. X        if (p != SUN)
  845. X        f_double (fw(row,C_ELONG), "%6.1f", sky.s_elong);
  846. X        f_double (fw(row,C_SIZE), sky.s_size >= 99.95 ?"%4.0f":"%4.1f",
  847. X                                sky.s_size);
  848. X        f_double (fw(row,C_MAG), sky.s_mag <= -9.95 ? "%4.0f" : "%4.1f",
  849. X                                sky.s_mag);
  850. X        if (sky.s_sdist > 0.0)
  851. X        f_double (fw(row,C_PHASE), "%3.0f", sky.s_phase);
  852. X    }
  853. X
  854. X    f_angle (fw(row,C_AZ), sky.s_az);
  855. X    f_angle (fw(row,C_ALT), sky.s_alt);
  856. }
  857. X
  858. static
  859. show_constellation (np, row, sp)
  860. Now *np;
  861. int row;
  862. Sky *sp;
  863. {
  864. X    char nm[10], *name;
  865. X        confnd (sp->s_ra, sp->s_dec, epoch == EOD ? mjd : epoch, &name);
  866. X    (void) sprintf (nm, "%.3s", name);
  867. X    f_string(fw(row,C_CONSTEL), nm);
  868. }
  869. SHAR_EOF
  870. chmod 0644 datamenu.c ||
  871. echo 'restore of datamenu.c failed'
  872. Wc_c="`wc -c < 'datamenu.c'`"
  873. test 24197 -eq "$Wc_c" ||
  874.     echo 'datamenu.c: original size 24197, current size' "$Wc_c"
  875. rm -f _shar_wnt_.tmp
  876. fi
  877. # ============= eq_ecl.c ==============
  878. if test -f 'eq_ecl.c' -a X"$1" != X"-c"; then
  879.     echo 'x - skipping eq_ecl.c (File already exists)'
  880.     rm -f _shar_wnt_.tmp
  881. else
  882. > _shar_wnt_.tmp
  883. echo 'x - extracting eq_ecl.c (Text)'
  884. sed 's/^X//' << 'SHAR_EOF' > 'eq_ecl.c' &&
  885. #include <stdio.h>
  886. #include <math.h>
  887. #include "astro.h"
  888. X
  889. #define    EQtoECL    1
  890. #define    ECLtoEQ    (-1)
  891. X
  892. /* given the modified Julian date, mjd, and an equitorial ra and dec, each in
  893. X * radians, find the corresponding geocentric ecliptic latitude, *lat, and
  894. X * longititude, *lng, also each in radians.
  895. X * correction for the effect on the angle of the obliquity due to nutation is
  896. X * included.
  897. X */
  898. eq_ecl (mjd, ra, dec, lat, lng)
  899. double mjd, ra, dec;
  900. double *lat, *lng;
  901. {
  902. X    ecleq_aux (EQtoECL, mjd, ra, dec, lng, lat);
  903. }
  904. X
  905. /* given the modified Julian date, mjd, and a geocentric ecliptic latitude,
  906. X * *lat, and longititude, *lng, each in radians, find the corresponding
  907. X * equitorial ra and dec, also each in radians.
  908. X * correction for the effect on the angle of the obliquity due to nutation is
  909. X * included.
  910. X */
  911. ecl_eq (mjd, lat, lng, ra, dec)
  912. double mjd, lat, lng;
  913. double *ra, *dec;
  914. {
  915. X    ecleq_aux (ECLtoEQ, mjd, lng, lat, ra, dec);
  916. }
  917. X
  918. static
  919. ecleq_aux (sw, mjd, x, y, p, q)
  920. int sw;            /* +1 for eq to ecliptic, -1 for vv. */
  921. double mjd, x, y;    /* sw==1: x==ra, y==dec.  sw==-1: x==lng, y==lat. */
  922. double *p, *q;        /* sw==1: p==lng, q==lat. sw==-1: p==ra, q==dec. */
  923. {
  924. X    static double lastmjd = -10000;    /* last mjd calculated */
  925. X    static double seps, ceps;    /* sin and cos of mean obliquity */
  926. X    double sx, cx, sy, cy, ty;
  927. X
  928. X    if (mjd != lastmjd) {
  929. X        double eps;
  930. X        double deps, dpsi;
  931. X        obliquity (mjd, &eps);        /* mean obliquity for date */
  932. X        nutation (mjd, &deps, &dpsi);
  933. X        eps += deps;
  934. X            seps = sin(eps);
  935. X        ceps = cos(eps);
  936. X        lastmjd = mjd;
  937. X    }
  938. X
  939. X    sy = sin(y);
  940. X    cy = cos(y);                /* always non-negative */
  941. X        if (fabs(cy)<1e-20) cy = 1e-20;        /* insure > 0 */
  942. X        ty = sy/cy;
  943. X    cx = cos(x);
  944. X    sx = sin(x);
  945. X        *q = asin((sy*ceps)-(cy*seps*sx*sw));
  946. X        *p = atan(((sx*ceps)+(ty*seps*sw))/cx);
  947. X        if (cx<0) *p += PI;        /* account for atan quad ambiguity */
  948. X    range (p, 2*PI);
  949. }
  950. SHAR_EOF
  951. chmod 0644 eq_ecl.c ||
  952. echo 'restore of eq_ecl.c failed'
  953. Wc_c="`wc -c < 'eq_ecl.c'`"
  954. test 1899 -eq "$Wc_c" ||
  955.     echo 'eq_ecl.c: original size 1899, current size' "$Wc_c"
  956. rm -f _shar_wnt_.tmp
  957. fi
  958. # ============= flog.c ==============
  959. if test -f 'flog.c' -a X"$1" != X"-c"; then
  960.     echo 'x - skipping flog.c (File already exists)'
  961.     rm -f _shar_wnt_.tmp
  962. else
  963. > _shar_wnt_.tmp
  964. echo 'x - extracting flog.c (Text)'
  965. sed 's/^X//' << 'SHAR_EOF' > 'flog.c' &&
  966. /* this is a simple little package to manage the saving and retrieving of
  967. X * field values, which we call field logging or "flogs". a flog consists of a
  968. X * field location, ala rcfpack(), its value as a double and its value as
  969. X * a string (ie, however it was printed). you can reset the list of flogs, add
  970. X * to and remove from the list of registered fields and log a field if it has
  971. X * been registered.
  972. X *
  973. X * this is used by the plotting and searching facilities of ephem to maintain
  974. X * the values of the fields that are being plotted or used in search
  975. X * expressions. it is used by the listing facility to generate listing files.
  976. X *
  977. X * a field can be in use for more than one
  978. X * thing at a time (eg, all the X plot values may the same time field, or
  979. X * searching and plotting might be on at one time using the same field) so
  980. X * we consider the field to be in use as long a usage count is > 0.
  981. X */
  982. X
  983. #include <X11/Xlib.h>
  984. #include <Xm/Xm.h>
  985. X
  986. #if 0
  987. extern char *strcpy(), *strncpy();
  988. #endif
  989. X
  990. #define    NFLOGS    32        /* max number of distinct simultaneous logged
  991. X                 * fields
  992. X                 */
  993. X
  994. typedef struct {
  995. X    int fl_usagecnt;    /* number of "users" logging to this field */
  996. X    Widget fl_fld;        /* what widget we are storing this for */
  997. X    double fl_val;        /* stored value as a double */
  998. X    char fl_str[16];    /* stored value as a formatted string.
  999. X                 * N.B.: never overwrite last char: keep as \0
  1000. X                 */
  1001. } FLog;
  1002. X
  1003. static FLog flog[NFLOGS];
  1004. X
  1005. /* add fld to the list. if already there, just increment usage count.
  1006. X * return 0 if ok, else -1 if no more room.
  1007. X */
  1008. flog_add (fld)
  1009. Widget fld;
  1010. {
  1011. X    FLog *flp, *unusedflp = 0;
  1012. X
  1013. X    /* scan for fld already in list, or find an unused one along the way */
  1014. X    for (flp = &flog[NFLOGS]; --flp >= flog; ) {
  1015. X        if (flp->fl_usagecnt > 0) {
  1016. X        if (flp->fl_fld == fld) {
  1017. X            flp->fl_usagecnt++;
  1018. X            return (0);
  1019. X        }
  1020. X        } else
  1021. X        unusedflp = flp;
  1022. X    }
  1023. X    if (unusedflp) {
  1024. X        unusedflp->fl_fld = fld;
  1025. X        unusedflp->fl_usagecnt = 1;
  1026. X        return (0);
  1027. X    }
  1028. X    return (-1);
  1029. }
  1030. X
  1031. /* decrement usage count for flog for fld. if goes to 0 take it out of list.
  1032. X * ok if not in list i guess...
  1033. X */
  1034. flog_delete (fld)
  1035. Widget fld;
  1036. {
  1037. X    FLog *flp;
  1038. X
  1039. X    for (flp = &flog[NFLOGS]; --flp >= flog; )
  1040. X        if (flp->fl_fld == fld && flp->fl_usagecnt > 0) {
  1041. X        if (--flp->fl_usagecnt <= 0) {
  1042. X            flp->fl_usagecnt = 0;
  1043. X        }
  1044. X        break;
  1045. X        }
  1046. }
  1047. X
  1048. /* if plotting, listing or searching is active then
  1049. X * if widget fld is in the fld list, set its value to val.
  1050. X * return 0 if ok, else -1 if not in list.
  1051. X */
  1052. flog_log (fld, val, str)
  1053. Widget fld;
  1054. double val;
  1055. char *str;
  1056. {
  1057. X    if (plot_ison() || listing_ison() || srch_ison()) {
  1058. X        FLog *flp;
  1059. X        for (flp = &flog[NFLOGS]; --flp >= flog; )
  1060. X        if (flp->fl_fld == fld && flp->fl_usagecnt > 0) {
  1061. X            flp->fl_val = val;
  1062. X            (void) strncpy (flp->fl_str, str, sizeof(flp->fl_str)-1);
  1063. X            return(0);
  1064. X        }
  1065. X        return (-1);
  1066. X    } else
  1067. X        return (0);
  1068. }
  1069. X
  1070. /* search for fld in list. if find it, return its value and str, if str.
  1071. X * return 0 if found it, else -1 if not in list.
  1072. X */
  1073. flog_get (fld, vp, str)
  1074. Widget fld;
  1075. double *vp;
  1076. char *str;
  1077. {
  1078. X    FLog *flp;
  1079. X
  1080. X    for (flp = &flog[NFLOGS]; --flp >= flog; )
  1081. X        if (flp->fl_fld == fld && flp->fl_usagecnt > 0) {
  1082. X        *vp = flp->fl_val;
  1083. X        if (str) 
  1084. X            (void) strcpy (str, flp->fl_str);
  1085. X        return (0);
  1086. X        }
  1087. X    return (-1);
  1088. }
  1089. SHAR_EOF
  1090. chmod 0644 flog.c ||
  1091. echo 'restore of flog.c failed'
  1092. Wc_c="`wc -c < 'flog.c'`"
  1093. test 3268 -eq "$Wc_c" ||
  1094.     echo 'flog.c: original size 3268, current size' "$Wc_c"
  1095. rm -f _shar_wnt_.tmp
  1096. fi
  1097. # ============= formats.c ==============
  1098. if test -f 'formats.c' -a X"$1" != X"-c"; then
  1099.     echo 'x - skipping formats.c (File already exists)'
  1100.     rm -f _shar_wnt_.tmp
  1101. else
  1102. > _shar_wnt_.tmp
  1103. echo 'x - extracting formats.c (Text)'
  1104. sed 's/^X//' << 'SHAR_EOF' > 'formats.c' &&
  1105. /* basic formating routines.
  1106. X * all the screen oriented printing should go through here.
  1107. X * we always save the string in XmNlabelString.
  1108. X */
  1109. X
  1110. #include <stdio.h>
  1111. #include <math.h>
  1112. #include <ctype.h>
  1113. #ifdef VMS
  1114. #include <stdlib.h>
  1115. #endif
  1116. #include <X11/Xlib.h>
  1117. #include <Xm/Xm.h>
  1118. #include <Xm/MessageB.h>
  1119. #include "astro.h"
  1120. X
  1121. X
  1122. #if 0
  1123. extern char *strcpy();
  1124. #endif
  1125. extern Widget toplevel_w;
  1126. X
  1127. /* suppress screen io if this is true, but always flog stuff.
  1128. X */
  1129. static int f_scrnoff;
  1130. f_on ()
  1131. {
  1132. X    f_scrnoff = 0;
  1133. }
  1134. f_off ()
  1135. {
  1136. X    f_scrnoff = 1;
  1137. }
  1138. f_ison()
  1139. {
  1140. X    return (!f_scrnoff);
  1141. }
  1142. X
  1143. /* print the given value, v, in "sexadecimal" format at [r,c]
  1144. X * ie, in the form A:m.P, where A is a digits wide, P is p digits.
  1145. X * if p == 0, then no decimal point either.
  1146. X */
  1147. f_sexad (w, a, p, mod, v)
  1148. Widget w;
  1149. int a, p;    /* left space, min precision */
  1150. int mod;    /* don't let whole portion get this big */
  1151. double v;
  1152. {
  1153. X    char astr[32], str[32];
  1154. X    long dec;
  1155. X    double frac;
  1156. X    int visneg;
  1157. X    double vsav = v;
  1158. X
  1159. X    if (v >= 0.0)
  1160. X        visneg = 0;
  1161. X    else {
  1162. X        if (v <= -0.5/60.0*pow(10.0,-1.0*p)) {
  1163. X        v = -v;
  1164. X        visneg = 1;
  1165. X        } else {
  1166. X        /* don't show as negative if less than the precision showing */
  1167. X        v = 0.0;
  1168. X        visneg = 0;
  1169. X        }
  1170. X    }
  1171. X
  1172. X    dec = v;
  1173. X    frac = (v - dec)*60.0;
  1174. X    (void) sprintf (str, "59.%.*s5", p, "999999999");
  1175. X    if (frac >= atof (str)) {
  1176. X        dec += 1;
  1177. X        frac = 0.0;
  1178. X    }
  1179. X    dec %= mod;
  1180. X    if (dec == 0 && visneg)
  1181. X        (void) strcpy (str, "-0");
  1182. X    else
  1183. X        (void) sprintf (str, "%ld", visneg ? -dec : dec);
  1184. X
  1185. X    /* would just do this if Turbo-C 2.0 %?.0f" worked:
  1186. X     * sprintf (astr, "%*s:%0*.*f", a, str, p == 0 ? 2 : p+3, p, frac);
  1187. X     */
  1188. X    if (p == 0)
  1189. X        (void) sprintf (astr, "%*s:%02d", a, str, (int)(frac+0.5));
  1190. X    else
  1191. X        (void) sprintf (astr, "%*s:%0*.*f", a, str, p+3, p, frac);
  1192. X
  1193. X    (void) flog_log (w, vsav, astr);
  1194. X
  1195. X    f_string (w, astr);
  1196. }
  1197. X
  1198. /* print the given value, t, in sexagesimal format at [r,c]
  1199. X * ie, in the form T:mm:ss, where T is nd digits wide.
  1200. X * N.B. we assume nd >= 2.
  1201. X */
  1202. f_sexag (w, nd, t)
  1203. Widget w;
  1204. int nd;
  1205. double t;
  1206. {
  1207. X    char tstr[32];
  1208. X    int h, m, s;
  1209. X    int tisneg;
  1210. X    
  1211. X    dec_sex (t, &h, &m, &s, &tisneg);
  1212. X    if (h == 0 && tisneg)
  1213. X        (void) sprintf (tstr, "%*s-0:%02d:%02d", nd-2, "", m, s);
  1214. X    else
  1215. X        (void) sprintf (tstr, "%*d:%02d:%02d", nd, tisneg ? -h : h, m, s);
  1216. X
  1217. X    (void) flog_log (w, t, tstr);
  1218. X    f_string (w, tstr);
  1219. }
  1220. X
  1221. /* print angle ra, in radians, in ra hours as hh:mm.m at [r,c]
  1222. X * N.B. we assume ra is >= 0.
  1223. X */
  1224. f_ra (w, ra)
  1225. Widget w;
  1226. double ra;
  1227. {
  1228. X    f_sexad (w, 2, 1, 24, radhr(ra));
  1229. }
  1230. X
  1231. /* print time, t, as hh:mm:ss */
  1232. f_time (w, t)
  1233. Widget w;
  1234. double t;
  1235. {
  1236. X    f_sexag (w, 2, t);
  1237. }
  1238. X
  1239. /* print time, t, as +/-hh:mm:ss (don't show leading +) */
  1240. f_signtime (w, t)
  1241. Widget w;
  1242. double t;
  1243. {
  1244. X    f_sexag (w, 3, t);
  1245. }
  1246. X
  1247. /* print time, t, as hh:mm */
  1248. f_mtime (w, t)
  1249. Widget w;
  1250. double t;
  1251. {
  1252. X    f_sexad (w, 2, 0, 24, t);
  1253. }
  1254. X
  1255. /* print angle, a, in rads, as degress at [r,c] in form ddd:mm */
  1256. f_angle(w, a)
  1257. Widget w;
  1258. double a;
  1259. {
  1260. X    f_sexad (w, 3, 0, 360, raddeg(a));
  1261. }
  1262. X
  1263. /* print angle, a, in rads, as degress at [r,c] in form dddd:mm:ss */
  1264. f_gangle(w, a)
  1265. Widget w;
  1266. double a;
  1267. {
  1268. X    f_sexag (w, 4, raddeg(a));
  1269. }
  1270. X
  1271. /* print the given modified Julian date, jd, as the starting date at [r,c]
  1272. X * in the form mm/dd/yyyy.
  1273. X */
  1274. f_date (w, jd)
  1275. Widget w;
  1276. double jd;
  1277. {
  1278. X    char dstr[32];
  1279. X    int m, y;
  1280. X    double d, tmp;
  1281. X
  1282. X    mjd_cal (jd, &m, &d, &y);
  1283. X    (void) sprintf (dstr, "%2d/%02d/%-4d", m, (int)(d), y);
  1284. X
  1285. X    /* shadow to the plot subsystem as years. */
  1286. X    mjd_year (jd, &tmp);
  1287. X    (void) flog_log (w, tmp, dstr);
  1288. X    f_string (w, dstr);
  1289. }
  1290. X
  1291. /* print the given double as a rounded int, with the given format.
  1292. X * this is used to plot full precision, but display far less.
  1293. X * N.B. caller beware that we really do expect fmt to refer to an int, not
  1294. X *   a long for example. also beware of range that implies.
  1295. X */
  1296. f_int (w, fmt, f)
  1297. Widget w;
  1298. char fmt[];
  1299. double f;
  1300. {
  1301. X    char str[80];
  1302. X    int i;
  1303. X
  1304. X    i = (f < 0) ? (int)(f-0.5) : (int)(f+0.5);
  1305. X    (void) sprintf (str, fmt, i);
  1306. X
  1307. X    (void) flog_log (w, f, str);
  1308. X    f_string (w, str);
  1309. }
  1310. X
  1311. f_string (w, s)
  1312. Widget w;
  1313. char *s;
  1314. {
  1315. X    char *txtp;
  1316. X
  1317. X    if (f_scrnoff)
  1318. X        return;
  1319. X    get_xmstring (w, XmNlabelString, &txtp);
  1320. X    if (strcmp (txtp, s))
  1321. X        set_xmstring (w, XmNlabelString, s);
  1322. X    XtFree (txtp);
  1323. }
  1324. X
  1325. f_double (w, fmt, f)
  1326. Widget w;
  1327. char *fmt;
  1328. double f;
  1329. {
  1330. X    char str[80];
  1331. X    (void) sprintf (str, fmt, f);
  1332. X    (void) flog_log (w, f, str);
  1333. X    f_string (w, str);
  1334. }
  1335. X
  1336. /* print a message and possibly wait for op to hit ok */
  1337. f_msg (p, app_modal)
  1338. char *p;
  1339. int app_modal;    /* set if want msg to be set APPLICATION_MODAL */
  1340. {
  1341. X    static Widget msg_w;
  1342. X    XmString message_string;
  1343. X    Arg args[20];
  1344. X    int n;
  1345. X
  1346. X    if (!msg_w) {
  1347. X        XmString button_string;
  1348. X        XmString title_string;
  1349. X        Widget w;
  1350. X
  1351. X        button_string = XmStringCreate("Ok", XmSTRING_DEFAULT_CHARSET);
  1352. X        title_string = XmStringCreate ("xephem Message",
  1353. X                        XmSTRING_DEFAULT_CHARSET);
  1354. X
  1355. X        /* Create MessageBox dialog. */
  1356. X        n = 0;
  1357. X        XtSetArg (args[n], XmNdialogTitle, title_string);  n++;
  1358. X        XtSetArg (args[n], XmNokLabelString, button_string);  n++;
  1359. X        msg_w = XmCreateMessageDialog (toplevel_w, "message", args, n);
  1360. X
  1361. X        XmStringFree (title_string);
  1362. X        XmStringFree (button_string);
  1363. X
  1364. X        w = XmMessageBoxGetChild (msg_w, XmDIALOG_CANCEL_BUTTON);
  1365. X        XtUnmanageChild (w);
  1366. X        w = XmMessageBoxGetChild (msg_w, XmDIALOG_HELP_BUTTON);
  1367. X        XtUnmanageChild (w);
  1368. X    }
  1369. X
  1370. X    message_string = XmStringCreateLtoR (p, XmSTRING_DEFAULT_CHARSET);
  1371. X
  1372. X    n = 0;
  1373. X    XtSetArg (args[n], XmNmessageString, message_string);  n++;
  1374. X    XtSetArg (args[n], XmNdialogStyle,
  1375. X        app_modal ? XmDIALOG_APPLICATION_MODAL : XmDIALOG_MODELESS);  n++;
  1376. X    XtSetValues (msg_w, args, n);
  1377. X    XmStringFree (message_string);
  1378. X
  1379. X    /* Display help window. rely on autoUnmanage to bring back down. */
  1380. X    XtManageChild (msg_w);
  1381. }
  1382. X
  1383. /* crack a line of the form X?X?X into its components,
  1384. X *   where X is an integer and ? can be any character except '0-9' or '-',
  1385. X *   such as ':' or '/'.
  1386. X * only change those fields that are specified:
  1387. X *   eg:  ::10    only changes *s
  1388. X *        10    only changes *d
  1389. X *        10:0  changes *d and *m
  1390. X * if see '-' anywhere, first non-zero component will be made negative.
  1391. X * TODO: s should be a double *.
  1392. X */
  1393. f_sscansex (bp, d, m, s)
  1394. char *bp;
  1395. int *d, *m, *s;
  1396. {
  1397. X    char c;
  1398. X    int *p = d;
  1399. X    int *nonzp = 0;
  1400. X    int sawneg = 0;
  1401. X    int innum = 0;
  1402. X
  1403. X    while (c = *bp++)
  1404. X        if (isdigit(c)) {
  1405. X        if (!innum) {
  1406. X            *p = 0;
  1407. X            innum = 1;
  1408. X        }
  1409. X        *p = *p*10 + (c - '0');
  1410. X        if (*p && !nonzp)
  1411. X            nonzp = p;
  1412. X        } else if (c == '-') {
  1413. X        sawneg = 1;
  1414. X        } else if (p == s && c == '.') {
  1415. X        c = *bp++;
  1416. X        if (isdigit(c) && c >= '5') {
  1417. X            /* round up if see at least .5 */
  1418. X            if (++(*s) == 60) {
  1419. X            if (++(*m) == 60) {
  1420. X                ++(*d);
  1421. X                *m = 0;
  1422. X            }
  1423. X            *s = 0;
  1424. X            }
  1425. X        }
  1426. X        break;
  1427. X        } else if (c != ' ') {
  1428. X        /* advance to next component */
  1429. X        p = (p == d) ? m : s;
  1430. X        innum = 0;
  1431. X        }
  1432. X
  1433. X    if (sawneg && nonzp)
  1434. X        *nonzp = -*nonzp;
  1435. }
  1436. X
  1437. /* crack a floating date string, bp, of the form m/d/y, where d may be a
  1438. X *   floating point number, into its components.
  1439. X * leave any component unspecified unchanged.
  1440. X * actually, the slashes may be anything but digits or a decimal point.
  1441. X * this is functionally the same as f_sscansex() exept we allow for
  1442. X *   the day portion to be real, and we don't handle negative numbers.
  1443. X *   maybe someday we could make a combined one and use it everywhere.
  1444. X */
  1445. f_sscandate (bp, m, d, y)
  1446. char *bp;
  1447. int *m, *y;
  1448. double *d;
  1449. {
  1450. X    char *bp0, c;
  1451. X
  1452. X    bp0 = bp;
  1453. X    while ((c = *bp++) && isdigit(c))
  1454. X        continue;
  1455. X    if (bp > bp0+1)
  1456. X        *m = atoi (bp0);
  1457. X    if (c == '\0')
  1458. X        return;
  1459. X    bp0 = bp;
  1460. X    while ((c = *bp++) && (isdigit(c) || c == '.'))
  1461. X        continue;
  1462. X    if (bp > bp0+1)
  1463. X        *d = atof (bp0);
  1464. X    if (c == '\0')
  1465. X        return;
  1466. X    bp0 = bp;
  1467. X    while (c = *bp++)
  1468. X        continue;
  1469. X    if (bp > bp0+1)
  1470. X        *y = atoi (bp0);
  1471. }
  1472. X
  1473. /* just like dec_sex() but makes the first non-zero element negative if
  1474. X * x is negative (instead of returning a sign flag).
  1475. X */
  1476. f_dec_sexsign (x, h, m, s)
  1477. double x;
  1478. int *h, *m, *s;
  1479. {
  1480. X    int n;
  1481. X    dec_sex (x, h, m, s, &n);
  1482. X    if (n) {
  1483. X        if (*h)
  1484. X        *h = -*h;
  1485. X        else if (*m)
  1486. X        *m = -*m;
  1487. X        else
  1488. X        *s = -*s;
  1489. X    }
  1490. }
  1491. X
  1492. /* return 1 if bp looks like a decimal year; else 0.
  1493. X * any number greater than 12 or less than 0 is assumed to be a year, or any
  1494. X * string with exactly one decimal point, an optional minus sign, and nothing
  1495. X * else but digits.
  1496. X */
  1497. decimal_year (bp)
  1498. char *bp;
  1499. {
  1500. X    char c;
  1501. X    int ndig = 0, ndp = 0, nneg = 0, nchar = 0;
  1502. X    double y = atof(bp);
  1503. X
  1504. X    while (c = *bp++) {
  1505. X        nchar++;
  1506. X        if (isdigit(c))
  1507. X        ndig++;
  1508. X        else if (c == '.')
  1509. X        ndp++;
  1510. X        else if (c == '-')
  1511. X        nneg++;
  1512. X    }
  1513. X
  1514. X    return (y > 12 || y < 0
  1515. X            || (ndp == 1 && nneg <= 1 && nchar == ndig+ndp+nneg));
  1516. }
  1517. SHAR_EOF
  1518. chmod 0644 formats.c ||
  1519. echo 'restore of formats.c failed'
  1520. Wc_c="`wc -c < 'formats.c'`"
  1521. test 8556 -eq "$Wc_c" ||
  1522.     echo 'formats.c: original size 8556, current size' "$Wc_c"
  1523. rm -f _shar_wnt_.tmp
  1524. fi
  1525. # ============= help.c ==============
  1526. if test -f 'help.c' -a X"$1" != X"-c"; then
  1527.     echo 'x - skipping help.c (File already exists)'
  1528.     rm -f _shar_wnt_.tmp
  1529. else
  1530. > _shar_wnt_.tmp
  1531. echo 'x - extracting help.c (Text)'
  1532. sed 's/^X//' << 'SHAR_EOF' > 'help.c' &&
  1533. /* this file contains the code to put up help messages.
  1534. X * the messages come from a file or, if no file is found or there is no
  1535. X * help entry for the requested subject, a small default text is provided.
  1536. X */
  1537. X
  1538. #include <stdio.h>
  1539. #include <ctype.h>
  1540. #include <math.h>
  1541. #ifdef VMS
  1542. #include <stdlib.h>
  1543. #endif
  1544. #include <X11/Xlib.h>
  1545. #include <Xm/Xm.h>
  1546. #include <Xm/Form.h>
  1547. #include <Xm/PushB.h>
  1548. #include <Xm/Text.h>
  1549. X
  1550. extern Widget toplevel_w;
  1551. extern char *getenv();
  1552. X
  1553. #define    MAXLINE        128    /* longest allowable help file line */
  1554. #define    HLP_TAG        '@'    /* help file tag marker */
  1555. #define    HLP_NEST    '+'    /* help file nested tag marker */
  1556. X
  1557. #define    NR    15
  1558. #define    NC    75
  1559. X
  1560. static char *hlpfile;            /* !0 if set by -h option */
  1561. static char hlpfdef[] = "xephem.hlp";    /* default help file name */
  1562. X
  1563. /* put up a help dialog. it contains a scrolled text area and an Ok button.
  1564. X * make a new dialog each time so we can have several up at once.
  1565. X * this means we need an explicit callback on the Ok button to destroy it
  1566. X * again (rather than being able to use the autoUnmanage feature).
  1567. X * if can't find any help, say so.
  1568. X */
  1569. hlp_dialog (tag, deflt, ndeflt)
  1570. char *tag;    /* tag to look for in help file - also dialog title */
  1571. char *deflt[];    /* help text to use if tag not found */
  1572. int ndeflt;    /* number of strings in deflt[] */
  1573. {
  1574. X    Widget hlp_create_dialog();
  1575. X    Widget txt_w, form_w;
  1576. X
  1577. X    txt_w = hlp_create_dialog (tag);
  1578. X    form_w = XtParent(XtParent(txt_w));
  1579. X
  1580. X    if (hlp_fillfromfile(tag, txt_w, 0) < 0) {
  1581. X        if (!deflt || ndeflt == 0) {
  1582. X        char buf[MAXLINE];
  1583. X        (void) sprintf (buf, "No help for %s", tag);
  1584. X        f_msg (buf, 0);
  1585. X        XtDestroyWidget (form_w);
  1586. X        return;
  1587. X        } else
  1588. X        hlp_fillfromstrings(deflt, ndeflt, txt_w);
  1589. X    }
  1590. X
  1591. X    XtManageChild (form_w);
  1592. X    /* everything gets destroyed when the Ok button is selected */
  1593. }
  1594. X
  1595. /* set an alternate help file name.
  1596. X * N.B. we assume the storage pointed to by name is permanent.
  1597. X */
  1598. hlp_setfilename (name)
  1599. char *name;
  1600. {
  1601. X    hlpfile = name;
  1602. }
  1603. X
  1604. /* create the help dialog with a scrolled text area and an Ok button.
  1605. X * return the text area widget; when ready to view, manage its parent's parent:
  1606. X *   dialog -> form -> scrolled_window -> text.
  1607. X * pass the dialog widget as the client parameter of the ok activate callback
  1608. X *   so it can destroy it.
  1609. X */
  1610. static Widget
  1611. hlp_create_dialog (tag)
  1612. char *tag;
  1613. {
  1614. X    void hlp_ok_cb();
  1615. X    Widget hlp_w;
  1616. X    Widget t_w, cb_w;
  1617. X    Arg args[20];
  1618. X    char title[MAXLINE];
  1619. X    int n;
  1620. X    int l;
  1621. X
  1622. X    /* make the help shell form-dialog widget */
  1623. X
  1624. X    n = 0;
  1625. X    XtSetArg (args[n], XmNautoUnmanage, False); n++;
  1626. X    hlp_w = XmCreateFormDialog (toplevel_w, "HelpD", args, n);
  1627. X
  1628. X    (void) sprintf (title, "xephem Help on %s", tag);
  1629. X    set_something (XtParent(hlp_w), XmNtitle, title);
  1630. X
  1631. X    /* make the Ok button - make it the default for RETURN */
  1632. X
  1633. X    n = 0;
  1634. X    XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1635. X    XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1636. X    XtSetArg (args[n], XmNshowAsDefault, True); n++;
  1637. SHAR_EOF
  1638. true || echo 'restore of help.c failed'
  1639. fi
  1640. echo 'End of  part 3'
  1641. echo 'File help.c is continued in part 4'
  1642. echo 4 > _shar_seq_.tmp
  1643. exit 0
  1644. -- 
  1645. --
  1646. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  1647. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  1648. Sunnyvale, California 94086            at&t: 408/522-9236
  1649.