IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 16, 2006, 10:12:55 AM (20 years ago)
Author:
eugene
Message:

updating to new DVO APIs

Location:
trunk/Ohana/src/libdvo
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libdvo/include/dvo.h

    r8342 r8386  
    280280int dvo_catalog_catformat (char *catformat);
    281281int dvo_catalog_catmode (char *catmode);
     282void dvo_catalog_test (Catalog *catalog, int halt);
    282283
    283284/* catmode-specific APIs */
  • trunk/Ohana/src/libdvo/src/dvo_catalog.c

    r8342 r8386  
    11# include <dvo.h>
    22# define DEBUG 1
     3
     4void dvo_catalog_test (Catalog *catalog, int halt) {
     5
     6  Catalog *subcat;
     7
     8  // fprintf (stderr, "catalog: Naverage = %d, average = %zx\n", catalog[0].Naverage, (size_t) catalog[0].average);
     9  // fprintf (stderr, "catalog: Nmeasure = %d, measure = %zx\n", catalog[0].Nmeasure, (size_t) catalog[0].measure);
     10  // fprintf (stderr, "catalog: Nmissing = %d, missing = %zx\n", catalog[0].Nmissing, (size_t) catalog[0].missing);
     11  // fprintf (stderr, "catalog: Nsecfilt = %d, secfilt = %zx\n", catalog[0].Nsecfilt, (size_t) catalog[0].secfilt);
     12
     13  if (!catalog[0].measure || !catalog[0].secfilt) {
     14    fprintf (stderr, "error: %s\n", catalog[0].filename);
     15    if (halt) abort ();
     16  }
     17
     18  // XXX test that things are correctly initialized
     19  if (catalog[0].catmode != DVO_MODE_SPLIT) return;
     20
     21  subcat = catalog[0].measure_catalog;
     22  if (subcat) {
     23    if (subcat[0].measure_catalog || subcat[0].secfilt_catalog || subcat[0].missing_catalog) {
     24      fprintf (stderr, "error in init\n");
     25      abort ();
     26    }
     27  }
     28  subcat = catalog[0].missing_catalog;
     29  if (subcat) {
     30    if (subcat[0].measure_catalog || subcat[0].secfilt_catalog || subcat[0].missing_catalog) {
     31      fprintf (stderr, "error in init\n");
     32      abort ();
     33    }
     34  }
     35  subcat = catalog[0].secfilt_catalog;
     36  if (subcat) {
     37    if (subcat[0].measure_catalog || subcat[0].secfilt_catalog || subcat[0].missing_catalog) {
     38      fprintf (stderr, "error in init\n");
     39      abort ();
     40    }
     41  }
     42}
    343
    444int dvo_catalog_catformat (char *catformat) {
     
    3575    catalog[0].catflags = 0;
    3676    catalog[0].sorted = 0;
    37 
    38     gfits_init_header (&catalog[0].header);
    39   }
     77  }
     78
     79  gfits_init_header (&catalog[0].header);
    4080
    4181  // the following describe the catalog files on disk
     
    102142  // attempt to unlink an empty file
    103143  fd = fileno (catalog[0].f);
    104   if (fstat (fd, &filestat)) {
     144  if (!fstat (fd, &filestat)) {
    105145    if (filestat.st_size == 0) {
    106146      unlink (catalog[0].filename);
     
    121161// returns FALSE if a catalog could not be opened
    122162// returns TRUE if the catalog was empty
     163enum {DVO_OPEN_NONE, DVO_OPEN_READ, DVO_OPEN_WRITE, DVO_OPEN_UPDATE);
    123164int dvo_catalog_open (Catalog *catalog, SkyRegion *region, int VERBOSE, char *iomode) {
    124165
    125   int Nsecfilt;
    126   int readonly;
    127 
    128   readonly = -1;
    129   if (!strcasecmp (iomode, "r")) readonly = TRUE;
    130   if (!strcasecmp (iomode, "w")) readonly = FALSE;
    131   if (readonly == -1) return (FALSE);
     166  int Nsecfilt, mode;
     167
     168  mode = DVO_OPEN_NONE;
     169  if (!strcasecmp (iomode, "r")) mode = DVO_OPEN_READ;
     170  if (!strcasecmp (iomode, "w")) mode = DVO_OPEN_WRITE;
     171  if (!strcasecmp (iomode, "a")) mode = DVO_OPEN_UPDATE;
     172  if (mode == DVO_OPEN_NONE) return (FALSE);
    132173
    133174  catalog[0].lockmode  = LCK_XCLD;
    134   if (readonly) catalog[0].lockmode  = LCK_SOFT;
     175  if (mode == DVO_OPEN_READ) catalog[0].lockmode  = LCK_SOFT;
    135176
    136177  // XXX make a backup?  always?
     
    161202    break;
    162203  case 2:
    163     if (readonly) return (TRUE);
     204    if (DVO_OPEN_READ || DVO_OPEN_UPDATE) return (TRUE);
    164205    dvo_catalog_create (region, catalog, Nsecfilt); /* fills in new header info */
    165206    if (VERBOSE) fprintf (stderr, "creating new file %s\n", catalog[0].filename);
     
    177218  char measure[80];
    178219
     220  dvo_catalog_init (catalog, FALSE);
     221
    179222  // load the main catalog header, determine characteristics
    180223  if (!gfits_fread_header (catalog[0].f, &catalog[0].header)) {
     
    200243  catalog[0].catformat = DVO_FORMAT_UNDEF;
    201244
    202   catalog[0].average = NULL;
    203   catalog[0].secfilt = NULL;
    204   catalog[0].measure = NULL;
    205   catalog[0].missing = NULL;
    206 
    207245  switch (catalog[0].catmode) {
    208246    case DVO_MODE_RAW:
     
    217255      if (VERBOSE) fprintf (stderr, "reading catalog (mode DVO_MODE_SPLIT)\n");
    218256      dvo_catalog_load_split (catalog, VERBOSE);
     257      dvo_catalog_test (catalog, TRUE);
    219258      break;
    220259    default:
  • trunk/Ohana/src/libdvo/src/dvo_catalog_create.c

    r8342 r8386  
    11# include <dvo.h>
    2 # define DEBUG 1
     2# define DEBUG 0
    33
    44// create a new dvo catalog file (if split, lock extra files as well?)
  • trunk/Ohana/src/libdvo/src/dvo_catalog_split.c

    r8342 r8386  
    6060    gfits_free_header (&header);
    6161  }
     62  dvo_catalog_test (catalog, FALSE);
    6263
    6364  /*** Measure Table ***/
     
    6869  if (catalog[0].catflags & LOAD_MEAS) {
    6970    ALLOCATE (measure, Catalog, 1);
    70     measure[0].measure_catalog = NULL;
    71     measure[0].missing_catalog = NULL;
    72     measure[0].secfilt_catalog = NULL;
     71    dvo_catalog_init (measure, TRUE);
    7372
    7473    /* get split filename from main header (paths relative to cpt file) */
     
    9089    /* matrix should be empty */
    9190    if (!gfits_fread_matrix (measure[0].f, &matrix, &measure[0].header)) {
    92       if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     91      if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    9392      return (FALSE);
    9493    }
    9594    /* read Measure table header */
    9695    if (!gfits_fread_header (measure[0].f, &header)) {
    97       if (VERBOSE) fprintf (stderr, "can't read measure PHU header");
     96      if (VERBOSE) fprintf (stderr, "can't read measure PHU header\n");
    9897      return (FALSE);
    9998    }
    10099    /* read Measure table data */
    101100    if (!gfits_fread_ftable_data (measure[0].f, &ftable)) {
    102       if (VERBOSE) fprintf (stderr, "can't read table measure data");
     101      if (VERBOSE) fprintf (stderr, "can't read table measure data\n");
    103102      return (FALSE);
    104103    }
     
    112111    gfits_free_matrix (&matrix);
    113112  }
     113  dvo_catalog_test (catalog, FALSE);
    114114
    115115  /* (Meta Load) */
    116116  if (catalog[0].catflags & LOAD_MEAS_META) {
    117117    ALLOCATE (measure, Catalog, 1);
     118    dvo_catalog_init (measure, TRUE);
    118119
    119120    /* get split filename from main header (paths relative to cpt file) */
     
    142143  }
    143144  catalog[0].measure_catalog = measure;
     145  dvo_catalog_test (catalog, FALSE);
    144146
    145147  /*** Missing Table ***/
     
    148150  if (catalog[0].catflags & LOAD_MISS) {
    149151    ALLOCATE (missing, Catalog, 1);
    150     missing[0].measure_catalog = NULL;
    151     missing[0].missing_catalog = NULL;
    152     missing[0].secfilt_catalog = NULL;
     152    dvo_catalog_init (missing, TRUE);
    153153
    154154    /* get split filename from main header (paths relative to cpt file) */
     
    170170    /* matrix should be empty */
    171171    if (!gfits_fread_matrix (missing[0].f, &matrix, &missing[0].header)) {
    172       if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     172      if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    173173      return (FALSE);
    174174    }
    175175    /* read Missing table header */
    176176    if (!gfits_fread_header (missing[0].f, &header)) {
    177       if (VERBOSE) fprintf (stderr, "can't read table missing header");
     177      if (VERBOSE) fprintf (stderr, "can't read table missing header\n");
    178178      return (FALSE);
    179179    }
    180180    /* read Missing table data */
    181181    if (!gfits_fread_ftable_data (missing[0].f, &ftable)) {
    182       if (VERBOSE) fprintf (stderr, "can't read table missing data");
     182      if (VERBOSE) fprintf (stderr, "can't read table missing data\n");
    183183      return (FALSE);
    184184    }
     
    192192  }
    193193  catalog[0].missing_catalog = missing;
     194  dvo_catalog_test (catalog, FALSE);
    194195
    195196  /*** Secfilt Table ***/
     
    198199  if (catalog[0].catflags & LOAD_SECF) {
    199200    ALLOCATE (secfilt, Catalog, 1);
    200     secfilt[0].measure_catalog = NULL;
    201     secfilt[0].missing_catalog = NULL;
    202     secfilt[0].secfilt_catalog = NULL;
     201    dvo_catalog_init (secfilt, TRUE);
    203202
    204203    /* get split filename from main header (paths relative to cpt file) */
     
    220219    /* matrix should be empty */
    221220    if (!gfits_fread_matrix (secfilt[0].f, &matrix, &secfilt[0].header)) {
    222       if (VERBOSE) fprintf (stderr, "can't read primary matrix");
     221      if (VERBOSE) fprintf (stderr, "can't read primary matrix\n");
    223222      return (FALSE);
    224223    }
    225224    /* read secfilt table header */
    226225    if (!gfits_fread_header (secfilt[0].f, &header)) {
    227       if (VERBOSE) fprintf (stderr, "can't read table secfilt header");
     226      if (VERBOSE) fprintf (stderr, "can't read table secfilt header\n");
    228227      return (FALSE);
    229228    }
    230229    /* read secfilt table data */
    231230    if (!gfits_fread_ftable_data (secfilt[0].f, &ftable)) {
    232       if (VERBOSE) fprintf (stderr, "can't read table secfilt data");
     231      if (VERBOSE) fprintf (stderr, "can't read table secfilt data\n");
    233232      return (FALSE);
    234233    }
     
    242241  }
    243242  catalog[0].secfilt_catalog = secfilt;
     243  dvo_catalog_test (catalog, FALSE);
    244244
    245245  /* save the current number so we can do partial updates */
  • trunk/Ohana/src/libdvo/src/skyregion_gsc.c

    r8342 r8386  
    22# define NDECBANDS 24
    33# define NDIV 4
     4# define DEBUG 0
    45
    56static int DecLines[] = {593, 584, 551, 530, 522, 465, 406, 362, 280, 198, 123, 25, 597, 578, 574, 577, 534, 499, 442, 376, 294, 212, 144, 48};
     
    8586  L0.regions[0].childE  =  NDECBANDS;
    8687  strcpy (L0.regions[0].name, "fullsky");
    87   // SkyRegionPrint (&L0.regions[0]);
     88  if (DEBUG) SkyRegionPrint (&L0.regions[0]);
    8889
    8990  /* allocate space for all levels */
     
    9394  ALLOCATE (L3.regions, SkyRegion, 1);
    9495  ALLOCATE (L4.regions, SkyRegion, 1);
     96
     97  // skipLines = 0;
     98  // for (i = 0; i < 16; i++) skipLines += DecLines[i];
     99  // for (i = 16; i < 17; i++) {
    95100
    96101  /* L1 : dec bands */
     
    107112    L1.regions[i].table    = -1;
    108113    strcpy (L1.regions[i].name, DecNames[i]);
    109     // SkyRegionPrint (&L1.regions[i]);
     114    if (DEBUG) SkyRegionPrint (&L1.regions[i]);
    110115
    111116    /* build the L2 regions for this L1 region (based on zones) */
     
    123128    /* subdivide each zone */
    124129    for (j = 0; j < Nzones; j++) {
     130      if (DEBUG) fprintf (stderr, "zone: %d : %f - %f : %f - %f\n", j, zones[j].Rmin, zones[j].Rmax, zones[j].Dmin, zones[j].Dmax);
    125131      SkyTableL2fromZone (&L2, &L3, &L4, band, &zones[j], i);
    126132    }
     
    273279    Dmax = MAX (regions[i].Dmax, Dmax);
    274280    dDec = regions[i].Dmax - regions[i].Dmin;
    275     if (dDec != zones[Nz].dDec) {
     281    if (fabs(dDec - zones[Nz].dDec) > 0.001) {
    276282      /* we've found the end of the current zone */
    277283      zones[Nz].L3end = i;
     
    347353    *p = '/';
    348354    strcpy (L2[0].regions[Nr].name, name);
    349     // SkyRegionPrint (&L2[0].regions[Nr]);
     355    if (DEBUG) SkyRegionPrint (&L2[0].regions[Nr]);
    350356
    351357    /* childS and childE are set in SkyTableL3fromL2 */
     
    383389    L3[0].regions[Nr].childE   =  0;
    384390
    385     // SkyRegionPrint (&L3[0].regions[Nr]);
     391    if (DEBUG) SkyRegionPrint (&L3[0].regions[Nr]);
    386392    /* name is set for the band in SkyRegionForDecBand */
    387393
     
    432438      sprintf (name, "%s.%02d", L3[0].name, Nbox);
    433439      strcpy (L4[0].regions[Nr].name, name);
    434       // SkyRegionPrint (&L4[0].regions[Nr]);
     440      if (DEBUG) SkyRegionPrint (&L4[0].regions[Nr]);
    435441
    436442      Nr ++;
Note: See TracChangeset for help on using the changeset viewer.