Changeset 35255
- Timestamp:
- Mar 7, 2013, 4:33:58 AM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130306/Ohana/src/addstar
- Files:
-
- 6 edited
-
Makefile (modified) (2 diffs)
-
include/addstar.h (modified) (2 diffs)
-
src/ExternImageIDs.c (modified) (7 diffs)
-
src/UpdateImageIDs.c (modified) (1 diff)
-
src/addstar.c (modified) (1 diff)
-
test/simple.dvo (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130306/Ohana/src/addstar/Makefile
r34405 r35255 90 90 $(SRC)/GetFileMode.$(ARCH).o \ 91 91 $(SRC)/ReadImageHeader.$(ARCH).o \ 92 $(SRC)/ExternImageIDs.$(ARCH).o \ 92 93 $(SRC)/UpdateImageIDs.$(ARCH).o \ 93 94 $(SRC)/update_coords.$(ARCH).o \ … … 207 208 $(SRC)/ReadStarsTEXT.$(ARCH).o \ 208 209 $(SRC)/ReadStarsSDSS.$(ARCH).o \ 210 $(SRC)/ExternImageIDs.$(ARCH).o \ 209 211 $(SRC)/UpdateImageIDs.$(ARCH).o \ 210 212 $(SRC)/FilterStars.$(ARCH).o \ -
branches/eam_branches/ipp-20130306/Ohana/src/addstar/include/addstar.h
r34405 r35255 56 56 char *refcat; 57 57 } DVO_DATA; 58 59 # define IDTYPE int 60 61 typedef struct { 62 IDTYPE Nimage; 63 IDTYPE minID; 64 IDTYPE maxID; 65 IDTYPE range; 66 IDTYPE *imageID; 67 IDTYPE *externID; 68 char *found; 69 } ExtID_Index; 58 70 59 71 typedef struct sockaddr_in SockAddress; … … 275 287 int UpdateImageIDs (Stars *stars, unsigned int Nstars, Image *images, off_t Nimages); 276 288 289 int CheckDuplicateImageIDs (Image *images, off_t Nimages); 290 277 291 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); 278 292 int LoadDataPMM (FILE *f, char *file, Image **images, off_t *nvalid, Stars **stars, unsigned int *Nstars); -
branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/ExternImageIDs.c
r35254 r35255 1 1 # include "addstar.h" 2 3 typedef 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 2 12 3 ExtID_Index *ExtID_Load (char *filename) { … … 24 15 FILE *f = fopen (filename, "r"); 25 16 if (!f) { 26 fprintf (stderr, "ERROR: cannot open image subsetfile %s\n", filename);17 fprintf (stderr, "ERROR: cannot open imageID/externID file %s\n", filename); 27 18 return NULL; 28 19 } … … 30 21 /* load in PHU segment (ignore) */ 31 22 if (!gfits_fread_header (f, &header)) { 32 if (VERBOSE) fprintf (stderr, "can't read image subsetheader\n");23 if (VERBOSE) fprintf (stderr, "can't read imageID/externID header\n"); 33 24 fclose (f); 34 25 return NULL; 35 26 } 36 27 if (!gfits_fread_matrix (f, &matrix, &header)) { 37 if (VERBOSE) fprintf (stderr, "can't read image subsetmatrix\n");28 if (VERBOSE) fprintf (stderr, "can't read imageID/externID matrix\n"); 38 29 gfits_free_header (&header); 39 30 fclose (f); … … 56 47 fclose (f); 57 48 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. 49 char type[16]; 50 extID->externID = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol); 51 myAssert (!strcmp(type, "int"), "wrong column type"); 60 52 61 char type[16]; 62 63 extID->value = gfits_get_bintable_column_data (&theader, &ftable, "EXTERN_ID", type, &Nrow, &Ncol); 53 extID->imageID = gfits_get_bintable_column_data (&theader, &ftable, "IMAGE_ID", type, &Nrow, &Ncol); 64 54 myAssert (!strcmp(type, "int"), "wrong column type"); 65 55 66 56 extID->Nimage = Nrow; 67 57 58 // find the range of externID values 68 59 extID->minID = -1; 69 60 extID->maxID = -1; 70 61 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]);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]); 74 65 } 75 66 extID->range = extID->maxID- extID->minID + 1; 76 67 68 // init the index 77 69 ALLOCATE (extID->found, char, extID->range); 78 70 for (i = 0; i < extID->range; i++) extID->found[i] = FALSE; 79 71 72 // generate the index (set this value to the imageID?) 80 73 for (i = 0; i < extID->Nimage; i++) { 81 off_t N = extID->value[i] - extID->minID;82 extID->found[N] = TRUE 74 IDTYPE N = extID->externID[i] - extID->minID; 75 extID->found[N] = TRUE; 83 76 } 84 77 … … 86 79 } 87 80 81 // STATUS is value expected for success 82 # define CHECK_STATUS(STATUS,MSG,...) \ 83 if (!(STATUS)) { \ 84 fprintf (stderr, MSG, __VA_ARGS__); \ 85 return FALSE; \ 86 } 87 88 int ExtID_Save (char *filename, ExtID_Index *extID) { 89 90 Header header; 91 Header theader; 92 Matrix matrix; 93 FTable ftable; 94 95 gfits_init_header (&header); 96 header.extend = TRUE; 97 gfits_create_header (&header); 98 gfits_create_matrix (&header, &matrix); 99 100 gfits_create_table_header (&theader, "BINTABLE", "EXTERN_ID"); 101 gfits_define_bintable_column (&theader, "J", "IMAGE_ID", "image ID", NULL, 1.0, 0); 102 gfits_define_bintable_column (&theader, "J", "EXTERN_ID", "extern ID", NULL, 1.0, 0); 103 104 // generate the output array that carries the data 105 gfits_create_table (&theader, &ftable); 106 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); 110 111 FILE *f = fopen (filename, "w"); 112 if (!f) { 113 fprintf (stderr, "ERROR: cannot open extID file for output %s\n", filename); 114 return FALSE; 115 } 116 117 int status; 118 status = gfits_fwrite_header (f, &header); 119 CHECK_STATUS (status, "ERROR: cannot write header for imageID/externID %s\n", filename); 120 121 status = gfits_fwrite_matrix (f, &matrix); 122 CHECK_STATUS (status, "ERROR: cannot write matrix for imageID/externID %s\n", filename); 123 124 status = gfits_fwrite_Theader (f, &theader); 125 CHECK_STATUS (status, "ERROR: cannot write table header for imageID/externID %s\n", filename); 126 127 status = gfits_fwrite_table (f, &ftable); 128 CHECK_STATUS (status, "ERROR: cannot write table data for imageID/externID %s\n", filename); 129 130 gfits_free_header (&header); 131 gfits_free_matrix (&matrix); 132 gfits_free_header (&theader); 133 gfits_free_table (&ftable); 134 135 int fd = fileno (f); 136 137 status = fflush (f); 138 CHECK_STATUS (!status, "ERROR: cannot flush file imageID/externID %s\n", filename); 139 140 status = fsync (fd); 141 CHECK_STATUS (!status, "ERROR: cannot flush file imageID/externID %s\n", filename); 142 143 status = fclose (f); 144 CHECK_STATUS (!status, "ERROR: problem closing imageID/externID file %s\n", filename); 145 146 return TRUE; 147 } 148 88 149 int CheckDuplicateImageIDs (Image *images, off_t Nimages) { 150 151 IDTYPE i, offset; 89 152 90 153 // load the image ID table … … 94 157 ExtID_Index *extID = ExtID_Load (filename); 95 158 96 for (i = 0; i < Nimages; i++) { 97 off_t ID = images[i].externID; 159 // if we 160 161 for (i = 0; extID && (i < Nimages); i++) { 162 IDTYPE ID = images[i].externID; 98 163 if (ID == 0) continue; 99 164 … … 106 171 107 172 if (!extID->found[offset]) continue; 108 fprintf (stderr, "duplicate external image ID "OFF_T_FMT" found, exiting\n", extID);173 fprintf (stderr, "duplicate external image ID %lld found, exiting\n", (long long) ID); 109 174 exit (1); 110 175 } 111 176 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 // extend the storage arrays 185 REALLOCATE (extID->imageID, IDTYPE, extID->Nimage + Nimages); 186 REALLOCATE (extID->externID, IDTYPE, extID->Nimage + Nimages); 187 112 188 // append the new ext IDs and save 113 189 for (i = 0; i < Nimages; i++) { 114 append(); 190 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 ++; 115 194 } 116 195 -
branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/UpdateImageIDs.c
r28248 r35255 51 51 } 52 52 53 // set and update the imageID sequence 54 CheckDuplicateImageIDs (images, Nimages); 55 53 56 imageID += Nimages; 54 57 status = gfits_modify (&db.header, "IMAGEID", "%u", 1, imageID); -
branches/eam_branches/ipp-20130306/Ohana/src/addstar/src/addstar.c
r35253 r35255 56 56 57 57 // set and update the imageID sequence 58 CheckDuplicateImageIDs (images, Nimages);59 60 // set and update the imageID sequence61 58 UpdateImageIDs (stars, Nstars, images, Nimages); 62 59 -
branches/eam_branches/ipp-20130306/Ohana/src/addstar/test/simple.dvo
r34405 r35255 68 68 69 69 for i 0 $testfields:n 70 if ($TAP_VERBOSE) echo $testfields:$i 70 71 list name -split $testfields:$i 71 72 if ("$name:0" == "SKIP") continue … … 337 338 PSF_INST_FLUX : SKIP # not ingested into DVO 338 339 PSF_INST_FLUX_SIG : SKIP # not ingested into DVO 339 AP_MAG _STANDARD: mag:aperinst # FAIL340 AP_MAG : mag:aperinst # FAIL 340 341 AP_MAG_RAW : SKIP # not ingested into DVO 341 342 AP_MAG_RADIUS : SKIP # not ingested into DVO … … 346 347 PEAK_FLUX_AS_MAG : SKIP # not ingested into DVO 347 348 SKY : sky 348 SKY_SIG : sky_err349 SKY_SIGMA : sky_err 349 350 PSF_CHISQ : psf_chisq 350 351 CR_NSIGMA : cr_nsigma
Note:
See TracChangeset
for help on using the changeset viewer.
