Changeset 5438
- Timestamp:
- Oct 21, 2005, 9:27:54 AM (21 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 2 edited
-
dvo2/skydbsearch.c (modified) (13 diffs)
-
include/dvo2.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo2/skydbsearch.c
r2598 r5438 9 9 10 10 /* find region which overlaps c at given depth (-1 : max depth) */ 11 SkyRegion *SkyFindPoint (SkyRegion *db, SkyCoord c, int depth) { 11 SkyRegion *SkyFindPoint (SkyRegionTable *table, double ra, double dec, int depth) { 12 13 SkyRegion *region; 14 15 region = table[0].region; 16 17 Ns = 0; 18 Ne = 1; 19 20 while (1) { 21 No = -1; 22 for (i = Ns; (i < Ne) && (i < table[0].Nregion); i++) { 23 if (ra < region[i].Rmin) continue; 24 if (ra > region[i].Rmax) continue; 25 if (dec < region[i].Dmin) continue; 26 if (dec > region[i].Dmax) continue; 27 No = i; 28 break; 29 } 30 if (No == -1) return (NULL); 31 if (depth == region[No].depth) return (®ion[No]); 32 if ((depth == -1) && (!region[No].child)) return (®ion[No]); 33 if ((depth > region[No].depth) && !region[No].child) return (NULL); 34 35 /* need to check Ns, Ne, or guarantee valid range */ 36 Ns = region[No].childS; 37 Ne = region[No].childE; 38 } 39 } 40 41 /* find regions at all levels which overlap c */ 42 SkyRegionList *SkyFindLevels (SkyRegionTable *table, double ra, double dec) { 43 44 SkyRegion *region; 45 SkyRegionList *list; 12 46 13 47 Ns = 0; 14 48 Ne = 1; 15 49 50 N = 0; 51 NREGION = 10; 52 ALLOCATE (list, SkyRegionList, 1); 53 ALLOCATE (list[0].region, SkyRegion *, NREGION); 54 list[0].Nregion = N; 55 56 region = table[0].region; 57 16 58 while (1) { 17 59 No = -1; 18 for (i = Ns; i < Ne; i++) {19 if ( c.r < db[i].Rmin) continue;20 if ( c.r > db[i].Rmax) continue;21 if ( c.d < db[i].Dmin) continue;22 if ( c.d > db[i].Dmax) continue;60 for (i = Ns; (i < Ne) && (i < table[0].region); i++) { 61 if (ra < region[i].Rmin) continue; 62 if (ra > region[i].Rmax) continue; 63 if (dec < region[i].Dmin) continue; 64 if (dec > region[i].Dmax) continue; 23 65 No = i; 24 66 break; 25 67 } 26 if (No == -1) return ((SkyRegion *) NULL); 27 if (depth == db[No].depth) return (&db[No]); 28 if ((depth > db[No].depth) && !db[No].child) return ((SkyRegion *) NULL); 29 30 /* need to check Ns, Ne, or guarantee valid range */ 31 Ns = db[No].childS; 32 Ne = db[No].childE; 33 34 if ((depth > db[No].depth) && db[No].child) continue; 35 return (&db[No]); 36 } 37 } 38 39 /* find regions at all levels which overlap c */ 40 SkyRegion **SkyFindLevels (SkyRegion *db, SkyCoord c, int *Nregion) { 41 42 SkyRegion **region; 43 44 Ns = 0; 45 Ne = 1; 46 47 N = 0; 48 NREGION = 10; 49 ALLOCATE (region, SkyRegion *, NREGION); 50 51 while (1) { 52 No = -1; 53 for (i = Ns; i < Ne; i++) { 54 if (c.r < db[i].Rmin) continue; 55 if (c.r > db[i].Rmax) continue; 56 if (c.d < db[i].Dmin) continue; 57 if (c.d > db[i].Dmax) continue; 58 No = i; 59 break; 60 } 61 if (No == -1) return ((SkyRegion *) NULL); 62 63 region[N] = &db[No]; 68 if (No == -1) return (list); 69 70 list[N] = ®ion[No]; 64 71 N++; 65 72 if (N == NREGION) { 66 73 NREGION += 10; 67 REALLOCATE ( region, SkyRegion *, NREGION);74 REALLOCATE (list[0].region, SkyRegion *, NREGION); 68 75 } 76 list[0].Nregion = N; 69 77 70 78 /* need to check Ns, Ne, or guarantee valid range */ 71 if ( db[No].child) {72 Ns = db[No].childS;73 Ne = db[No].childE;79 if (region[No].child) { 80 Ns = region[No].childS; 81 Ne = region[No].childE; 74 82 } else { 75 *Nregion = N; 76 return (region); 83 return (list); 77 84 } 78 85 } … … 102 109 *nlist = Nlist; 103 110 return (list); 104 105 111 } 106 112 … … 109 115 Nlist = 1; 110 116 ALLOCATE (list, SkyRegion *, Nlist); 111 list[0] = & db[0];112 getchild = db[0].child;117 list[0] = ®ion[0]; 118 getchild = region[0].child; 113 119 114 120 while (getchild) { … … 160 166 161 167 for (i = Ns; i < Ne; i++) { 162 if ( db[i].Rmax < c1.r) continue;163 if ( db[i].Rmin > c2.r) continue;164 if ( db[i].Dmax < c1.d) continue;165 if ( db[i].Dmin > c2.d) continue;166 region[Nregion] = & db[i];168 if (region[i].Rmax < c1.r) continue; 169 if (region[i].Rmin > c2.r) continue; 170 if (region[i].Dmax < c1.d) continue; 171 if (region[i].Dmin > c2.d) continue; 172 region[Nregion] = ®ion[i]; 167 173 Nregion++; 168 174 if (Nregion == NREGION) { … … 195 201 196 202 /* full sky */ 197 strcpy ( db[0].name, "fullsky.cpt");198 db[0].Rmin = 0; db[0].Rmax = 360;199 db[0].Dmin = -90; db[0].Dmax = 90;200 db[0].depth = 0;201 db[0].child = FALSE;203 strcpy (region[0].name, "fullsky.cpt"); 204 region[0].Rmin = 0; region[0].Rmax = 360; 205 region[0].Dmin = -90; region[0].Dmax = 90; 206 region[0].depth = 0; 207 region[0].child = FALSE; 202 208 N = 1; 203 209 204 db[0].childS = N;210 region[0].childS = N; 205 211 /* north dec bands */ 206 212 for (dec = 0; dec < 90; dec += 7.5) { 207 sprintf ( db[N].name, "n%04d.cpt", (int) 100*dec);208 db[N].Rmin = 0; db[N].Rmax = 360;209 db[N].Dmin = dec; db[N].Dmax = dec + 7.5;210 db[N].depth = 1;211 db[N].child = FALSE;213 sprintf (region[N].name, "n%04d.cpt", (int) 100*dec); 214 region[N].Rmin = 0; region[N].Rmax = 360; 215 region[N].Dmin = dec; region[N].Dmax = dec + 7.5; 216 region[N].depth = 1; 217 region[N].child = FALSE; 212 218 N++; 213 219 } 214 220 /* south dec bands */ 215 221 for (dec = 0; dec > -90; dec -= 7.5) { 216 sprintf ( db[N].name, "s%04d.cpt", (int) 100*dec);217 db[N].Rmin = 0; db[N].Rmax = 360;218 db[N].Dmin = dec - 7.5; db[N].Dmax = dec;219 db[N].depth = 1;220 db[N].child = FALSE;222 sprintf (region[N].name, "s%04d.cpt", (int) 100*dec); 223 region[N].Rmin = 0; region[N].Rmax = 360; 224 region[N].Dmin = dec - 7.5; region[N].Dmax = dec; 225 region[N].depth = 1; 226 region[N].child = FALSE; 221 227 N++; 222 228 } 223 db[0].childE = N;229 region[0].childE = N; 224 230 225 231 /* subdivide dec bands based on seed */ 226 232 Rnumber = 0; 227 childS = db[0].childS;228 childE = db[0].childE;233 childS = region[0].childS; 234 childE = region[0].childE; 229 235 for (i = childS; i < childE; i++) { 230 236 … … 234 240 235 241 for (j = 0; j < Nseed; j++) { 236 if (seed[j].Rmin > db[i].Rmax) continue; 237 if (seed[j].Rmax < db[i].Rmin) continue; 238 if (seed[j].Dmin > db[i].Dmax) continue; 239 if (seed[j].Dmax < db[i].Dmin) continue; 242 /* skip seeds outside of parent bound */ 243 if (seed[j].Rmin > region[i].Rmax) continue; 244 if (seed[j].Rmax < region[i].Rmin) continue; 245 if (seed[j].Dmin > region[i].Dmax) continue; 246 if (seed[j].Dmax < region[i].Dmin) continue; 240 247 241 248 for (k = 0; k < Nnew; k++) { … … 250 257 } 251 258 } 259 /* new region spans full DEC band. */ 260 new[Nnew].Dmin = region[i].Dmin; 261 new[Nnew].Dmax = region[i].Dmax; 262 263 Ntall = (region[i].Dmax - region[i].Dmin) / (seed[j].Dmax - seed[j].Dmin); 264 265 /* fi 266 252 267 new[Nnew].Rmin = seed[j].Rmin; 253 268 new[Nnew].Rmax = seed[j].Rmax; 254 new[Nnew].Dmin = db[i].Dmin;255 new[Nnew].Dmax = db[i].Dmax;256 269 new[Nnew].depth = 2; 257 270 new[Nnew].child = FALSE; 258 strncpy (root, db[i].name, 5); root[5] = 0;271 strncpy (root, region[i].name, 5); root[5] = 0; 259 272 sprintf (new[Nnew].name, "%s/r%04d.cpt", root, Rnumber); 260 273 Rnumber ++; … … 267 280 } 268 281 /* update db list */ 269 db[i].childS = N;270 db[i].childE = N + Nnew;282 region[i].childS = N; 283 region[i].childE = N + Nnew; 271 284 NREGION = N + Nnew + 100; 272 285 REALLOCATE (db, SkyRegion, NREGION); 273 memcpy (& db[N], new, Nnew*sizeof(SkyRegion));286 memcpy (®ion[N], new, Nnew*sizeof(SkyRegion)); 274 287 free (new); 275 288 N += Nnew; … … 277 290 278 291 /* subdivide ra strips based on seed */ 279 childS = db[db[0].childS].childS;280 childE = db[db[0].childE - 1].childE;292 childS = region[region[0].childS].childS; 293 childE = region[region[0].childE - 1].childE; 281 294 nextS = N; 282 295 for (i = childS; i < childE; i++) { … … 287 300 288 301 for (j = 0; j < Nseed; j++) { 289 if (seed[j].Rmin > db[i].Rmax) continue;290 if (seed[j].Rmax < db[i].Rmin) continue;291 if (seed[j].Dmin > db[i].Dmax) continue;292 if (seed[j].Dmax < db[i].Dmin) continue;302 if (seed[j].Rmin > region[i].Rmax) continue; 303 if (seed[j].Rmax < region[i].Rmin) continue; 304 if (seed[j].Dmin > region[i].Dmax) continue; 305 if (seed[j].Dmax < region[i].Dmin) continue; 293 306 294 307 for (k = 0; k < Nnew; k++) { … … 305 318 new[Nnew].Dmin = seed[j].Dmin; 306 319 new[Nnew].Dmax = seed[j].Dmax; 307 new[Nnew].Rmin = db[i].Rmin;308 new[Nnew].Rmax = db[i].Rmax;320 new[Nnew].Rmin = region[i].Rmin; 321 new[Nnew].Rmax = region[i].Rmax; 309 322 new[Nnew].depth = 3; 310 323 new[Nnew].child = FALSE; … … 319 332 320 333 /* update db list */ 321 db[i].childS = N;322 db[i].childE = N + Nnew;334 region[i].childS = N; 335 region[i].childE = N + Nnew; 323 336 NREGION = N + Nnew + 100; 324 337 REALLOCATE (db, SkyRegion, NREGION); 325 memcpy (& db[N], new, Nnew*sizeof(SkyRegion));338 memcpy (®ion[N], new, Nnew*sizeof(SkyRegion)); 326 339 free (new); 327 340 N += Nnew; … … 334 347 for (i = childS; i < childE; i++) { 335 348 Rnumber = 0; 336 db[i].childS = N;337 dDec = ( db[i].Dmax - db[i].Dmin) / 5.0;338 dRa = ( db[i].Rmax - db[i].Rmin) / 5.0;349 region[i].childS = N; 350 dDec = (region[i].Dmax - region[i].Dmin) / 5.0; 351 dRa = (region[i].Rmax - region[i].Rmin) / 5.0; 339 352 for (nx = 0; nx < 5; nx++) { 340 353 for (ny = 0; ny < 5; ny++) { 341 db[N].Dmin = db[i].Dmin + dDec * (nx + 0);342 db[N].Dmax = db[i].Dmax + dDec * (nx + 1);343 db[N].Rmin = db[i].Rmin + dDec * (nx + 0);344 db[N].Rmax = db[i].Rmax + dDec * (nx + 1);345 db[N].depth = 3;346 db[N].child = FALSE;347 strncpy (root, db[i].name, 10); root[10] = 0;348 sprintf ( db[N].name, "%s.%02d.cpt", root, Rnumber);354 region[N].Dmin = region[i].Dmin + dDec * (nx + 0); 355 region[N].Dmax = region[i].Dmax + dDec * (nx + 1); 356 region[N].Rmin = region[i].Rmin + dDec * (nx + 0); 357 region[N].Rmax = region[i].Rmax + dDec * (nx + 1); 358 region[N].depth = 3; 359 region[N].child = FALSE; 360 strncpy (root, region[i].name, 10); root[10] = 0; 361 sprintf (region[N].name, "%s.%02d.cpt", root, Rnumber); 349 362 Rnumber ++; 350 363 N ++; -
trunk/Ohana/src/opihi/include/dvo2.h
r2598 r5438 12 12 float r, d; 13 13 } SkyCoord; 14 15 typedef struct { 16 int Nregion; 17 SkyRegion *region; 18 } SkyRegionTable; 19 20 typedef struct { 21 int Nregion; 22 SkyRegion **region; 23 } SkyRegionList; 14 24 15 25 typedef struct {
Note:
See TracChangeset
for help on using the changeset viewer.
