IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 21, 2005, 5:53:44 PM (21 years ago)
Author:
eugene
Message:

working on skydb tools

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/dvo2/skydbsearch.c

    r5438 r5439  
    181181}
    182182
    183 SkyRegion *SkyBuildTable (SkyRegion *seed, int Nseed, int level, int depth) {
    184 
    185   /* given a table of Rmin, Dmin, Rmax, Dmax, name, at level 3, generate
    186      all higher levels and 'depth' extra levels */
    187 
    188   /* levels:
    189      0 - fullsky.cpt
    190      1 - n????.cpt, s????.cpt
    191      2 - r????.cpt
    192      3 - ????.cpt
    193      4 - ????.??.cpt
    194   */
    195  
    196   SkyRegion *db;
    197 
    198   /* allocate at least 30 for levels 0 & 1 */
    199   NREGION = 100;
    200   ALLOCATE (db, SkyRegion, NREGION);
    201 
    202   /* full sky */
    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;
    208   N = 1;
    209 
    210   region[0].childS = N;
    211   /* north dec bands */
    212   for (dec = 0; dec < 90; dec += 7.5) {
    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;
    218     N++;
    219   }
    220   /* south dec bands */
    221   for (dec = 0; dec > -90; dec -= 7.5) {
    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;
    227     N++;
    228   }
    229   region[0].childE = N;
    230 
    231   /* subdivide dec bands based on seed */
    232   Rnumber = 0;
    233   childS = region[0].childS;
    234   childE = region[0].childE;
    235   for (i = childS; i < childE; i++) {
    236 
    237     Nnew = 0;
    238     NNEW = 100;
    239     ALLOCATE (new, SkyRegion, NNEW);
    240 
    241     for (j = 0; j < Nseed; j++) {
    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;
    247      
    248       for (k = 0; k < Nnew; k++) {
    249         if ((seed[j].Rmin == new[k].Rmin) &&
    250             (seed[j].Rmax == new[k].Rmax)) {
    251           goto next_seed;
    252         }
    253         if ((seed[j].Rmin == new[k].Rmin) ^^
    254             (seed[j].Rmax != new[k].Rmax)) {
    255           fprintf (stderr, "inconsistent blocks in seed file\n");
    256           return (NULL);
    257         }
    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 
    267       new[Nnew].Rmin = seed[j].Rmin;
    268       new[Nnew].Rmax = seed[j].Rmax;
    269       new[Nnew].depth = 2;
    270       new[Nnew].child = FALSE;
    271       strncpy (root, region[i].name, 5); root[5] = 0;
    272       sprintf (new[Nnew].name, "%s/r%04d.cpt", root, Rnumber);
    273       Rnumber ++;     
    274       Nnew ++;
    275       if (Nnew == NNEW) {
    276         NNEW += 100;
    277         REALLOCATE (new, SkyRegion, NNEW);
    278       }
    279     next_seed:
    280     }
    281     /* update db list */
    282     region[i].childS = N;
    283     region[i].childE = N + Nnew;
    284     NREGION = N + Nnew + 100;
    285     REALLOCATE (db, SkyRegion, NREGION);
    286     memcpy (&region[N], new, Nnew*sizeof(SkyRegion));
    287     free (new);
    288     N += Nnew;
    289   }
    290 
    291   /* subdivide ra strips based on seed */
    292   childS = region[region[0].childS].childS;
    293   childE = region[region[0].childE - 1].childE;
    294   nextS = N;
    295   for (i = childS; i < childE; i++) {
    296 
    297     Nnew = 0;
    298     NNEW = 100;
    299     ALLOCATE (new, SkyRegion, NNEW);
    300 
    301     for (j = 0; j < Nseed; j++) {
    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;
    306      
    307       for (k = 0; k < Nnew; k++) {
    308         if ((seed[j].Dmin == new[k].Dmin) &&
    309             (seed[j].Dmax == new[k].Dmax)) {
    310           goto next_seed;
    311         }
    312         if ((seed[j].Dmin == new[k].Dmin) ^^
    313             (seed[j].Dmax != new[k].Dmax)) {
    314           fprintf (stderr, "inconsistent blocks in seed file\n");
    315           return (NULL);
    316         }
    317       }
    318       new[Nnew].Dmin = seed[j].Dmin;
    319       new[Nnew].Dmax = seed[j].Dmax;
    320       new[Nnew].Rmin = region[i].Rmin;
    321       new[Nnew].Rmax = region[i].Rmax;
    322       new[Nnew].depth = 3;
    323       new[Nnew].child = FALSE;
    324       strcpy (new[Nnew].name, seed[j].name);
    325       Nnew ++;
    326       if (Nnew == NNEW) {
    327         NNEW += 100;
    328         REALLOCATE (new, SkyRegion, NNEW);
    329       }
    330     next_seed:
    331     }
    332    
    333     /* update db list */
    334     region[i].childS = N;
    335     region[i].childE = N + Nnew;
    336     NREGION = N + Nnew + 100;
    337     REALLOCATE (db, SkyRegion, NREGION);
    338     memcpy (&region[N], new, Nnew*sizeof(SkyRegion));
    339     free (new);
    340     N += Nnew;
    341   }
    342   nextE = N;
    343 
    344   /* subdivide entries once more */
    345   childS = nextS;
    346   childE = nextE;
    347   for (i = childS; i < childE; i++) {
    348     Rnumber = 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;
    352     for (nx = 0; nx < 5; nx++) {
    353       for (ny = 0; ny < 5; ny++) {
    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);
    362         Rnumber ++;
    363         N ++;
    364         if (N == NREGION) {
    365           NREGION += 100;
    366           REALLOCATE (new, SkyRegion, NREGION);
    367         }
    368       }
    369     }
    370   }
    371 
    372 }
    373 
    374183/* region is pointer to entry in db */
    375184SkyRegion *SkyExtend (SkyRegion *db, SkyRegion *region) {
Note: See TracChangeset for help on using the changeset viewer.