IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37490


Ignore:
Timestamp:
Oct 16, 2014, 11:10:21 AM (12 years ago)
Author:
eugene
Message:

adding new program to check for duplicate image IDs (extern_id)

Location:
branches/eam_branches/ipp-20140904/Ohana/src/dvomerge
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140904/Ohana/src/dvomerge/Makefile

    r37489 r37490  
    154154$(SRC)/dvoutils.$(ARCH).o \
    155155$(SRC)/dvoutils_args.$(ARCH).o \
    156 $(SRC)/dvoutils_uniq_images.$(ARCH).o
     156$(SRC)/dvoutils_uniq_images.$(ARCH).o \
     157$(SRC)/dvoutils_load_image_index.$(ARCH).o
    157158
    158159$(DVOUTILS)  : $(INC)/dvoutils.h
  • branches/eam_branches/ipp-20140904/Ohana/src/dvomerge/include/dvoutils.h

    r37489 r37490  
    3030int dvoutils_args (int *argc, char **argv);
    3131int dvoutils_uniq_images (char *filename);
     32int *dvoutils_load_image_index (char *filename, int *nindex);
     33
     34Image *dvoutils_load_image_table (char *filename, int *nimage);
  • branches/eam_branches/ipp-20140904/Ohana/src/dvomerge/src/dvoutils_uniq_images.c

    r37489 r37490  
    1717  }
    1818
    19   int minID = -1;
    20   int maxID = -1;
    21   int *IDlist = NULL;
     19  int    minID  = -1;
     20  int    maxID  = -1;
     21  int  *IDlist  = NULL;
     22  int  *DBfound = NULL;
     23  int  *DBindex = NULL;
    2224 
     25  int Ndb = 0;
     26  int NDB = 100;
     27  char **DBlist = NULL;
     28  ALLOCATE (DBlist, char *, NDB); // list of the names of the image database tables. 
     29
    2330  char imFile[1024];
    2431  while (scan_line_maxlen (f, imFile, 1024) != EOF) {
     
    3340    }
    3441
    35     FITS_DB db;
     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;
    3646
    37     gfits_db_init (&db);
    38     db.lockstate = LCK_SOFT;
    39     db.timeout   = 120.0;
    40 
    41     if (!gfits_db_lock (&db, imFile)) {
    42       fprintf (stderr, "error opening image catalog %s (1)\n", imFile);
    43       exit (3);
    44     }
    45 
    46     if (db.dbstate == LCK_EMPTY) {
    47       fprintf (stderr, "note: image catalog is empty\n");
    48       // free db
    49       continue;
    50     }
    51 
    52     int status = dvo_image_load (&db, TRUE, FALSE);
    53     gfits_db_close (&db);
    54    
    55     if (!status) {
    56       fprintf (stderr, "problem loading image database table\n");
    57       exit (4);
    58     }
    59 
    60     off_t Nimage;
    61     Image *image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
    62     if (!image) {
    63       fprintf (stderr, "ERROR: failed to read images\n");
    64       exit (5);
    65     }
     47    DBlist[Ndb] = strcreate (imFile);
    6648
    6749    // now loop over all of the images and accumulate the array of extern_id values (skip
     
    7658    int i;
    7759    for (i = 0; i < Nimage; i++) {
    78       if (!image[i].externID) continue;
    79       myMaxID = MAX(image[i].externID, myMaxID);
    80       myMinID = MIN(image[i].externID, myMinID);
     60      if (!extern_id[i]) continue;
     61      myMaxID = MAX(extern_id[i], myMaxID);
     62      myMinID = MIN(extern_id[i], myMinID);
    8163    }
    8264
     
    8668    if (!IDlist) {
    8769      int Nindex = myMaxID - myMinID + 1;
    88       ALLOCATE (IDlist, int, Nindex);
    89       memset (IDlist, 0, Nindex*sizeof(int));
     70      ALLOCATE (IDlist,  int,  Nindex); // number of times this ID is seen.  IDlist[i] corresponds to extern_id = i + minID
     71      ALLOCATE (DBfound, int,  Nindex); // index of first DB in which this ID is seen (if n = DBfound[i], the correspond ID was seen in DB n
     72      ALLOCATE (DBindex, int,  Nindex); // sequence of this image in the first DB for which this ID was found
     73
     74      for (i = 0; i < Nindex; i++) {
     75        IDlist[i]  =  0;
     76        DBfound[i] = -1;
     77        DBindex[i] = -1;
     78      }
     79
    9080      minID = myMinID;
    9181      maxID = myMaxID;
     
    9989      myAssert (oldNindex <= Nindex, "impossible!");
    10090
    101       int *newIDlist = NULL;
    102       ALLOCATE (newIDlist, int, Nindex);
    103       memset (newIDlist, 0, Nindex*sizeof(int));
     91      int *newIDlist  = NULL;
     92      int *newDBfound = NULL;
     93      int *newDBindex = NULL;
     94
     95      ALLOCATE (newIDlist,  int, Nindex);
     96      ALLOCATE (newDBfound, int, Nindex);
     97      ALLOCATE (newDBindex, int, Nindex);
     98
     99      for (i = 0; i < Nindex; i++) {
     100        newIDlist[i]  =  0;
     101        newDBfound[i] = -1;
     102        newDBindex[i] = -1;
     103      }
    104104     
    105105      // if myMinID >= minID, newMinID = minID -> offset = 0
     
    108108
    109109      // save the old values
    110       memcpy (&newIDlist[offset], IDlist, oldNindex*sizeof(int));
     110      memcpy (&newIDlist [offset], IDlist,  oldNindex*sizeof(int));
     111      memcpy (&newDBfound[offset], DBfound, oldNindex*sizeof(int));
     112      memcpy (&newDBindex[offset], DBindex, oldNindex*sizeof(int));
    111113
    112114      free (IDlist);
    113       IDlist = newIDlist;
     115      free (DBfound);
     116      free (DBindex);
     117
     118      IDlist  = newIDlist;
     119      DBfound = newDBfound;
     120      DBindex = newDBindex;
    114121
    115122      minID = newMinID;
     
    118125
    119126    for (i = 0; i < Nimage; i++) {
    120       if (!image[i].externID) continue;
    121       int n = image[i].externID - minID;
     127      if (!extern_id[i]) continue;
     128      int n = extern_id[i] - minID;
     129      if (IDlist[n] == 0) {
     130        DBfound[n] = Ndb;
     131        DBindex[n] = i;
     132      }
    122133      IDlist[n] ++;
    123134    }
     
    127138
    128139      for (i = 0; i < Nimage; i++) {
    129         if (!image[i].externID) continue;
    130         fprintf (stderr, "%d => %d\n", image[i].externID, image[i].externID - minID);
     140        if (!extern_id[i]) continue;
     141        fprintf (stderr, "%d => %d\n", extern_id[i], extern_id[i] - minID);
    131142      }
    132143
     
    138149      }
    139150    }
     151
     152    // we are done with the db file, bump the counter
     153    Ndb ++;
     154    CHECK_REALLOCATE (DBlist, char *, NDB, Ndb, 100);
    140155  }
    141156
     
    147162  for (i = 0; i < Nindex; i++) {
    148163    if (IDlist[i] < 2) continue;
    149     fprintf (stderr, "%d : %d\n", i + minID, IDlist[i]);
     164    int n = DBfound[i];
     165    myAssert (n > -1, "impossible!");
     166    fprintf (stderr, "%d : %d -- in %s (%d) : %d \n", i + minID, IDlist[i], DBlist[n], DBfound[i], DBindex[i]);
    150167  }
    151168
Note: See TracChangeset for help on using the changeset viewer.