Changeset 29787
- Timestamp:
- Nov 16, 2010, 3:23:17 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src
- Files:
-
- 3 edited
-
dvorepairFixCPT.c (modified) (5 diffs)
-
dvoverify.c (modified) (1 diff)
-
help.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvorepairFixCPT.c
r29779 r29787 8 8 // * obj_id, cat_id are defined in detection 9 9 10 int FixCPTfile (char *rootname, Image *image, off_t Nimage); 11 10 12 int dvorepairFixCPT (int argc, char **argv) { 11 13 14 int i, j, N, Nfiles, NFILES; 15 off_t Nimage; 12 16 FITS_DB db; // database handle pointing to input image table 13 14 off_t Nmeasure, Nimage; 15 int i, N, Nbytes, NaveMax, Naverage, NAVERAGE, Nave, Nold; 16 int *found; 17 18 Image *image, *thisImage; 19 Average *average; 20 Measure *measure; 21 22 Matrix matrix; 23 24 char *cpmFilename, *cptFilenameSrc, *cptFilenameTgt, *imageFilename; 25 26 Header cptHeaderPHU, cptHeaderTBL; 27 Header cpmHeaderPHU, cpmHeaderTBL; 28 FTable cpmFtable, cptFtable; 29 30 FILE *cptFileSrc = NULL; 31 FILE *cptFileTgt = NULL; 32 FILE *cpmFile = NULL; 33 34 char catformat; 17 Image *image; 18 char *listFilename, *imageFilename; 19 char **files; 35 20 36 21 N = get_argument (argc, argv, "-fix-cpt"); … … 38 23 remove_argument (N, &argc, argv); 39 24 40 if (argc != 5) {41 fprintf (stderr, "USAGE: dvorepair -fix-cpt (images) ( cpm) (cptInput) (cptOutput)\n");25 if (argc != 3) { 26 fprintf (stderr, "USAGE: dvorepair -fix-cpt (images) (filelist)\n"); 42 27 exit (2); 43 28 } 44 29 45 30 imageFilename = argv[1]; 46 cpmFilename = argv[2]; 47 cptFilenameSrc = argv[3]; 48 cptFilenameTgt = argv[4]; 49 50 cpmFtable.header = &cpmHeaderTBL; 51 cptFtable.header = &cptHeaderTBL; 31 listFilename = argv[2]; 52 32 53 33 // XXX don't bother locking for now: this is totally manual.. … … 57 37 BuildChipMatch (image, Nimage); 58 38 39 FILE *file = fopen (listFilename, "r"); 40 myAssert(file, "failed to open list"); 41 42 Nfiles = 0; 43 NFILES = 100; 44 ALLOCATE(files, char *, NFILES); 45 for (i = 0; i < NFILES; i++) { 46 ALLOCATE (files[i], char, 256); 47 memset (files[i], 0, 256); 48 } 49 50 for (i = 0; TRUE; i++) { 51 if (fscanf (file, "%s", files[i]) == EOF) { 52 break; 53 } 54 if (i == NFILES - 1) { 55 NFILES += 100; 56 REALLOCATE(files, char *, NFILES); 57 for (j = i + 1; j < NFILES; j++) { 58 ALLOCATE (files[j], char, 256); 59 memset (files[j], 0, 256); 60 } 61 } 62 } 63 Nfiles = i; 64 65 for (i = 0; i < Nfiles; i++) { 66 FixCPTfile(files[i], image, Nimage); 67 } 68 69 exit (0); 70 } 71 72 // fix the CPT file. in the process, we rewrite the CPM file so that the averef entries are correctly set. 73 int FixCPTfile (char *rootFilename, Image *image, off_t Nimage) { 74 75 char cptFilenameSrc[256], cptFilenameTgt[256], cpsFilenameSrc[256], cpsFilenameTgt[256], cpmFilenameSrc[256], cpmFilenameTgt[256]; 76 77 Header cpmHeaderPHU, cpmHeaderTBL; 78 FTable cpmFtable; 79 FILE *cpmFile = NULL; 80 81 off_t Nbytes, Nmeasure; 82 83 Measure *measure; 84 85 Matrix matrix; 86 87 char catformat; 88 89 cpmFtable.header = &cpmHeaderTBL; 90 91 sprintf (cpmFilenameSrc, "%s.cpm", rootFilename); 92 sprintf (cpmFilenameTgt, "%s.cpm.fixed", rootFilename); 93 sprintf (cptFilenameSrc, "%s.cpt", rootFilename); 94 sprintf (cptFilenameTgt, "%s.cpt.fixed", rootFilename); 95 sprintf (cpsFilenameSrc, "%s.cps", rootFilename); 96 sprintf (cpsFilenameTgt, "%s.cps.fixed", rootFilename); 97 59 98 // open cpm file 60 cpmFile = fopen(cpmFilename , "r");99 cpmFile = fopen(cpmFilenameSrc, "r"); 61 100 myAssert(cpmFile, "failed to open cpm file"); 62 101 … … 75 114 } 76 115 // read Measure table data : format is irrelevant here */ 116 // XXX this should not be running on broken CPM files 77 117 if (!gfits_fread_ftable_data (cpmFile, &cpmFtable, FALSE)) { 78 118 myAbort("can't read data for cpm table"); … … 82 122 myAssert(measure, "failed to convert ftable to measure data"); 83 123 84 NaveMax = 0; 85 NAVERAGE = 1000; 86 ALLOCATE (average, Average, NAVERAGE); 87 memset (average, 0, NAVERAGE*sizeof(Average)); 124 // the CPT and CPS tables need to be regenerated. This must happen first because, in the process, we also update measure->averef 125 RepairTableCPT(cptFilenameSrc, cptFilenameTgt, cpsFilenameSrc, cpsFilenameTgt, measure, Nmeasure, image, Nimage, catformat); 88 126 89 ALLOCATE (found, int, NAVERAGE); 90 memset (found, 0, NAVERAGE*sizeof(int)); 91 92 // examine all measurements and new objects as needed 93 for (i = 0; i < Nmeasure; i++) { 94 Nave = measure[i].averef; 95 if (found[Nave]) { 96 average[Nave].Nmeasure ++; 97 myAssert(average[Nave].objID == measure[i].objID, "objIDs do not match!"); 98 myAssert(average[Nave].catID == measure[i].catID, "catIDs do not match!"); 99 continue; 100 } 101 102 if (Nave >= NAVERAGE) { 103 Nold = NAVERAGE; 104 NAVERAGE = MAX(Nave + 1000, NAVERAGE + 1000); 105 REALLOCATE (average, Average, NAVERAGE); 106 memset (&average[Nold], 0, (NAVERAGE - Nold)*sizeof(Average)); 107 108 REALLOCATE (found, int, NAVERAGE); 109 memset (&found[Nold], 0, (NAVERAGE - Nold)*sizeof(int)); 110 } 111 112 NaveMax = MAX(Nave, NaveMax); 113 114 found[Nave] = TRUE; 115 116 // we are going to leave most of the elements of average unset: they are the result of 117 // the relastro analysis for this object and can be recreated with a call to relastro 118 119 // fields we have to set: 120 121 // need to find image so we can use ccd coordinates to determine RA & DEC 122 thisImage = MatchImage (image, Nimage, measure[i].t, measure[i].photcode, measure[i].imageID); 123 XY_to_RD (&average[Nave].R, &average[Nave].D, measure[i].Xccd, measure[i].Yccd, &thisImage[0].coords); 124 125 average[Nave].Nmeasure = 1; 126 average[Nave].Nmissing = 0; 127 128 // assume the resulting table set is unsorted 129 average[Nave].measureOffset = -1; 130 average[Nave].missingOffset = -1; 131 average[Nave].extendOffset = -1; 132 133 average[Nave].objID = measure[i].objID; 134 average[Nave].catID = measure[i].catID; 135 average[Nave].extID = CreatePSPSObjectID(average[Nave].R, average[Nave].D); 136 } 137 Naverage = NaveMax + 1; 138 139 // have we created all objects in the range 0 - Naverage? 140 for (i = 0; i < Naverage; i++) { 141 myAssert(found[i], "failed to find one"); 142 } 143 144 // open source cpt file 145 cptFileSrc = fopen(cptFilenameSrc, "r"); 146 myAssert(cptFileSrc, "failed to open cpt file"); 147 148 // load the cpt header (use for CATID, RA,DEC range, filenames) 149 if (!gfits_fread_header (cptFileSrc, &cptHeaderPHU)) { 150 myAbort("failure to cpt header"); 151 } 152 153 // update the output header 154 gfits_modify (&cptHeaderPHU, "NSTARS", "%d", 1, Naverage); 155 gfits_modify (&cptHeaderPHU, "NMEAS", OFF_T_FMT, 1, Nmeasure); 156 gfits_modify (&cptHeaderPHU, "NMISS", "%d", 1, 0); 157 gfits_modify_alt (&cptHeaderPHU, "SORTED", "%t", 1, FALSE); 158 159 /* convert internal to external format */ 160 if (!AverageToFtable (&cptFtable, average, Naverage, catformat, NULL)) { 127 // convert internal to external format 128 if (!MeasureToFtable (&cpmFtable, measure, Nmeasure, catformat)) { 161 129 myAbort("trouble converting format"); 162 130 } 163 131 164 132 // create and write the output file 165 cp tFileTgt = fopen(cptFilenameTgt, "w");166 myAssert(cp tFileTgt, "failed to open cpt file");167 133 cpmFile = fopen(cpmFilenameTgt, "w"); 134 myAssert(cpmFile, "failed to open cpt file"); 135 168 136 // write PHU header 169 if (!gfits_fwrite_header (cp tFileTgt, &cptHeaderPHU)) {137 if (!gfits_fwrite_header (cpmFile, &cpmHeaderPHU)) { 170 138 myAbort("can't write primary header"); 171 139 } 172 140 173 141 // write the PHU matrix; this is probably a NOP, do I have to keep it in? 174 gfits_create_matrix (&cp tHeaderPHU, &matrix);175 if (!gfits_fwrite_matrix (cp tFileTgt, &matrix)) {142 gfits_create_matrix (&cpmHeaderPHU, &matrix); 143 if (!gfits_fwrite_matrix (cpmFile, &matrix)) { 176 144 myAbort("can't write primary matrix"); 177 145 } 178 146 gfits_free_matrix (&matrix); 179 147 180 148 // write the table data 181 if (!gfits_fwrite_ftable_range (cp tFileTgt, &cptFtable, 0, Naverage, 0, Naverage)) {149 if (!gfits_fwrite_ftable_range (cpmFile, &cpmFtable, 0, Nmeasure, 0, Nmeasure)) { 182 150 myAbort("can't write table data"); 183 151 } 152 153 gfits_free_header (&cpmHeaderPHU); 154 gfits_free_header (&cpmHeaderTBL); 155 free (measure); 156 fclose(cpmFile); 184 157 185 fclose(cptFileTgt); 186 fclose(cptFileSrc); 187 fclose(cpmFile); 188 189 exit (0); 158 return TRUE; 190 159 } -
branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/dvoverify.c
r29786 r29787 81 81 if (!inlist[0].regions[i][0].table) continue; 82 82 83 //if (i % 1000 == 0) fprintf (stderr, ".");83 if (i % 1000 == 0) fprintf (stderr, "."); 84 84 85 85 sprintf (filename, "%s/%s.cpt", catdir, inlist[0].regions[i][0].name); -
branches/eam_branches/ipp-20101103/Ohana/src/dvomerge/src/help.c
r29779 r29787 98 98 99 99 fprintf (stderr, "USAGE\n"); 100 fprintf (stderr, " dvorepair -fix-cpt (images) ( cpm) (cptInput) (cptOutput) - regenerate a specific cpt file from the cpm file\n");100 fprintf (stderr, " dvorepair -fix-cpt (images) (rootlist) - regenerate cpt & cps files from the cpm files\n"); 101 101 fprintf (stderr, " dvorepair -images-vs-measures (catdir) (Ntol) - find images with too many missing detections\n"); 102 102 fprintf (stderr, " dvorepair -delete-image-list (catdir) (deleteList) - delete a set of images based on image IDs (output from -images-vs-measures)\n");
Note:
See TracChangeset
for help on using the changeset viewer.
