Changeset 13640
- Timestamp:
- Jun 5, 2007, 9:36:41 AM (19 years ago)
- Location:
- trunk/ppStats/src
- Files:
-
- 5 edited
-
ppStats.c (modified) (2 diffs)
-
ppStatsLoop.c (modified) (18 diffs)
-
ppStatsLoop.h (modified) (1 diff)
-
ppStatsSetupFromArgs.c (modified) (6 diffs)
-
ppStatsStandAlone.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStats/src/ppStats.c
r8749 r13640 15 15 ) 16 16 { 17 psExit status; 18 17 19 // Get the options, open the files 18 20 ppStatsData *data = ppStatsSetupFromRecipe(NULL, config); … … 29 31 30 32 // Go through the FPA and do the hard work 31 out = ppStatsLoop(out, data, config); 33 psMetadata *result = ppStatsLoop(&status, out, data, config); 34 if (status != PS_EXIT_SUCCESS) { 35 psError (PS_ERR_UNKNOWN, false, "trouble getting stats\n"); 36 psFree(result); 37 psFree(data); 38 return (NULL); 39 } 32 40 33 41 psFree(data); 34 35 return out; 42 return result; 36 43 } -
trunk/ppStats/src/ppStatsLoop.c
r13607 r13640 68 68 69 69 70 static voidcellStats(psMetadata *chipResults, // Metadata holding the chip results71 pmCell *cell, // Cell for which to get statistics72 psFits *fits, // FITS file handle73 ppStatsData *data,// The data74 const pmConfig *config // Configuration70 static psExit cellStats(psMetadata *chipResults, // Metadata holding the chip results 71 pmCell *cell, // Cell for which to get statistics 72 psFits *fits, // FITS file handle 73 ppStatsData *data,// The data 74 const pmConfig *config // Configuration 75 75 ) 76 76 { 77 77 assert(chipResults); 78 78 assert(cell); 79 assert(fits); 79 80 assert(data); 80 81 assert(config); … … 84 85 // Check to see if this is a cell of interest 85 86 if (!doThis(data->cells, cellName)) { 86 return ;87 return PS_EXIT_SUCCESS; 87 88 } 88 89 … … 95 96 96 97 if (psListLength(data->headers) > 0 && cell->hdu) { 97 if (fits && !pmCellReadHeader(cell, fits)) { 98 goto cellDone; 98 if (!pmCellReadHeader(cell, fits)) { 99 psError (PS_ERR_IO, false, "trouble reading cell header\n"); 100 return PS_EXIT_DATA_ERROR; 99 101 } 100 102 pmHDU *hdu = cell->hdu; // HDU for headers … … 102 104 } 103 105 if (psListLength(data->concepts) > 0) { 104 if (fits && !pmCellReadHeader(cell, fits)) { 105 goto cellDone; 106 if (!pmCellReadHeader(cell, fits)) { 107 psError (PS_ERR_IO, false, "trouble reading cell header\n"); 108 return PS_EXIT_DATA_ERROR; 106 109 } 107 110 pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_ALL, false, config->database); … … 120 123 pmHDU *hdu = pmHDUFromCell(cell); // HDU for cell 121 124 if (!hdu || hdu->blankPHU) { 122 goto cellDone; 123 } 124 125 if (fits && !pmCellRead(cell, fits, config->database)) { 126 psLogMsg(__func__, PS_LOG_WARN, "Unable to read cell %s\n", cellName); 127 goto cellDone; 125 psError (PS_ERR_UNKNOWN, false, "trouble finding HDU for cell\n"); 126 return PS_EXIT_CONFIG_ERROR; 127 } 128 129 if (!pmCellRead(cell, fits, config->database)) { 130 psError (PS_ERR_IO, false, "trouble reading cell data\n"); 131 return PS_EXIT_DATA_ERROR; 128 132 } 129 133 130 134 psArray *readouts = cell->readouts; // Array of component readouts 131 135 if (readouts->n == 0) { 136 psLogMsg(__func__, PS_LOG_WARN, "No readouts present in cell %s --- skipping\n", cellName); 132 137 goto cellDone; 133 138 } … … 138 143 pmReadout *readout = readouts->data[0]; // The readout of interest 139 144 if (!readout->image) { 140 psLogMsg(__func__, PS_LOG_WARN, "No image associated with readout in cell %s --- " 141 "ignored.\n", cellName); 145 psLogMsg(__func__, PS_LOG_WARN, "No image associated with readout in cell %s --- ignored.\n", cellName); 142 146 goto cellDone; 143 147 } … … 146 150 if (data->sample <= 0.0) { 147 151 if (!psImageStats(data->stats, readout->image, readout->mask, data->maskVal)) { 148 psLogMsg(__func__, PS_LOG_WARN, "Unable to perform statistics on cell %s --- " 149 "ignored.\n", cellName); 152 psLogMsg(__func__, PS_LOG_WARN, "Unable to perform statistics on cell %s --- ignored.\n", cellName); 150 153 goto statsDone; 151 154 } … … 216 219 } 217 220 218 if (!get_nSatPixels && !get_fSatPixels) goto cellDone; 221 if (!get_nSatPixels && !get_fSatPixels) { 222 goto cellDone; 223 } 219 224 220 225 // Get the "concepts" of interest … … 222 227 if (!mdok || isnan(saturation)) { 223 228 psLogMsg(__func__, PS_LOG_WARN, "CELL.SATURATION is not set --- unable to measure N_SAT_PIXELS.\n"); 229 if (get_nSatPixels) psMetadataAddS32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_NUM", 0, NULL, 0); 230 if (get_fSatPixels) psMetadataAddF32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_FRAC", 0, NULL, NAN); 224 231 goto cellDone; 225 232 } … … 240 247 // Add the cell results to the chip 241 248 addToHierarchy(cellResults, chipResults, cellName, "Results for cell"); 242 if (fits) { 243 pmCellFreeData(cell); 244 } 245 return; 246 } 247 248 static bool chipStats(psMetadata *fpaResults, // Metadata holding the fpa results 249 pmChip *chip, // Chip for which to get statistics 250 psFits *fits, // FITS file handle 251 pmFPAview *view, // View for analysis 252 ppStatsData *data,// The data 253 const pmConfig *config // Configuration 249 pmCellFreeData(cell); 250 return PS_EXIT_SUCCESS; 251 } 252 253 static psExit chipStats(psMetadata *fpaResults, // Metadata holding the fpa results 254 pmChip *chip, // Chip for which to get statistics 255 psFits *fits, // FITS file handle 256 pmFPAview *view, // View for analysis 257 ppStatsData *data,// The data 258 const pmConfig *config // Configuration 254 259 ) 255 260 { 256 261 assert(fpaResults); 257 262 assert(chip); 263 assert(fits); 258 264 assert(view); 259 265 assert(data); 260 266 assert(config); 261 267 268 psExit result = PS_EXIT_SUCCESS; 269 262 270 const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip 263 271 264 272 // Check to see if this is a chip of interest 265 273 if (!doThis(data->chips, chipName)) { 266 return true;274 return PS_EXIT_SUCCESS; 267 275 } 268 276 … … 271 279 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Desired cell view (%d) doesn't match " 272 280 "number of cells (%ld)\n", view->cell, cells->n); 273 return false;281 return PS_EXIT_CONFIG_ERROR; 274 282 } 275 283 … … 282 290 283 291 if (psListLength(data->headers) > 0 && chip->hdu) { 284 if (fits && !pmChipReadHeader(chip, fits)) { 285 goto chipDone; 292 if (!pmChipReadHeader(chip, fits)) { 293 psError (PS_ERR_IO, false, "trouble reading chip header\n"); 294 return PS_EXIT_DATA_ERROR; 286 295 } 287 296 pmHDU *hdu = chip->hdu; // HDU for headers … … 289 298 } 290 299 if (psListLength(data->concepts) > 0) { 291 if (fits && !pmChipReadHeader(chip, fits)) { 292 goto chipDone; 300 if (!pmChipReadHeader(chip, fits)) { 301 psError (PS_ERR_IO, false, "trouble reading chip header\n"); 302 return PS_EXIT_DATA_ERROR; 293 303 } 294 304 pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_ALL, false, false, config->database); … … 298 308 if (view->cell >= 0) { 299 309 pmCell *cell = cells->data[view->cell]; // Cell of interest 300 cellStats(chipResults, cell, fits, data, config); 301 goto chipDone; 310 result = cellStats(chipResults, cell, fits, data, config); 311 if (result != PS_EXIT_SUCCESS) { 312 psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", view->cell); 313 pmChipFreeData(chip); 314 return result; 315 } 316 addToHierarchy(chipResults, fpaResults, chipName, "Results for chip"); 317 pmChipFreeData(chip); 318 return PS_EXIT_SUCCESS; 302 319 } 303 320 … … 305 322 for (int i = 0; i < cells->n; i++) { 306 323 pmCell *cell = cells->data[i]; // Cell of interest 307 cellStats(chipResults, cell, fits, data, config); 308 } 309 310 chipDone: 324 result = cellStats(chipResults, cell, fits, data, config); 325 if (result != PS_EXIT_SUCCESS) { 326 psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", i); 327 pmChipFreeData(chip); 328 return result; 329 } 330 } 331 311 332 addToHierarchy(chipResults, fpaResults, chipName, "Results for chip"); 312 if (fits) { 313 pmChipFreeData(chip); 314 } 315 316 return true; 317 } 318 319 320 psMetadata *ppStatsLoop(psMetadata *fpaResults, // Metadata to hold the FPA results 333 pmChipFreeData(chip); 334 return PS_EXIT_SUCCESS; 335 } 336 337 psMetadata *ppStatsLoop(psExit *result, 338 psMetadata *fpaResults, // Metadata to hold the FPA results 321 339 ppStatsData *data, // The data 322 340 const pmConfig *config // Configuration … … 327 345 psFits *fits = data->fits; // FITS file handle 328 346 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 329 330 pmFPAview *view = psMemIncrRefCounter(data->view); // View for analysis 331 if (!view) { 332 view = pmFPAviewAlloc(0); 333 } 334 335 if (!fpaResults) { 336 fpaResults = psMetadataAlloc(); 347 PS_ASSERT_PTR_NON_NULL(fits, NULL); 348 349 *result = PS_EXIT_SUCCESS; 350 351 // allocate or bump the ref counter (so we can just free below) 352 pmFPAview *view = (data->view) ? psMemIncrRefCounter(data->view) : pmFPAviewAlloc(0); 353 354 // allocate a new one if needed 355 psMetadata *newResults = psMemIncrRefCounter(fpaResults); 356 if (!newResults) { 357 newResults = psMetadataAlloc(); 337 358 } 338 359 339 360 // Iterate through the FPA 340 361 if (psListLength(data->headers) > 0 && fpa->hdu) { 341 if (fits) { 342 pmFPAReadHeader(fpa, fits); 343 } 362 pmFPAReadHeader(fpa, fits); 344 363 pmHDU *hdu = fpa->hdu; // HDU for headers 345 getMetadata( fpaResults, hdu->header, data->headers);364 getMetadata(newResults, hdu->header, data->headers); 346 365 } 347 366 if (psListLength(data->concepts) > 0) { 348 if (fits) { 349 pmFPAReadHeader(fpa, fits); 350 } 367 pmFPAReadHeader(fpa, fits); 351 368 pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_ALL, false, config->database); 352 getMetadata( fpaResults, fpa->concepts, data->concepts);369 getMetadata(newResults, fpa->concepts, data->concepts); 353 370 } 354 371 … … 356 373 if (view->chip >= 0) { 357 374 pmChip *chip = chips->data[view->chip]; // Chip of interest 358 chipStats(fpaResults, chip, fits, view, data, config); 359 goto fpaDone; 375 *result = chipStats(newResults, chip, fits, view, data, config); 376 if (*result != PS_EXIT_SUCCESS) { 377 psError(PS_ERR_UNKNOWN, false, "trouble with stats for cell %d\n", view->cell); 378 psFree (view); 379 psFree (newResults); 380 return NULL; 381 } 382 pmFPAFreeData(fpa); 383 psFree(view); 384 return newResults; 360 385 } 361 386 … … 363 388 for (int i = 0; i < chips->n; i++) { 364 389 pmChip *chip = chips->data[i]; // Chip of interest 365 chipStats(fpaResults, chip, fits, view, data, config); 366 } 367 368 fpaDone: 369 if (fits) { 370 pmFPAFreeData(fpa); 371 } 390 *result = chipStats(newResults, chip, fits, view, data, config); 391 if (*result != PS_EXIT_SUCCESS) { 392 psError(PS_ERR_UNKNOWN, false, "trouble with stats for chip %d\n", i); 393 psFree (view); 394 psFree (newResults); 395 return NULL; 396 } 397 } 398 399 pmFPAFreeData(fpa); 372 400 psFree(view); 373 374 return fpaResults; 375 } 401 return newResults; 402 } -
trunk/ppStats/src/ppStatsLoop.h
r8337 r13640 6 6 7 7 // Loop over the input image and do all the hard work 8 psMetadata *ppStatsLoop(psMetadata *fpaResults, // Metadata to hold the FPA results 8 psMetadata *ppStatsLoop(psExit *result, 9 psMetadata *fpaResults, // Metadata to hold the FPA results 9 10 ppStatsData *data, // The data 10 11 const pmConfig *config // Configuration -
trunk/ppStats/src/ppStatsSetupFromArgs.c
r13181 r13640 151 151 152 152 // Open the input file, determine the camera 153 int result = PS_EXIT_UNKNOWN_ERROR; 153 154 { 154 155 psString resolved = pmConfigConvertFilename(inName, config, false); // Resolved filename … … 157 158 psError(PS_ERR_IO, false, "Unable to open input file %s\n", resolved); 158 159 psFree(resolved); 160 result = PS_EXIT_DATA_ERROR; 159 161 goto die; 160 162 } … … 166 168 psError(PS_ERR_UNKNOWN, false, "Unable to determine camera format for %s\n", inName); 167 169 psFree(header); 170 result = PS_EXIT_DATA_ERROR; 168 171 goto die; 169 172 } … … 173 176 psFree(header); 174 177 psFree(format); 178 result = PS_EXIT_CONFIG_ERROR; 175 179 goto die; 176 180 } … … 180 184 if (!view) { 181 185 psError(PS_ERR_UNKNOWN, false, "Unable to add input file %s to FPA.\n", inName); 186 result = PS_EXIT_CONFIG_ERROR; 182 187 goto die; 183 188 } … … 206 211 pmConfigDone(); 207 212 psLibFinalize(); 208 exit( EXIT_FAILURE);209 } 213 exit(result); 214 } -
trunk/ppStats/src/ppStatsStandAlone.c
r13628 r13640 52 52 } else { 53 53 psErrorStackPrint(stderr, "Unable to open output file %s.\n", resolved); 54 psFree(resolved); 55 status = PS_EXIT_CONFIG_ERROR; 56 goto die; 54 exit(PS_EXIT_CONFIG_ERROR); 57 55 } 58 56 psFree(resolved); … … 60 58 61 59 // Go through the FPA and do the hard work 62 psMetadata *results = ppStatsLoop(NULL, data, config); 60 psMetadata *results = ppStatsLoop(&status, NULL, data, config); 61 if (status != PS_EXIT_SUCCESS) { 62 psErrorStackPrint(stderr, "Error in stats loop.\n"); 63 exit (status); 64 } 63 65 if (psListLength(results->list) == 0) { 64 66 psErrorStackPrint(stderr, "No output.\n"); 65 psFree(results); 66 status = PS_EXIT_DATA_ERROR; 67 goto die; 67 exit (status); 68 68 } 69 69 … … 78 78 psErrorStackPrint(stderr, "Unable to generate configuration file with result.\n"); 79 79 psFree(results); 80 status = PS_EXIT_CONFIG_ERROR; 81 goto die; 80 exit(PS_EXIT_CONFIG_ERROR); 82 81 } 83 82 fprintf(outFile, "%s", output);
Note:
See TracChangeset
for help on using the changeset viewer.
