Changeset 29714
- Timestamp:
- Nov 8, 2010, 6:20:37 PM (16 years ago)
- Location:
- branches/eam_branches/ipp-20101103/Ohana/src
- Files:
-
- 3 added
- 11 edited
-
addstar/src/ReadStarsFITS.c (modified) (1 diff)
-
addstar/src/ReadStarsSDSS.c (modified) (1 diff)
-
dvomerge/doc (added)
-
dvomerge/doc/notes.txt (added)
-
dvomerge/src/dvorepair.c (modified) (1 diff)
-
dvomerge/src/dvorepairCPT.c (added)
-
imregister/imphot/rfits.c (modified) (1 diff)
-
libdvo/src/dvo_catalog_mef.c (modified) (4 diffs)
-
libdvo/src/dvo_catalog_split.c (modified) (4 diffs)
-
libdvo/src/fits_db.c (modified) (1 diff)
-
libfits/include/gfitsio.h (modified) (2 diffs)
-
libfits/table/F_read_T.c (modified) (3 diffs)
-
opihi/cmd.data/rd.c (modified) (1 diff)
-
opihi/cmd.data/read_vectors.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101103/Ohana/src/addstar/src/ReadStarsFITS.c
r29541 r29714 22 22 23 23 /* load the table data */ 24 if (!gfits_fread_ftable_data (f, &table )) {24 if (!gfits_fread_ftable_data (f, &table, FALSE)) { 25 25 fprintf (stderr, "ERROR: can't read table header\n"); 26 26 exit (1); -
branches/eam_branches/ipp-20101103/Ohana/src/addstar/src/ReadStarsSDSS.c
r28939 r29714 60 60 61 61 /* load the table data */ 62 if (!gfits_fread_ftable_data (f, &table )) {62 if (!gfits_fread_ftable_data (f, &table, FALSE)) { 63 63 fprintf (stderr, "ERROR: can't read table header\n"); 64 64 exit (1); -
branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepair.c
r29694 r29714 4 4 # define myAssert(LOGIC,MSG) { if (!LOGIC) { fprintf (stderr, "%s\n", MSG); abort(); } } 5 5 6 // broken cpt file, valid cpm file: we can recover everything in the cpt file from the cpm file: 7 // * load the full cpm file 8 // * loop over detections 9 // * if ave_ref is new: create a new object 10 // * determine RA & DEC from ext_id 11 // * obj_id, cat_id are defined in detection 12 // * 6 // find images which are missing detections: 7 // * load the Images.dat file 8 // * create an index for imageID (seq = imageIDindex[i]) 9 // * scan over all catalog files 10 // * load the cpm file (pad if short, identify the padded section) 11 // * loop over detections: increment detection count for each imageID 13 12 14 13 int main (int argc, char **argv) { 15 14 16 off_t Nmeasure, Nimage;17 int i, Nbytes, NaveMax, Naverage, NAVERAGE, Nave, Nold;18 int * found;15 off_t i, j, Nmeasure, Nvalid, Nimage, Nindex, *imageIdx, index, imageSeq; 16 int Nbytes, NbytesPerRow, Nbad, Ncheck, Ntol; 17 int *detCounts; 19 18 20 Image *image, *thisImage; 21 Average *average; 19 Image *image; 22 20 Measure *measure; 23 21 24 Matrix matrix; 22 SkyTable *insky; 23 SkyList *inlist; 25 24 26 char *cpmFilename, *cptFilenameSrc, *cptFilenameTgt, *imageFilename; 25 char *catdir = NULL; 26 char *cpmFilename = NULL; 27 char *imageFilename = NULL; 27 28 28 Header cp tHeaderPHU, cptHeaderTBL;29 Header cpmHeader PHU, cpmHeaderTBL;30 FTable cpmFtable , cptFtable;29 Header cpmHeaderPHU; 30 Header cpmHeaderTBL; 31 FTable cpmFtable; 31 32 32 FILE *cptFileSrc = NULL;33 FILE *cptFileTgt = NULL;34 33 FILE *cpmFile = NULL; 35 34 36 35 char catformat; 37 36 38 if (argc != 5) { 39 fprintf (stderr, "USAGE: dvorepair (images) (cpm) (cptInput) (cptOutput)\n"); 37 if (argc != 3) { 38 fprintf (stderr, "USAGE: dvorepair (catdir) (Ntol)\n"); 39 fprintf (stderr, " catdir : database of interest\n"); 40 fprintf (stderr, " Ntol : allow Ntol missing detections\n"); 40 41 exit (2); 41 42 } 42 43 43 imageFilename = argv[1]; 44 cpmFilename = argv[2]; 45 cptFilenameSrc = argv[3]; 46 cptFilenameTgt = argv[4]; 47 48 cpmFtable.header = &cpmHeaderTBL; 49 cptFtable.header = &cptHeaderTBL; 50 51 // XXX don't bother locking for now: this is totally manual.. 44 catdir = argv[1]; 45 Ntol = atoi(argv[2]); 52 46 53 47 // load the image data 48 ALLOCATE(imageFilename, char, strlen(catdir) + 12); 49 sprintf (imageFilename, "%s/Images.dat", catdir); 54 50 if ((image = LoadImages (imageFilename, &Nimage)) == NULL) return (FALSE); 55 51 BuildChipMatch (image, Nimage); 56 52 57 // open cpm file 58 cpmFile = fopen(cpmFilename, "r"); 59 myAssert(cpmFile, "failed to open cpm file"); 53 // generate an index for imageIDs: 54 Nindex = 0; 55 for (i = 0; i < Nimage; i++) { 56 Nindex = MAX(image[i].imageID, Nindex); 57 } 58 ALLOCATE (imageIdx, off_t, (Nindex + 1)); 59 memset (imageIdx, 0, (Nindex + 1)*sizeof(off_t)); 60 60 61 // load the cpm header 62 if (!gfits_fread_header (cpmFile, &cpmHeaderPHU)) { 63 myAbort("failure to cpm header"); 61 for (i = 0; i < Nimage; i++) { 62 index = image[i].imageID; 63 if (index == 0) { 64 fprintf (stderr, "?"); 65 continue; 66 } 67 if (imageIdx[index]) { 68 fprintf (stderr, "!"); 69 continue; 70 } 71 imageIdx[index] = i; 64 72 } 65 73 66 // move to TBL header67 Nbytes = cpmHeaderPHU.datasize + gfits_data_size (&cpmHeaderPHU);68 fseeko (cpmFile, Nbytes, SEEK_SET);74 // generate a list of the detection counts: 75 ALLOCATE (detCounts, int, Nimage); 76 memset (detCounts, 0, Nimage*sizeof(int)); 69 77 70 // read cpm TBL header 71 if (!gfits_fread_header (cpmFile, &cpmHeaderTBL)) { 72 myAbort("can't read header for cpm table"); 78 // load the sky table for the existing database 79 insky = SkyTableLoadOptimal (catdir, NULL, NULL, FALSE, SKY_DEPTH_HST, VERBOSE); 80 myAssert(insky, "can't read SkyTable"); 81 SkyTableSetFilenames (insky, catdir, "cpt"); 82 83 // XXX apply this...generate the subset matching the user-selected region 84 SkyRegion UserPatch; 85 UserPatch.Rmin = 0.0; 86 UserPatch.Rmax = 360.0; 87 UserPatch.Dmin = -90.0; 88 UserPatch.Dmax = +90.0; 89 inlist = SkyListByPatch (insky, -1, &UserPatch); 90 91 // SkyListPopulatedRange (&Ns, &Ne, inlist, 0); 92 // depth = inlist[0].regions[Ns][0].depth; 93 94 ALLOCATE(cpmFilename, char, strlen(catdir) + 64); 95 96 // loop over the populated input regions 97 Ncheck = 0; 98 for (i = 0; i < inlist[0].Nregions; i++) { 99 if (!inlist[0].regions[i][0].table) continue; 100 101 if (1) { 102 sprintf (cpmFilename, "%s/%s.cpm", catdir, inlist[0].regions[i][0].name); 103 cpmFtable.header = &cpmHeaderTBL; 104 105 // open cpm file 106 cpmFile = fopen(cpmFilename, "r"); 107 if (!cpmFile) continue; 108 // myAssert(cpmFile, "failed to open cpm file"); 109 110 // fprintf (stderr, "input: %s\n", inlist[0].regions[i][0].name); 111 112 // load the cpm header 113 if (!gfits_fread_header (cpmFile, &cpmHeaderPHU)) { 114 myAbort("failure to cpm header"); 115 } 116 117 // move to TBL header 118 Nbytes = cpmHeaderPHU.datasize + gfits_data_size (&cpmHeaderPHU); 119 fseeko (cpmFile, Nbytes, SEEK_SET); 120 121 // read cpm TBL header 122 if (!gfits_fread_header (cpmFile, &cpmHeaderTBL)) { 123 myAbort("can't read header for cpm table"); 124 } 125 126 // read Measure table data : format is irrelevant here */ 127 if (!gfits_fread_ftable_data (cpmFile, &cpmFtable, TRUE)) { 128 myAbort("can't read data for cpm table"); 129 } 130 131 gfits_scan(&cpmHeaderTBL, "NAXIS1", "%d", 1, &NbytesPerRow); 132 133 measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat); 134 myAssert(measure, "failed to convert ftable to measure data"); 135 136 Nvalid = (int)(cpmFtable.validsize / NbytesPerRow); 137 Nvalid = MIN(Nmeasure, Nvalid); 138 139 // examine all measurements and new objects as needed 140 for (j = 0; j < Nvalid; j++) { 141 index = measure[j].imageID; 142 if (!index) { 143 fprintf (stderr, "?"); 144 continue; 145 } 146 147 imageSeq = imageIdx[index]; 148 // XXX check the range? 149 150 detCounts[imageSeq] ++; 151 } 152 fclose(cpmFile); 153 gfits_free_header (&cpmHeaderPHU); 154 gfits_free_header (&cpmHeaderTBL); 155 free (measure); 156 157 Ncheck ++; 158 if (Ncheck % 1000 == 0) { 159 fprintf (stderr, "%s...", inlist[0].regions[i][0].name); 160 } 161 } 73 162 } 74 // read Measure table data : format is irrelevant here */ 75 if (!gfits_fread_ftable_data (cpmFile, &cpmFtable)) { 76 myAbort("can't read data for cpm table"); 163 fprintf (stderr, "\n"); 164 165 Nbad = 0; 166 for (i = 0; i < Nimage; i++) { 167 if (detCounts[i] < image[i].nstar - Ntol) { 168 fprintf (stdout, "image %s : %d vs %d\n", image[i].name, detCounts[i], image[i].nstar); 169 Nbad ++; 170 } 77 171 } 78 79 measure = FtableToMeasure (&cpmFtable, &Nmeasure, &catformat); 80 myAssert(measure, "failed to convert ftable to measure data"); 81 82 NaveMax = 0; 83 NAVERAGE = 1000; 84 ALLOCATE (average, Average, NAVERAGE); 85 memset (average, 0, NAVERAGE*sizeof(Average)); 86 87 ALLOCATE (found, int, NAVERAGE); 88 memset (found, 0, NAVERAGE*sizeof(int)); 89 90 // examine all measurements and new objects as needed 91 for (i = 0; i < Nmeasure; i++) { 92 Nave = measure[i].averef; 93 if (found[Nave]) { 94 average[Nave].Nmeasure ++; 95 myAssert(average[Nave].objID == measure[i].objID, "objIDs do not match!"); 96 myAssert(average[Nave].catID == measure[i].catID, "catIDs do not match!"); 97 continue; 98 } 99 100 if (Nave >= NAVERAGE) { 101 Nold = NAVERAGE; 102 NAVERAGE = MAX(Nave + 1000, NAVERAGE + 1000); 103 REALLOCATE (average, Average, NAVERAGE); 104 memset (&average[Nold], 0, (NAVERAGE - Nold)*sizeof(Average)); 105 106 REALLOCATE (found, int, NAVERAGE); 107 memset (&found[Nold], 0, (NAVERAGE - Nold)*sizeof(int)); 108 } 109 110 NaveMax = MAX(Nave, NaveMax); 111 112 found[Nave] = TRUE; 113 114 // we are going to leave most of the elements of average unset: they are the result of 115 // the relastro analysis for this object and can be recreated with a call to relastro 116 117 // fields we have to set: 118 119 // need to find image so we can use ccd coordinates to determine RA & DEC 120 thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID); 121 XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords); 122 123 average[Nave].Nmeasure = 1; 124 average[Nave].Nmissing = 0; 125 126 // assume the resulting table set is unsorted 127 average[Nave].measureOffset = -1; 128 average[Nave].missingOffset = -1; 129 average[Nave].extendOffset = -1; 130 131 average[Nave].objID = measure[i].objID; 132 average[Nave].catID = measure[i].catID; 133 average[Nave].extID = CreatePSPSObjectID(average[Nave].R, average[Nave].D); 172 if (!Nbad) { 173 fprintf (stderr, "no bad images found\n"); 134 174 } 135 Naverage = NaveMax + 1;136 137 // have we created all objects in the range 0 - Naverage?138 for (i = 0; i < Naverage; i++) {139 myAssert(found[i], "failed to find one");140 }141 142 // open source cpt file143 cptFileSrc = fopen(cptFilenameSrc, "r");144 myAssert(cptFileSrc, "failed to open cpt file");145 146 // load the cpt header (use for CATID, RA,DEC range, filenames)147 if (!gfits_fread_header (cptFileSrc, &cptHeaderPHU)) {148 myAbort("failure to cpt header");149 }150 151 // update the output header152 gfits_modify (&cptHeaderPHU, "NSTARS", "%d", 1, Naverage);153 gfits_modify (&cptHeaderPHU, "NMEAS", OFF_T_FMT, 1, Nmeasure);154 gfits_modify (&cptHeaderPHU, "NMISS", "%d", 1, 0);155 gfits_modify_alt (&cptHeaderPHU, "SORTED", "%t", 1, FALSE);156 157 /* convert internal to external format */158 if (!AverageToFtable (&cptFtable, average, Naverage, catformat, NULL)) {159 myAbort("trouble converting format");160 }161 162 // create and write the output file163 cptFileTgt = fopen(cptFilenameTgt, "w");164 myAssert(cptFileTgt, "failed to open cpt file");165 166 // write PHU header167 if (!gfits_fwrite_header (cptFileTgt, &cptHeaderPHU)) {168 myAbort("can't write primary header");169 }170 171 // write the PHU matrix; this is probably a NOP, do I have to keep it in?172 gfits_create_matrix (&cptHeaderPHU, &matrix);173 if (!gfits_fwrite_matrix (cptFileTgt, &matrix)) {174 myAbort("can't write primary matrix");175 }176 gfits_free_matrix (&matrix);177 178 // write the table data179 if (!gfits_fwrite_ftable_range (cptFileTgt, &cptFtable, 0, Naverage, 0, Naverage)) {180 myAbort("can't write table data");181 }182 183 fclose(cptFileTgt);184 fclose(cptFileSrc);185 fclose(cpmFile);186 175 187 176 exit (0); -
branches/eam_branches/ipp-20101103/Ohana/src/imregister/imphot/rfits.c
r7080 r29714 17 17 return (FALSE); 18 18 } 19 if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable )) {19 if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable, FALSE)) { 20 20 fprintf (stderr, "can't read table data"); 21 21 return (FALSE); -
branches/eam_branches/ipp-20101103/Ohana/src/libdvo/src/dvo_catalog_mef.c
r29001 r29714 66 66 /* read Average table data (or skip) */ 67 67 if (catalog[0].catflags & LOAD_AVES) { 68 if (!gfits_fread_ftable_data (f, &ftable )) {68 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { 69 69 if (VERBOSE) fprintf (stderr, "can't read table average data"); 70 70 return (FALSE); … … 94 94 /* read Measure table data */ 95 95 if (catalog[0].catflags & LOAD_MEAS) { 96 if (!gfits_fread_ftable_data (f, &ftable )) {96 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { 97 97 if (VERBOSE) fprintf (stderr, "can't read table measure data"); 98 98 return (FALSE); … … 119 119 /* read Missing table data */ 120 120 if (catalog[0].catflags & LOAD_MISS) { 121 if (!gfits_fread_ftable_data (f, &ftable )) {121 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { 122 122 if (VERBOSE) fprintf (stderr, "can't read table missing data"); 123 123 return (FALSE); … … 149 149 /* read secfilt table data */ 150 150 if (catalog[0].catflags & LOAD_SECF) { 151 if (!gfits_fread_ftable_data (f, &ftable )) {151 if (!gfits_fread_ftable_data (f, &ftable, FALSE)) { 152 152 if (VERBOSE) fprintf (stderr, "can't read table secfilt data"); 153 153 return (FALSE); -
branches/eam_branches/ipp-20101103/Ohana/src/libdvo/src/dvo_catalog_split.c
r29001 r29714 218 218 } 219 219 /* read Average table data : format is irrelevant here */ 220 if (!gfits_fread_ftable_data (catalog[0].f, &ftable )) {220 if (!gfits_fread_ftable_data (catalog[0].f, &ftable, FALSE)) { 221 221 if (VERBOSE) fprintf (stderr, "can't read table average data"); 222 222 return (FALSE); … … 249 249 // XXX this allows an empty Measure catalog with non-empty Average catalog : is that OK? 250 250 /* read Measure table data */ 251 if (!gfits_fread_ftable_data (catalog[0].measure_catalog[0].f, &ftable )) {251 if (!gfits_fread_ftable_data (catalog[0].measure_catalog[0].f, &ftable, FALSE)) { 252 252 if (VERBOSE) fprintf (stderr, "can't read table measure data\n"); 253 253 return (FALSE); … … 279 279 if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_MISS)) { 280 280 /* read Missing table data */ 281 if (!gfits_fread_ftable_data (catalog[0].missing_catalog[0].f, &ftable )) {281 if (!gfits_fread_ftable_data (catalog[0].missing_catalog[0].f, &ftable, FALSE)) { 282 282 if (VERBOSE) fprintf (stderr, "can't read table missing data\n"); 283 283 return (FALSE); … … 313 313 if ((status != DVO_CAT_OPEN_EMPTY) && (catalog[0].catflags & LOAD_SECF)) { 314 314 /* read secfilt table data */ 315 if (!gfits_fread_ftable_data (catalog[0].secfilt_catalog[0].f, &ftable )) {315 if (!gfits_fread_ftable_data (catalog[0].secfilt_catalog[0].f, &ftable, FALSE)) { 316 316 if (VERBOSE) fprintf (stderr, "can't read table secfilt data\n"); 317 317 return (FALSE); -
branches/eam_branches/ipp-20101103/Ohana/src/libdvo/src/fits_db.c
r28246 r29714 83 83 return (FALSE); 84 84 } 85 if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable )) {85 if (!gfits_fread_ftable_data (db[0].f, &db[0].ftable, FALSE)) { 86 86 fprintf (stderr, "can't read table data"); 87 87 gfits_db_free (db); -
branches/eam_branches/ipp-20101103/Ohana/src/libfits/include/gfitsio.h
r29537 r29714 64 64 char *buffer; 65 65 off_t datasize; 66 off_t validsize; 66 67 } FTable; 67 68 … … 172 173 int gfits_define_table_column PROTO((Header *header, char *format, char *label, char *comment, char *unit)); 173 174 int gfits_fread_ftable PROTO((FILE *f, FTable *ftable, char *extname)); 174 int gfits_fread_ftable_data PROTO((FILE *f, FTable *ftable ));175 int gfits_fread_ftable_data PROTO((FILE *f, FTable *ftable, int padIfShort)); 175 176 int gfits_fread_ftable_range PROTO((FILE *f, FTable *ftable, off_t start, off_t Nrows)); 176 177 int gfits_fread_vtable PROTO((FILE *f, VTable *vtable, char *extname, off_t Nrow, off_t *row)); -
branches/eam_branches/ipp-20101103/Ohana/src/libfits/table/F_read_T.c
r28241 r29714 36 36 gfits_scan (header, "EXTNAME", "%s", 1, tname); 37 37 if (!strcmp (tname, extname)) { 38 if (gfits_fread_ftable_data (f, table )) return (TRUE);38 if (gfits_fread_ftable_data (f, table, FALSE)) return (TRUE); 39 39 gfits_free_header (header); 40 40 return (FALSE); … … 50 50 51 51 /*********************** fits read ftable data ***********************************/ 52 int gfits_fread_ftable_data (FILE *f, FTable *table ) {52 int gfits_fread_ftable_data (FILE *f, FTable *table, int padIfShort) { 53 53 54 54 off_t Nbytes, Nread; … … 65 65 if (Nread < gfits_data_min_size (table[0].header)) { 66 66 fprintf (stderr, "error: fits read error in %s, read "OFF_T_FMT", need "OFF_T_FMT"\n", __func__, Nread, gfits_data_min_size (table[0].header)); 67 gfits_free_table (table); 68 return (FALSE); 67 if (padIfShort) { 68 memset (&table[0].buffer[Nread], 0, Nbytes - Nread); 69 fprintf (stderr, "warning: file missing data, padding with zeros: USE AT YOUR OWN RISK!\n"); 70 table[0].validsize = Nread; 71 table[0].datasize = Nbytes; 72 return (TRUE); 73 } else { 74 gfits_free_table (table); 75 return (FALSE); 76 } 69 77 } 70 78 fprintf (stderr, "warning: file missing pad\n"); 71 79 } 80 table[0].validsize = Nread; 72 81 table[0].datasize = Nbytes; 73 82 return (TRUE); -
branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/rd.c
r28241 r29714 184 184 ftable.header[0].buffer = NULL; 185 185 gfits_copy_header (&buf[0].header, ftable.header); 186 status = gfits_fread_ftable_data (f, &ftable ); // this just reads the bytes (not even a SWAP)186 status = gfits_fread_ftable_data (f, &ftable, FALSE); // this just reads the bytes (not even a SWAP) 187 187 status = gfits_uncompress_image (&buf[0].header, &buf[0].matrix, &ftable); 188 188 // uncompressing the image leaves the format as an extension -
branches/eam_branches/ipp-20101103/Ohana/src/opihi/cmd.data/read_vectors.c
r29540 r29714 160 160 161 161 off_t Nbytes; 162 int i, j, k, N, Nextend, Ny, Binary, vecType ;162 int i, j, k, N, Nextend, Ny, Binary, vecType, padIfShort; 163 163 char type[16], ID[80], *CCDKeyword; 164 164 FTable table; … … 174 174 CCDKeyword = strcreate (argv[N]); 175 175 remove_argument (N, &argc, argv); 176 } 177 178 padIfShort = FALSE; 179 if ((N = get_argument (argc, argv, "-pad-if-short"))) { 180 remove_argument (N, &argc, argv); 181 padIfShort = TRUE; 176 182 } 177 183 … … 205 211 } 206 212 if (!gfits_load_header (f, &header)) ESCAPE ("error reading header for extension"); 207 if (!gfits_fread_ftable_data (f, &table )) ESCAPE ("error reading table for extension");213 if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension"); 208 214 209 215 } else { … … 236 242 continue; 237 243 } 238 if (!gfits_fread_ftable_data (f, &table )) ESCAPE ("error reading table for extension");244 if (!gfits_fread_ftable_data (f, &table, padIfShort)) ESCAPE ("error reading table for extension"); 239 245 break; 240 246 }
Note:
See TracChangeset
for help on using the changeset viewer.
