IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30349


Ignore:
Timestamp:
Jan 24, 2011, 1:36:50 PM (15 years ago)
Author:
eugene
Message:

verify IDs as well as FITS tables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/Ohana/src/dvomerge/src/dvoverify.c

    r29938 r30349  
    99
    1010int VerifyTableFile (char *filename);
     11int CheckCatalogIndexes (char *catdir, char *filename,  SkyRegion *region);
    1112
    1213# define DEBUG 0
     14
     15int VERBOSE;
    1316
    1417int main (int argc, char **argv) {
     
    2225  SkyRegion UserPatch;
    2326  // Catalog catalog;
     27
     28  VERBOSE = FALSE;
     29  if ((N = get_argument (argc, argv, "-v"))) {
     30    VERBOSE = TRUE;
     31    remove_argument (N, &argc, argv);
     32  }
    2433
    2534  // restrict to a portion of the sky
     
    8392    if (i % 1000 == 0) fprintf (stderr, ".");
    8493
    85     sprintf (filename, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name);
    86     if (!VerifyTableFile (filename)) {
     94    // sprintf (filename, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name);
     95    if (!VerifyTableFile (inlist[0].filename[i])) {
    8796      Nbad ++;
    8897    }
     
    95104    sprintf (filename, "%s/%s.cpm", catdir, inlist[0].regions[i][0].name);
    96105    if (!VerifyTableFile (filename)) {
     106      Nbad ++;
     107    }
     108
     109    if (!CheckCatalogIndexes(catdir, inlist[0].filename[i], inlist[0].regions[i])){
    97110      Nbad ++;
    98111    }
     
    212225}
    213226
    214   // gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    215   // gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows);
     227// CheckCatalogIndexes(catdir, inlist[0].regions[i][0].name);
     228
     229int CheckCatalogIndexes (char *catdir, char *filename,  SkyRegion *region) {
     230
     231  Catalog catalog;
     232  int i, j, m, status;
     233
     234  status = TRUE;
     235
     236  // set the parameters which guide catalog open/load/create
     237  catalog.filename  = filename;
     238  catalog.catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
     239  catalog.catmode   = dvo_catalog_catmode (CATMODE);      // set the default catmode from config data
     240  catalog.catflags  = LOAD_AVES | LOAD_MEAS;
     241  catalog.Nsecfilt  = 0;
     242 
     243  // an error exit status here is a significant error (disk I/O or file access)
     244  if (!dvo_catalog_open (&catalog, region, VERBOSE, "r")) {
     245    fprintf (stderr, "ERROR: failure to open catalog file %s\n", catalog.filename);
     246    return FALSE;
     247  }
     248
     249  // Naves_disk == 0 implies an empty catalog file, skip empty catalogs
     250  if (catalog.Naves_disk == 0) {
     251    dvo_catalog_unlock (&catalog);
     252    dvo_catalog_free (&catalog);
     253    return TRUE;
     254  }
     255
     256  // if the table is SORTED, then the following can be checked
     257  // check the following:
     258  // measure[j].averef -> average[averef]
     259  // measure[j].objID = average[averef].objID
     260  // measure[j].catID = average[averef].catID
     261  // measure[j].measureOffset < Nmeasure
     262  // \sum average[].Nmeasure = Nmeasure
     263
     264  // if the table is NOT SORTED, we have a subset of checks we can make
     265  if (!catalog.sorted) {
     266    fprintf (stderr, "!");
     267    dvo_catalog_unlock (&catalog);
     268    dvo_catalog_free (&catalog);
     269    return TRUE;
     270  }
     271
     272  int NmeasureTotal = 0;
     273  int measureOffsetOK = TRUE;
     274  for (i = 0; i < catalog.Naverage; i++) {
     275    NmeasureTotal += catalog.average[i].Nmeasure;
     276    if (VERBOSE && !(NmeasureTotal <= catalog.Nmeasure)) {
     277      fprintf (stderr, "NmeasureTotal > catalog.Nmeasure: %d %d %d\n", i, catalog.average[i].Nmeasure, (int) catalog.Nmeasure);
     278    }
     279    measureOffsetOK &= (catalog.average[i].measureOffset < catalog.Nmeasure);
     280    if (VERBOSE && !(catalog.average[i].measureOffset < catalog.Nmeasure)) {
     281      fprintf (stderr, "measureOffset >= catalog.Nmeasure: %d %d %d\n", i, catalog.average[i].measureOffset, (int) catalog.Nmeasure);
     282    }
     283    measureOffsetOK &= (catalog.average[i].measureOffset + catalog.average[i].Nmeasure <= catalog.Nmeasure);
     284    if (VERBOSE && !(catalog.average[i].measureOffset + catalog.average[i].Nmeasure <= catalog.Nmeasure)) {
     285      fprintf (stderr, "measureOffset + Nmeasure > catalog.Nmeasure : %d %d %d\n", i, catalog.average[i].Nmeasure, (int) catalog.Nmeasure);
     286    }
     287  }
     288
     289  if (!measureOffsetOK) {
     290    fprintf (stderr, "ERROR: catalog %s has an invalid measureOffset\n", catalog.filename);
     291    status = FALSE;
     292  }
     293
     294  if (NmeasureTotal != catalog.Nmeasure) {
     295    fprintf (stderr, "ERROR: catalog %s has an invalid Nmeasure\n", catalog.filename);
     296    status = FALSE;
     297  }
     298
     299  if (!status) {
     300    dvo_catalog_unlock (&catalog);
     301    dvo_catalog_free (&catalog);
     302    return (status);
     303  }
     304
     305  int objIDsOK = TRUE;
     306  int catIDsOK = TRUE;
     307  int averefOK = TRUE;
     308
     309  for (i = 0; i < catalog.Naverage; i++) {
     310    m = catalog.average[i].measureOffset;
     311    for (j = 0; j < catalog.average[i].Nmeasure; j++) {
     312      objIDsOK &= (catalog.average[i].objID == catalog.measure[m+j].objID);
     313      catIDsOK &= (catalog.average[i].catID == catalog.measure[m+j].catID);
     314      averefOK &= (catalog.measure[m+j].averef == i);
     315    }
     316  }
     317   
     318  if (!objIDsOK) {
     319    fprintf (stderr, "ERROR: catalog %s has invalid obj IDs\n", catalog.filename);
     320    status = FALSE;
     321  }
     322  if (!catIDsOK) {
     323    fprintf (stderr, "ERROR: catalog %s has invalid cat IDs\n", catalog.filename);
     324    status = FALSE;
     325  }
     326  if (!averefOK) {
     327    fprintf (stderr, "ERROR: catalog %s has invalid averef values\n", catalog.filename);
     328    status = FALSE;
     329  }
     330
     331//  for (i = 0; i < catalog.Naverage; i++) {
     332//    m = catalog.average[i].measureOffset;
     333//    for (j = 0; i < catalog.Nmeasure; i++) {
     334//      objIDsOK &= (catalog.average[i].objID == catalog.measure[m+j].objID);
     335//      catIDsOK &= (catalog.average[i].catID == catalog.measure[m+j].catID);
     336//      averefOK &= (catalog.measure[m+j].averef = i);
     337//    }
     338//  }
     339
     340  dvo_catalog_unlock (&catalog);
     341  dvo_catalog_free (&catalog);
     342
     343  return status;
     344}
     345
     346// gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
     347// gfits_scan(&cpmHeaderTBL, "NAXIS2", "%d", 1, &Nrows);
    216348   
    217349 
Note: See TracChangeset for help on using the changeset viewer.