IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35256


Ignore:
Timestamp:
Mar 7, 2013, 9:22:43 AM (13 years ago)
Author:
eugene
Message:

cleanup the behavior on the initial pass (create an empty image index); rename structure to ImageIndex

Location:
branches/eam_branches/ipp-20130306/Ohana/src/addstar
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/include/addstar.h

    r35255 r35256  
    6767  IDTYPE *externID;
    6868  char *found;
    69 } ExtID_Index;
     69} ImageIndex;
    7070
    7171typedef struct sockaddr_in SockAddress;
     
    288288
    289289int CheckDuplicateImageIDs (Image *images, off_t Nimages);
     290int ImageIndexFileInit ();
    290291
    291292int LoadDataSDSS (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars, Header **headers, off_t *extsize, HeaderSet *headerSets, off_t Nimages);
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/ExternImageIDs.c

    r35255 r35256  
    11# include "addstar.h"
    22
    3 ExtID_Index *ExtID_Load (char *filename) {
     3ImageIndex *ImageIndexLoad (char *filename) {
    44
    55  int i, Ncol;
     
    1010  FTable ftable;
    1111
    12   ExtID_Index *extID = NULL;
    13   ALLOCATE (extID, ExtID_Index, 1);
     12  ImageIndex *index = NULL;
     13  ALLOCATE (index, ImageIndex, 1);
    1414
    1515  FILE *f = fopen (filename, "r");
    1616  if (!f) {
    17     fprintf (stderr, "ERROR: cannot open imageID/externID file %s\n", filename);
     17    fprintf (stderr, "ERROR: cannot open image index file %s\n", filename);
    1818    return NULL;
    1919  }
     
    2121  /* load in PHU segment (ignore) */
    2222  if (!gfits_fread_header (f, &header)) {
    23     if (VERBOSE) fprintf (stderr, "can't read imageID/externID header\n");
     23    if (VERBOSE) fprintf (stderr, "can't read image index header\n");
    2424    fclose (f);
    2525    return NULL;
    2626  }
    2727  if (!gfits_fread_matrix (f, &matrix, &header)) {
    28     if (VERBOSE) fprintf (stderr, "can't read imageID/externID matrix\n");
     28    if (VERBOSE) fprintf (stderr, "can't read image index matrix\n");
    2929    gfits_free_header (&header);
    3030    fclose (f);
     
    4848
    4949  char type[16];
    50   extID->externID = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol);
     50  index->externID = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol);
    5151  myAssert (!strcmp(type, "int"), "wrong column type");
    5252
    53   extID->imageID  = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol);
     53  index->imageID  = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol);
    5454  myAssert (!strcmp(type, "int"), "wrong column type");
    5555
    56   extID->Nimage = Nrow;
     56  index->Nimage = Nrow;
    5757
    5858  // find the range of externID values
    59   extID->minID = -1;
    60   extID->maxID = -1;
    61   for (i = 0; i < extID->Nimage; i++) {
    62     if (extID->minID == -1) extID->minID = extID->externID[i];
    63     extID->minID = MIN(extID->minID, extID->externID[i]);
    64     extID->maxID = MAX(extID->maxID, extID->externID[i]);
    65   }
    66   extID->range = extID->maxID- extID->minID + 1;
     59  index->minID = -1;
     60  index->maxID = -1;
     61  for (i = 0; i < index->Nimage; i++) {
     62    if (index->minID == -1) index->minID = index->externID[i];
     63    index->minID = MIN(index->minID, index->externID[i]);
     64    index->maxID = MAX(index->maxID, index->externID[i]);
     65  }
     66  index->range = index->maxID- index->minID + 1;
    6767 
    6868  // init the index
    69   ALLOCATE (extID->found, char, extID->range);
    70   for (i = 0; i < extID->range; i++) extID->found[i] = FALSE;
     69  ALLOCATE (index->found, char, index->range);
     70  for (i = 0; i < index->range; i++) index->found[i] = FALSE;
    7171
    7272  // generate the index (set this value to the imageID?)
    73   for (i = 0; i < extID->Nimage; i++) {
    74     IDTYPE N = extID->externID[i] - extID->minID;
    75     extID->found[N] = TRUE;
    76   }
    77 
    78   return extID;
     73  for (i = 0; i < index->Nimage; i++) {
     74    IDTYPE N = index->externID[i] - index->minID;
     75    index->found[N] = TRUE;
     76  }
     77
     78  return index;
    7979}
    8080
     
    8686  }
    8787
    88 int ExtID_Save (char *filename, ExtID_Index *extID) {
     88int ImageIndexSave (char *filename, ImageIndex *index) {
    8989
    9090  Header header;
     
    106106
    107107  // add the columns to the output array
    108   gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",       extID->imageID,  extID->Nimage);
    109   gfits_set_bintable_column (&theader, &ftable, "EXTERN_ID",      extID->externID, extID->Nimage);
     108  gfits_set_bintable_column (&theader, &ftable, "IMAGE_ID",       index->imageID,  index->Nimage);
     109  gfits_set_bintable_column (&theader, &ftable, "EXTERN_ID",      index->externID, index->Nimage);
    110110
    111111  FILE *f = fopen (filename, "w");
    112112  if (!f) {
    113     fprintf (stderr, "ERROR: cannot open extID file for output %s\n", filename);
     113    fprintf (stderr, "ERROR: cannot open index file for output %s\n", filename);
    114114    return FALSE;
    115115  }
     
    117117  int status;
    118118  status = gfits_fwrite_header  (f, &header);
    119   CHECK_STATUS (status, "ERROR: cannot write header for imageID/externID %s\n", filename);
     119  CHECK_STATUS (status, "ERROR: cannot write header for image index %s\n", filename);
    120120
    121121  status = gfits_fwrite_matrix  (f, &matrix);
    122   CHECK_STATUS (status, "ERROR: cannot write matrix for imageID/externID %s\n", filename);
     122  CHECK_STATUS (status, "ERROR: cannot write matrix for image index %s\n", filename);
    123123
    124124  status = gfits_fwrite_Theader (f, &theader);
    125   CHECK_STATUS (status, "ERROR: cannot write table header for imageID/externID %s\n", filename);
     125  CHECK_STATUS (status, "ERROR: cannot write table header for image index %s\n", filename);
    126126
    127127  status = gfits_fwrite_table  (f, &ftable);
    128   CHECK_STATUS (status, "ERROR: cannot write table data for imageID/externID %s\n", filename);
     128  CHECK_STATUS (status, "ERROR: cannot write table data for image index %s\n", filename);
    129129
    130130  gfits_free_header (&header);
     
    136136
    137137  status = fflush (f);
    138   CHECK_STATUS (!status, "ERROR: cannot flush file imageID/externID %s\n", filename);
     138  CHECK_STATUS (!status, "ERROR: cannot flush file image index %s\n", filename);
    139139
    140140  status = fsync (fd);
    141   CHECK_STATUS (!status, "ERROR: cannot flush file imageID/externID %s\n", filename);
     141  CHECK_STATUS (!status, "ERROR: cannot fsync file image index %s\n", filename);
    142142
    143143  status = fclose (f);
    144   CHECK_STATUS (!status, "ERROR: problem closing imageID/externID file %s\n", filename);
     144  CHECK_STATUS (!status, "ERROR: problem closing image index file %s\n", filename);
    145145
    146146  return TRUE;
     
    153153  // load the image ID table
    154154  char filename[DVO_MAX_PATH];
    155   snprintf (filename, DVO_MAX_PATH, "%s/ExternImageIDs.fits", CATDIR);
    156 
    157   ExtID_Index *extID = ExtID_Load (filename);
    158 
    159   // if we
    160 
    161   for (i = 0; extID && (i < Nimages); i++) {
     155  snprintf (filename, DVO_MAX_PATH, "%s/ImageIndex.fits", CATDIR);
     156
     157  ImageIndex *index = ImageIndexLoad (filename);
     158
     159  if (!index) {
     160      fprintf (stderr, "image index file is not found, cannot check for image duplicates\n");
     161      exit (2);
     162  }
     163
     164  for (i = 0; i < Nimages; i++) {
    162165    IDTYPE ID = images[i].externID;
    163166    if (ID == 0) continue;
    164167
    165     if (ID < extID->minID) continue;
    166     if (ID > extID->maxID) continue;
    167 
    168     offset = ID - extID->minID;
     168    if (ID < index->minID) continue;
     169    if (ID > index->maxID) continue;
     170
     171    offset = ID - index->minID;
    169172    myAssert (offset >= 0, "offset out of range?");
    170     myAssert (offset <= extID->range, "offset out of range?");
    171 
    172     if (!extID->found[offset]) continue;
     173    myAssert (offset <= index->range, "offset out of range?");
     174
     175    if (!index->found[offset]) continue;
    173176    fprintf (stderr, "duplicate external image ID %lld found, exiting\n", (long long) ID);
    174177    exit (1);
    175178  }
    176179 
    177   if (!extID) {
    178     ALLOCATE (extID, ExtID_Index, 1);
    179     ALLOCATE (extID->imageID,  IDTYPE, 1);
    180     ALLOCATE (extID->externID, IDTYPE, 1);
    181     extID->Nimage = 0;
    182   }
    183 
    184180  // extend the storage arrays
    185   REALLOCATE (extID->imageID,  IDTYPE, extID->Nimage + Nimages);
    186   REALLOCATE (extID->externID, IDTYPE, extID->Nimage + Nimages);
     181  REALLOCATE (index->imageID,  IDTYPE, index->Nimage + Nimages);
     182  REALLOCATE (index->externID, IDTYPE, index->Nimage + Nimages);
    187183
    188184  // append the new ext IDs and save
    189185  for (i = 0; i < Nimages; i++) {
    190186    if (images[i].externID == 0) continue;
    191     extID->imageID[extID->Nimage] = images[i].imageID;
    192     extID->externID[extID->Nimage] = images[i].externID;
    193     extID->Nimage ++;
     187    index->imageID[index->Nimage] = images[i].imageID;
     188    index->externID[index->Nimage] = images[i].externID;
     189    index->Nimage ++;
    194190  }
    195191
    196192  // do this as an 'extend' operation
    197   ExtID_Save (filename, extID);
     193  ImageIndexSave (filename, index);
    198194  return TRUE;
    199195}
     196
     197int ImageIndexFileInit () {
     198
     199  // load the image ID table
     200  char filename[DVO_MAX_PATH];
     201  snprintf (filename, DVO_MAX_PATH, "%s/ImageIndex.fits", CATDIR);
     202
     203  ImageIndex *index = NULL;
     204  ALLOCATE (index, ImageIndex, 1);
     205  ALLOCATE (index->imageID,  IDTYPE, 1);
     206  ALLOCATE (index->externID, IDTYPE, 1);
     207  index->Nimage = 0;
     208
     209  // do this as an 'extend' operation
     210  ImageIndexSave (filename, index);
     211  return TRUE;
     212}
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/UpdateImageIDs.c

    r35255 r35256  
    1818    if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat);
    1919    dvo_image_create (&db, GetZeroPoint());
    20     isEmpty = TRUE;
     20    ImageIndexFileInit ();
     21  isEmpty = TRUE;
    2122  } else {
    2223    /* position to start of file */
     
    5253
    5354  // set and update the imageID sequence
     55  // the file holding the index is created above if this is an empty db
    5456  CheckDuplicateImageIDs (images, Nimages);
    5557
  • branches/eam_branches/ipp-20130306/Ohana/src/addstar/test/simple.dvo

    r35255 r35256  
    5252  exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1
    5353  if ($TAP_VERBOSE)
     54    echo exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    5455    exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass
    5556  else
Note: See TracChangeset for help on using the changeset viewer.