Blame


1 8a3b2ceb 2004-04-24 devnull #include <u.h>
2 8a3b2ceb 2004-04-24 devnull #include <libc.h>
3 8a3b2ceb 2004-04-24 devnull #include <bio.h>
4 8a3b2ceb 2004-04-24 devnull #include "sky.h"
5 8a3b2ceb 2004-04-24 devnull
6 8a3b2ceb 2004-04-24 devnull /*
7 8a3b2ceb 2004-04-24 devnull * dec varies from -89 to 89, inclusive.
8 8a3b2ceb 2004-04-24 devnull * ra varies depending on dec; each patch is about 1 square degree.
9 8a3b2ceb 2004-04-24 devnull *
10 8a3b2ceb 2004-04-24 devnull * Northern hemisphere (0<=dec<=89):
11 8a3b2ceb 2004-04-24 devnull * from 0<=dec<=59, ra is every 4m, 360 values
12 8a3b2ceb 2004-04-24 devnull * from 60<=dec<=69, ra is every 8m, 180 values
13 8a3b2ceb 2004-04-24 devnull * from 70<=dec<=79, ra is every 12m, 120 values
14 8a3b2ceb 2004-04-24 devnull * from 80<=dec<=84, ra is every 24m, 60 values
15 8a3b2ceb 2004-04-24 devnull * at dec=85 and 86, ra is every 48m, 30 values
16 8a3b2ceb 2004-04-24 devnull * at dec=87, ra is every 60m, 24 values
17 8a3b2ceb 2004-04-24 devnull * at dec=88, ra is every 120m, 12 values
18 8a3b2ceb 2004-04-24 devnull * at dec=89, ra is 12h, 1 value
19 8a3b2ceb 2004-04-24 devnull *
20 8a3b2ceb 2004-04-24 devnull * Total number of patches in northern hemisphere is therefore:
21 8a3b2ceb 2004-04-24 devnull * 360*60+180*10+120*10+60*5+30*2+24*1+12*1+1 = 24997
22 8a3b2ceb 2004-04-24 devnull * Total number of patches is therefore
23 8a3b2ceb 2004-04-24 devnull * 2*24997-360 = 49634 (dec=0 has been counted twice)
24 8a3b2ceb 2004-04-24 devnull * (cf. 41253 square degrees in the sky)
25 8a3b2ceb 2004-04-24 devnull */
26 8a3b2ceb 2004-04-24 devnull
27 8a3b2ceb 2004-04-24 devnull void
28 8a3b2ceb 2004-04-24 devnull radec(int p, int *rah, int *ram, int *deg)
29 8a3b2ceb 2004-04-24 devnull {
30 8a3b2ceb 2004-04-24 devnull *deg = (p&255)-90;
31 8a3b2ceb 2004-04-24 devnull p >>= 8;
32 8a3b2ceb 2004-04-24 devnull *rah = p/15;
33 8a3b2ceb 2004-04-24 devnull *ram = (p%15)*4;
34 8a3b2ceb 2004-04-24 devnull if(*deg<0)
35 8a3b2ceb 2004-04-24 devnull (*deg)++;
36 8a3b2ceb 2004-04-24 devnull }
37 8a3b2ceb 2004-04-24 devnull
38 347aa646 2009-04-30 rsc int32
39 8a3b2ceb 2004-04-24 devnull patcha(Angle ra, Angle dec)
40 8a3b2ceb 2004-04-24 devnull {
41 8a3b2ceb 2004-04-24 devnull ra = DEG(ra);
42 8a3b2ceb 2004-04-24 devnull dec = DEG(dec);
43 8a3b2ceb 2004-04-24 devnull if(dec >= 0)
44 8a3b2ceb 2004-04-24 devnull return patch(floor(ra/15), ((int)floor(ra*4))%60, floor(dec));
45 8a3b2ceb 2004-04-24 devnull dec = -dec;
46 8a3b2ceb 2004-04-24 devnull return patch(floor(ra/15), ((int)floor(ra*4))%60, -floor(dec));
47 8a3b2ceb 2004-04-24 devnull }
48 8a3b2ceb 2004-04-24 devnull
49 8a3b2ceb 2004-04-24 devnull #define round scatround
50 8a3b2ceb 2004-04-24 devnull
51 8a3b2ceb 2004-04-24 devnull char round[91]={ /* extra 0 is to offset the array */
52 8a3b2ceb 2004-04-24 devnull /* 0 */ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
53 8a3b2ceb 2004-04-24 devnull /* 10 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
54 8a3b2ceb 2004-04-24 devnull /* 20 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
55 8a3b2ceb 2004-04-24 devnull /* 30 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
56 8a3b2ceb 2004-04-24 devnull /* 40 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
57 8a3b2ceb 2004-04-24 devnull /* 50 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
58 8a3b2ceb 2004-04-24 devnull /* 60 */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
59 8a3b2ceb 2004-04-24 devnull /* 70 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
60 8a3b2ceb 2004-04-24 devnull /* 80 */ 6, 6, 6, 6, 6, 12, 12, 15, 30, -1,
61 8a3b2ceb 2004-04-24 devnull /* 90 */
62 8a3b2ceb 2004-04-24 devnull };
63 8a3b2ceb 2004-04-24 devnull
64 347aa646 2009-04-30 rsc int32
65 8a3b2ceb 2004-04-24 devnull patch(int rah, int ram, int deg)
66 8a3b2ceb 2004-04-24 devnull {
67 8a3b2ceb 2004-04-24 devnull int ra, dec;
68 8a3b2ceb 2004-04-24 devnull
69 8a3b2ceb 2004-04-24 devnull /*
70 8a3b2ceb 2004-04-24 devnull * patches go from lower limit <= position < upper limit.
71 8a3b2ceb 2004-04-24 devnull * therefore dec ' " can be ignored; always inc. dec degrees.
72 8a3b2ceb 2004-04-24 devnull * the computed angle is then the upper limit (ignoring sign).
73 8a3b2ceb 2004-04-24 devnull * when done, +ve values are shifted down so 90 (0 degrees) is a value;
74 8a3b2ceb 2004-04-24 devnull */
75 8a3b2ceb 2004-04-24 devnull if(rah<0 || rah>=24 || ram<0 || abs(deg)>=90){
76 8a3b2ceb 2004-04-24 devnull fprint(2, "scat: patch: bad ra or dec %dh%dm %d\n", rah, ram, deg);
77 8a3b2ceb 2004-04-24 devnull abort();
78 8a3b2ceb 2004-04-24 devnull }
79 8a3b2ceb 2004-04-24 devnull if(deg < 0)
80 8a3b2ceb 2004-04-24 devnull deg--;
81 8a3b2ceb 2004-04-24 devnull else if(deg < 90)
82 8a3b2ceb 2004-04-24 devnull deg++;
83 8a3b2ceb 2004-04-24 devnull dec = deg+90;
84 8a3b2ceb 2004-04-24 devnull deg = abs(deg);
85 8a3b2ceb 2004-04-24 devnull if(deg<1 || deg>90){
86 8a3b2ceb 2004-04-24 devnull fprint(2, "scat: patch: panic %dh%dm %d\n", rah, ram, deg);
87 8a3b2ceb 2004-04-24 devnull abort();
88 8a3b2ceb 2004-04-24 devnull }
89 8a3b2ceb 2004-04-24 devnull if(deg == 90)
90 8a3b2ceb 2004-04-24 devnull ra = 180;
91 8a3b2ceb 2004-04-24 devnull else{
92 8a3b2ceb 2004-04-24 devnull ra = 15*rah+ram/4;
93 8a3b2ceb 2004-04-24 devnull ra -= ra%round[deg];
94 8a3b2ceb 2004-04-24 devnull }
95 8a3b2ceb 2004-04-24 devnull /* close the hole at 0 */
96 8a3b2ceb 2004-04-24 devnull if(dec > 90)
97 8a3b2ceb 2004-04-24 devnull --dec;
98 8a3b2ceb 2004-04-24 devnull if(ra >= 360)
99 8a3b2ceb 2004-04-24 devnull ra -= 360;
100 8a3b2ceb 2004-04-24 devnull return (ra<<8)|dec;
101 8a3b2ceb 2004-04-24 devnull }