xref: /plan9/sys/src/cmd/astro/search.c (revision 7dd7cddf99dd7472612f1413b4da293630e6b1bc)
1 #include "astro.h"
2 
3 char*	solstr[] =
4 {
5 	"Fall equinox",
6 	"Winter solstice",
7 	"Spring equinox",
8 	"Summer solstice",
9 };
10 
11 struct
12 {
13 	double	beta;
14 	int	rta;
15 	int	dec;
16 	char	*betstr;
17 } bettab[] =
18 {
19 	-1.3572, 231,	50,	"Quadrantid",
20 	 0.7620, 336,	0,	"Eta aquarid",
21 	 1.5497, 260,	-20,	"Ophiuchid",
22 	 2.1324, 315,	-15,	"Capricornid",
23 	 2.1991, 339,	-17,	"Delta aquarid",
24 	 2.2158, 340,	-30,	"Pisces australid",
25 	 2.4331, 46,	58,	"Perseid",
26 	-2.6578, 95,	15,	"Orionid",
27 	-1.8678, 15,	-55,	"Phoenicid",
28 	-1.7260, 113,	32,	"Geminid",
29 	0
30 };
31 
32 void
search(void)33 search(void)
34 {
35 	Obj2 *p, *q;
36 	int i, j;
37 	double t;
38 
39 	for(i=0; objlst[i]; i++) {
40 		p = objlst[i];
41 		if(p == &oshad)
42 			continue;
43 		t = rise(p, -.833);
44 		if(t >= 0.)
45 			event("%s rises at ", p->name, "", t,
46 				i==0? PTIME: PTIME|DARK);
47 		t = set(p, -.833);
48 		if(t >= 0.)
49 			event("%s sets at ", p->name, "", t,
50 				i==0? PTIME: PTIME|DARK);
51 		if(p == &osun) {
52 			for(j=0; j<4; j++) {
53 				t = solstice(j);
54 				if(t >= 0)
55 					event("%s at ", solstr[j], "", t,
56 						SIGNIF|PTIME);
57 			}
58 			for(j=0; bettab[j].beta!=0; j++) {
59 				t = betcross(bettab[j].beta);
60 				if(t >= 0)
61 					event("%s  meeteeor shouwer",
62 					bettab[j].betstr, "", t, SIGNIF);
63 			}
64 			t = rise(p, -18);
65 			if(t >= 0)
66 				event("Twilight starts at ", "", "", t, PTIME);
67 			t = set(p, -18);
68 			if(t >= 0)
69 				event("Twilight ends at ", "", "", t, PTIME);
70 		}
71 		if(p == &omoon)
72 		for(j=0; j<NPTS; j++) {
73 			if(p->point[j].mag > .75 && p->point[j+1].mag < .25)
74 				event("New moon", "", "", 0, 0);
75 			if(p->point[j].mag <= .25 && p->point[j+1].mag > .25)
76 				event("First quarter moon", "", "", 0, 0);
77 			if(p->point[j].mag <= .50 && p->point[j+1].mag > .50)
78 				event("Full moon", "", "", 0, 0);
79 			if(p->point[j].mag <= .75 && p->point[j+1].mag > .75)
80 				event("Last quarter moon", "", "", 0, 0);
81 		}
82 		if(p == &omerc || p == &ovenus) {
83 			t = melong(p);
84 			if(t >= 0) {
85 				t = rise(p, 0) - rise(&osun, 0);
86 				if(t < 0)
87 					t += NPTS;
88 				if(t > NPTS)
89 					t -= NPTS;
90 				if(t > NPTS/2)
91 				event("Morning elongation of %s", p->name,
92 					"", 0, SIGNIF);
93 				else
94 				event("Evening elongation of %s", p->name,
95 					"", 0, SIGNIF);
96 			}
97 		}
98 		for(j=i; objlst[j]; j++) {
99 			if(i == j)
100 				continue;
101 			q = objlst[j];
102 			if(p == &omoon || q == &omoon) {
103 				occult(p, q, 0);
104 				if(occ.t3 < 0)
105 					continue;
106 				if(p == &osun || q == &oshad) {
107 					if(occ.t1 >= 0)
108 					event("Partial eclipse of %s begins at ", p->name, "",
109 						occ.t1, SIGNIF|PTIME);
110 					if(occ.t2 >= 0)
111 					event("Total eclipse of %s begins at ", p->name, "",
112 						occ.t2, SIGNIF|PTIME);
113 					if(occ.t4 >= 0)
114 					event("Total eclipse of %s ends at ", p->name, "",
115 						occ.t4, SIGNIF|PTIME);
116 					if(occ.t5 >= 0)
117 					event("Partial eclipse of %s ends at ", p->name, "",
118 						occ.t5, SIGNIF|PTIME);
119 				} else {
120 					if(occ.t1 >= 0)
121 					event("Occultation of %s begins at ", q->name, "",
122 						occ.t1, SIGNIF|PTIME);
123 					if(occ.t5 >= 0)
124 					event("Occultation of %s ends at ", q->name, "",
125 						occ.t5, SIGNIF|PTIME);
126 				}
127 				continue;
128 			}
129 			if(p == &osun) {
130 				if(q != &omerc && q != &ovenus)
131 					continue;
132 				occult(p, q, -1);
133 				if(occ.t3 >= 0.) {
134 					if(occ.t1 >= 0)
135 					event("Transit of %s begins at ", q->name, "",
136 						occ.t1, SIGNIF|LIGHT|PTIME);
137 					if(occ.t5 >= 0)
138 					event("Transit of %s ends at ", q->name, "",
139 						occ.t5, SIGNIF|LIGHT|PTIME);
140 				}
141 				continue;
142 			}
143 			t = dist(&p->point[0], &q->point[0]);
144 			if(t > 5000)
145 				continue;
146 			event("%s is in the house of %s",
147 				p->name, q->name, 0, 0);
148 		}
149 	}
150 	if(flags['o'])
151 		stars();
152 	if(flags['a'])
153 		satels();
154 	evflush();
155 }
156