IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5438


Ignore:
Timestamp:
Oct 21, 2005, 9:27:54 AM (21 years ago)
Author:
eugene
Message:

working on skydb

Location:
trunk/Ohana/src/opihi
Files:
2 edited

Legend:

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

    r2598 r5438  
    99
    1010/* find region which overlaps c at given depth (-1 : max depth) */
    11 SkyRegion *SkyFindPoint (SkyRegion *db, SkyCoord c, int depth) {
     11SkyRegion *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 (&region[No]);
     32    if ((depth == -1) && (!region[No].child)) return (&region[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 */
     42SkyRegionList *SkyFindLevels (SkyRegionTable *table, double ra, double dec) {
     43
     44  SkyRegion *region;
     45  SkyRegionList *list;
    1246 
    1347  Ns = 0;
    1448  Ne = 1;
    1549
     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
    1658  while (1) {
    1759    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;
    2365      No = i;
    2466      break;
    2567    }
    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] = &region[No];
    6471    N++;
    6572    if (N == NREGION) {
    6673      NREGION += 10;
    67       REALLOCATE (region, SkyRegion *, NREGION);
     74      REALLOCATE (list[0].region, SkyRegion *, NREGION);
    6875    }     
     76    list[0].Nregion = N;
    6977
    7078    /* 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;
    7482    } else {
    75       *Nregion = N;
    76       return (region);
     83      return (list);
    7784    }
    7885  }
     
    102109    *nlist = Nlist;
    103110    return (list);
    104 
    105111  }   
    106112
     
    109115  Nlist = 1;
    110116  ALLOCATE (list, SkyRegion *, Nlist);
    111   list[0] = &db[0];
    112   getchild = db[0].child;
     117  list[0] = &region[0];
     118  getchild = region[0].child;
    113119
    114120  while (getchild) {
     
    160166
    161167  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] = &region[i];
    167173    Nregion++;
    168174    if (Nregion == NREGION) {
     
    195201
    196202  /* 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;
    202208  N = 1;
    203209
    204   db[0].childS = N;
     210  region[0].childS = N;
    205211  /* north dec bands */
    206212  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;
    212218    N++;
    213219  }
    214220  /* south dec bands */
    215221  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;
    221227    N++;
    222228  }
    223   db[0].childE = N;
     229  region[0].childE = N;
    224230
    225231  /* subdivide dec bands based on seed */
    226232  Rnumber = 0;
    227   childS = db[0].childS;
    228   childE = db[0].childE;
     233  childS = region[0].childS;
     234  childE = region[0].childE;
    229235  for (i = childS; i < childE; i++) {
    230236
     
    234240
    235241    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;
    240247     
    241248      for (k = 0; k < Nnew; k++) {
     
    250257        }
    251258      }
     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
    252267      new[Nnew].Rmin = seed[j].Rmin;
    253268      new[Nnew].Rmax = seed[j].Rmax;
    254       new[Nnew].Dmin = db[i].Dmin;
    255       new[Nnew].Dmax = db[i].Dmax;
    256269      new[Nnew].depth = 2;
    257270      new[Nnew].child = FALSE;
    258       strncpy (root, db[i].name, 5); root[5] = 0;
     271      strncpy (root, region[i].name, 5); root[5] = 0;
    259272      sprintf (new[Nnew].name, "%s/r%04d.cpt", root, Rnumber);
    260273      Rnumber ++;     
     
    267280    }
    268281    /* 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;
    271284    NREGION = N + Nnew + 100;
    272285    REALLOCATE (db, SkyRegion, NREGION);
    273     memcpy (&db[N], new, Nnew*sizeof(SkyRegion));
     286    memcpy (&region[N], new, Nnew*sizeof(SkyRegion));
    274287    free (new);
    275288    N += Nnew;
     
    277290
    278291  /* 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;
    281294  nextS = N;
    282295  for (i = childS; i < childE; i++) {
     
    287300
    288301    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;
    293306     
    294307      for (k = 0; k < Nnew; k++) {
     
    305318      new[Nnew].Dmin = seed[j].Dmin;
    306319      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;
    309322      new[Nnew].depth = 3;
    310323      new[Nnew].child = FALSE;
     
    319332   
    320333    /* 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;
    323336    NREGION = N + Nnew + 100;
    324337    REALLOCATE (db, SkyRegion, NREGION);
    325     memcpy (&db[N], new, Nnew*sizeof(SkyRegion));
     338    memcpy (&region[N], new, Nnew*sizeof(SkyRegion));
    326339    free (new);
    327340    N += Nnew;
     
    334347  for (i = childS; i < childE; i++) {
    335348    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;
    339352    for (nx = 0; nx < 5; nx++) {
    340353      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);
    349362        Rnumber ++;
    350363        N ++;
  • trunk/Ohana/src/opihi/include/dvo2.h

    r2598 r5438  
    1212  float r, d;
    1313} SkyCoord;
     14
     15typedef struct {
     16  int Nregion;
     17  SkyRegion *region;
     18} SkyRegionTable;
     19
     20typedef struct {
     21  int Nregion;
     22  SkyRegion **region;
     23} SkyRegionList;
    1424
    1525typedef struct {
Note: See TracChangeset for help on using the changeset viewer.