1 /* code to handle constellation boundaries and figures */
2
3 /*
4 Constellation boundaries:
5
6 Primary reference:
7
8 METHOD TO DETERMINE THE CONSTELLATION IN WHICH A POSITION IS LOCATED
9
10 Recently, Mr. Barry N. Rappaport of New Mexico State University
11 transcribed the constellation boundaries as fixed by the IAU into
12 machine-readable form. These have been transcribed by Dr. Nancy G.
13 Roman to make it possible to determine by computer the constellation
14 in which a position is located.
15
16 NSSDC catalog description:
17 6042 AN Catalog of Constellation Boundary Data (Delporte, E. 1930,
18 Cambridge Univ. Press)
19 Comment(s): includes constellation identification software
20 (ADC 1987; see Roman, N.G. 1987, Publ. Astron. Soc. Pacific
21 99, 695); 23 description, 118 software, 358 data records.
22 3 files: 23x80, 118x80, 358x29
23
24 Further adapted for xephem by:
25
26 Craig Counterman: conversion from original F77 to C
27 Elwood Downey: incorporation into xephem
28 Ernie Wright: additional speed and time improvments
29
30 Constellation figures:
31
32 Chris Marriott: original figures
33 Elwood Downey: incorporated into xephem
34 */
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <ctype.h>
40 #include <math.h>
41
42 #include "astro.h"
43
44 /*
45 ======================================================================
46 Ernie Wright 2 Mar 94
47
48 Find the constellation for a given position.
49
50 First C version by Craig Counterman and Elwood Downey. Based on a
51 FORTRAN program by Nancy G. Roman (Roman, N.G. 1987, Publ. Astron.
52 Soc. Pacific 99, 695). IAU constellation boundaries transcribed into
53 machine-readable form by Barry N. Rappaport, New Mexico State Univ.
54 ======================================================================
55 */
56
57 #define NBOUNDS 357
58
59 /* constellation ids */
60 #define And 0
61 #define Ant 1
62 #define Aps 2
63 #define Aql 3
64 #define Aqr 4
65 #define Ara 5
66 #define Ari 6
67 #define Aur 7
68 #define Boo 8
69 #define CMa 9
70 #define CMi 10
71 #define CVn 11
72 #define Cae 12
73 #define Cam 13
74 #define Cap 14
75 #define Car 15
76 #define Cas 16
77 #define Cen 17
78 #define Cep 18
79 #define Cet 19
80 #define Cha 20
81 #define Cir 21
82 #define Cnc 22
83 #define Col 23
84 #define Com 24
85 #define CrA 25
86 #define CrB 26
87 #define Crt 27
88 #define Cru 28
89 #define Crv 29
90 #define Cyg 30
91 #define Del 31
92 #define Dor 32
93 #define Dra 33
94 #define Equ 34
95 #define Eri 35
96 #define For 36
97 #define Gem 37
98 #define Gru 38
99 #define Her 39
100 #define Hor 40
101 #define Hya 41
102 #define Hyi 42
103 #define Ind 43
104 #define LMi 44
105 #define Lac 45
106 #define Leo 46
107 #define Lep 47
108 #define Lib 48
109 #define Lup 49
110 #define Lyn 50
111 #define Lyr 51
112 #define Men 52
113 #define Mic 53
114 #define Mon 54
115 #define Mus 55
116 #define Nor 56
117 #define Oct 57
118 #define Oph 58
119 #define Ori 59
120 #define Pav 60
121 #define Peg 61
122 #define Per 62
123 #define Phe 63
124 #define Pic 64
125 #define PsA 65
126 #define Psc 66
127 #define Pup 67
128 #define Pyx 68
129 #define Ret 69
130 #define Scl 70
131 #define Sco 71
132 #define Sct 72
133 #define Se1 73
134 #define Sex 74
135 #define Sge 75
136 #define Sgr 76
137 #define Tau 77
138 #define Tel 78
139 #define TrA 79
140 #define Tri 80
141 #define Tuc 81
142 #define UMa 82
143 #define UMi 83
144 #define Vel 84
145 #define Vir 85
146 #define Vol 86
147 #define Vul 87
148 #define Se2 88
149
150 static char *cns_namemap[ NCNS ] = {
151 /* 0 */ "And: Andromeda",
152 /* 1 */ "Ant: Antlia",
153 /* 2 */ "Aps: Apus",
154 /* 3 */ "Aql: Aquila",
155 /* 4 */ "Aqr: Aquarius",
156 /* 5 */ "Ara: Ara",
157 /* 6 */ "Ari: Aries",
158 /* 7 */ "Aur: Auriga",
159 /* 8 */ "Boo: Bootes",
160 /* 9 */ "CMa: Canis Major",
161 /* 10 */ "CMi: Canis Minor",
162 /* 11 */ "CVn: Canes Venatici",
163 /* 12 */ "Cae: Caelum",
164 /* 13 */ "Cam: Camelopardalis",
165 /* 14 */ "Cap: Capricornus",
166 /* 15 */ "Car: Carina",
167 /* 16 */ "Cas: Cassiopeia",
168 /* 17 */ "Cen: Centaurus",
169 /* 18 */ "Cep: Cepheus",
170 /* 19 */ "Cet: Cetus",
171 /* 20 */ "Cha: Chamaeleon",
172 /* 21 */ "Cir: Circinus",
173 /* 22 */ "Cnc: Cancer",
174 /* 23 */ "Col: Columba",
175 /* 24 */ "Com: Coma Berenices",
176 /* 25 */ "CrA: Corona Australis",
177 /* 26 */ "CrB: Corona Borealis",
178 /* 27 */ "Crt: Crater",
179 /* 28 */ "Cru: Crux",
180 /* 29 */ "Crv: Corvus",
181 /* 30 */ "Cyg: Cygnus",
182 /* 31 */ "Del: Delphinus",
183 /* 32 */ "Dor: Dorado",
184 /* 33 */ "Dra: Draco",
185 /* 34 */ "Equ: Equuleus",
186 /* 35 */ "Eri: Eridanus",
187 /* 36 */ "For: Fornax",
188 /* 37 */ "Gem: Gemini",
189 /* 38 */ "Gru: Grus",
190 /* 39 */ "Her: Hercules",
191 /* 40 */ "Hor: Horologium",
192 /* 41 */ "Hya: Hydra",
193 /* 42 */ "Hyi: Hydrus",
194 /* 43 */ "Ind: Indus",
195 /* 44 */ "LMi: Leo Minor",
196 /* 45 */ "Lac: Lacerta",
197 /* 46 */ "Leo: Leo",
198 /* 47 */ "Lep: Lepus",
199 /* 48 */ "Lib: Libra",
200 /* 49 */ "Lup: Lupus",
201 /* 50 */ "Lyn: Lynx",
202 /* 51 */ "Lyr: Lyra",
203 /* 52 */ "Men: Mensa",
204 /* 53 */ "Mic: Microscopium",
205 /* 54 */ "Mon: Monoceros",
206 /* 55 */ "Mus: Musca",
207 /* 56 */ "Nor: Norma",
208 /* 57 */ "Oct: Octans",
209 /* 58 */ "Oph: Ophiuchus",
210 /* 59 */ "Ori: Orion",
211 /* 60 */ "Pav: Pavo",
212 /* 61 */ "Peg: Pegasus",
213 /* 62 */ "Per: Perseus",
214 /* 63 */ "Phe: Phoenix",
215 /* 64 */ "Pic: Pictor",
216 /* 65 */ "PsA: Piscis Austrinus",
217 /* 66 */ "Psc: Pisces",
218 /* 67 */ "Pup: Puppis",
219 /* 68 */ "Pyx: Pyxis",
220 /* 69 */ "Ret: Reticulum",
221 /* 70 */ "Scl: Sculptor",
222 /* 71 */ "Sco: Scorpius",
223 /* 72 */ "Sct: Scutum",
224 /* 73 */ "Se1: Serpens Caput",
225 /* 74 */ "Sex: Sextans",
226 /* 75 */ "Sge: Sagitta",
227 /* 76 */ "Sgr: Sagittarius",
228 /* 77 */ "Tau: Taurus",
229 /* 78 */ "Tel: Telescopium",
230 /* 79 */ "TrA: Triangulum Australe",
231 /* 80 */ "Tri: Triangulum",
232 /* 81 */ "Tuc: Tucana",
233 /* 82 */ "UMa: Ursa Major",
234 /* 83 */ "UMi: Ursa Minor",
235 /* 84 */ "Vel: Vela",
236 /* 85 */ "Vir: Virgo",
237 /* 86 */ "Vol: Volans",
238 /* 87 */ "Vul: Vulpecula",
239 /* 88 */ "Se2: Serpens Cauda",
240 };
241
242 static struct {
243 unsigned short lower_ra; /* hours * 1800 */
244 unsigned short upper_ra; /* hours * 1800 */
245 short lower_dec; /* degrees * 60 */
246 short index;
247 } cbound[ NBOUNDS ] = {
248 { 0, 43200, 5280, UMi },
249 { 14400, 26100, 5190, UMi },
250 { 37800, 41400, 5170, UMi },
251 { 32400, 37800, 5160, UMi },
252 { 0, 14400, 5100, Cep },
253 { 16500, 19200, 4920, Cam },
254 { 0, 9000, 4800, Cep },
255 { 19200, 26100, 4800, Cam },
256 { 31500, 32400, 4800, UMi },
257 { 36300, 37800, 4800, Dra },
258 { 0, 6315, 4620, Cep },
259 { 20700, 24450, 4620, Cam },
260 { 29760, 31500, 4500, UMi },
261 { 36300, 37200, 4500, Cep },
262 { 14340, 16500, 4410, Cam },
263 { 16500, 20400, 4410, Dra },
264 { 23400, 29760, 4200, UMi },
265 { 5580, 6150, 4080, Cas },
266 { 36750, 37200, 4020, Dra },
267 { 20400, 21600, 3990, Dra },
268 { 0, 600, 3960, Cep },
269 { 25200, 28200, 3960, UMi },
270 { 42450, 43200, 3960, Cep },
271 { 21600, 24300, 3840, Dra },
272 { 24300, 25950, 3780, Dra },
273 { 41700, 42450, 3780, Cep },
274 { 10980, 12600, 3720, Cam },
275 { 36000, 36750, 3690, Dra },
276 { 36966, 37080, 3655, Cep },
277 { 12600, 14340, 3600, Cam },
278 { 14340, 15150, 3600, UMa },
279 { 35580, 36000, 3570, Dra },
280 { 36000, 36966, 3570, Cep },
281 { 41160, 41700, 3545, Cep },
282 { 0, 4380, 3510, Cas },
283 { 34950, 35580, 3480, Dra },
284 { 3060, 3435, 3450, Cas },
285 { 4380, 5580, 3420, Cas },
286 { 5580, 5700, 3420, Cam },
287 { 40170, 41160, 3375, Cep },
288 { 9000, 10980, 3360, Cam },
289 { 25260, 25950, 3330, UMa },
290 { 25950, 34950, 3330, Dra },
291 { 5700, 6000, 3300, Cam },
292 { 39840, 40170, 3300, Cep },
293 { 37080, 39540, 3290, Cep },
294 { 0, 3060, 3240, Cas },
295 { 10980, 11700, 3240, Lyn },
296 { 21750, 24300, 3180, UMa },
297 { 27450, 28350, 3180, Dra },
298 { 39540, 39840, 3165, Cep },
299 { 6000, 9000, 3150, Cam },
300 { 41160, 42000, 3150, Cas },
301 { 28350, 30600, 3090, Dra },
302 { 3675, 4530, 3030, Per },
303 { 30600, 32820, 3030, Dra },
304 { 0, 2460, 3000, Cas },
305 { 2460, 3000, 3000, Per },
306 { 11700, 12240, 3000, Lyn },
307 { 42000, 43200, 3000, Cas },
308 { 24300, 25260, 2910, UMa },
309 { 0, 2010, 2880, Cas },
310 { 42450, 43200, 2880, Cas },
311 { 32715, 32820, 2850, Her },
312 { 32820, 34350, 2850, Dra },
313 { 34350, 34500, 2850, Cyg },
314 { 3000, 3675, 2820, Per },
315 { 15150, 16500, 2820, UMa },
316 { 300, 1560, 2760, Cas },
317 { 21600, 21750, 2700, UMa },
318 { 12240, 13260, 2670, Lyn },
319 { 39435, 39540, 2640, Cyg },
320 { 39375, 39435, 2625, Cyg },
321 { 34500, 34920, 2610, Cyg },
322 { 16500, 18300, 2520, UMa },
323 { 18300, 19410, 2400, UMa },
324 { 27780, 28350, 2400, Boo },
325 { 28350, 29400, 2400, Her },
326 { 16650, 17250, 2385, Lyn },
327 { 0, 4530, 2205, And },
328 { 4530, 4620, 2205, Per },
329 { 34845, 34920, 2190, Lyr },
330 { 8100, 8445, 2160, Per },
331 { 39120, 39375, 2160, Cyg },
332 { 39375, 39600, 2160, Lac },
333 { 11760, 13260, 2130, Aur },
334 { 13260, 13950, 2130, Lyn },
335 { 0, 3600, 2100, And },
336 { 39600, 41070, 2100, Lac },
337 { 41070, 41160, 2070, Lac },
338 { 41160, 42300, 2070, And },
339 { 4620, 4890, 2040, Per },
340 { 19410, 19800, 2040, UMa },
341 { 21600, 22200, 2040, CVn },
342 { 13950, 16650, 2010, Lyn },
343 { 16650, 17790, 2010, LMi },
344 { 1290, 2535, 1980, And },
345 { 27330, 27780, 1980, Boo },
346 { 42300, 42750, 1925, And },
347 { 22200, 23850, 1920, CVn },
348 { 42750, 43200, 1880, And },
349 { 25125, 25260, 1845, CVn },
350 { 4350, 4890, 1840, Tri },
351 { 4890, 8100, 1840, Per },
352 { 8100, 8550, 1800, Aur },
353 { 32715, 34845, 1800, Lyr },
354 { 19800, 21600, 1740, UMa },
355 { 35400, 37650, 1740, Cyg },
356 { 8550, 10590, 1710, Aur },
357 { 17790, 18900, 1710, LMi },
358 { 23850, 25125, 1710, CVn },
359 { 0, 120, 1680, And },
360 { 2535, 3000, 1680, Tri },
361 { 10590, 11760, 1680, Aur },
362 { 14190, 14400, 1680, Gem },
363 { 37650, 39120, 1680, Cyg },
364 { 34665, 35400, 1650, Cyg },
365 { 3450, 4350, 1635, Tri },
366 { 29100, 29400, 1620, CrB },
367 { 27150, 27330, 1560, Boo },
368 { 27330, 29100, 1560, CrB },
369 { 33060, 33960, 1560, Lyr },
370 { 19350, 19800, 1530, LMi },
371 { 33960, 34665, 1530, Lyr },
372 { 3000, 3450, 1500, Tri },
373 { 1290, 1530, 1425, Psc },
374 { 18900, 19350, 1410, LMi },
375 { 38250, 38550, 1410, Vul },
376 { 10260, 10590, 1370, Tau },
377 { 120, 255, 1320, And },
378 { 28650, 28860, 1320, Se1 },
379 { 10590, 11190, 1290, Gem },
380 { 35700, 36450, 1275, Vul },
381 { 33960, 34650, 1265, Vul },
382 { 255, 1530, 1260, And },
383 { 36450, 37020, 1230, Vul },
384 { 14055, 14190, 1200, Gem },
385 { 37020, 38250, 1170, Vul },
386 { 34650, 35700, 1150, Vul },
387 { 5910, 6060, 1140, Ari },
388 { 33960, 34200, 1110, Sge },
389 { 10260, 10380, 1080, Ori },
390 { 11190, 11355, 1050, Gem },
391 { 34200, 35700, 970, Sge },
392 { 8940, 9600, 960, Tau },
393 { 28650, 28950, 960, Her },
394 { 35700, 36450, 945, Sge },
395 { 8310, 8940, 930, Tau },
396 { 9600, 10080, 930, Tau },
397 { 23100, 24300, 900, Com },
398 { 31050, 32850, 860, Her },
399 { 21360, 23100, 840, Com },
400 { 13500, 14055, 810, Gem },
401 { 30150, 31050, 770, Her },
402 { 0, 255, 750, Peg },
403 { 10080, 10380, 750, Tau },
404 { 12600, 13500, 750, Gem },
405 { 38010, 38400, 750, Peg },
406 { 11355, 12480, 720, Gem },
407 { 32850, 33960, 720, Her },
408 { 37575, 37890, 710, Del },
409 { 37890, 38010, 710, Peg },
410 { 20730, 21360, 660, Leo },
411 { 11235, 11355, 600, Ori },
412 { 12480, 12600, 600, Gem },
413 { 14055, 14265, 600, Cnc },
414 { 42900, 43200, 600, Peg },
415 { 3000, 5910, 595, Ari },
416 { 36255, 36540, 510, Del },
417 { 24300, 27150, 480, Boo },
418 { 40950, 42900, 450, Peg },
419 { 14265, 16650, 420, Cnc },
420 { 16650, 19350, 420, Leo },
421 { 32850, 33592, 375, Oph },
422 { 33592, 33960, 375, Aql },
423 { 37500, 37575, 360, Del },
424 { 12600, 12630, 330, CMi },
425 { 32850, 33165, 270, Se2 },
426 { 28950, 30150, 240, Her },
427 { 32850, 33165, 180, Oph },
428 { 38640, 39000, 165, Peg },
429 { 0, 3600, 120, Psc },
430 { 33450, 33960, 120, Se2 },
431 { 36540, 37500, 120, Del },
432 { 37500, 38400, 120, Equ },
433 { 38400, 38640, 120, Peg },
434 { 39600, 40950, 120, Peg },
435 { 39000, 39600, 105, Peg },
436 { 12630, 12960, 90, CMi },
437 { 6450, 8310, 0, Tau },
438 { 8310, 8400, 0, Ori },
439 { 12960, 14550, 0, CMi },
440 { 26400, 27150, 0, Vir },
441 { 32100, 32850, 0, Oph },
442 { 4770, 5910, -105, Cet },
443 { 5910, 6450, -105, Tau },
444 { 27150, 29280, -195, Se1 },
445 { 8400, 9150, -240, Ori },
446 { 10500, 11235, -240, Ori },
447 { 32100, 32340, -240, Se2 },
448 { 32850, 33450, -240, Se2 },
449 { 33450, 33960, -240, Aql },
450 { 40950, 42900, -240, Psc },
451 { 19350, 20730, -360, Leo },
452 { 20730, 21300, -360, Vir },
453 { 0, 600, -420, Psc },
454 { 42900, 43200, -420, Psc },
455 { 25650, 26400, -480, Vir },
456 { 28650, 29280, -480, Oph },
457 { 36000, 36960, -540, Aql },
458 { 38400, 39360, -540, Aqr },
459 { 30900, 32340, -600, Oph },
460 { 10500, 14550, -660, Mon },
461 { 8850, 9150, -660, Eri },
462 { 9150, 10500, -660, Ori },
463 { 14550, 15060, -660, Hya },
464 { 17250, 19350, -660, Sex },
465 { 21300, 23100, -660, Vir },
466 { 31650, 31800, -700, Oph },
467 { 33960, 36000, -722, Aql },
468 { 8700, 8850, -870, Eri },
469 { 36960, 38400, -900, Aqr },
470 { 30900, 32850, -960, Se2 },
471 { 32850, 33960, -960, Sct },
472 { 15060, 15450, -1020, Hya },
473 { 29280, 29475, -1095, Oph },
474 { 15450, 16350, -1140, Hya },
475 { 19350, 19500, -1140, Crt },
476 { 29280, 29475, -1155, Sco },
477 { 28200, 28650, -1200, Lib },
478 { 22650, 23100, -1320, Crv },
479 { 23100, 25650, -1320, Vir },
480 { 16350, 17550, -1440, Hya },
481 { 3000, 4770, -1463, Cet },
482 { 4770, 6750, -1463, Eri },
483 { 19500, 21300, -1470, Crt },
484 { 21300, 22650, -1470, Crv },
485 { 25650, 26850, -1470, Lib },
486 { 29280, 30150, -1475, Oph },
487 { 0, 3000, -1530, Cet },
488 { 38400, 39360, -1530, Cap },
489 { 39360, 42900, -1530, Aqr },
490 { 42900, 43200, -1530, Cet },
491 { 17550, 18450, -1590, Hya },
492 { 8460, 8700, -1635, Eri },
493 { 8700, 11010, -1635, Lep },
494 { 36000, 38400, -1680, Cap },
495 { 18450, 19050, -1750, Hya },
496 { 22650, 26850, -1770, Hya },
497 { 26850, 28200, -1770, Lib },
498 { 28200, 28800, -1770, Sco },
499 { 8250, 8460, -1800, Eri },
500 { 30150, 31680, -1800, Oph },
501 { 31680, 32100, -1800, Sgr },
502 { 19050, 19500, -1870, Hya },
503 { 11010, 13260, -1980, CMa },
504 { 22050, 22650, -1980, Hya },
505 { 19500, 22050, -2100, Hya },
506 { 6300, 6750, -2160, For },
507 { 15060, 16860, -2205, Pyx },
508 { 7680, 8250, -2220, Eri },
509 { 32100, 34500, -2220, Sgr },
510 { 38400, 41400, -2220, PsA },
511 { 41400, 42000, -2220, Scl },
512 { 5400, 6300, -2375, For },
513 { 16860, 19800, -2385, Ant },
514 { 0, 3000, -2400, Scl },
515 { 3000, 5400, -2400, For },
516 { 6960, 7680, -2400, Eri },
517 { 42000, 43200, -2400, Scl },
518 { 25500, 26850, -2520, Cen },
519 { 28200, 28800, -2520, Lup },
520 { 28800, 29557, -2520, Sco },
521 { 8700, 9000, -2580, Cae },
522 { 9000, 11850, -2580, Col },
523 { 14400, 15060, -2580, Pup },
524 { 6150, 6960, -2640, Eri },
525 { 29557, 32100, -2730, Sco },
526 { 32100, 34500, -2730, CrA },
527 { 34500, 36600, -2730, Sgr },
528 { 36600, 38400, -2730, Mic },
529 { 5400, 6150, -2760, Eri },
530 { 8100, 8700, -2790, Cae },
531 { 27600, 28200, -2880, Lup },
532 { 0, 4200, -2890, Phe },
533 { 4800, 5400, -2940, Eri },
534 { 7350, 7680, -2940, Hor },
535 { 7680, 8100, -2940, Cae },
536 { 38400, 39600, -3000, Gru },
537 { 10800, 14400, -3045, Pup },
538 { 14400, 14700, -3045, Vel },
539 { 4350, 4800, -3060, Eri },
540 { 6900, 7350, -3060, Hor },
541 { 0, 3300, -3090, Phe },
542 { 10800, 11100, -3150, Car },
543 { 14700, 15210, -3180, Vel },
544 { 6300, 6900, -3190, Hor },
545 { 6900, 7200, -3190, Dor },
546 { 0, 2850, -3210, Phe },
547 { 3900, 4350, -3240, Eri },
548 { 8100, 9000, -3240, Pic },
549 { 27090, 27600, -3240, Lup },
550 { 15210, 15900, -3270, Vel },
551 { 11100, 11700, -3300, Car },
552 { 21300, 23100, -3300, Cen },
553 { 25500, 27090, -3300, Lup },
554 { 27090, 27600, -3300, Nor },
555 { 7200, 7800, -3390, Dor },
556 { 15900, 19800, -3390, Vel },
557 { 19800, 20250, -3390, Cen },
558 { 31500, 32400, -3420, Ara },
559 { 32400, 36600, -3420, Tel },
560 { 39600, 42000, -3420, Gru },
561 { 5760, 6300, -3450, Hor },
562 { 9000, 9900, -3450, Pic },
563 { 11700, 12300, -3480, Car },
564 { 0, 2400, -3510, Phe },
565 { 2400, 3900, -3510, Eri },
566 { 42000, 43200, -3510, Phe },
567 { 7800, 8250, -3540, Dor },
568 { 27600, 29557, -3600, Nor },
569 { 36600, 38400, -3600, Ind },
570 { 9900, 10800, -3660, Pic },
571 { 27300, 27600, -3660, Cir },
572 { 29557, 29850, -3660, Ara },
573 { 26850, 27300, -3815, Cir },
574 { 29850, 30150, -3815, Ara },
575 { 10800, 12300, -3840, Pic },
576 { 12300, 16260, -3840, Car },
577 { 20250, 21300, -3840, Cen },
578 { 21300, 23100, -3840, Cru },
579 { 23100, 26160, -3840, Cen },
580 { 24300, 24600, -3900, Cir },
581 { 30150, 30300, -3900, Ara },
582 { 3900, 5760, -4050, Hor },
583 { 5760, 8250, -4050, Ret },
584 { 26550, 26850, -4050, Cir },
585 { 30300, 31500, -4050, Ara },
586 { 31500, 32400, -4050, Pav },
587 { 39600, 42000, -4050, Tuc },
588 { 8250, 11850, -4200, Dor },
589 { 24600, 26550, -4200, Cir },
590 { 26550, 30600, -4200, TrA },
591 { 0, 2400, -4500, Tuc },
592 { 6300, 8250, -4500, Hyi },
593 { 11850, 16260, -4500, Vol },
594 { 16260, 20250, -4500, Car },
595 { 20250, 24600, -4500, Mus },
596 { 32400, 38400, -4500, Pav },
597 { 38400, 42000, -4500, Ind },
598 { 42000, 43200, -4500, Tuc },
599 { 1350, 2400, -4560, Tuc },
600 { 0, 6300, -4950, Hyi },
601 { 13800, 24600, -4950, Cha },
602 { 24600, 32400, -4950, Aps },
603 { 6300, 13800, -5100, Men },
604 { 0, 43200, -5400, Oct }
605 };
606
607 static short start[] = {
608 355, 352, 343, 340, 332, 320,
609 303, 288, 277, 266, 257, 251,
610 239, 229, 221, 211, 203, 189,
611 177, 163, 149, 136, 124, 104,
612 87, 75, 69, 54, 43, 29,
613 23, 16, 12, 6, 4, 0, 0
614 };
615
616
617 /*
618 ======================================================================
619 constellation_pick()
620
621 Do a constellation pick from RA and Dec.
622
623 INPUTS
624 r right ascension, radians
625 d declination, radians
626 e epoch to which r and d precessed, as an mjd
627
628 RESULTS
629 Returns an index for the constellation region that the coordinates
630 belong to, or -1 if no constellation pick can be found.
631
632 The constellation is identified by linear search. We look for a
633 member of cbound[] whose lower_dec is less than the declination of the
634 pick point and whose lower_ra and upper_ra bracket the pick point's
635 right ascension. The data for that cbound[] member describes a sub-
636 region belonging to the picked constellation.
637
638 In geometric terms, the search amounts to starting at the north pole
639 and traveling south on a line of constant right ascension through the
640 pick point. At every declination where a cbound[] member lives, we
641 wake up, and if (1) the pick point is now behind us, and (2) the
642 cbound[] segment is crossing our path, we know we've hit the edge of
643 a constellation subregion that the pick point belongs to.
644
645 The cbound[] right ascension and declination values are scaled into
646 integers; this conserves storage and makes comparisons faster. The
647 start[] array, which gives starting points in cbound[] for different
648 declinations in 5-degree increments, further speeds the search by
649 skipping early parts of the list for which we know the search can't
650 succeed--geometrically, we start no more than 5 degrees north of the
651 pick point, rather than at the north pole.
652
653 The data in cbound[] are for epoch 1875.
654 ======================================================================
655 */
656
657 int
cns_pick(double r,double d,double e)658 cns_pick(double r, double d, double e)
659 {
660 double Mjd;
661 unsigned short ra;
662 short de, i;
663
664 cal_mjd( 1, 1.0, 1875, &Mjd );
665 precess( e, Mjd, &r, &d );
666 ra = ( unsigned short )( radhr( r ) * 1800 );
667 de = ( short )( raddeg( d ) * 60 );
668 if (d < 0.0) --de;
669
670 i = ( de + 5400 ) / 300;
671 if ( i < 0 || i > 36 ) return -1;
672 i = start[ i ];
673
674 for ( ; i < NBOUNDS; i++ )
675 if ( cbound[ i ].lower_dec <= de &&
676 cbound[ i ].upper_ra > ra &&
677 cbound[ i ].lower_ra <= ra ) break;
678
679 return ( i == NBOUNDS ) ? -1 : ( int ) cbound[ i ].index;
680 }
681
682 /* given a constellation id (as from cns_pick()), return pointer to static
683 * storage containg its name in the form "AAA: Name".
684 * return "???: ???" if id is invalid.
685 */
686 char *
cns_name(int id)687 cns_name (int id)
688 {
689 if (id < 0 || id >= NCNS)
690 return ("???: ???");
691 return (cns_namemap[id]);
692 }
693
694 /* return cns_namemap index matching first three chars in abbrev[], else -1.
695 */
696 int
cns_id(char * abbrev)697 cns_id (char *abbrev)
698 {
699 int i;
700
701 for (i = 0; i < NCNS; i++)
702 if (strncmp (abbrev, cns_namemap[i], 3) == 0)
703 return (i);
704 return (-1);
705 }
706
707 /* edges of constant ra */
708 static struct {
709 unsigned short ra; /* hours * 1800 */
710 short dec0, dec1; /* degrees * 60 */
711 } ra_edges[] = {
712 { 0, -4950, -4500 },
713 { 0, 600, 750 },
714 { 0, 1680, 1879 },
715 { 120, 1320, 1680 },
716 { 255, 750, 1260 },
717 { 255, 1260, 1320 },
718 { 300, 2760, 2880 },
719 { 599, -420, 0 },
720 { 599, 0, 120 },
721 { 599, 3960, 4620 },
722 { 1290, 1425, 1980 },
723 { 1350, -4500, -4560 },
724 { 1530, 1260, 1425 },
725 { 1560, 2760, 2880 },
726 { 2010, 2880, 3000 },
727 { 2399, -4560, -3510 },
728 { 2399, -3510, -3210 },
729 { 2460, 3000, 3240 },
730 { 2534, 1680, 1980 },
731 { 2534, 1980, 2100 },
732 { 2849, -3210, -3090 },
733 { 3000, -2400, -1530 },
734 { 3000, -1530, -1462 },
735 { 3000, 595, 1500 },
736 { 3000, 1500, 1680 },
737 { 3000, 2820, 3000 },
738 { 3060, 3240, 3450 },
739 { 3299, -3090, -2890 },
740 { 3434, 3450, 3510 },
741 { 3450, 1500, 1635 },
742 { 3600, 120, 595 },
743 { 3600, 2100, 2205 },
744 { 3675, 2820, 3030 },
745 { 3900, -4050, -3510 },
746 { 3900, -3510, -3240 },
747 { 4199, -2890, -2400 },
748 { 4350, -3240, -3060 },
749 { 4350, 1635, 1840 },
750 { 4379, 3420, 3510 },
751 { 4530, 2205, 3030 },
752 { 4620, 2040, 2205 },
753 { 4770, -1462, -105 },
754 { 4800, -3060, -2940 },
755 { 4890, 1840, 2040 },
756 { 5400, -2940, -2760 },
757 { 5400, -2400, -2374 },
758 { 5580, 3420, 4080 },
759 { 5700, 3300, 3420 },
760 { 5760, -3450, -4050 },
761 { 5909, -105, 0 },
762 { 5909, 0, 595 },
763 { 5909, 595, 1140 },
764 { 5999, 3150, 3300 },
765 { 6060, 1140, 1840 },
766 { 6150, -2760, -2640 },
767 { 6150, 4080, 4620 },
768 { 6300, -5100, -4950 },
769 { 6300, -4950, -4500 },
770 { 6300, -3190, -3450 },
771 { 6300, -2374, -2160 },
772 { 6314, 4620, 4800 },
773 { 6449, -105, 0 },
774 { 6750, -2160, -1462 },
775 { 6899, -3060, -3190 },
776 { 6960, -2640, -2400 },
777 { 7200, -3390, -3190 },
778 { 7349, -2940, -3060 },
779 { 7680, -2400, -2940 },
780 { 7680, -2220, -2400 },
781 { 7799, -3540, -3390 },
782 { 8100, -3240, -2940 },
783 { 8100, -2940, -2790 },
784 { 8100, 1800, 1840 },
785 { 8100, 1840, 2160 },
786 { 8249, -4500, -4200 },
787 { 8249, -4050, -4200 },
788 { 8249, -4050, -3540 },
789 { 8249, -1800, -2220 },
790 { 8310, 0, 930 },
791 { 8400, -240, 0 },
792 { 8445, 2160, 3150 },
793 { 8460, -1635, -1800 },
794 { 8550, 1710, 1800 },
795 { 8699, -2790, -2580 },
796 { 8699, -870, -1635 },
797 { 8850, -660, -870 },
798 { 8940, 930, 960 },
799 { 9000, -3450, -3240 },
800 { 9000, -2580, -1635 },
801 { 9000, 3150, 3360 },
802 { 9000, 4800, 5100 },
803 { 9149, -660, -240 },
804 { 9599, 930, 960 },
805 { 9900, -3660, -3450 },
806 { 10080, 750, 930 },
807 { 10260, 1080, 1369 },
808 { 10380, 750, 1080 },
809 { 10499, -660, -240 },
810 { 10589, 1290, 1369 },
811 { 10589, 1369, 1680 },
812 { 10589, 1680, 1710 },
813 { 10800, -3840, -3660 },
814 { 10800, -3150, -3045 },
815 { 10800, -3045, -2580 },
816 { 10980, 3240, 3360 },
817 { 10980, 3360, 3720 },
818 { 11010, -1980, -1635 },
819 { 11010, -1635, -660 },
820 { 11100, -3300, -3150 },
821 { 11190, 1050, 1290 },
822 { 11235, -240, 0 },
823 { 11235, 0, 600 },
824 { 11354, 600, 720 },
825 { 11354, 720, 1050 },
826 { 11700, -3480, -3300 },
827 { 11700, 3000, 3240 },
828 { 11759, 1680, 2130 },
829 { 11849, -4200, -4500 },
830 { 11849, -4200, -3840 },
831 { 11849, -1980, -2580 },
832 { 12240, 2670, 3000 },
833 { 12299, -3840, -3480 },
834 { 12479, 600, 720 },
835 { 12600, 330, 600 },
836 { 12600, 600, 750 },
837 { 12600, 3600, 3720 },
838 { 12630, 90, 330 },
839 { 12960, 0, 90 },
840 { 13260, -660, -1980 },
841 { 13260, 2130, 2670 },
842 { 13500, 750, 810 },
843 { 13800, -5100, -4950 },
844 { 13800, -4500, -4950 },
845 { 13950, 2010, 2130 },
846 { 14054, 600, 810 },
847 { 14054, 810, 1200 },
848 { 14189, 1200, 1680 },
849 { 14265, 420, 600 },
850 { 14340, 3600, 4410 },
851 { 14400, -3045, -2580 },
852 { 14400, 1680, 2010 },
853 { 14400, 5100, 5190 },
854 { 14400, 5280, 5190 },
855 { 14549, -660, 0 },
856 { 14549, 0, 420 },
857 { 14700, -3180, -3045 },
858 { 15060, -2580, -2205 },
859 { 15060, -2205, -1020 },
860 { 15060, -1020, -660 },
861 { 15150, 2820, 3600 },
862 { 15209, -3270, -3180 },
863 { 15449, -1140, -1020 },
864 { 15899, -3390, -3270 },
865 { 16259, -4500, -3840 },
866 { 16349, -1440, -1140 },
867 { 16500, 2520, 2820 },
868 { 16500, 4410, 4920 },
869 { 16650, 420, 2010 },
870 { 16650, 2010, 2385 },
871 { 16860, -2385, -2205 },
872 { 16860, -1440, -2205 },
873 { 17249, -660, 0 },
874 { 17249, 0, 420 },
875 { 17249, 2385, 2520 },
876 { 17550, -1590, -1440 },
877 { 17789, 1710, 2010 },
878 { 18300, 2400, 2520 },
879 { 18450, -1750, -1590 },
880 { 18900, 1410, 1710 },
881 { 19049, -1870, -1750 },
882 { 19200, 4800, 4920 },
883 { 19350, -660, -1140 },
884 { 19350, -360, -660 },
885 { 19350, -360, 0 },
886 { 19350, 0, 420 },
887 { 19350, 1410, 1530 },
888 { 19409, 2040, 2400 },
889 { 19499, -2100, -1870 },
890 { 19499, -1140, -1470 },
891 { 19800, -3390, -2385 },
892 { 19800, -2385, -2100 },
893 { 19800, 1530, 1740 },
894 { 19800, 1740, 2040 },
895 { 20250, -4500, -3840 },
896 { 20250, -3840, -3390 },
897 { 20399, 3990, 4410 },
898 { 20700, 4620, 4800 },
899 { 20730, -360, 0 },
900 { 20730, 0, 660 },
901 { 21299, -3840, -3300 },
902 { 21299, -1470, -660 },
903 { 21299, -660, -360 },
904 { 21360, 660, 840 },
905 { 21360, 840, 1740 },
906 { 21600, 1740, 2040 },
907 { 21600, 2040, 2700 },
908 { 21600, 3840, 3990 },
909 { 21749, 2700, 3180 },
910 { 22050, -1980, -2100 },
911 { 22199, 1920, 2040 },
912 { 22649, -1770, -1980 },
913 { 22649, -1470, -1320 },
914 { 23099, -3840, -3300 },
915 { 23099, -1320, -660 },
916 { 23099, 840, 900 },
917 { 23400, 4620, 4200 },
918 { 23850, 1710, 1920 },
919 { 24300, -3900, -3840 },
920 { 24300, 480, 900 },
921 { 24300, 900, 1710 },
922 { 24300, 2910, 3180 },
923 { 24300, 3780, 3840 },
924 { 24449, 4800, 4620 },
925 { 24600, -4950, -4500 },
926 { 24600, -4500, -4200 },
927 { 24600, -4200, -3900 },
928 { 25124, 1710, 1845 },
929 { 25200, 4200, 3960 },
930 { 25259, 1845, 2910 },
931 { 25259, 2910, 3330 },
932 { 25500, -3300, -2520 },
933 { 25650, -1320, -1470 },
934 { 25650, -480, -1320 },
935 { 25950, 3330, 3780 },
936 { 26100, 5190, 4800 },
937 { 26159, -3840, -3300 },
938 { 26400, 0, -480 },
939 { 26550, -4200, -4050 },
940 { 26850, -4050, -3814 },
941 { 26850, -2520, -1770 },
942 { 26850, -1470, -1770 },
943 { 27090, -3300, -3240 },
944 { 27149, -195, 0 },
945 { 27149, 0, 480 },
946 { 27149, 480, 1560 },
947 { 27300, -3814, -3660 },
948 { 27329, 1560, 1980 },
949 { 27450, 3180, 3330 },
950 { 27599, -3660, -3600 },
951 { 27599, -3600, -3300 },
952 { 27599, -3240, -2880 },
953 { 27779, 1980, 2400 },
954 { 28200, -2880, -2520 },
955 { 28200, -1770, -1200 },
956 { 28200, 3960, 4200 },
957 { 28350, 2400, 3090 },
958 { 28350, 3090, 3180 },
959 { 28650, -1200, -480 },
960 { 28650, -480, -195 },
961 { 28650, 960, 1320 },
962 { 28800, -2520, -1770 },
963 { 28859, 1320, 1560 },
964 { 28949, 240, 960 },
965 { 29100, 1560, 1620 },
966 { 29280, -1474, -1155 },
967 { 29280, -1095, -480 },
968 { 29280, -195, 0 },
969 { 29280, 0, 240 },
970 { 29399, 1620, 2400 },
971 { 29475, -1155, -1095 },
972 { 29557, -3660, -3600 },
973 { 29557, -3600, -2730 },
974 { 29557, -2730, -2520 },
975 { 29759, 4200, 4500 },
976 { 29849, -3814, -3660 },
977 { 30150, -3900, -3814 },
978 { 30150, -1800, -1474 },
979 { 30150, 240, 769 },
980 { 30299, -4050, -3900 },
981 { 30600, -4050, -4200 },
982 { 30600, 3030, 3090 },
983 { 30900, -960, -600 },
984 { 31050, 769, 859 },
985 { 31500, -3420, -4050 },
986 { 31500, 4500, 4800 },
987 { 31649, -700, -600 },
988 { 31680, -960, -1800 },
989 { 31800, -700, -600 },
990 { 32099, -2730, -2220 },
991 { 32099, -1800, -2220 },
992 { 32099, -240, 0 },
993 { 32340, -600, -240 },
994 { 32400, -4950, -4500 },
995 { 32400, -4500, -4050 },
996 { 32400, -2730, -3420 },
997 { 32400, 4800, 5160 },
998 { 32715, 1800, 2850 },
999 { 32819, 2850, 3030 },
1000 { 32850, -240, -960 },
1001 { 32850, 0, 180 },
1002 { 32850, 270, 375 },
1003 { 32850, 720, 859 },
1004 { 33060, 1560, 1800 },
1005 { 33165, 180, 270 },
1006 { 33449, -240, 0 },
1007 { 33449, 0, 120 },
1008 { 33591, 375, 720 },
1009 { 33960, -960, -721 },
1010 { 33960, -721, -240 },
1011 { 33960, 120, 375 },
1012 { 33960, 720, 1110 },
1013 { 33960, 1110, 1264 },
1014 { 33960, 1264, 1530 },
1015 { 33960, 1530, 1560 },
1016 { 34200, 970, 1110 },
1017 { 34349, 2850, 3330 },
1018 { 34500, -2220, -2730 },
1019 { 34500, 2610, 2850 },
1020 { 34650, 1150, 1264 },
1021 { 34664, 1530, 1650 },
1022 { 34664, 1650, 1800 },
1023 { 34844, 1800, 2190 },
1024 { 34920, 2190, 2610 },
1025 { 34950, 3330, 3480 },
1026 { 35400, 1650, 1740 },
1027 { 35580, 3480, 3570 },
1028 { 35699, 945, 970 },
1029 { 35699, 1150, 1275 },
1030 { 36000, -1680, -721 },
1031 { 36000, -540, -721 },
1032 { 36000, 3570, 3690 },
1033 { 36255, 510, 945 },
1034 { 36300, 4500, 4800 },
1035 { 36450, 945, 1230 },
1036 { 36450, 1230, 1275 },
1037 { 36540, 120, 510 },
1038 { 36599, -3600, -3420 },
1039 { 36599, -3420, -2730 },
1040 { 36599, -2730, -1680 },
1041 { 36750, 3690, 4020 },
1042 { 36959, -900, -540 },
1043 { 36959, -540, 0 },
1044 { 36959, 0, 120 },
1045 { 36966, 3570, 3655 },
1046 { 37020, 1170, 1230 },
1047 { 37080, 3289, 3655 },
1048 { 37200, 4020, 4500 },
1049 { 37499, 120, 360 },
1050 { 37575, 360, 709 },
1051 { 37650, 1680, 1740 },
1052 { 37800, 4800, 5160 },
1053 { 37800, 5160, 5169 },
1054 { 37890, 709, 1170 },
1055 { 38010, 709, 750 },
1056 { 38250, 1170, 1410 },
1057 { 38399, -4500, -3600 },
1058 { 38399, -3000, -2730 },
1059 { 38399, -2220, -2730 },
1060 { 38399, -1680, -2220 },
1061 { 38399, -1680, -1530 },
1062 { 38399, -540, -900 },
1063 { 38399, 120, 750 },
1064 { 38550, 1410, 1680 },
1065 { 38640, 120, 165 },
1066 { 39000, 105, 165 },
1067 { 39119, 1680, 2160 },
1068 { 39360, -1530, -540 },
1069 { 39375, 2160, 2625 },
1070 { 39434, 2625, 2640 },
1071 { 39540, 2640, 3165 },
1072 { 39540, 3165, 3289 },
1073 { 39600, -4050, -3420 },
1074 { 39600, -3420, -3000 },
1075 { 39600, 105, 120 },
1076 { 39600, 2100, 2160 },
1077 { 39839, 3165, 3300 },
1078 { 40170, 3300, 3375 },
1079 { 40950, -240, 0 },
1080 { 40950, 0, 120 },
1081 { 40950, 120, 450 },
1082 { 41070, 2070, 2100 },
1083 { 41160, 2070, 3150 },
1084 { 41160, 3150, 3375 },
1085 { 41160, 3375, 3544 },
1086 { 41400, -2220, -1530 },
1087 { 41400, 5169, 5280 },
1088 { 41700, 3544, 3780 },
1089 { 41999, -4500, -4050 },
1090 { 41999, -3510, -3420 },
1091 { 41999, -3420, -2400 },
1092 { 41999, -2400, -2220 },
1093 { 41999, 3000, 3150 },
1094 { 42300, 1924, 2070 },
1095 { 42449, 2880, 3000 },
1096 { 42449, 3780, 3960 },
1097 { 42750, 1879, 1924 },
1098 { 42899, -1530, -420 },
1099 { 42899, -420, -240 },
1100 { 42899, 450, 600 },
1101 };
1102
1103 #define NRA ((int)(sizeof(ra_edges)/sizeof(ra_edges[0])))
1104
1105 /* edges of constant dec */
1106 static struct {
1107 short dec; /* degrees * 60 */
1108 unsigned short ra0, ra1; /* hours * 1800 */
1109 } dec_edges[] = {
1110 { -5100, 6300, 13800 },
1111 { -4950, 0, 6300 },
1112 { -4950, 13800, 24600 },
1113 { -4950, 24600, 32400 },
1114 { -4560, 1350, 2399 },
1115 { -4500, 0, 1350 },
1116 { -4500, 6300, 8249 },
1117 { -4500, 11849, 13800 },
1118 { -4500, 13800, 16259 },
1119 { -4500, 16259, 20250 },
1120 { -4500, 20250, 24600 },
1121 { -4500, 32400, 38399 },
1122 { -4500, 38399, 41999 },
1123 { -4500, 41999, 0 },
1124 { -4200, 8249, 11849 },
1125 { -4200, 24600, 26550 },
1126 { -4200, 30600, 26550 },
1127 { -4050, 3900, 5760 },
1128 { -4050, 5760, 8249 },
1129 { -4050, 26550, 26850 },
1130 { -4050, 30299, 30600 },
1131 { -4050, 31500, 30600 },
1132 { -4050, 31500, 32400 },
1133 { -4050, 39600, 41999 },
1134 { -3900, 24300, 24600 },
1135 { -3900, 30150, 30299 },
1136 { -3840, 10800, 11849 },
1137 { -3840, 11849, 12299 },
1138 { -3840, 12299, 16259 },
1139 { -3840, 20250, 21299 },
1140 { -3840, 21299, 23099 },
1141 { -3840, 23099, 24300 },
1142 { -3840, 24300, 26159 },
1143 { -3814, 26850, 27300 },
1144 { -3814, 29849, 30150 },
1145 { -3660, 9900, 10800 },
1146 { -3660, 27300, 27599 },
1147 { -3660, 29557, 29849 },
1148 { -3600, 27599, 29557 },
1149 { -3600, 36599, 38399 },
1150 { -3540, 7799, 8249 },
1151 { -3510, 2399, 3900 },
1152 { -3510, 2399, 41999 },
1153 { -3510, 3900, 2399 },
1154 { -3510, 41999, 2399 },
1155 { -3480, 11700, 12299 },
1156 { -3450, 6300, 5760 },
1157 { -3450, 9000, 9900 },
1158 { -3420, 32400, 31500 },
1159 { -3420, 32400, 36599 },
1160 { -3420, 39600, 41999 },
1161 { -3390, 7200, 7799 },
1162 { -3390, 15899, 19800 },
1163 { -3390, 19800, 20250 },
1164 { -3300, 11100, 11700 },
1165 { -3300, 21299, 23099 },
1166 { -3300, 25500, 26159 },
1167 { -3300, 26159, 27090 },
1168 { -3300, 27090, 27599 },
1169 { -3270, 15209, 15899 },
1170 { -3240, 3900, 4350 },
1171 { -3240, 8100, 9000 },
1172 { -3240, 27090, 27599 },
1173 { -3210, 2399, 2849 },
1174 { -3190, 6899, 6300 },
1175 { -3190, 6899, 7200 },
1176 { -3180, 14700, 15209 },
1177 { -3150, 10800, 11100 },
1178 { -3090, 2849, 3299 },
1179 { -3060, 4350, 4800 },
1180 { -3060, 7349, 6899 },
1181 { -3045, 10800, 14400 },
1182 { -3045, 14400, 14700 },
1183 { -3000, 38399, 39600 },
1184 { -2940, 4800, 5400 },
1185 { -2940, 7680, 7349 },
1186 { -2940, 7680, 8100 },
1187 { -2890, 3299, 4199 },
1188 { -2880, 27599, 28200 },
1189 { -2790, 8100, 8699 },
1190 { -2760, 5400, 6150 },
1191 { -2730, 29557, 32099 },
1192 { -2730, 32099, 32400 },
1193 { -2730, 34500, 32400 },
1194 { -2730, 34500, 36599 },
1195 { -2730, 38399, 36599 },
1196 { -2640, 6150, 6960 },
1197 { -2580, 8699, 9000 },
1198 { -2580, 10800, 9000 },
1199 { -2580, 11849, 10800 },
1200 { -2580, 14400, 15060 },
1201 { -2520, 25500, 26850 },
1202 { -2520, 28200, 28800 },
1203 { -2520, 29557, 28800 },
1204 { -2400, 3000, 41999 },
1205 { -2400, 4199, 3000 },
1206 { -2400, 4199, 5400 },
1207 { -2400, 6960, 7680 },
1208 { -2385, 16860, 19800 },
1209 { -2374, 5400, 6300 },
1210 { -2220, 8249, 7680 },
1211 { -2220, 32099, 34500 },
1212 { -2220, 38399, 41400 },
1213 { -2220, 41999, 41400 },
1214 { -2205, 16860, 15060 },
1215 { -2160, 6300, 6750 },
1216 { -2100, 19800, 19499 },
1217 { -2100, 22050, 19800 },
1218 { -1980, 11010, 11849 },
1219 { -1980, 13260, 11849 },
1220 { -1980, 22649, 22050 },
1221 { -1870, 19499, 19049 },
1222 { -1800, 8460, 8249 },
1223 { -1800, 30150, 31680 },
1224 { -1800, 31680, 32099 },
1225 { -1770, 26850, 22649 },
1226 { -1770, 26850, 28200 },
1227 { -1770, 28800, 28200 },
1228 { -1750, 19049, 18450 },
1229 { -1680, 36000, 36599 },
1230 { -1680, 36599, 38399 },
1231 { -1635, 8699, 8460 },
1232 { -1635, 8699, 9000 },
1233 { -1635, 9000, 11010 },
1234 { -1590, 18450, 17550 },
1235 { -1530, 3000, 42899 },
1236 { -1530, 38399, 39360 },
1237 { -1530, 41400, 39360 },
1238 { -1530, 41400, 42899 },
1239 { -1530, 42899, 3000 },
1240 { -1530, 42899, 41400 },
1241 { -1474, 29280, 30150 },
1242 { -1470, 19499, 21299 },
1243 { -1470, 21299, 22649 },
1244 { -1470, 25650, 26850 },
1245 { -1462, 3000, 4770 },
1246 { -1462, 4770, 6750 },
1247 { -1440, 16349, 16860 },
1248 { -1440, 17550, 16860 },
1249 { -1320, 22649, 23099 },
1250 { -1320, 23099, 25650 },
1251 { -1200, 28200, 28650 },
1252 { -1155, 29280, 29475 },
1253 { -1140, 15449, 16349 },
1254 { -1140, 19350, 19499 },
1255 { -1095, 29280, 29475 },
1256 { -1020, 15060, 15449 },
1257 { -960, 30900, 31680 },
1258 { -960, 32850, 31680 },
1259 { -960, 32850, 33960 },
1260 { -900, 38399, 36959 },
1261 { -870, 8850, 8699 },
1262 { -721, 36000, 33960 },
1263 { -700, 31649, 31800 },
1264 { -660, 9149, 8850 },
1265 { -660, 10499, 9149 },
1266 { -660, 11010, 10499 },
1267 { -660, 11010, 13260 },
1268 { -660, 14549, 13260 },
1269 { -660, 15060, 14549 },
1270 { -660, 17249, 19350 },
1271 { -660, 23099, 21299 },
1272 { -600, 30900, 31649 },
1273 { -600, 31800, 32340 },
1274 { -540, 36959, 36000 },
1275 { -540, 39360, 38399 },
1276 { -480, 26400, 25650 },
1277 { -480, 28650, 29280 },
1278 { -420, 599, 42899 },
1279 { -360, 20730, 19350 },
1280 { -360, 21299, 20730 },
1281 { -240, 8400, 9149 },
1282 { -240, 10499, 11235 },
1283 { -240, 32099, 32340 },
1284 { -240, 33449, 32850 },
1285 { -240, 33960, 33449 },
1286 { -240, 40950, 42899 },
1287 { -195, 28650, 27149 },
1288 { -195, 28650, 29280 },
1289 { -105, 4770, 5909 },
1290 { -105, 5909, 6449 },
1291 { 0, 6449, 8310 },
1292 { 0, 8310, 8400 },
1293 { 0, 12960, 14549 },
1294 { 0, 27149, 26400 },
1295 { 0, 32099, 32850 },
1296 { 90, 12630, 12960 },
1297 { 105, 39000, 39600 },
1298 { 120, 599, 3600 },
1299 { 120, 33449, 33960 },
1300 { 120, 36540, 36959 },
1301 { 120, 36959, 37499 },
1302 { 120, 37499, 38399 },
1303 { 120, 38399, 38640 },
1304 { 120, 39600, 40950 },
1305 { 165, 38640, 39000 },
1306 { 180, 32850, 33165 },
1307 { 240, 28949, 29280 },
1308 { 240, 29280, 30150 },
1309 { 270, 33165, 32850 },
1310 { 330, 12600, 12630 },
1311 { 360, 37499, 37575 },
1312 { 375, 32850, 33591 },
1313 { 375, 33591, 33960 },
1314 { 420, 14265, 14549 },
1315 { 420, 14549, 16650 },
1316 { 420, 16650, 17249 },
1317 { 420, 17249, 19350 },
1318 { 450, 40950, 42899 },
1319 { 480, 24300, 27149 },
1320 { 510, 36255, 36540 },
1321 { 595, 3000, 3600 },
1322 { 595, 3600, 5909 },
1323 { 600, 0, 42899 },
1324 { 600, 11235, 11354 },
1325 { 600, 12479, 12600 },
1326 { 600, 14054, 14265 },
1327 { 600, 42899, 0 },
1328 { 660, 20730, 21360 },
1329 { 709, 37575, 37890 },
1330 { 709, 37890, 38010 },
1331 { 720, 11354, 12479 },
1332 { 720, 32850, 33591 },
1333 { 720, 33591, 33960 },
1334 { 750, 0, 255 },
1335 { 750, 10080, 10380 },
1336 { 750, 12600, 13500 },
1337 { 750, 38010, 38399 },
1338 { 769, 30150, 31050 },
1339 { 810, 13500, 14054 },
1340 { 840, 21360, 23099 },
1341 { 859, 31050, 32850 },
1342 { 900, 23099, 24300 },
1343 { 930, 8310, 8940 },
1344 { 930, 9599, 10080 },
1345 { 945, 35699, 36255 },
1346 { 945, 36255, 36450 },
1347 { 960, 8940, 9599 },
1348 { 960, 28650, 28949 },
1349 { 970, 34200, 35699 },
1350 { 1050, 11190, 11354 },
1351 { 1080, 10260, 10380 },
1352 { 1110, 33960, 34200 },
1353 { 1140, 5909, 6060 },
1354 { 1150, 34650, 35699 },
1355 { 1170, 37020, 37890 },
1356 { 1170, 37890, 38250 },
1357 { 1200, 14054, 14189 },
1358 { 1230, 36450, 37020 },
1359 { 1260, 255, 1530 },
1360 { 1264, 33960, 34650 },
1361 { 1275, 35699, 36450 },
1362 { 1290, 10589, 11190 },
1363 { 1320, 120, 255 },
1364 { 1320, 28650, 28859 },
1365 { 1369, 10260, 10589 },
1366 { 1410, 18900, 19350 },
1367 { 1410, 38250, 38550 },
1368 { 1425, 1290, 1530 },
1369 { 1500, 3000, 3450 },
1370 { 1530, 19350, 19800 },
1371 { 1530, 33960, 34664 },
1372 { 1560, 27149, 27329 },
1373 { 1560, 27329, 28859 },
1374 { 1560, 28859, 29100 },
1375 { 1560, 33060, 33960 },
1376 { 1620, 29100, 29399 },
1377 { 1635, 3450, 4350 },
1378 { 1650, 34664, 35400 },
1379 { 1680, 0, 120 },
1380 { 1680, 2534, 3000 },
1381 { 1680, 10589, 11759 },
1382 { 1680, 14189, 14400 },
1383 { 1680, 37650, 38550 },
1384 { 1680, 38550, 39119 },
1385 { 1710, 8550, 10589 },
1386 { 1710, 17789, 18900 },
1387 { 1710, 23850, 24300 },
1388 { 1710, 24300, 25124 },
1389 { 1740, 19800, 21360 },
1390 { 1740, 21360, 21600 },
1391 { 1740, 35400, 37650 },
1392 { 1800, 8100, 8550 },
1393 { 1800, 32715, 33060 },
1394 { 1800, 34664, 34844 },
1395 { 1840, 4350, 4890 },
1396 { 1840, 4890, 6060 },
1397 { 1840, 6060, 8100 },
1398 { 1845, 25124, 25259 },
1399 { 1879, 0, 42750 },
1400 { 1920, 22199, 23850 },
1401 { 1924, 42300, 42750 },
1402 { 1980, 1290, 2534 },
1403 { 1980, 27329, 27779 },
1404 { 2010, 13950, 14400 },
1405 { 2010, 14400, 16650 },
1406 { 2010, 16650, 17789 },
1407 { 2040, 4620, 4890 },
1408 { 2040, 19409, 19800 },
1409 { 2040, 21600, 22199 },
1410 { 2070, 41070, 41160 },
1411 { 2070, 41160, 42300 },
1412 { 2100, 2534, 3600 },
1413 { 2100, 39600, 41070 },
1414 { 2130, 11759, 13260 },
1415 { 2130, 13260, 13950 },
1416 { 2160, 8100, 8445 },
1417 { 2160, 39119, 39375 },
1418 { 2160, 39375, 39600 },
1419 { 2190, 34844, 34920 },
1420 { 2205, 3600, 4530 },
1421 { 2205, 4530, 4620 },
1422 { 2385, 16650, 17249 },
1423 { 2400, 18300, 19409 },
1424 { 2400, 27779, 28350 },
1425 { 2400, 28350, 29399 },
1426 { 2520, 16500, 17249 },
1427 { 2520, 17249, 18300 },
1428 { 2610, 34500, 34920 },
1429 { 2625, 39375, 39434 },
1430 { 2640, 39434, 39540 },
1431 { 2670, 12240, 13260 },
1432 { 2700, 21600, 21749 },
1433 { 2760, 300, 1560 },
1434 { 2820, 3000, 3675 },
1435 { 2820, 15150, 16500 },
1436 { 2850, 32715, 32819 },
1437 { 2850, 32819, 34349 },
1438 { 2850, 34349, 34500 },
1439 { 2880, 300, 42449 },
1440 { 2880, 1560, 2010 },
1441 { 2880, 42449, 300 },
1442 { 2910, 24300, 25259 },
1443 { 3000, 2010, 2460 },
1444 { 3000, 2460, 3000 },
1445 { 3000, 11700, 12240 },
1446 { 3000, 41999, 42449 },
1447 { 3030, 3675, 4530 },
1448 { 3030, 30600, 32819 },
1449 { 3090, 28350, 30600 },
1450 { 3150, 5999, 8445 },
1451 { 3150, 8445, 9000 },
1452 { 3150, 41160, 41999 },
1453 { 3165, 39540, 39839 },
1454 { 3180, 21749, 24300 },
1455 { 3180, 27450, 28350 },
1456 { 3240, 2460, 3060 },
1457 { 3240, 10980, 11700 },
1458 { 3289, 37080, 39540 },
1459 { 3300, 5700, 5999 },
1460 { 3300, 39839, 40170 },
1461 { 3330, 25259, 25950 },
1462 { 3330, 25950, 27450 },
1463 { 3330, 34349, 34950 },
1464 { 3360, 9000, 10980 },
1465 { 3375, 40170, 41160 },
1466 { 3420, 4379, 5580 },
1467 { 3420, 5580, 5700 },
1468 { 3450, 3060, 3434 },
1469 { 3480, 34950, 35580 },
1470 { 3510, 3434, 4379 },
1471 { 3544, 41160, 41700 },
1472 { 3570, 35580, 36000 },
1473 { 3570, 36000, 36966 },
1474 { 3600, 12600, 14340 },
1475 { 3600, 14340, 15150 },
1476 { 3655, 36966, 37080 },
1477 { 3690, 36000, 36750 },
1478 { 3720, 10980, 12600 },
1479 { 3780, 24300, 25950 },
1480 { 3780, 41700, 42449 },
1481 { 3840, 21600, 24300 },
1482 { 3960, 599, 42449 },
1483 { 3960, 25200, 28200 },
1484 { 3960, 42449, 599 },
1485 { 3990, 20399, 21600 },
1486 { 4020, 36750, 37200 },
1487 { 4080, 5580, 6150 },
1488 { 4200, 23400, 25200 },
1489 { 4200, 28200, 29759 },
1490 { 4410, 14340, 16500 },
1491 { 4410, 16500, 20399 },
1492 { 4500, 29759, 31500 },
1493 { 4500, 36300, 37200 },
1494 { 4620, 599, 6150 },
1495 { 4620, 6150, 6314 },
1496 { 4620, 20700, 23400 },
1497 { 4620, 24449, 23400 },
1498 { 4800, 6314, 9000 },
1499 { 4800, 19200, 20700 },
1500 { 4800, 26100, 24449 },
1501 { 4800, 31500, 32400 },
1502 { 4800, 36300, 37800 },
1503 { 4920, 16500, 19200 },
1504 { 5100, 9000, 14400 },
1505 { 5160, 32400, 37800 },
1506 { 5169, 37800, 41400 },
1507 { 5190, 14400, 26100 },
1508 { 5280, 6300, 14400 },
1509 { 5280, 41400, 6300 },
1510 };
1511
1512 #define NDEC ((int)(sizeof(dec_edges)/sizeof(dec_edges[0])))
1513
1514 /* given an epoch, give caller a list of all constellation edges.
1515 * return count if ok, else -1.
1516 * N.B. caller should *not* free what we return because we cache it here.
1517 */
1518 int
cns_edges(double e,double ** ra0p,double ** dec0p,double ** ra1p,double ** dec1p)1519 cns_edges (double e, double **ra0p, double **dec0p, double **ra1p,
1520 double **dec1p)
1521 {
1522 #define NEDGES (NRA+NDEC)
1523 static double *ra0, *dec0, *ra1, *dec1;
1524 static double laste = -12345.6; /* any bogus value */
1525 double mjd0;
1526 int i, n;
1527
1528 /* if same epoch just return the same list */
1529 if (e == laste) {
1530 *ra0p = ra0;
1531 *dec0p = dec0;
1532 *ra1p = ra1;
1533 *dec1p = dec1;
1534 return (NEDGES);
1535 }
1536
1537 /* get space for arrays, first time only */
1538 if (!ra0) {
1539 ra0 = (double *)malloc (NEDGES * sizeof(double));
1540 if (!ra0)
1541 return (-1);
1542 dec0 = (double *)malloc (NEDGES * sizeof(double));
1543 if (!dec0) {
1544 free ((void *)ra0);
1545 return (-1);
1546 }
1547 ra1 = (double *)malloc (NEDGES * sizeof(double));
1548 if (!ra1) {
1549 free ((void *)ra0);
1550 free ((void *)dec0);
1551 return (-1);
1552 }
1553 dec1 = (double *)malloc (NEDGES * sizeof(double));
1554 if (!dec1) {
1555 free ((void *)ra0);
1556 free ((void *)dec0);
1557 free ((void *)ra1);
1558 return (-1);
1559 }
1560 }
1561
1562 /* prepare for precession from 1875 */
1563 cal_mjd (1, 1.0, 1875, &mjd0);
1564
1565 /* build the constant-ra edge lists */
1566 n = 0;
1567 for (i = 0; i < NRA; i++) {
1568 ra0[n] = ra1[n] = hrrad((double)ra_edges[i].ra/1800.0);
1569 dec0[n] = degrad((double)ra_edges[i].dec0/60.0);
1570 dec1[n] = degrad((double)ra_edges[i].dec1/60.0);
1571 precess (mjd0, e, &ra0[n], &dec0[n]);
1572 precess (mjd0, e, &ra1[n], &dec1[n]);
1573 n++;
1574 }
1575
1576 /* add the constant-dec edge lists */
1577 for (i = 0; i < NDEC; i++) {
1578 ra0[n] = hrrad((double)dec_edges[i].ra0/1800.0);
1579 ra1[n] = hrrad((double)dec_edges[i].ra1/1800.0);
1580 dec0[n] = dec1[n] = degrad((double)dec_edges[i].dec/60.0);
1581 precess (mjd0, e, &ra0[n], &dec0[n]);
1582 precess (mjd0, e, &ra1[n], &dec1[n]);
1583 n++;
1584 }
1585
1586 /* sanity check the count */
1587 if (n != NEDGES) {
1588 printf ("cns_edges(): n=%d NEDGES=%ld\n", n, (long)NEDGES);
1589 abort();
1590 }
1591
1592 /* ok */
1593 *ra0p = ra0;
1594 *dec0p = dec0;
1595 *ra1p = ra1;
1596 *dec1p = dec1;
1597 laste = e;
1598 return (NEDGES);
1599 }
1600
1601 /* given an ra, dec and epoch return the list of constellation ids which
1602 * *may* fall within the given radius of said location.
1603 * return the number of ids.
1604 * ids[] need be no larger than 89.
1605 */
1606 /* ARGSUSED */
1607 int
cns_list(double ra,double dec,double e,double rad,int ids[])1608 cns_list (double ra, double dec, double e, double rad, int ids[])
1609 {
1610 int i;
1611
1612 /* TODO: this! */
1613 for (i = 0; i < NCNS; i++)
1614 ids[i] = i;
1615 return (NCNS);
1616 }
1617
1618 /* epoch 2000 RA/Dec of constellation figure end-points.
1619 * drawcodes: 0=move to; 1=draw to; 2=draw to dashed; -1=end
1620 */
1621 typedef struct {
1622 int drawcode; /* draw code */
1623 float ra; /* rads */
1624 float dec; /* rads */
1625 } ConFig;
1626
1627 /* array of malloced lists of ConFigs, same order as cns_namemap[]
1628 */
1629 static ConFig *figmap[NCNS];
1630
1631 /* add one entry to the drawing code lists */
1632 static void
addFigList(ConFig ** new,int * nused,int c,int drawcode,double ra,double dec)1633 addFigList (ConFig **new, int *nused, int c, int drawcode, double ra, double dec)
1634 {
1635 ConFig *cp;
1636
1637 new[c]= (ConFig*) realloc (new[c], (nused[c]+1)*sizeof(ConFig));
1638 cp = &new[c][nused[c]++];
1639 cp->drawcode = drawcode;
1640 cp->ra = (float)hrrad(ra);
1641 cp->dec = (float)degrad(dec);
1642 }
1643
1644 /* load the given constellation definition file.
1645 * return 0 if ok else reason why not in msg[] and -1.
1646 */
1647 int
cns_loadfigs(FILE * fp,char * msg)1648 cns_loadfigs (FILE *fp, char *msg)
1649 {
1650 char line[1024]; /* one line from the file */
1651 char cname[1024]; /* constellation name */
1652 ConFig **new; /* array of ConFig[] for each cnstn */
1653 int *nused; /* number of ConFig[] for each cnstn */
1654 int c = -1; /* index, same as cns_namemap[] */
1655 int s = 0; /* status */
1656
1657 /* init the temp lists */
1658 new = (ConFig **) calloc (NCNS, sizeof(ConFig*));
1659 nused = (int *) calloc (NCNS, sizeof(int));
1660
1661 /* read the file */
1662 while (fgets (line, sizeof(line), fp)) {
1663 char rastr[64], decstr[64];
1664 char *lp;
1665 int code;
1666
1667 /* skip leading/trailing whitespace, blank lines and # lines */
1668 for (lp = line+strlen(line)-1; lp>=line && isspace(*lp); --lp)
1669 *lp = '\0';
1670 for (lp = line; isspace(*lp); lp++)
1671 continue;
1672 if (*lp == '#' || *lp == '\0')
1673 continue;
1674
1675 /* ok, line looks interesting, look more carefully */
1676 if (sscanf (lp, "%d %s %s", &code, rastr, decstr) == 3) {
1677 /* looks like a drawing line */
1678 double ra, dec;
1679
1680 /* must be working on a current constellation */
1681 if (c < 0) {
1682 sprintf (msg,"Found coord line before first constellation");
1683 s = -1;
1684 break;
1685 }
1686
1687 /* check draw code */
1688 if (code < 0 || code > 2) {
1689 sprintf (msg, "Bad draw code in %s: %d", cname, code);
1690 s = -1;
1691 break;
1692 }
1693
1694 /* crack ra dec */
1695 if (f_scansexa (rastr, &ra) < 0 || ra < 0 || ra >= 24) {
1696 sprintf (msg, "Bad RA format in %s: %s", cname, rastr);
1697 s = -1;
1698 break;
1699 }
1700 if (f_scansexa (decstr, &dec) < 0 || dec < -90 || dec > 90) {
1701 sprintf (msg, "Bad Dec format in %s: %s", cname, decstr);
1702 s = -1;
1703 break;
1704 }
1705
1706 /* add to list */
1707 addFigList (new, nused, c, code, ra, dec);
1708
1709 } else {
1710 /* finish previous list, if any */
1711 if (c >= 0)
1712 addFigList (new, nused, c, -1, 0.0, 0.0);
1713
1714 /* see if it's a recognized constellation name */
1715 for (c = 0; c < NCNS; c++)
1716 if (strcmp (lp, cns_namemap[c]+5) == 0)
1717 break;
1718 if (c == NCNS) {
1719 sprintf (msg, "Unknown constellation: %s", lp);
1720 s = -1;
1721 break;
1722 }
1723 if (new[c]) {
1724 sprintf (msg, "Duplicate definition for %s", lp);
1725 s = -1;
1726 break;
1727 }
1728
1729 /* init its list */
1730 strcpy (cname, lp);
1731 new[c] = (ConFig *) malloc (1); /* realloc seed */
1732 }
1733 }
1734
1735 /* even if ok check we found all definitions */
1736 if (s == 0) {
1737 int l = 0;
1738
1739 /* finish last list */
1740 addFigList (new, nused, c, -1, 0.0, 0.0);
1741
1742 for (c = 0; c < NCNS; c++)
1743 if (!new[c])
1744 l += sprintf (msg+l, "%s ", cns_namemap[c]+5);
1745 if (l > 0) {
1746 strcat (msg, ": no definition found");
1747 s = -1;
1748 }
1749 }
1750
1751 /* handle ok or error */
1752 if (s < 0) {
1753 /* trouble: free temp lists */
1754 for (c = 0; c < NCNS; c++)
1755 if (new[c])
1756 free (new[c]);
1757 } else {
1758 /* make temp lists persistent */
1759 for (c = 0; c < NCNS; c++) {
1760 if (figmap[c])
1761 free (figmap[c]);
1762 figmap[c] = new[c];
1763 }
1764 }
1765
1766 /* done with lists themselves regardless */
1767 free (new);
1768 free (nused);
1769
1770 /* done */
1771 return (s);
1772 }
1773
1774 /* given a constellation id and epoch, return arrays of ra[] and dec[]
1775 * end-points precessed to the desired epoch that, if connected, will form the
1776 * given constellation figure.
1777 * dcodes is 0 if the coord is a "move-to", 1 if a "draw-to" or 2 if a "draw-to
1778 * as dotted-line".
1779 * return the total number of tripples or -1 if id is bogus.
1780 * the arrays need be no larger than 35 entries.
1781 */
1782 int
cns_figure(int id,double e,double ra[],double dec[],int dcodes[])1783 cns_figure (int id, double e, double ra[], double dec[], int dcodes[])
1784 {
1785 ConFig *cfp;
1786
1787 if (id < 0 || id >= NCNS)
1788 return (-1);
1789
1790 for (cfp = figmap[id]; cfp->drawcode >= 0; cfp++) {
1791 *ra = (double)cfp->ra;
1792 *dec = (double)cfp->dec;
1793 precess (J2000, e, ra, dec);
1794 ra++;
1795 dec++;
1796 *dcodes++ = cfp->drawcode;
1797 }
1798
1799 return (cfp - figmap[id]);
1800 }
1801
1802