Changeset 7889
- Timestamp:
- Jul 12, 2006, 4:24:06 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ppFringe/src/ppFringeLoop.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppFringe/src/ppFringeLoop.c
r7838 r7889 9 9 ) 10 10 { 11 ps FitsWriteBlank(data->outFile, NULL);11 psRandom *rng = NULL; // Random number generator 12 12 13 // Set up output header 14 const char *detId = psMetadataLookupStr(NULL, config->arguments, "-detid"); // Detector ID, for header 15 const char *classId = psMetadataLookupStr(NULL, config->arguments, "-classid"); // Class ID, for header 16 psMetadata *outHeader = psMetadataAlloc(); // Header for output 17 if (detId && strlen(detId) > 0) { 18 psMetadataAddStr(outHeader, PS_LIST_TAIL, "DETID", 0, "Detector ID for this image.", detId); 19 } 20 if (classId && strlen(classId) > 0) { 21 psMetadataAddStr(outHeader, PS_LIST_TAIL, "CLASSID", 0, "Class ID for this image.", classId); 22 } 23 24 // Get table of contents for the output FITS file 25 psMetadata *contents = psFitsReadHeaderSet(NULL, data->outFile); 26 #if 0 27 psMetadataPrint(stdout, contents, 0); 28 exit(EXIT_FAILURE); 29 #endif 30 if (!contents || contents->list->n == 0) { 31 psFitsWriteBlank(data->outFile, NULL); 32 } 33 34 // Iterate through the FPA 13 35 pmFPA *fpa = data->inFPA; // The FPA of interest 14 36 psArray *chips = fpa->chips; // Array of component chips … … 50 72 } 51 73 52 // Create points to measure fringes 53 pmFringeRegions *regions = pmFringeRegionsAlloc(data->numPoints, data->xWidth, data->yWidth, 54 data->xSmooth, data->ySmooth); 55 if (!pmFringeRegionsCreatePoints(regions, readout->image)) { 56 psLogMsg(__func__, PS_LOG_WARN, "Unable to create fringe regions for chip %s cell %s --- " 74 // Look for this chip/cell in the output file 75 pmFringeRegions *regions = NULL; // Points at which to measure fringes 76 bool preDefined = false; // Are the regions defined in the output file? 77 psString extname = NULL; 78 psStringAppend(&extname, "%s_%s", chipName, cellName); 79 if (contents && contents->list->n > 0) { 80 bool mdok; // Status of MD lookup 81 psMetadata *header = psMetadataLookupMD(&mdok, contents, extname); // Header 82 if (mdok && header) { 83 regions = pmFringeRegionsReadFits(NULL, data->outFile, extname); 84 if (regions) { 85 preDefined = true; 86 } else { 87 psLogMsg(__func__, PS_LOG_WARN, "Unable to read fringe regions for chip %s cell %s " 88 " --- will generate new regions.\n", chipName, cellName); 89 } 90 } 91 } 92 93 // Otherwise, generate one ourselves 94 if (!regions) { 95 if (!rng) { 96 rng = psRandomAlloc(PS_RANDOM_TAUS, 0); 97 } 98 // Create points to measure fringes 99 regions = pmFringeRegionsAlloc(data->numPoints, data->xWidth, data->yWidth, 100 data->xSmooth, data->ySmooth); 101 if (!pmFringeRegionsCreatePoints(regions, readout->image, rng)) { 102 psLogMsg(__func__, PS_LOG_WARN, "Unable to create fringe regions for chip %s cell %s --- " 103 "ignored.\n", chipName, cellName); 104 psFree(extname); 105 psFree(regions); 106 pmCellFreeData(cell); 107 continue; 108 } 109 } 110 111 // Measure fringes 112 pmFringeStats *fringeStats = pmFringeStatsMeasure(regions, readout, data->maskVal); 113 psFree(regions); // Drop reference 114 if (!fringeStats) { 115 psLogMsg(__func__, PS_LOG_WARN, "Unable to measure fringes for chip %s cell %s --- " 57 116 "ignored.\n", chipName, cellName); 58 psFree(regions);59 117 pmCellFreeData(cell); 60 118 continue; 61 119 } 62 120 63 // Measure fringes64 pmFringeStats *fringeStats = pmFringeStatsMeasure(regions, readout, data->maskVal);65 if (!fringeStats) {66 psLogMsg(__func__, PS_LOG_WARN, "Unable to measure fringes for chip %s cell %s --- "121 // Write fringe regions 122 if (!preDefined && 123 !pmFringeRegionsWriteFits(data->outFile, NULL, fringeStats->regions, extname)) { 124 psLogMsg(__func__, PS_LOG_WARN, "Unable to write fringe regions for chip %s cell %s --- " 67 125 "ignored.\n", chipName, cellName); 68 psFree(regions); 126 psFree(fringeStats); 127 psFree(extname); 69 128 pmCellFreeData(cell); 70 129 continue; 71 130 } 72 131 132 int version = 0; // Version number 133 if (preDefined) { 134 // Find the lowest possible version number that isn't already taken 135 psMetadata *header = NULL; // Header from the table of contents 136 bool mdok = true; // Status of MD lookup 137 do { 138 version++; 139 psString checkName = NULL; // Extension name to check 140 psStringAppend(&checkName, "%s:%d", extname, version); 141 header = psMetadataLookupMD(&mdok, contents, checkName); 142 psFree(checkName); 143 } while (mdok && header); 144 } 145 73 146 // Write fringe measurements 74 psString extname = NULL; 75 psStringAppend(&extname, "%s_%s", chipName, cellName); 76 if (!pmFringeStatsWriteFits(data->outFile, fringeStats, extname)) { 147 psStringAppend(&extname, ":%d", version); 148 if (!pmFringeStatsWriteFits(data->outFile, outHeader, fringeStats, extname)) { 77 149 psLogMsg(__func__, PS_LOG_WARN, "Unable to write fringe measurements for chip %s cell %s --- " 78 150 "ignored.\n", chipName, cellName); 79 psFree(regions);80 151 psFree(fringeStats); 152 psFree(extname); 81 153 pmCellFreeData(cell); 82 154 continue; 83 155 } 84 156 85 psFree(regions);86 157 psFree(fringeStats); 158 psFree(extname); 87 159 pmCellFreeData(cell); 88 160 } … … 90 162 } 91 163 pmFPAFreeData(fpa); 164 165 psFree(rng); 166 psFree(contents); 167 psFree(outHeader); 168 169 return; 92 170 }
Note:
See TracChangeset
for help on using the changeset viewer.
