IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 27, 2015, 4:49:06 PM (11 years ago)
Author:
eugene
Message:

extensive work on relphot, relastro, uniphot, dvomerge aiming to the construction and calibration of PV3

Location:
trunk/Ohana
Files:
35 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/dvomerge/Makefile

    r38468 r38986  
    4040$(SRC)/dvo_image_merge_dbs.$(ARCH).o \
    4141$(SRC)/IDmapIO.$(ARCH).o \
     42$(SRC)/ConfigInit.$(ARCH).o \
    4243$(SRC)/SetSignals.$(ARCH).o \
    43 $(SRC)/ConfigInit.$(ARCH).o \
    4444$(SRC)/Shutdown.$(ARCH).o \
    4545$(SRC)/help.$(ARCH).o \
     
    5151$(SRC)/replace_match.$(ARCH).o \
    5252$(SRC)/replace_tycho.$(ARCH).o \
     53$(SRC)/repair_catalog_by_objID.$(ARCH).o \
    5354$(SRC)/merge_catalogs_new.$(ARCH).o \
    5455$(SRC)/merge_catalogs_old.$(ARCH).o
     
    7576$(SRC)/replace_match.$(ARCH).o \
    7677$(SRC)/replace_tycho.$(ARCH).o \
     78$(SRC)/repair_catalog_by_objID.$(ARCH).o \
    7779$(SRC)/merge_catalogs_new.$(ARCH).o \
    7880$(SRC)/merge_catalogs_old.$(ARCH).o
     
    122124$(SRC)/dvorepair.$(ARCH).o \
    123125$(SRC)/dvorepairFixCPT.$(ARCH).o \
     126$(SRC)/dvorepairFixWarpIDs.$(ARCH).o \
    124127$(SRC)/dvorepairImagesVsMeasures.$(ARCH).o \
    125128$(SRC)/dvorepairDeleteImageList.$(ARCH).o \
     
    127130$(SRC)/dvorepairDeleteImagesByExternID.$(ARCH).o \
    128131$(SRC)/dvorepairFixImages.$(ARCH).o \
     132$(SRC)/dvorepair_by_objID.$(ARCH).o \
     133$(SRC)/repair_catalog_by_objID.$(ARCH).o \
    129134$(SRC)/psps_ids.$(ARCH).o \
    130135$(SRC)/LoadImages.$(ARCH).o \
    131136$(SRC)/ReadDeleteList.$(ARCH).o \
    132137$(SRC)/ReadDeleteListExternID.$(ARCH).o \
     138$(SRC)/SetSignals.$(ARCH).o \
     139$(SRC)/Shutdown.$(ARCH).o \
    133140$(SRC)/myIndex.$(ARCH).o \
    134141$(SRC)/match_image.$(ARCH).o \
     
    140147
    141148DVOVERIFY = \
     149$(SRC)/SetSignals.$(ARCH).o \
     150$(SRC)/Shutdown.$(ARCH).o \
    142151$(SRC)/dvoverify.$(ARCH).o \
    143152$(SRC)/dvoverify_args.$(ARCH).o \
     
    149158
    150159DVOVERIFY_CLIENT = \
     160$(SRC)/SetSignals.$(ARCH).o \
     161$(SRC)/Shutdown.$(ARCH).o \
    151162$(SRC)/dvoverify_client.$(ARCH).o \
    152163$(SRC)/dvoverify_args.$(ARCH).o \
     
    158169
    159170DVOUTILS = \
     171$(SRC)/SetSignals.$(ARCH).o \
     172$(SRC)/Shutdown.$(ARCH).o \
    160173$(SRC)/dvoutils.$(ARCH).o \
    161174$(SRC)/dvoutils_args.$(ARCH).o \
  • trunk/Ohana/src/dvomerge/include/dvomerge.h

    r38553 r38986  
    4747
    4848int    MATCHED_TABLES;
     49int    REPAIR_BY_OBJID;
    4950
    5051char *SINGLE_CPT;
     
    202203int        dvomergeUpdate_catalogs PROTO((char *input, char *output, SkyTable *outsky, SkyList *inlist, int NsecfiltInput, int NsecfiltOutput, IDmapType *IDmap, int *secfiltMap));
    203204
    204 int        replace_match           PROTO((Average *average_out, Measure *measure_out, Average *average_in, Measure *measure_in));
     205int        replace_match           PROTO((Average *average_out, Measure *measure_out, off_t *next_meas, Average *average_in, Measure *measure_in));
    205206
    206207int        IDmapSave               PROTO((char *filename, IDmapType *IDmap));
     
    241242
    242243void replace_tycho_init ();
    243 int  replace_tycho (Average *averageInp, Measure *measureInp, Average *averageOut, Measure *measureOut);
     244int  replace_tycho (Average *averageInp, Measure *measureInp, off_t *next_meas, Average *averageOut, Measure *measureOut);
     245int repair_catalog_by_objID (Catalog *catalog);
     246
     247int dvorepair_by_objID (int argc, char **argv);
     248int dvorepairFixWarpIDs (int argc, char **argv);
     249
  • trunk/Ohana/src/dvomerge/include/dvoutils.h

    r37807 r38986  
    2222} DVOUTILS_OP_TYPE;
    2323
     24typedef struct {
     25  int   *externID;
     26  short *photcode;
     27  int Nimages;
     28} ImageData;
     29
    2430int VERBOSE;
    2531int DVOUTILS_OP;
     
    3036int dvoutils_args (int *argc, char **argv);
    3137int dvoutils_uniq_images (char *filename);
    32 int *dvoutils_load_image_index (char *filename, int *nindex);
     38
     39ImageData *dvoutils_load_image_index (char *filename);
    3340
    3441Image *dvoutils_load_image_table (char *filename, int *nimage);
     42
     43int        SetSignals             PROTO((void));
     44void       SetProtect             PROTO((int mode));
     45void       TrapSignal             PROTO((int sig));
     46int        Shutdown               PROTO((char *format, ...)) OHANA_FORMAT(printf, 1, 2);
     47
  • trunk/Ohana/src/dvomerge/include/dvoverify.h

    r38553 r38986  
    3737int    LIST_MISSING;
    3838
     39int    IGNORE_SORTED_STATE;
     40
    3941SkyRegion UserPatch;
    4042
     
    6264
    6365void FreeImageIDs (void);
     66
     67int        SetSignals             PROTO((void));
     68void       SetProtect             PROTO((int mode));
     69void       TrapSignal             PROTO((int sig));
     70int        Shutdown               PROTO((char *format, ...)) OHANA_FORMAT(printf, 1, 2);
     71
  • trunk/Ohana/src/dvomerge/src/LoadCatalog.c

    r38471 r38986  
    99
    1010  // always load all of the data (if any exists)
    11   catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;
     11  // XXXX TEMP HACK : skip GALPHOT
     12  // XXXX catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;
     13  catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR;
    1214 
    1315  catalog[0].catformat = dvo_catalog_catformat (CATFORMAT);  // set the default catformat from config data
  • trunk/Ohana/src/dvomerge/src/ReadDeleteListExternID.c

    r37807 r38986  
    4747      // confirm we have 9 fields broken by 8 spaces:
    4848      space = c0; // pointer to track the space-separated words
    49       indexPoint = c0; // pointer to the ID on this line
     49      indexPoint = strchr(c0, ' '); // pointer to the ID on this line
    5050
    51       for (j = 0; j < 8; j++) {
     51      for (j = 0; j < 9; j++) {
    5252        space = strchr(space, ' ');
    5353        if (!space) {
     
    6262      indexList[Nindex] = index;
    6363
    64       // fprintf (stderr, "index: %d, line: %s\n", index, c0);
     64      fprintf (stderr, "index: %d, line: %s\n", index, c0);
    6565
    6666      Nindex ++;
  • trunk/Ohana/src/dvomerge/src/args.c

    r38553 r38986  
    9494  if ((N = get_argument (*argc, argv, "-replace-tycho"))) {
    9595    REPLACE_TYCHO = TRUE;
     96    remove_argument (N, argc, argv);
     97  }
     98
     99  REPAIR_BY_OBJID = FALSE;
     100  if ((N = get_argument (*argc, argv, "-repair-by-objid"))) {
     101    REPAIR_BY_OBJID = TRUE;
    96102    remove_argument (N, argc, argv);
    97103  }
     
    266272  }
    267273
     274  REPAIR_BY_OBJID = FALSE;
     275  if ((N = get_argument (*argc, argv, "-repair-by-objid"))) {
     276    REPAIR_BY_OBJID = TRUE;
     277    remove_argument (N, argc, argv);
     278  }
     279
    268280  NTHREADS = 0;
    269281  if ((N = get_argument (*argc, argv, "-threads"))) {
  • trunk/Ohana/src/dvomerge/src/build_links.c

    r37814 r38986  
    145145    n = average[i].measureOffset;
    146146    average[i].measureOffset = N;
     147    int myObjID = average[i].objID;
    147148    for (k = 0; k < average[i].Nmeasure; k++, N++) {
    148149      if (n == -1) abort();
    149150      tmpmeasure[N] = measure[n];
    150       if (measure[n].averef != i) abort();
     151      myAssert (measure[n].averef == i, "error in averef?");
     152      myAssert (measure[n].objID == myObjID, "error in objID?");
    151153      tmpmeasure[N].averef = i;
    152154      n = next_meas[n];
  • trunk/Ohana/src/dvomerge/src/dvoconvert.c

    r38441 r38986  
    9494
    9595    outcatalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     96
     97    SetProtect (TRUE);
     98    if (!dvo_catalog_save (&outcatalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", outcatalog.filename); exit (1); }
     99    if (!dvo_catalog_unlock (&outcatalog)) { fprintf (stderr, "ERROR: failed to unlock %s\n", outcatalog.filename); exit (1); }
     100    SetProtect (FALSE);
     101
    96102    dvo_catalog_save (&outcatalog, VERBOSE);
    97103    dvo_catalog_unlock (&outcatalog);
  • trunk/Ohana/src/dvomerge/src/dvomergeContinue.c

    r38441 r38986  
    133133      // if we receive a signal which would cause us to exit, wait until the full catalog is written
    134134      SetProtect (TRUE);
    135       if (!dvo_catalog_save (&outcatalog, VERBOSE)) {
    136         fprintf (stderr, "ERROR: failed to save catalog %s\n", outlist[0].filename[j]);
    137         exit (1);
    138       }
     135      if (!dvo_catalog_save (&outcatalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", outcatalog.filename); exit (1); }
     136      if (!dvo_catalog_unlock (&outcatalog)) { fprintf (stderr, "ERROR: failed to unlock %s\n", outcatalog.filename); exit (1); }
    139137      SetProtect (FALSE);
    140138
    141       dvo_catalog_unlock (&outcatalog);
    142139      dvo_catalog_free (&outcatalog);
    143140
  • trunk/Ohana/src/dvomerge/src/dvomergeContinue_threaded.c

    r38441 r38986  
    7777      SetProtect (TRUE);
    7878      if (!dvo_catalog_save (&outcatalog, VERBOSE)) {
    79         fprintf (stderr, "ERROR: failed to save catalog %s\n", outlist[0].filename[j]);
     79        fprintf (stderr, "ERROR: failed to save catalog %s\n", outcatalog.filename);
     80        threadData->state = TS_FAIL;
     81        continue;
     82      }
     83      if (!dvo_catalog_unlock (&outcatalog)) {
     84        fprintf (stderr, "ERROR: failed to unlock catalog %s\n", outcatalog.filename);
    8085        threadData->state = TS_FAIL;
    8186        continue;
     
    8388      SetProtect (FALSE);
    8489
    85       dvo_catalog_unlock (&outcatalog);
    8690      dvo_catalog_free (&outcatalog);
    8791
  • trunk/Ohana/src/dvomerge/src/dvomergeCreate.c

    r38441 r38986  
    178178    SkyListFree (inlist);
    179179
    180     dvo_catalog_save (&outcatalog, VERBOSE);
    181     dvo_catalog_unlock (&outcatalog);
     180    SetProtect (TRUE);
     181    if (!dvo_catalog_save (&outcatalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", outcatalog.filename); exit (1); }
     182    if (!dvo_catalog_unlock (&outcatalog)) { fprintf (stderr, "ERROR: failed to unlock %s\n", outcatalog.filename); exit (1); }
     183    SetProtect (FALSE);
     184
    182185    dvo_catalog_free (&outcatalog);
    183186  }
  • trunk/Ohana/src/dvomerge/src/dvomergeFromList.c

    r38441 r38986  
    147147    // if we receive a signal which would cause us to exit, wait until the full catalog is written
    148148    SetProtect (TRUE);
    149     if (!dvo_catalog_save (&outcatalog, VERBOSE)) {
    150       fprintf (stderr, "ERROR: failed to save catalog %s\n", outputfile);
    151       exit (1);
    152     }
     149    if (!dvo_catalog_save (&outcatalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save catalog %s\n", outcatalog.filename); exit (1); }
     150    if (!dvo_catalog_unlock (&outcatalog)) { fprintf (stderr, "ERROR: failed to unlock catalog %s\n", outcatalog.filename); exit (1); }
    153151    SetProtect (FALSE);
    154152   
     
    158156    OutputStatusFree (outstat, 1);
    159157
    160     dvo_catalog_unlock (&outcatalog);
    161158    dvo_catalog_free (&outcatalog);
    162159   
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r38470 r38986  
    177177      LoadCatalog (&outcatalog, outlist[0].regions[j], outcatalog.filename, "w", NsecfiltOutput);
    178178
    179       // if no catalog already exists, use the input catalog to define the format or the specified format
    180179      if (UPDATE_CATFORMAT) {
    181180        outcatalog.catformat = dvo_catalog_catformat (UPDATE_CATFORMAT);
    182181      } else {
    183         outcatalog.catformat = incatalog.catformat;
    184       }
     182        // IF no catalog already exists, use the input catalog to define the format
     183        if (outcatalog.Naverage_disk == 0) {
     184          outcatalog.catformat = incatalog.catformat;
     185        }
     186      }
     187
    185188      if (UPDATE_CATCOMPRESS) {
    186189        outcatalog.catcompress = dvo_catalog_catcompress (UPDATE_CATCOMPRESS);
    187190      } else {
    188         outcatalog.catcompress = incatalog.catcompress;
     191        // IF no catalog already exists, use the input catalog to define the compression
     192        if (outcatalog.Naverage_disk == 0) {
     193          outcatalog.catcompress = incatalog.catcompress;
     194        }
     195      }
     196
     197      if (REPAIR_BY_OBJID) {
     198        // For gpc1 / PV3, I broke some catalogs with dvomerge -replace: the last object can
     199        // contaminate the first set of new measurements
     200        repair_catalog_by_objID (&outcatalog);
    189201      }
    190202
     
    195207      }
    196208
    197       if (!dvo_catalog_backup (&outcatalog, TRUE)) {
     209      if (!dvo_catalog_backup (&outcatalog, "~", TRUE)) {
    198210        fprintf (stderr, "ERROR: failed to make backup for catalog %s\n", outlist[0].filename[j]);
    199211        exit (1);
     
    202214      // if we receive a signal which would cause us to exit, wait until the full catalog is written
    203215      SetProtect (TRUE);
    204       if (!dvo_catalog_save (&outcatalog, VERBOSE)) {
    205         fprintf (stderr, "ERROR: failed to save catalog %s\n", outlist[0].filename[j]);
    206         exit (1);
    207       }
     216      if (!dvo_catalog_save (&outcatalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save catalog %s\n", outcatalog.filename); exit (1); }
     217      if (!dvo_catalog_unlock (&outcatalog)) { fprintf (stderr, "ERROR: failed to unlock catalog %s\n", outcatalog.filename); exit (1); }
    208218      SetProtect (FALSE);
    209219
    210       if (!dvo_catalog_unlock (&outcatalog)) {
    211         fprintf (stderr, "ERROR: failed to unlock catalog %s\n", outlist[0].filename[j]);
    212         exit (1);
    213       }
    214 
    215       if (!dvo_catalog_unlink_backup (&outcatalog, TRUE)) {
     220      if (!dvo_catalog_unlink_backup (&outcatalog, "~", TRUE)) {
    216221        fprintf (stderr, "WARNING: failed to remove backup for catalog %s\n", outlist[0].filename[j]);
    217222      }
     
    282287
    283288    // options / arguments that can affect relastro_client -update-objects:
    284     char command[DVO_MAX_PATH];
    285     snprintf (command, DVO_MAX_PATH, "dvomerge_client %s into %s -hostID %d -hostdir %s -region %f %f %f %f -D ADDSTAR_RADIUS %f",
    286               absinput, absoutput, group->hosts[i][0].hostID, group->hosts[i][0].pathname,
    287               UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, RADIUS
    288       );
    289 
    290     char tmpline[DVO_MAX_PATH];
    291     if (VERBOSE)             { snprintf (tmpline, DVO_MAX_PATH, "%s -v",                command); strcpy (command, tmpline); }
    292     if (VERIFY)              { snprintf (tmpline, DVO_MAX_PATH, "%s -verify",           command); strcpy (command, tmpline); }
    293     if (VERIFY_CATALOG_ONLY) { snprintf (tmpline, DVO_MAX_PATH, "%s -verify-catalogs",  command); strcpy (command, tmpline); }
    294     if (REPLACE_BY_PHOTCODE) { snprintf (tmpline, DVO_MAX_PATH, "%s -replace",          command); strcpy (command, tmpline); }
    295     if (REPLACE_TYCHO)       { snprintf (tmpline, DVO_MAX_PATH, "%s -replace-tycho",    command); strcpy (command, tmpline); }
    296     if (PARALLEL_INPUT)      { snprintf (tmpline, DVO_MAX_PATH, "%s -parallel-input",   command); strcpy (command, tmpline); }
    297     if (FORCE_MERGE)         { snprintf (tmpline, DVO_MAX_PATH, "%s -force-merge",      command); strcpy (command, tmpline); }
    298     if (MATCHED_TABLES)      { snprintf (tmpline, DVO_MAX_PATH, "%s -matched-tables",   command); strcpy (command, tmpline); }
    299     if (UPDATE_CATFORMAT)    { snprintf (tmpline, DVO_MAX_PATH, "%s -update-catformat %s", command, UPDATE_CATFORMAT); strcpy (command, tmpline); }
     289    char *command = NULL;
     290    strextend (&command, "dvomerge_client %s into %s -hostID %d -hostdir %s -region %f %f %f %f -D ADDSTAR_RADIUS %f",
     291               absinput, absoutput, group->hosts[i][0].hostID, group->hosts[i][0].pathname,
     292               UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax, RADIUS);
     293
     294    if (VERBOSE)             { strextend (&command, "-v"); }
     295    if (VERIFY)              { strextend (&command, "-verify"); }
     296    if (VERIFY_CATALOG_ONLY) { strextend (&command, "-verify-catalogs"); }
     297    if (REPLACE_BY_PHOTCODE) { strextend (&command, "-replace"); }
     298    if (REPLACE_TYCHO)       { strextend (&command, "-replace-tycho"); }
     299    if (PARALLEL_INPUT)      { strextend (&command, "-parallel-input"); }
     300    if (FORCE_MERGE)         { strextend (&command, "-force-merge"); }
     301    if (MATCHED_TABLES)      { strextend (&command, "-matched-tables"); }
     302    if (UPDATE_CATFORMAT)    { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
     303    if (UPDATE_CATCOMPRESS)  { strextend (&command, "-update-catcompress %s", UPDATE_CATCOMPRESS); }
     304    if (REPAIR_BY_OBJID)     { strextend (&command, "-repair-by-objid"); }
    300305
    301306    // add some config variables:
    302     snprintf (tmpline, DVO_MAX_PATH, "%s -D CATMODE %s",    command, CATMODE);   strcpy (command, tmpline);
    303     snprintf (tmpline, DVO_MAX_PATH, "%s -D CATFORMAT %s",  command, CATFORMAT); strcpy (command, tmpline);
    304     snprintf (tmpline, DVO_MAX_PATH, "%s -D SKY_DEPTH %d",  command, SKY_DEPTH); strcpy (command, tmpline);
     307    strextend (&command, "-D CATMODE %s", CATMODE);
     308    strextend (&command, "-D CATFORMAT %s", CATFORMAT);
     309    strextend (&command, "-D SKY_DEPTH %d", SKY_DEPTH);
    305310
    306311    fprintf (stderr, "command: %s\n", command);
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate_threaded.c

    r38441 r38986  
    7575      SetProtect (TRUE);
    7676      if (!dvo_catalog_save (&outcatalog, VERBOSE)) {
    77         fprintf (stderr, "ERROR: failed to save catalog %s\n", outlist[0].filename[j]);
     77        fprintf (stderr, "ERROR: failed to save catalog %s\n", outcatalog.filename);
     78        threadData->state = TS_FAIL;
     79        continue;
     80      }
     81      if (!dvo_catalog_unlock (&outcatalog)) {
     82        fprintf (stderr, "ERROR: failed to save catalog %s\n", outcatalog.filename);
    7883        threadData->state = TS_FAIL;
    7984        continue;
     
    8186      SetProtect (FALSE);
    8287
    83       dvo_catalog_unlock (&outcatalog);
    8488      dvo_catalog_free (&outcatalog);
    8589
  • trunk/Ohana/src/dvomerge/src/dvomerge_client.c

    r35818 r38986  
    33int main (int argc, char **argv) {
    44
     5  SetSignals ();
    56  dvomerge_client_help (argc, argv);
    67  ConfigInit (&argc, argv);
     
    8384  // loop over the populatable output tables; check for data in input in the corresponding regions
    8485
    85   SetPhotcodeTable(NULL);
    86  
     86  if (REPLACE_TYCHO) replace_tycho_init();
     87
    8788  dvomergeUpdate_catalogs (input, output, outsky, inlist, NsecfiltInput, NsecfiltOutput, IDmap, secfiltMap);
    8889
  • trunk/Ohana/src/dvomerge/src/dvorepair.c

    r37807 r38986  
    77  // exit (2);
    88
     9  SetSignals ();
    910  dvorepair_help(argc, argv);
    1011 
     12  if (!strcmp(argv[1], "-fix-warp-ids")) dvorepairFixWarpIDs(argc, argv);
     13
    1114  if (!strcmp(argv[1], "-fix-cpt")) dvorepairFixCPT(argc, argv);
     15  if (!strcmp(argv[1], "-fix-cpt-by-objID")) dvorepair_by_objID(argc, argv);
    1216  // if (!strcmp(argv[1], "-fix-tables")) dvorepairFixTables(argc, argv);
    1317  if (!strcmp(argv[1], "-images-vs-measures")) dvorepairImagesVsMeasures(argc, argv);
  • trunk/Ohana/src/dvomerge/src/dvorepairCPT.c

    r38441 r38986  
    3939    exit (2);
    4040  }
     41
     42  SetSignals ();
    4143
    4244  imageFilename  = argv[1];
  • trunk/Ohana/src/dvomerge/src/dvorepairDeleteImagesByExternID.c

    r38468 r38986  
    1616int SaveImageTable (Image *image, off_t Nimage, char *catdir, FITS_DB *oldDB);
    1717Image *DeleteSelectedImages (Image *image, off_t Nimage, int *deleteImage, myIndexType *imageIDindex, off_t *NnewImage);
     18int DeleteLensing (Catalog *catalog, myIndexType *imageIDindex, int *deleteImage, int *nDelete);
     19int DeleteMeasure (Catalog *catalog, myIndexType *imageIDindex, int *deleteImage, int *nDelete);
     20int RepairAverage (Catalog *catalog);
    1821
    1922int dvorepairDeleteImagesByExternID (int argc, char **argv) {
     
    2124  FITS_DB db;  // database handle pointing to input image table
    2225 
    23   int i, j, N, NmeasureNew, Ndelete, Nvalid;
    24   off_t Nimage, Nmeasure;
     26  int i, N;
     27  off_t Nimage;
    2528  int nPass, raPass;
    2629
    2730  Image *image;
    28   Measure *measure;
    29   Measure *measureNew;
    30 
    31   char *cpmFilenameSrc = NULL;
    32   char *cptFilenameSrc = NULL;
    33   char *cpsFilenameSrc = NULL;
    34   char *cpmFilenameTgt = NULL;
    35   char *cptFilenameTgt = NULL;
    36   char *cpsFilenameTgt = NULL;
    37 
    3831  char *imageFilename = NULL;
    39 
    40   DVOCatFormat catformat;
     32  char filename[DVO_MAX_PATH];
    4133
    4234  N = get_argument (argc, argv, "-delete-images-by-extern-id");
     
    5951  char *catdir = argv[1];
    6052  char *delList = argv[2];
     53
     54  sprintf (filename, "%s/Photcodes.dat", catdir);
     55  if (!LoadPhotcodes (filename, NULL, FALSE)) {
     56    fprintf (stderr, "error reading photcodes from %s\n", catdir);
     57    exit (1);
     58  }     
    6159
    6260  // load the image data
     
    196194  }
    197195 
    198   ALLOCATE(cpmFilenameSrc, char, strlen(catdir) + 64);
    199   ALLOCATE(cptFilenameSrc, char, strlen(catdir) + 64);
    200   ALLOCATE(cpsFilenameSrc, char, strlen(catdir) + 64);
    201   ALLOCATE(cpmFilenameTgt, char, strlen(catdir) + 64);
    202   ALLOCATE(cptFilenameTgt, char, strlen(catdir) + 64);
    203   ALLOCATE(cpsFilenameTgt, char, strlen(catdir) + 64);
    204 
    205   int NdeleteTotal = 0;
     196  int NmeasureDelTotal = 0;
     197  int NlensingDelTotal = 0;
    206198
    207199  for (raPass = 0; raPass < nPass; raPass++) {
     
    231223 
    232224    // loop over the populated input regions
    233     int Ncheck = 0;
    234225    for (i = 0; i < inlist[0].Nregions; i++) {
    235226      if (!inlist[0].regions[i][0].table) continue;
    236227
    237       sprintf (cpmFilenameSrc, "%s/%s.cpm", catdir, inlist[0].regions[i][0].name);
    238       sprintf (cptFilenameSrc, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name);
    239       sprintf (cpsFilenameSrc, "%s/%s.cps", catdir, inlist[0].regions[i][0].name);
    240       sprintf (cpmFilenameTgt, "%s/%s.cpm.broken", catdir, inlist[0].regions[i][0].name);
    241       sprintf (cptFilenameTgt, "%s/%s.cpt.broken", catdir, inlist[0].regions[i][0].name);
    242       sprintf (cpsFilenameTgt, "%s/%s.cps.broken", catdir, inlist[0].regions[i][0].name);
    243 
    244       Header cpmHeaderPHU;
    245       Header cpmHeaderTBL;
    246       FTable cpmFtable;
    247 
    248       /*** read and examine the CPM file ***/
    249       {
    250         if (VERBOSE) fprintf (stderr, "check %s\n", cpmFilenameSrc);
    251 
    252         cpmFtable.header = &cpmHeaderTBL;
    253 
    254         // open cpm file
    255         FILE *cpmFile = fopen(cpmFilenameSrc, "r");
    256         if (!cpmFile) continue;
    257         // myAssert(cpmFile, "failed to open cpm file");
    258    
    259         // load the cpm header
    260         if (!gfits_fread_header (cpmFile, &cpmHeaderPHU)) {
    261           myAbort("failure to cpm header");
    262         }
    263 
    264         // move to TBL header
    265         int Nbytes = cpmHeaderPHU.datasize + gfits_data_size (&cpmHeaderPHU);
    266         fseeko (cpmFile, Nbytes, SEEK_SET);
    267 
    268         // read cpm TBL header
    269         if (!gfits_fread_header (cpmFile, &cpmHeaderTBL)) {
    270           myAbort("can't read header for cpm table");
    271         }
    272 
    273         // read Measure table data : format is irrelevant here */
    274         if (!gfits_fread_ftable_data (cpmFile, &cpmFtable, TRUE)) {
    275           myAbort("can't read data for cpm table");
    276         }
    277 
    278         int NbytesPerRow;
    279         gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow);
    280 
    281         myAbort ("fix compression");
    282 
    283         // this function can only handle PS1_V5 and later formats
    284         // NOTE: FtableToMeasure (and equivalent) free the data associated with cpmFtable.
    285         // We are left with the data in measure.
    286         measure = FtableToMeasure (&cpmFtable, NULL, &Nmeasure, &catformat, FALSE);
    287         myAssert(measure, "failed to convert ftable to measure data");
    288    
    289         Nvalid = (int)(cpmFtable.validsize / NbytesPerRow);
    290         Nvalid = MIN(Nmeasure, Nvalid);
    291 
    292         // close the input cpm file
    293         fclose(cpmFile);
    294 
    295         // allocate an output array of measures (to replace, if needed)
    296         ALLOCATE (measureNew, Measure, Nvalid);
    297 
    298         NmeasureNew = 0;
    299         Ndelete = 0;
    300 
    301         // examine all measurements: find ones that need to be deleted
    302         for (j = 0; j < Nvalid; j++) {
    303           int imageID = measure[j].imageID;
    304           myAssert(imageID, "measure is missing an image ID");
    305           // XXX this case is valid if we have REF detections (no associated image)
    306 
    307           int N = myIndexGetEntry(imageIDindex, imageID);
    308           if (N < 0) {
    309             // this detection comes from a non-existant image, delete
    310             Ndelete ++;
    311             continue;
    312           }
    313 
    314           if (deleteImage[N]) {
    315             Ndelete ++;
    316             continue;
    317           }
    318           measureNew[NmeasureNew] = measure[j];
    319           NmeasureNew ++;
    320         }
     228      snprintf (filename, DVO_MAX_PATH, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name);
     229
     230      Catalog catalog;
     231
     232      // set up the basic catalog info
     233      dvo_catalog_init (&catalog, TRUE);
     234      catalog.filename  = filename; // XXX only allow non-parallel dbs for now
     235      catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT | DVO_LOAD_LENSING;
     236      catalog.Nsecfilt  = GetPhotcodeNsecfilt ();
     237     
     238      if (!dvo_catalog_open (&catalog, inlist[0].regions[i], VERBOSE, "w")) {
     239        fprintf (stderr, "ERROR: failure reading catalog %s\n", catalog.filename);
     240        exit (1);
    321241      }
    322 
    323       NdeleteTotal += Ndelete;
    324 
    325       // if we actually want to delete any measurements, write out a new cpm file
    326       if (Ndelete > 0) {
    327 
    328         fprintf (stderr, "deleting %d of %d (keep %d) detections from %s -> %s\n", (int) Ndelete, (int) Nvalid, (int) NmeasureNew, cpmFilenameSrc, cpmFilenameTgt);
     242      if (!catalog.Naverage_disk) {
     243        if (VERBOSE) fprintf (stderr, "no data in %s, skipping\n", catalog.filename);
     244        dvo_catalog_unlock (&catalog);
     245        dvo_catalog_free (&catalog);
     246        continue;
     247      }
    329248     
    330         // the CPT and CPS tables need to be regenerated.  This must happen first because, in the process, we also update measure->averef
    331         // what about other tables?
    332         RepairTableCPT_V1(cptFilenameSrc, cptFilenameTgt, cpsFilenameSrc, cpsFilenameTgt, measureNew, NmeasureNew, image, Nimage, imageIDindex, catformat);
    333 
    334         // convert internal to external format
    335         if (!MeasureToFtable (&cpmFtable, NULL, measureNew, NmeasureNew, catformat, TRUE)) {
    336           myAbort("trouble converting format");
    337         }
    338 
    339         // rename the old cpm file:
    340         if (rename (cpmFilenameSrc, cpmFilenameTgt)) {
    341           perror ("tried to rename file");
    342           exit (2);
    343         }
    344 
    345         // create and write the output file
    346         FILE *cpmFile = fopen(cpmFilenameSrc, "w");
    347         myAssert(cpmFile, "failed to open cpt file");
    348        
    349         // write PHU header
    350         if (!gfits_fwrite_header (cpmFile, &cpmHeaderPHU)) {
    351           myAbort("can't write primary header");
    352         }
    353 
    354         Matrix matrix;
    355 
    356         // write the PHU matrix; this is probably a NOP, do I have to keep it in?
    357         gfits_create_matrix (&cpmHeaderPHU, &matrix);
    358         if (!gfits_fwrite_matrix  (cpmFile, &matrix)) {
    359           myAbort("can't write primary matrix");
    360         }
    361         gfits_free_matrix (&matrix);
    362        
    363         // write the table data
    364         if (!gfits_fwrite_ftable_range (cpmFile, &cpmFtable, 0, NmeasureNew, 0, NmeasureNew)) {
    365           myAbort("can't write table data");
    366         }
    367         fclose (cpmFile);
    368 
    369         gfits_free_table (&cpmFtable);
    370       } else {
    371         if (VERBOSE) fprintf (stderr, "nothing to delete in %s\n", cpmFilenameSrc);
     249      /*** delete the measure and lensing entries matching the list of imageIDs ***/
     250      int NmeasureDel = 0;
     251      DeleteMeasure (&catalog, imageIDindex, deleteImage, &NmeasureDel);
     252
     253      int NlensingDel = 0;
     254      DeleteLensing (&catalog, imageIDindex, deleteImage, &NlensingDel);
     255
     256      fprintf (stderr, "deleting %d measure, %d lensing (keep %d, %d)\n", NmeasureDel, NlensingDel, (int) catalog.Nmeasure, (int) catalog.Nlensing);
     257
     258      if (!NmeasureDel && !NlensingDel) {
     259        if (VERBOSE) fprintf (stderr, "nothing to delete in %s\n", catalog.filename);
     260        dvo_catalog_unlock (&catalog);
     261        dvo_catalog_free (&catalog);
     262        continue;
    372263      }
    373264
    374       gfits_free_header (&cpmHeaderPHU);
    375       gfits_free_header (&cpmHeaderTBL);
    376       free (measure);
    377       free (measureNew);
    378 
    379       Ncheck ++;
    380       if (Ncheck % 1000 == 0) {
    381         fprintf (stderr, "%s...", inlist[0].regions[i][0].name);
     265      NmeasureDelTotal += NmeasureDel;
     266      NlensingDelTotal += NlensingDel;
     267
     268      // the CPT and CPS tables need to be regenerated.  This must happen first because, in the process, we also update measure->averef
     269      // what about other tables?
     270      RepairAverage (&catalog);
     271
     272      if (VERBOSE) fprintf (stderr, "saving catalog %s\n", catalog.filename);
     273     
     274      if (!dvo_catalog_backup (&catalog, ".undel", TRUE)) {
     275        fprintf (stderr, "ERROR: failed to make backup for catalog %s\n", catalog.filename);
     276        exit (1);
    382277      }
     278
     279      SetProtect (TRUE);
     280      if (!dvo_catalog_save (&catalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", catalog.filename); exit (1); }
     281      if (!dvo_catalog_unlock (&catalog)) { fprintf (stderr, "ERROR: failed to unlock %s\n", catalog.filename); exit (1); }
     282      SetProtect (FALSE);
     283      dvo_catalog_free (&catalog);
    383284    }
    384285    fprintf (stderr, "\n");
     
    386287  }
    387288
    388   fprintf (stderr, "Deleted %d detections\n", NdeleteTotal);
     289  fprintf (stderr, "Deleted %d measure, %d lensing detections\n", NmeasureDelTotal, NlensingDelTotal);
    389290
    390291  off_t NnewImage;
     
    400301  free (deleteIDs);
    401302
    402   free(cpmFilenameSrc);
    403   free(cptFilenameSrc);
    404   free(cpsFilenameSrc);
    405   free(cpmFilenameTgt);
    406   free(cptFilenameTgt);
    407   free(cpsFilenameTgt);
    408 
    409303  SkyTableFree(insky);
    410304
    411305  gfits_db_free (&db);
     306
     307  ohana_memcheck (TRUE);
    412308
    413309  exit (0);
     
    661557  gfits_scan (&cptHeaderPHU, "NSECFILT",     "%d",      1,  &Nsecfilt);
    662558
    663   myAbort ("test for compression");
     559  if (0) {
     560    char compressMode[256];
     561    if (gfits_scan (&cptHeaderTBL, "DVO_CMP", "%s", 1, compressMode)) {
     562      if (strcmp (compressMode, "NONE")) {
     563        myAbort ("fix compression");
     564      }
     565    }
     566  }
    664567
    665568  /* convert internal to external format */
     
    774677}
    775678
     679int RepairAverage (Catalog *catalog) {
     680
     681  off_t i, j, Nave;
     682
     683  // average is sorted so averef is valid
     684  // secfilt is also sorted so sequence is valid (but this is kind of moot since it will be re-calculated)
     685  // average.measureOffset is NOT valid
     686  // average.lensingOffset is NOT valid
     687
     688  Average *average = catalog->average;
     689  Measure *measure = catalog->measure;
     690  Lensing *lensing = catalog->lensing;
     691 
     692  // reset the values of average.Nmeasure, average.Nlensing
     693  for (i = 0; i < catalog->Naverage; i++) {
     694    average[i].Nmeasure = 0;
     695    average[i].Nlensing = 0;
     696  }
     697
     698  // re-calculate average.Nmeasure
     699  for (i = 0; i < catalog->Nmeasure; i++) {
     700    Nave = measure[i].averef;
     701    myAssert (measure[i].objID == average[Nave].objID, "invalid measure:average match");
     702    average[Nave].Nmeasure ++;
     703  }
     704   
     705  // re-calculate average.Nlensing
     706  for (i = 0; i < catalog->Nlensing; i++) {
     707    Nave = lensing[i].averef;
     708    myAssert (lensing[i].objID == average[Nave].objID, "invalid lensing:average match");
     709    average[Nave].Nlensing ++;
     710  }
     711
     712  // create a copy of the average table, keeping only the entries with Nmeasure & Nlensing > 0
     713  ALLOCATE_PTR (averageNew, Average, catalog->Naverage);
     714  ALLOCATE_PTR (averefNew,  int,     catalog->Naverage);
     715
     716  Nave = 0;
     717  for (i = 0; i < catalog->Naverage; i++) {
     718    averefNew[i] = -1;
     719    if (!average[i].Nmeasure && !average[i].Nlensing) continue;
     720
     721    averageNew[Nave] = average[i];
     722    averefNew[i] = Nave;
     723    Nave ++;
     724  }
     725  off_t NaverageNew = Nave;
     726
     727  // update measure.averef values
     728  for (i = 0; i < catalog->Nmeasure; i++) {
     729    Nave = averefNew[measure[i].averef];
     730    myAssert (Nave >= 0, "oops");
     731    measure[i].averef = Nave;
     732  }
     733   
     734  // update lensing.averef values
     735  for (i = 0; i < catalog->Nlensing; i++) {
     736    Nave = averefNew[lensing[i].averef];
     737    myAssert (Nave >= 0, "oops");
     738    lensing[i].averef = Nave;
     739  }
     740 
     741  // XXX need to update measureOffset and lensingOffset
     742
     743  // measure[] should be blocked and sequential:
     744  // measure[i+1].averef >= measure[i].averef
     745
     746  // update average.measureOffset values
     747  Nave = -1;
     748  for (i = 0; i < catalog->Nmeasure; i++) {
     749    if (measure[i].averef == Nave) continue;
     750    Nave = measure[i].averef;
     751    averageNew[Nave].measureOffset = i;
     752  }
     753
     754  // update average.lensingOffset values
     755  Nave = -1;
     756  for (i = 0; i < catalog->Nlensing; i++) {
     757    if (lensing[i].averef == Nave) continue;
     758    Nave = lensing[i].averef;
     759    averageNew[Nave].lensingOffset = i;
     760  }
     761
     762  // check the result (measure -> average)
     763  for (i = 0; i < catalog->Nmeasure; i++) {
     764    Nave = measure[i].averef;
     765    myAssert(averageNew[Nave].objID == measure[i].objID, "objIDs do not match");
     766    myAssert(averageNew[Nave].catID == measure[i].catID, "catIDs do not match");
     767  }
     768  // check the result (average -> measure)
     769  for (i = 0; i < NaverageNew; i++) {
     770    int m = averageNew[i].measureOffset;
     771    for (j = 0; j < averageNew[i].Nmeasure; j++) {
     772      myAssert(averageNew[i].objID == measure[j+m].objID, "objIDs do not match");
     773      myAssert(averageNew[i].catID == measure[j+m].catID, "catIDs do not match");
     774      myAssert(measure[j+m].averef == i, "averef broken");
     775    }
     776  }
     777
     778  // check the result (lensing -> average)
     779  for (i = 0; i < catalog->Nlensing; i++) {
     780    Nave = lensing[i].averef;
     781    myAssert(averageNew[Nave].objID == lensing[i].objID, "objIDs do not match");
     782    myAssert(averageNew[Nave].catID == lensing[i].catID, "catIDs do not match");
     783  }
     784  // check the result (average -> lensing)
     785  for (i = 0; i < NaverageNew; i++) {
     786    int m = averageNew[i].lensingOffset;
     787    for (j = 0; j < averageNew[i].Nlensing; j++) {
     788      myAssert(averageNew[i].objID == lensing[j+m].objID, "objIDs do not match");
     789      myAssert(averageNew[i].catID == lensing[j+m].catID, "catIDs do not match");
     790      myAssert(lensing[j+m].averef == i, "averef broken");
     791    }
     792  }
     793
     794  free (catalog->secfilt);
     795  ALLOCATE (catalog->secfilt, SecFilt, NaverageNew*catalog->Nsecfilt);
     796  for (i = 0; i < NaverageNew*catalog->Nsecfilt; i++) {
     797    dvo_secfilt_init (&catalog->secfilt[i], SECFILT_RESET_ALL);
     798  }
     799
     800  free (averefNew);
     801  free (catalog->average);
     802  catalog->average = averageNew;
     803  catalog->Naverage = NaverageNew;
     804  catalog->Naverage_disk = NaverageNew;
     805
     806  catalog->Nsecfilt_disk = NaverageNew*catalog->Nsecfilt;
     807
     808  return (TRUE);
     809}
     810
     811// delete measure entries
     812int DeleteMeasure (Catalog *catalog, myIndexType *imageIDindex, int *deleteImage, int *nDelete) {
     813
     814  int j;
     815
     816  Measure *measure = catalog->measure;
     817
     818  // allocate an output array of measures (to replace, if needed)
     819  ALLOCATE_PTR (measureNew, Measure, catalog->Nmeasure);
     820
     821  int NmeasureNew = 0;
     822  int NmeasureDel = 0;
     823
     824  // examine all measurements: find ones that need to be deleted
     825  for (j = 0; j < catalog->Nmeasure; j++) {
     826    int imageID = measure[j].imageID;
     827    myAssert(imageID, "measure is missing an image ID");
     828    // XXX this case is valid if we have REF detections (no associated image)
     829
     830    int N = myIndexGetEntry(imageIDindex, imageID);
     831    if (N < 0) {
     832      // this detection comes from a non-existant image; delete
     833      NmeasureDel ++;
     834      continue;
     835    }
     836
     837    // measure matches a bad image; delete
     838    if (deleteImage[N]) {
     839      NmeasureDel ++;
     840      continue;
     841    }
     842
     843    // keep this measure
     844    measureNew[NmeasureNew] = measure[j];
     845    NmeasureNew ++;
     846  }
     847
     848  free (catalog->measure);
     849  catalog->measure = measureNew;
     850  catalog->Nmeasure = NmeasureNew;
     851  catalog->Nmeasure_disk = NmeasureNew;
     852
     853  *nDelete = NmeasureDel;
     854
     855  return TRUE;
     856}
     857
     858// delete lensing entries
     859int DeleteLensing (Catalog *catalog, myIndexType *imageIDindex, int *deleteImage, int *nDelete) {
     860
     861  int j;
     862
     863  Lensing *lensing = catalog->lensing;
     864
     865  // allocate an output array of measures (to replace, if needed)
     866  ALLOCATE_PTR (lensingNew, Lensing, catalog->Nlensing);
     867
     868  int NlensingNew = 0;
     869  int NlensingDel = 0;
     870
     871  // examine all lensingments: find ones that need to be deleted
     872  for (j = 0; j < catalog->Nlensing; j++) {
     873    int imageID = lensing[j].imageID;
     874    myAssert(imageID, "lensing is missing an image ID");
     875    // XXX this case is valid if we have REF detections (no associated image)
     876
     877    int N = myIndexGetEntry(imageIDindex, imageID);
     878    if (N < 0) {
     879      // this detection comes from a non-existant image; delete
     880      NlensingDel ++;
     881      continue;
     882    }
     883
     884    // lensing matches a bad image; delete
     885    if (deleteImage[N]) {
     886      NlensingDel ++;
     887      continue;
     888    }
     889
     890    // keep this lensing
     891    lensingNew[NlensingNew] = lensing[j];
     892    NlensingNew ++;
     893  }
     894
     895  free (catalog->lensing);
     896  catalog->lensing = lensingNew;
     897  catalog->Nlensing = NlensingNew;
     898  catalog->Nlensing_disk = NlensingNew;
     899
     900  *nDelete = NlensingDel;
     901
     902  return TRUE;
     903}
     904
  • trunk/Ohana/src/dvomerge/src/dvorepairFixImages.c

    r38441 r38986  
    255255
    256256  /* setup image table format and lock */
    257   gfits_db_init (oldDB);
     257  gfits_db_init (&db);
    258258  db.mode   = oldDB->mode;
    259259  db.format = oldDB->format;
     
    266266  /* load or create the image table */
    267267  myAssert (db.dbstate == LCK_EMPTY, "do not overwrite exiting image table");
    268   myAssert (db.format == DVO_FORMAT_PS1_V2, "format mismatch");
     268  // myAssert (db.format == DVO_FORMAT_PS1_V2, "format mismatch");
    269269
    270270  dvo_image_create (&db, GetZeroPoint());
     271  gfits_copy_header (&oldDB->header, &db.header);
    271272 
    272273  // replace the existing buffer with the image array
     
    277278  nbytes = gfits_data_size (db.ftable.header);
    278279  db.ftable.datasize = nbytes;
    279   db.ftable.buffer = (char *) imageOut;
    280   REALLOCATE (db.ftable.buffer, char, MAX (nbytes, 1));
     280
     281  free (db.ftable.buffer);
     282  ALLOCATE (db.ftable.buffer, char, MAX (nbytes, 1));
     283  memcpy (db.ftable.buffer, imageOut, nbytes);
    281284  memset (&db.ftable.buffer[Nx*Nout], ' ', nbytes - Nx*Nout);
    282285
     
    295298  dvo_image_unlock (&db);
    296299
     300  gfits_db_free (&db);
     301
    297302  return TRUE;
    298303}
  • trunk/Ohana/src/dvomerge/src/dvorepairImageVsMeasure.c

    r38441 r38986  
    3939  }
    4040
     41  SetSignals ();
    4142  catdir = argv[1];
    4243  Ntol = atoi(argv[2]);
  • trunk/Ohana/src/dvomerge/src/dvosecfilt_catalogs.c

    r38471 r38986  
    8282    catalog.Nsecfilt_disk = Nsecfilt * catalog.Naverage_disk;
    8383
    84     dvo_catalog_save (&catalog, VERBOSE);
    85     dvo_catalog_unlock (&catalog);
     84    SetProtect (TRUE);
     85    if (!dvo_catalog_save (&catalog, VERBOSE)) { fprintf (stderr, "ERROR: failed to save %s\n", catalog.filename); exit (1); }
     86    if (!dvo_catalog_unlock (&catalog)) { fprintf (stderr, "ERROR: failed to unlock %s\n", catalog.filename); exit (1); }
     87    SetProtect (FALSE);
     88
    8689    dvo_catalog_free (&catalog);
    8790  }
  • trunk/Ohana/src/dvomerge/src/dvoutils.c

    r37807 r38986  
    44
    55  // check various options
     6  SetSignals ();
    67  dvoutils_args (&argc, argv);
    78
  • trunk/Ohana/src/dvomerge/src/dvoutils_load_image_index.c

    r38441 r38986  
    22
    33// load the array of EXTERN_ID from the ImageIndex.fits tables
    4 int *dvoutils_load_image_index (char *filename, int *nindex) {
     4ImageData *dvoutils_load_image_index (char *filename) {
    55
    66  int Ncol;
    7   off_t Nrow;
     7  off_t Nrow, Nphot;
    88  Header header;
    99  Header theader;
     
    4646  fclose (f);
    4747
    48   int *externID = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol);
     48  ImageData *imdata = NULL;
     49  ALLOCATE (imdata, ImageData, 1);
     50
     51  imdata->externID = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol);
    4952  myAssert (!strcmp(type, "int"), "wrong column type");
     53
     54  imdata->photcode = gfits_get_bintable_column_data (&theader, &ftable, "PHOTCODE", type, &Nphot, &Ncol);
     55  myAssert (Nphot == Nrow, "photcode & extern_id mis-match");
     56
     57  imdata->Nimages = Nrow;
    5058
    5159  gfits_free_header (&header);
     
    5462  gfits_free_table  (&ftable);
    5563
    56   *nindex = Nrow;
    57 
    58   return externID;
     64  return imdata;
    5965}
    6066
  • trunk/Ohana/src/dvomerge/src/dvoutils_uniq_images.c

    r38441 r38986  
    4040    }
    4141
    42     int Nimage;
    43     // Image *image = dvoutils_load_image_table (imFile, &Nimage);
    44     int *extern_id = dvoutils_load_image_index (imFile, &Nimage);
    45     if (!extern_id) continue;
     42    ImageData *imdata = dvoutils_load_image_index (imFile);
     43    if (!imdata) continue;
    4644
    4745    DBlist[Ndb] = strcreate (imFile);
     
    5755
    5856    int i;
    59     for (i = 0; i < Nimage; i++) {
    60       if (!extern_id[i]) continue;
    61       myMaxID = MAX(extern_id[i], myMaxID);
    62       myMinID = MIN(extern_id[i], myMinID);
     57    int Nbad = 0;
     58    for (i = 0; i < imdata->Nimages; i++) {
     59      if (!imdata->photcode[i] && imdata->externID[i]) myAbort ("invalid combo");
     60
     61      if (!imdata->photcode[i]) continue;
     62      if (!imdata->externID[i]) {
     63        Nbad ++;
     64        continue;
     65      }
     66      myMaxID = MAX(imdata->externID[i], myMaxID);
     67      myMinID = MIN(imdata->externID[i], myMinID);
    6368    }
    6469
    65     fprintf (stderr, "read %s, %d images, %d - %d vs %d - %d\n", imFile, (int) Nimage, myMinID, myMaxID, minID, maxID);
     70    fprintf (stderr, "read %s, %d images, %d - %d vs %d - %d\n", imFile, (int) imdata->Nimages, myMinID, myMaxID, minID, maxID);
     71
     72    if (Nbad) {
     73      fprintf (stderr, "WARNING: %d images without extern_id set\n", (int) Nbad);
     74    }
    6675
    6776    // if this is new, we treat it a bit differently
     
    124133    }
    125134
    126     for (i = 0; i < Nimage; i++) {
    127       if (!extern_id[i]) continue;
    128       int n = extern_id[i] - minID;
     135    for (i = 0; i < imdata->Nimages; i++) {
     136      if (!imdata->externID[i]) continue;
     137      int n = imdata->externID[i] - minID;
    129138      if (IDlist[n] == 0) {
    130139        DBfound[n] = Ndb;
     
    133142      IDlist[n] ++;
    134143      if (VERBOSE && (IDlist[n] > 1)) {
    135         fprintf (stderr, "duplicate ext_id %d in file %s\n", extern_id[i], imFile);
     144        fprintf (stderr, "duplicate ext_id %d in file %s\n", imdata->externID[i], imFile);
    136145      }
    137146    }
     
    140149      fprintf (stderr, "------------ %s ----------\n", imFile);
    141150
    142       for (i = 0; i < Nimage; i++) {
    143         if (!extern_id[i]) continue;
    144         fprintf (stderr, "%d => %d\n", extern_id[i], extern_id[i] - minID);
     151      for (i = 0; i < imdata->Nimages; i++) {
     152        if (!imdata->externID[i]) continue;
     153        fprintf (stderr, "%d => %d\n", imdata->externID[i], imdata->externID[i] - minID);
    145154      }
    146155
     
    165174    int n = DBfound[i];
    166175    myAssert (n > -1, "impossible!");
    167     fprintf (stdout, "%d : %d -- in %s (%d) : %d \n", i + minID, IDlist[i], DBlist[n], DBfound[i], DBindex[i]);
     176    fprintf (stdout, "primary %d : %d -- in %s (%d) : %d \n", i + minID, IDlist[i], DBlist[n], DBfound[i], DBindex[i]);
    168177  }
    169178
  • trunk/Ohana/src/dvomerge/src/dvoverify.c

    r38553 r38986  
    1414
    1515  // check various options
     16  SetSignals ();
    1617  dvoverify_args (&argc, argv);
    1718  CATDIR = argv[1];
     
    7879  SkyListFree (skylist);
    7980
    80   ohana_memcheck (TRUE);
    81   ohana_memdump (TRUE);
     81  ohana_memcheck (VERBOSE);
     82  ohana_memdump (VERBOSE);
    8283  exit (0);
    8384}
  • trunk/Ohana/src/dvomerge/src/dvoverify_args.c

    r38553 r38986  
    2424  if ((N = get_argument (*argc, argv, "-sorted"))) {
    2525    CHECKSORTED = TRUE;
     26    remove_argument (N, argc, argv);
     27  }
     28
     29  // in some cases, the header sorted state can claim F but is actually T
     30  IGNORE_SORTED_STATE = FALSE;
     31  if ((N = get_argument (*argc, argv, "-ignore-sorted-state"))) {
     32    IGNORE_SORTED_STATE = TRUE;
    2633    remove_argument (N, argc, argv);
    2734  }
     
    5057    free (filename);
    5158
    52     ohana_memcheck (TRUE);
    53     ohana_memdump (TRUE);
     59    ohana_memcheck (VERBOSE);
     60    ohana_memdump (VERBOSE);
    5461
    5562    if (!isGood) exit (1);
     
    204211  }
    205212
     213  // in some cases, the header sorted state can claim F but is actually T
     214  IGNORE_SORTED_STATE = FALSE;
     215  if ((N = get_argument (*argc, argv, "-ignore-sorted-state"))) {
     216    IGNORE_SORTED_STATE = TRUE;
     217    remove_argument (N, argc, argv);
     218  }
     219
    206220  if (!HOST_ID || !HOSTDIR || (*argc != 2)) {
    207221    fprintf (stderr, "USAGE: dvoverify_client (catdir) -results (file) -hostID ID -hostdir DIR [-region Rmin Rmax Dmin Dmax] [-v] [-s]\n\n");
  • trunk/Ohana/src/dvomerge/src/dvoverify_catalogs.c

    r38553 r38986  
    117117
    118118    // options / arguments that can affect relastro_client -update-objects:
    119     char command[DVO_MAX_PATH];
    120     snprintf (command, DVO_MAX_PATH, "dvoverify_client %s -results %s -hostID %d -hostdir %s -region %f %f %f %f",
    121               abscatdir, table->hosts[i].results, table->hosts[i].hostID, table->hosts[i].pathname,
    122               UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax
    123       );
     119    char *command = NULL;
     120    strextend (&command, "dvoverify_client %s -results %s -hostID %d -hostdir %s -region %f %f %f %f",
     121               abscatdir, table->hosts[i].results, table->hosts[i].hostID, table->hosts[i].pathname,
     122               UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    124123
    125     char tmpline[DVO_MAX_PATH];
    126     if (VERBOSE)         { snprintf (tmpline, DVO_MAX_PATH, "%s -v", command); strcpy (command, tmpline); }
    127     if (CHECKSORTED)     { snprintf (tmpline, DVO_MAX_PATH, "%s -s", command); strcpy (command, tmpline); }
    128     if (!CHECK_IMAGE_ID) { snprintf (tmpline, DVO_MAX_PATH, "%s -skip-image-ids", command); strcpy (command, tmpline); }
    129     if (LIST_MISSING)    { snprintf (tmpline, DVO_MAX_PATH, "%s -list-missing", command); strcpy (command, tmpline); }
     124    if (VERBOSE)             { strextend (&command, "-v"); }
     125    if (CHECKSORTED)         { strextend (&command, "-s"); }
     126    if (IGNORE_SORTED_STATE) { strextend (&command, "-ignore-sorted-state"); }
     127    if (!CHECK_IMAGE_ID)     { strextend (&command, "-skip-image-ids"); }
     128    if (LIST_MISSING)        { strextend (&command, "-list-missing"); }
    130129
    131130    fprintf (stderr, "command: %s\n", command);
     
    149148      table->hosts[i].pid = pid; // save for future reference
    150149    }
     150    free (command);
    151151  }
    152152
  • trunk/Ohana/src/dvomerge/src/dvoverify_client.c

    r37360 r38986  
    88
    99  // check various options
     10  SetSignals ();
    1011  dvoverify_client_args (&argc, argv);
    1112  CATDIR = argv[1];
  • trunk/Ohana/src/dvomerge/src/dvoverify_utils.c

    r38553 r38986  
    188188  dvo_catalog_init (&catalog, TRUE);
    189189  catalog.filename  = filename;
    190   catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ;
     190  catalog.catflags  = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ | DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;
    191191  catalog.Nsecfilt  = 0;
    192192 
     
    214214
    215215  // if the table is NOT SORTED, do we have a subset of checks we can make?
    216   if (!catalog.sorted) {
     216  if (!catalog.sorted && !IGNORE_SORTED_STATE) {
    217217    fprintf (stderr, "!");
    218218    dvo_catalog_unlock (&catalog);
     
    222222    return TRUE;
    223223  }
    224 
    225   int NmeasureTotal = 0;
    226   int measureOffsetOK = TRUE;
    227   int NlensingTotal = 0;
    228   int lensingOffsetOK = TRUE;
    229   int NlensobjTotal = 0;
    230   int lensobjOffsetOK = TRUE;
    231   for (i = 0; i < catalog.Naverage; i++) {
    232     NmeasureTotal += catalog.average[i].Nmeasure;
    233     if (VERBOSE && !(NmeasureTotal <= catalog.Nmeasure)) {
    234       fprintf (stderr, "NmeasureTotal > catalog.Nmeasure: %d %d %d\n", i, catalog.average[i].Nmeasure, (int) catalog.Nmeasure);
    235     }
    236     measureOffsetOK &= (catalog.average[i].measureOffset < catalog.Nmeasure);
    237     if (VERBOSE && !(catalog.average[i].measureOffset < catalog.Nmeasure)) {
    238       fprintf (stderr, "measureOffset >= catalog.Nmeasure: %d %d %d\n", i, catalog.average[i].measureOffset, (int) catalog.Nmeasure);
    239     }
    240     measureOffsetOK &= (catalog.average[i].measureOffset + catalog.average[i].Nmeasure <= catalog.Nmeasure);
    241     if (VERBOSE && !(catalog.average[i].measureOffset + catalog.average[i].Nmeasure <= catalog.Nmeasure)) {
    242       fprintf (stderr, "measureOffset + Nmeasure > catalog.Nmeasure : %d %d %d\n", i, catalog.average[i].Nmeasure, (int) catalog.Nmeasure);
    243     }
    244 
    245     // sum of Nlensing for each object < Nlensing for catalog
    246     NlensingTotal += catalog.average[i].Nlensing;
    247     if (VERBOSE && !(NlensingTotal <= catalog.Nlensing)) {
    248       fprintf (stderr, "NlensingTotal > catalog.Nlensing: %d %d %d\n", i, catalog.average[i].Nlensing, (int) catalog.Nlensing);
    249     }
    250     // lensingOffset needs to be in range for each object
    251     lensingOffsetOK &= (!catalog.Nlensing || (catalog.average[i].lensingOffset < catalog.Nlensing));
    252     if (VERBOSE && catalog.Nlensing && !(catalog.average[i].lensingOffset < catalog.Nlensing)) {
    253       fprintf (stderr, "lensingOffset >= catalog.Nlensing: %d %d %d\n", i, catalog.average[i].lensingOffset, (int) catalog.Nlensing);
    254     }
    255     lensingOffsetOK &= (catalog.average[i].lensingOffset + catalog.average[i].Nlensing <= catalog.Nlensing);
    256     if (VERBOSE && !(catalog.average[i].lensingOffset + catalog.average[i].Nlensing <= catalog.Nlensing)) {
    257       fprintf (stderr, "lensingOffset + Nlensing > catalog.Nlensing : %d %d %d\n", i, catalog.average[i].Nlensing, (int) catalog.Nlensing);
    258     }
    259 
    260     NlensobjTotal += catalog.average[i].Nlensobj;
    261     if (VERBOSE && !(NlensobjTotal <= catalog.Nlensobj)) {
    262       fprintf (stderr, "NlensobjTotal > catalog.Nlensobj: %d %d %d\n", i, catalog.average[i].Nlensobj, (int) catalog.Nlensobj);
    263     }
    264     lensobjOffsetOK &= (catalog.average[i].lensobjOffset < catalog.Nlensobj);
    265     if (VERBOSE && !(catalog.average[i].lensobjOffset < catalog.Nlensobj)) {
    266       fprintf (stderr, "lensobjOffset >= catalog.Nlensobj: %d %d %d\n", i, catalog.average[i].lensobjOffset, (int) catalog.Nlensobj);
    267     }
    268     lensobjOffsetOK &= (catalog.average[i].lensobjOffset + catalog.average[i].Nlensobj <= catalog.Nlensobj);
    269     if (VERBOSE && !(catalog.average[i].lensobjOffset + catalog.average[i].Nlensobj <= catalog.Nlensobj)) {
    270       fprintf (stderr, "lensobjOffset + Nlensobj > catalog.Nlensobj : %d %d %d\n", i, catalog.average[i].Nlensobj, (int) catalog.Nlensobj);
    271     }
    272   }
    273 
    274   if (!measureOffsetOK) {
    275     fprintf (stderr, "ERROR: catalog %s has an invalid measureOffset\n", catalog.filename);
    276     status = FALSE;
    277   }
    278 
    279   if (NmeasureTotal != catalog.Nmeasure) {
    280     fprintf (stderr, "ERROR: catalog %s has an invalid Nmeasure\n", catalog.filename);
    281     status = FALSE;
    282   }
    283 
    284   if (!lensingOffsetOK) {
    285     fprintf (stderr, "ERROR: catalog %s has an invalid lensingOffset\n", catalog.filename);
    286     status = FALSE;
    287   }
    288 
    289   if (NlensingTotal != catalog.Nlensing) {
    290     fprintf (stderr, "ERROR: catalog %s has an invalid Nlensing\n", catalog.filename);
    291     status = FALSE;
    292   }
    293 
    294   if (!lensobjOffsetOK) {
    295     fprintf (stderr, "ERROR: catalog %s has an invalid lensobjOffset\n", catalog.filename);
    296     status = FALSE;
    297   }
    298 
    299   if (NlensobjTotal != catalog.Nlensobj) {
    300     fprintf (stderr, "ERROR: catalog %s has an invalid Nlensobj\n", catalog.filename);
    301     status = FALSE;
    302   }
     224 
     225# define CHECK_TABLE(NAME) {                                            \
     226    int Ntotal = 0; int offsetOK = TRUE; int isOK = FALSE;              \
     227    for (i = 0; i < catalog.Naverage; i++) {                            \
     228      Ntotal += catalog.average[i].N##NAME;                             \
     229      if (VERBOSE && !(Ntotal <= catalog.N##NAME)) {                    \
     230        fprintf (stderr, "Ntotal (%s) > catalog.N##NAME: %d %d : %d > %d\n", #NAME, i, Ntotal, catalog.average[i].N##NAME, (int) catalog.N##NAME); \
     231      }                                                                 \
     232      isOK = (catalog.average[i].N##NAME == 0) || (catalog.average[i].NAME##Offset < catalog.N##NAME); \
     233      offsetOK &= isOK;                                                 \
     234      if (VERBOSE && !isOK) {                                           \
     235        fprintf (stderr, "%sOffset >= catalog.N%s: %d : %d >= %d\n", #NAME, #NAME, i, catalog.average[i].NAME##Offset, (int) catalog.N##NAME); \
     236      }                                                                 \
     237      isOK = (catalog.average[i].N##NAME == 0) || (catalog.average[i].NAME##Offset + catalog.average[i].N##NAME <= catalog.N##NAME); \
     238      offsetOK &= isOK;                                                 \
     239      if (VERBOSE && !isOK) {                                           \
     240        fprintf (stderr, "%sOffset + N%s > catalog.N%s : %d : %d + %d > %d\n", #NAME, #NAME, #NAME, i, catalog.average[i].N##NAME, catalog.average[i].NAME##Offset, (int) catalog.N##NAME); \
     241      } }                                                               \
     242    if (!offsetOK) {                                                    \
     243      fprintf (stderr, "ERROR: catalog %s has an invalid %sOffset\n", catalog.filename, #NAME); \
     244      status = FALSE;                                                   \
     245    }                                                                   \
     246    if (Ntotal != catalog.N##NAME) {                                    \
     247      fprintf (stderr, "ERROR: catalog %s has an invalid N%s\n", catalog.filename, #NAME); \
     248      status = FALSE;                                                   \
     249    }                                                                   \
     250  }
     251 
     252  CHECK_TABLE(measure);
     253  CHECK_TABLE(lensing);
     254  CHECK_TABLE(lensobj);
     255  CHECK_TABLE(starpar);
     256  CHECK_TABLE(galphot);
    303257
    304258  // if we have a problem with Nmeasure and/or measureOffset values, we
     
    312266  // check measure <-> average links
    313267  {
    314     int objIDsOK = TRUE;
    315     int catIDsOK = TRUE;
    316     int averefOK = TRUE;
     268    int NobjIDsBAD = 0;
     269    int NcatIDsBAD = 0;
     270    int NaverefBAD = 0;
    317271
    318272    for (i = 0; i < catalog.Naverage; i++) {
    319273      m = catalog.average[i].measureOffset;
    320274      for (j = 0; j < catalog.average[i].Nmeasure; j++) {
    321         objIDsOK &= (catalog.average[i].objID == catalog.measure[m+j].objID);
    322         catIDsOK &= (catalog.average[i].catID == catalog.measure[m+j].catID);
    323         averefOK &= (catalog.measure[m+j].averef == i);
     275        if (catalog.average[i].objID != catalog.measure[m+j].objID) {
     276          NobjIDsBAD ++;
     277
     278          // check if objID matches R,D
     279          Measure *measure = &catalog.measure[m+j];
     280          int iTest = measure->objID;
     281          if (catalog.average[iTest].objID == iTest) {
     282            double dR = 3600.0*(catalog.average[iTest].R - measure->R) * cos (RAD_DEG*measure->D);
     283            double dD = 3600.0*(catalog.average[iTest].D - measure->D);
     284            double dRad = hypot (dR, dD);
     285            char *date = ohana_sec_to_date (measure->t);
     286            fprintf (stderr, "matches ave %d = %d, %s : %6.3f %5d : %f, %f = %f\n", iTest, measure->objID, date, measure->M, measure->photcode, dR, dD, dRad);
     287            free (date);
     288          } else {
     289            fprintf (stderr, "cannot find averef\n");
     290          }
     291        }
     292        if (catalog.average[i].catID != catalog.measure[m+j].catID) {
     293          NcatIDsBAD ++;
     294        }
     295        if (catalog.measure[m+j].averef != i) {
     296          NaverefBAD ++;
     297        }
    324298      }
    325299    }
    326300   
    327     if (!objIDsOK) {
    328       fprintf (stderr, "ERROR: catalog %s has invalid obj IDs\n", catalog.filename);
    329       status = FALSE;
    330     }
    331     if (!catIDsOK) {
    332       fprintf (stderr, "ERROR: catalog %s has invalid cat IDs\n", catalog.filename);
    333       status = FALSE;
    334     }
    335     if (!averefOK) {
    336       fprintf (stderr, "ERROR: catalog %s has invalid averef values\n", catalog.filename);
     301    if (NobjIDsBAD) {
     302      fprintf (stderr, "ERROR: catalog %s has %d invalid obj IDs\n", catalog.filename, NobjIDsBAD);
     303      status = FALSE;
     304    }
     305    if (NcatIDsBAD) {
     306      fprintf (stderr, "ERROR: catalog %s has %d invalid cat IDs\n", catalog.filename, NcatIDsBAD);
     307      status = FALSE;
     308    }
     309    if (NaverefBAD) {
     310      fprintf (stderr, "ERROR: catalog %s has %d invalid averef values\n", catalog.filename, NaverefBAD);
    337311      status = FALSE;
    338312    }
     
    387361    if (!catIDsOK) {
    388362      fprintf (stderr, "ERROR: catalog %s has invalid lensobj cat IDs\n", catalog.filename);
     363      status = FALSE;
     364    }
     365  }
     366
     367  // check starpar <-> average links
     368  {
     369    int objIDsOK = TRUE;
     370    int catIDsOK = TRUE;
     371    int averefOK = TRUE;
     372
     373    for (i = 0; i < catalog.Naverage; i++) {
     374      m = catalog.average[i].starparOffset;
     375      for (j = 0; j < catalog.average[i].Nstarpar; j++) {
     376        objIDsOK &= (catalog.average[i].objID == catalog.starpar[m+j].objID);
     377        catIDsOK &= (catalog.average[i].catID == catalog.starpar[m+j].catID);
     378        averefOK &= (catalog.starpar[m+j].averef == i);
     379      }
     380    }
     381   
     382    if (!objIDsOK) {
     383      fprintf (stderr, "ERROR: catalog %s has invalid starpar obj IDs\n", catalog.filename);
     384      status = FALSE;
     385    }
     386    if (!catIDsOK) {
     387      fprintf (stderr, "ERROR: catalog %s has invalid starpar cat IDs\n", catalog.filename);
     388      status = FALSE;
     389    }
     390    if (!averefOK) {
     391      fprintf (stderr, "ERROR: catalog %s has invalid starpar averef values\n", catalog.filename);
     392      status = FALSE;
     393    }
     394  }
     395
     396  // check galphot <-> average links
     397  {
     398    int objIDsOK = TRUE;
     399    int catIDsOK = TRUE;
     400    int averefOK = TRUE;
     401
     402    for (i = 0; i < catalog.Naverage; i++) {
     403      m = catalog.average[i].galphotOffset;
     404      for (j = 0; j < catalog.average[i].Ngalphot; j++) {
     405        objIDsOK &= (catalog.average[i].objID == catalog.galphot[m+j].objID);
     406        catIDsOK &= (catalog.average[i].catID == catalog.galphot[m+j].catID);
     407        averefOK &= (catalog.galphot[m+j].averef == i);
     408      }
     409    }
     410   
     411    if (!objIDsOK) {
     412      fprintf (stderr, "ERROR: catalog %s has invalid galphot obj IDs\n", catalog.filename);
     413      status = FALSE;
     414    }
     415    if (!catIDsOK) {
     416      fprintf (stderr, "ERROR: catalog %s has invalid galphot cat IDs\n", catalog.filename);
     417      status = FALSE;
     418    }
     419    if (!averefOK) {
     420      fprintf (stderr, "ERROR: catalog %s has invalid galphot averef values\n", catalog.filename);
    389421      status = FALSE;
    390422    }
  • trunk/Ohana/src/dvomerge/src/help.c

    r35590 r38986  
    172172
    173173  fprintf (stderr, "USAGE\n");
     174  fprintf (stderr, "  dvorepair -fix-warp-ids (catdir) (idfile) - regenerate images.dat warp_skyfile_ids (EXTERN_ID) values\n");
    174175  fprintf (stderr, "  dvorepair -fix-cpt (images) (rootlist) - regenerate cpt & cps files from the cpm files\n");
    175176  fprintf (stderr, "  dvorepair -images-vs-measures (catdir) (Ntol) - find images with too many missing detections\n");
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r38468 r38986  
    198198    int Nreplace = 0;
    199199    if (REPLACE_TYCHO) {
    200       int Mout = output[0].average[n].measureOffset; 
    201200      int Minp =  input[0].average[N].measureOffset;
    202       Nreplace = replace_tycho (&output[0].average[n], &output[0].measure[Mout], &input[0].average[N], &input[0].measure[Minp]);
     201      Nreplace = replace_tycho (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[Minp]);
    203202      if (Nreplace == 6) {
    204203        input[0].found_t[N] = Nmeas;
     
    216215        // index to first measure for this object
    217216        // XXX this does not support lensing measurements
    218         int Mout = output[0].average[n].measureOffset; 
    219         if (replace_match(&output[0].average[n], &output[0].measure[Mout], &input[0].average[N], &input[0].measure[offset])) {
    220           input[0].found_t[N] = Mout;
     217        if (replace_match (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[offset])) {
     218          input[0].found_t[N] = output[0].average[n].measureOffset; 
    221219          continue;
    222220        }
  • trunk/Ohana/src/dvomerge/src/replace_match.c

    r37046 r38986  
    11# include "dvomerge.h"
    22
     3// XXX this function does not work because it it loops over the average->Nmeasure entries
     4// as if they were sorted, but objects which have had entries added to them have elements
     5// out of sequence.  I probably need to step through next_meas to find the sequence.
     6
    37// average and measure pointers to the objects of interest and their first / current measurement
    4 int replace_match (Average *average_out, Measure *measure_out, Average *average_in, Measure *measure_in) {
     8int replace_match (Average *average_out, Measure *measure_out, off_t *next_meas, Average *average_in, Measure *measure_in) {
    59
    610  int Nout;
     
    812  unsigned int catID;
    913
     14  off_t m = average_out->measureOffset;
     15
    1016  // find the matching photcode in the object's list of measurements
    1117  for (Nout = 0; Nout < average_out[0].Nmeasure; Nout ++) {
    12     if (measure_out[Nout].photcode != measure_in[0].photcode) continue;
     18    myAssert (m > -1, "oops");
     19    if (measure_out[m].photcode != measure_in[0].photcode) {
     20      m = next_meas[m];
     21      continue;
     22    }
    1323   
    1424    // set the new measurements
    15     averef = measure_out[Nout].averef;
    16     catID  = measure_out[Nout].catID;
    17     measure_out[Nout] = measure_in[0];
     25    averef = measure_out[m].averef;
     26    catID  = measure_out[m].catID;
     27    measure_out[m] = measure_in[0];
    1828
    1929    // old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
     
    2434    // measure_out[Nout].dD = 3600.0*(average_out[0].D - Din);
    2535
    26     measure_out[Nout].dbFlags  = 0;  // XXX why reset these?
    27     measure_out[Nout].averef   = averef;
    28     measure_out[Nout].objID    = average_out[0].objID;
    29     measure_out[Nout].catID    = catID;
     36    measure_out[m].dbFlags  = 0;  // XXX why reset these?
     37    measure_out[m].averef   = averef;
     38    measure_out[m].objID    = average_out[0].objID;
     39    measure_out[m].catID    = catID;
    3040
    31     float dRoff = dvoOffsetR(&measure_out[Nout], average_out);
     41    float dRoff = dvoOffsetR(&measure_out[m], average_out);
    3242
    3343    // rationalize dR
    3444    if (dRoff > +180.0*3600.0) {
    3545      // average on high end of boundary, move star up
    36       measure_out[Nout].R += 360.0;
     46      measure_out[m].R += 360.0;
    3747      dRoff -= 360.0*3600.0;
    3848    }
    3949    if (dRoff < -180.0*3600.0) {
    4050      // average on low end of boundary, move star down
    41       measure_out[Nout].R -= 360.0;
     51      measure_out[m].R -= 360.0;
    4252      dRoff += 360.0*3600.0;
    4353    }
     
    4959      if (fabs(dRoff*cosD) > 10*RADIUS) {
    5060        fprintf (stderr, "surprisingly distant detection: %10.6f,%10.6f vs %10.6f,%10.6f\n",
    51                  average_out[0].R, average_out[0].D, measure_out[Nout].R, measure_out[Nout].D);
     61                 average_out[0].R, average_out[0].D, measure_out[m].R, measure_out[m].D);
    5262      }
    5363    }
  • trunk/Ohana/src/dvomerge/src/replace_tycho.c

    r38468 r38986  
    1010}
    1111
    12 int replace_tycho (Average *averageOut, Measure *measureOut, Average *averageInp, Measure *measureInp) {
     12int replace_tycho (Average *averageOut, Measure *measureOut, off_t *next_meas, Average *averageInp, Measure *measureInp) {
    1313
    1414  int i;
     
    1717  int index[6];
    1818
     19  off_t m = averageOut->measureOffset;
     20
    1921  // find all tycho measurements
    2022  for (i = 0; (i < averageOut->Nmeasure) && (Nindex < 6); i++) {
    2123
     24    myAssert (m > -1, "oops");
     25
    2226    int valid = FALSE;
    23     valid = valid || (measureOut[i].photcode == TYCHO_B);
    24     valid = valid || (measureOut[i].photcode == TYCHO_V);
    25     if (!valid) continue;
    26 
    27     index[Nindex] = i;
    28     Nindex ++;
     27    valid = valid || (measureOut[m].photcode == TYCHO_B);
     28    valid = valid || (measureOut[m].photcode == TYCHO_V);
     29    if (valid) {
     30      index[Nindex] = m;
     31      Nindex ++;
     32    }
     33    m = next_meas[m];
    2934  }
    3035
Note: See TracChangeset for help on using the changeset viewer.