IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35254


Ignore:
Timestamp:
Mar 6, 2013, 9:29:16 PM (13 years ago)
Author:
eugene
Message:

extern Id check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/ExternImageIDs.c

    r35252 r35254  
    11# include "addstar.h"
     2
     3typedef struct {
     4  off_t Nimage;
     5  off_t minID;
     6  off_t maxID;
     7  off_t range;
     8  off_t *value;
     9  char *found;
     10} ExtID_Index;
     11
     12ExtID_Index *ExtID_Load (char *filename) {
     13
     14  int i, Ncol;
     15  off_t Nrow;
     16  Header header;
     17  Header theader;
     18  Matrix matrix;
     19  FTable ftable;
     20
     21  ExtID_Index *extID = NULL;
     22  ALLOCATE (extID, ExtID_Index, 1);
     23
     24  FILE *f = fopen (filename, "r");
     25  if (!f) {
     26    fprintf (stderr, "ERROR: cannot open image subset file %s\n", filename);
     27    return NULL;
     28  }
     29
     30  /* load in PHU segment (ignore) */
     31  if (!gfits_fread_header (f, &header)) {
     32    if (VERBOSE) fprintf (stderr, "can't read image subset header\n");
     33    fclose (f);
     34    return NULL;
     35  }
     36  if (!gfits_fread_matrix (f, &matrix, &header)) {
     37    if (VERBOSE) fprintf (stderr, "can't read image subset matrix\n");
     38    gfits_free_header (&header);
     39    fclose (f);
     40    return NULL;
     41  }
     42
     43  ftable.header = &theader;
     44
     45  // load data for this header
     46  if (!gfits_load_header (f, &theader)) {
     47    fclose (f);
     48    return NULL;
     49  }
     50
     51  // read the fits table bytes
     52  if (!gfits_fread_ftable_data (f, &ftable, FALSE)) {
     53    fclose (f);
     54    return (NULL);
     55  }
     56  fclose (f);
     57
     58  // a bit annoying : we read the entire block of data, then extract the columns, then set the image structure values.
     59  // this means I need 3 copies in memory at some point.  ugh.
     60
     61  char type[16];
     62
     63  extID->value = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol);
     64  myAssert (!strcmp(type, "int"), "wrong column type");
     65
     66  extID->Nimage = Nrow;
     67
     68  extID->minID = -1;
     69  extID->maxID = -1;
     70  for (i = 0; i < extID->Nimage; i++) {
     71    if (extID->minID == -1) extID->minID = extID->value[i];
     72    extID->minID = MIN(extID->minID, extID->value[i]);
     73    extID->maxID = MAX(extID->maxID, extID->value[i]);
     74  }
     75  extID->range = extID->maxID- extID->minID + 1;
     76 
     77  ALLOCATE (extID->found, char, extID->range);
     78  for (i = 0; i < extID->range; i++) extID->found[i] = FALSE;
     79
     80  for (i = 0; i < extID->Nimage; i++) {
     81    off_t N = extID->value[i] - extID->minID;
     82    extID->found[N] = TRUE
     83  }
     84
     85  return extID;
     86}
    287
    388int CheckDuplicateImageIDs (Image *images, off_t Nimages) {
     
    691  char filename[DVO_MAX_PATH];
    792  snprintf (filename, DVO_MAX_PATH, "%s/ExternImageIDs.fits", CATDIR);
    8   ExternImageIDs *imageIDs = ExternImageIDsLoad (filename);
     93
     94  ExtID_Index *extID = ExtID_Load (filename);
    995
    1096  for (i = 0; i < Nimages; i++) {
    11     off_t extID = images[i].externID;
    12     if (extID == 0) continue;
     97    off_t ID = images[i].externID;
     98    if (ID == 0) continue;
    1399
    14     if (extID < imageIDs.minID) continue;
    15     if (extID > imageIDs.maxID) continue;
     100    if (ID < extID->minID) continue;
     101    if (ID > extID->maxID) continue;
    16102
    17     extIDoff = extID - imageIDs.min;
    18     if (imageIDs.value[extIDoff] == -1) continue;
     103    offset = ID - extID->minID;
     104    myAssert (offset >= 0, "offset out of range?");
     105    myAssert (offset <= extID->range, "offset out of range?");
     106
     107    if (!extID->found[offset]) continue;
    19108    fprintf (stderr, "duplicate external image ID "OFF_T_FMT" found, exiting\n", extID);
    20109    exit (1);
     
    27116
    28117  // do this as an 'extend' operation
    29   ExternImageIDsSave (filename, imageIDs);
     118  ExtID_Save (filename, extID);
    30119  return TRUE;
    31120}
Note: See TracChangeset for help on using the changeset viewer.