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