Changeset 35256
- Timestamp:
- Mar 7, 2013, 9:22:43 AM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130306/Ohana/src/addstar
- Files:
-
- 4 edited
-
include/addstar.h (modified) (2 diffs)
-
src/ExternImageIDs.c (modified) (9 diffs)
-
src/UpdateImageIDs.c (modified) (2 diffs)
-
test/simple.dvo (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130306/Ohana/src/addstar/include/addstar.h
r35255 r35256 67 67 IDTYPE *externID; 68 68 char *found; 69 } ExtID_Index;69 } ImageIndex; 70 70 71 71 typedef struct sockaddr_in SockAddress; … … 288 288 289 289 int CheckDuplicateImageIDs (Image *images, off_t Nimages); 290 int ImageIndexFileInit (); 290 291 291 292 int 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 1 1 # include "addstar.h" 2 2 3 ExtID_Index *ExtID_Load (char *filename) {3 ImageIndex *ImageIndexLoad (char *filename) { 4 4 5 5 int i, Ncol; … … 10 10 FTable ftable; 11 11 12 ExtID_Index *extID= NULL;13 ALLOCATE ( extID, ExtID_Index, 1);12 ImageIndex *index = NULL; 13 ALLOCATE (index, ImageIndex, 1); 14 14 15 15 FILE *f = fopen (filename, "r"); 16 16 if (!f) { 17 fprintf (stderr, "ERROR: cannot open image ID/externIDfile %s\n", filename);17 fprintf (stderr, "ERROR: cannot open image index file %s\n", filename); 18 18 return NULL; 19 19 } … … 21 21 /* load in PHU segment (ignore) */ 22 22 if (!gfits_fread_header (f, &header)) { 23 if (VERBOSE) fprintf (stderr, "can't read image ID/externIDheader\n");23 if (VERBOSE) fprintf (stderr, "can't read image index header\n"); 24 24 fclose (f); 25 25 return NULL; 26 26 } 27 27 if (!gfits_fread_matrix (f, &matrix, &header)) { 28 if (VERBOSE) fprintf (stderr, "can't read image ID/externIDmatrix\n");28 if (VERBOSE) fprintf (stderr, "can't read image index matrix\n"); 29 29 gfits_free_header (&header); 30 30 fclose (f); … … 48 48 49 49 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); 51 51 myAssert (!strcmp(type, "int"), "wrong column type"); 52 52 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); 54 54 myAssert (!strcmp(type, "int"), "wrong column type"); 55 55 56 extID->Nimage = Nrow;56 index->Nimage = Nrow; 57 57 58 58 // 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; 67 67 68 68 // 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; 71 71 72 72 // 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; 79 79 } 80 80 … … 86 86 } 87 87 88 int ExtID_Save (char *filename, ExtID_Index *extID) {88 int ImageIndexSave (char *filename, ImageIndex *index) { 89 89 90 90 Header header; … … 106 106 107 107 // 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); 110 110 111 111 FILE *f = fopen (filename, "w"); 112 112 if (!f) { 113 fprintf (stderr, "ERROR: cannot open extIDfile for output %s\n", filename);113 fprintf (stderr, "ERROR: cannot open index file for output %s\n", filename); 114 114 return FALSE; 115 115 } … … 117 117 int status; 118 118 status = gfits_fwrite_header (f, &header); 119 CHECK_STATUS (status, "ERROR: cannot write header for image ID/externID%s\n", filename);119 CHECK_STATUS (status, "ERROR: cannot write header for image index %s\n", filename); 120 120 121 121 status = gfits_fwrite_matrix (f, &matrix); 122 CHECK_STATUS (status, "ERROR: cannot write matrix for image ID/externID%s\n", filename);122 CHECK_STATUS (status, "ERROR: cannot write matrix for image index %s\n", filename); 123 123 124 124 status = gfits_fwrite_Theader (f, &theader); 125 CHECK_STATUS (status, "ERROR: cannot write table header for image ID/externID%s\n", filename);125 CHECK_STATUS (status, "ERROR: cannot write table header for image index %s\n", filename); 126 126 127 127 status = gfits_fwrite_table (f, &ftable); 128 CHECK_STATUS (status, "ERROR: cannot write table data for image ID/externID%s\n", filename);128 CHECK_STATUS (status, "ERROR: cannot write table data for image index %s\n", filename); 129 129 130 130 gfits_free_header (&header); … … 136 136 137 137 status = fflush (f); 138 CHECK_STATUS (!status, "ERROR: cannot flush file image ID/externID%s\n", filename);138 CHECK_STATUS (!status, "ERROR: cannot flush file image index %s\n", filename); 139 139 140 140 status = fsync (fd); 141 CHECK_STATUS (!status, "ERROR: cannot f lush file imageID/externID%s\n", filename);141 CHECK_STATUS (!status, "ERROR: cannot fsync file image index %s\n", filename); 142 142 143 143 status = fclose (f); 144 CHECK_STATUS (!status, "ERROR: problem closing image ID/externIDfile %s\n", filename);144 CHECK_STATUS (!status, "ERROR: problem closing image index file %s\n", filename); 145 145 146 146 return TRUE; … … 153 153 // load the image ID table 154 154 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++) { 162 165 IDTYPE ID = images[i].externID; 163 166 if (ID == 0) continue; 164 167 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; 169 172 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; 173 176 fprintf (stderr, "duplicate external image ID %lld found, exiting\n", (long long) ID); 174 177 exit (1); 175 178 } 176 179 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 184 180 // 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); 187 183 188 184 // append the new ext IDs and save 189 185 for (i = 0; i < Nimages; i++) { 190 186 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 ++; 194 190 } 195 191 196 192 // do this as an 'extend' operation 197 ExtID_Save (filename, extID);193 ImageIndexSave (filename, index); 198 194 return TRUE; 199 195 } 196 197 int 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 18 18 if (VERBOSE) fprintf (stderr, "can't find %s, creating a new one\n", ImageCat); 19 19 dvo_image_create (&db, GetZeroPoint()); 20 isEmpty = TRUE; 20 ImageIndexFileInit (); 21 isEmpty = TRUE; 21 22 } else { 22 23 /* position to start of file */ … … 52 53 53 54 // set and update the imageID sequence 55 // the file holding the index is created above if this is an empty db 54 56 CheckDuplicateImageIDs (images, Nimages); 55 57 -
branches/eam_branches/ipp-20130306/Ohana/src/addstar/test/simple.dvo
r35255 r35256 52 52 exec mkcmf test.in.txt test.cmf -date 2008/1/1 -time 01:00:00 -radec $RA $DEC -type $1 53 53 if ($TAP_VERBOSE) 54 echo exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass 54 55 exec addstar -D CATDIR catdir.test -D CAMERA simtest test.cmf -D CATFORMAT $2 -quick-airmass 55 56 else
Note:
See TracChangeset
for help on using the changeset viewer.
