Changeset 27517 for branches/eam_branches/20100225/pswarp/src/pswarpLoop.c
- Timestamp:
- Mar 29, 2010, 3:55:49 PM (16 years ago)
- Location:
- branches/eam_branches/20100225
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pswarp/src/pswarpLoop.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20100225
- Property svn:mergeinfo changed
-
branches/eam_branches/20100225/pswarp/src/pswarpLoop.c
r27063 r27517 19 19 20 20 21 // XXX these are generic functions which should be moved to psModules 22 // Activate a list of files 23 static void fileActivation(pmConfig *config, // Configuration 24 char **files, // Files to turn on/off 25 bool state // Activation state 26 ) 27 { 28 for (int i = 0; files[i] != NULL; i++) { 29 pmFPAfileActivate(config->files, state, files[i]); 30 } 31 return; 32 } 33 34 /** 35 * Run down the FPA hierarchy, checking files 36 */ 37 static bool ioChecksBefore(pmConfig *config ///< Configuration 38 ) 39 { 40 pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking 41 bool status = true; ///< Status of checks 42 status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 43 view->chip = 0; 44 status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 45 view->cell = 0; 46 status &= pmFPAfileIOChecks(config, view, PM_FPA_BEFORE); 47 psFree(view); 48 return status; 49 } 50 51 /** 52 * Run up the FPA hierarchy, checking files 53 */ 54 static bool ioChecksAfter(pmConfig *config ///< Configuration 55 ) 56 { 57 pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking 58 view->chip = view->cell = 0; 59 bool status = true; ///< Status of checks 60 status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 61 view->cell = -1; 62 status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 63 view->chip = -1; 64 status &= pmFPAfileIOChecks(config, view, PM_FPA_AFTER); 65 psFree(view); 66 return status; 67 } 68 69 70 /** 71 * Loop over the inputs, warp them to the output skycell and then write out the output. 72 */ 73 bool pswarpLoop(pmConfig *config) 21 22 // Loop over the inputs, warp them to the output skycell and then write out the output. 23 bool pswarpLoop(pmConfig *config, psMetadata *stats) 74 24 { 75 25 bool status; 26 bool mdok; // Status of MD lookup 76 27 77 28 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, 78 "SKYCELL.CAMERA"); // /<Name of camera for skycell29 "SKYCELL.CAMERA"); // Name of camera for skycell 79 30 pmConfigCamerasCull(config, skyCamera); 80 31 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG"); 81 82 32 83 33 // load the recipe 84 34 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSWARP_RECIPE); 85 35 if (!recipe) { 86 psError(PS PHOT_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE);36 psError(PSWARP_ERR_CONFIG, false, "missing recipe %s", PSWARP_RECIPE); 87 37 return false; 88 38 } 89 39 90 40 if (!pswarpSetMaskBits(config)) { 91 psError( PS_ERR_IO, false, "failed to set mask bits");41 psError(psErrorCodeLast(), false, "failed to set mask bits"); 92 42 return NULL; 93 43 } … … 111 61 112 62 if (astrom->camera != input->camera) { 113 psError(PS _ERR_UNKNOWN, true, "Input camera and astrometry camera do not match.");63 psError(PSWARP_ERR_DATA, true, "Input camera and astrometry camera do not match."); 114 64 return false; 115 65 } … … 127 77 psFree (view); 128 78 129 bool mdok; ///< Status of MD lookup130 const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics131 psMetadata *stats = NULL; ///< Container for statistics132 FILE *statsFile = NULL; ///< File stream for statistics133 if (mdok && statsName && strlen(statsName) > 0) {134 psString resolved = pmConfigConvertFilename(statsName, config, true, true);135 statsFile = fopen(resolved, "w");136 if (!statsFile) {137 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);138 psFree(resolved);139 return false;140 }141 psFree(resolved);142 stats = psMetadataAlloc();143 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);144 }145 79 146 80 // Turn all skycell files on to generate them, and then turn them off for the loop over the input images 147 81 // the input, which is in a different format. 148 82 { 149 fileActivation(config, detectorFiles, false); 150 fileActivation(config, photFiles, false); 151 fileActivation(config, independentFiles, false); 152 fileActivation(config, skycellFiles, true); 153 ioChecksBefore(config); 154 fileActivation(config, skycellFiles, false); 83 pswarpFileActivation(config, detectorFiles, false); 84 pswarpFileActivation(config, photFiles, false); 85 pswarpFileActivation(config, independentFiles, false); 86 pswarpFileActivation(config, skycellFiles, true); 87 if (!pswarpIOChecksBefore(config)) { 88 psError(psErrorCodeLast(), false, "Unable to read files."); 89 goto DONE; 90 } 91 pswarpFileActivation(config, skycellFiles, false); 155 92 } 156 93 … … 162 99 pmChip *chip; 163 100 pmFPAview *view = pmFPAviewAlloc(0); 164 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 165 return false; 101 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 102 psError(psErrorCodeLast(), false, "Unable to read files."); 103 goto DONE; 166 104 } 167 105 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { … … 169 107 if (!chip->process || !chip->file_exists) { continue; } 170 108 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 171 return false; 109 psError(psErrorCodeLast(), false, "Unable to read files."); 110 goto DONE; 172 111 } 173 112 pmCell *cell; … … 177 116 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) || 178 117 !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 179 return false; 118 psError(psErrorCodeLast(), false, "Unable to read files."); 119 goto DONE; 180 120 } 181 121 } 182 122 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 183 return false; 123 psError(psErrorCodeLast(), false, "Unable to write files."); 124 goto DONE; 184 125 } 185 126 } 186 127 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 187 return false; 188 } 189 psFree(view); 190 191 fileActivation(config, detectorFiles, true); 128 psError(psErrorCodeLast(), false, "Unable to write files."); 129 goto DONE; 130 } 131 psFree(view); 132 133 pswarpFileActivation(config, detectorFiles, true); 192 134 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 193 135 } … … 211 153 if (bilevelAstrometry) { 212 154 if (!pmAstromReadBilevelMosaic(input->fpa, phu->header)) { 213 psError( PS_ERR_UNKNOWN, false, "Unable to read bilevel mosaic astrometry for input FPA.");155 psError(psErrorCodeLast(), false, "Unable to read bilevel mosaic astrometry for input FPA."); 214 156 psFree(view); 215 157 psFree(stats); 216 return false;158 goto DONE; 217 159 } 218 160 } … … 222 164 // files associated with the science image 223 165 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 224 return false; 166 psError(psErrorCodeLast(), false, "Unable to read files."); 167 goto DONE; 225 168 } 226 169 … … 230 173 if (!chip->process || !chip->file_exists) { continue; } 231 174 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 232 return false; 175 psError(psErrorCodeLast(), false, "Unable to read files."); 176 goto DONE; 233 177 } 234 178 … … 237 181 if (bilevelAstrometry) { 238 182 if (!pmAstromReadBilevelChip (chip, hdu->header)) { 239 psError( PS_ERR_UNKNOWN, false, "Unable to read bilevel chip astrometry for input FPA.");183 psError(psErrorCodeLast(), false, "Unable to read bilevel chip astrometry for input FPA."); 240 184 psFree(view); 241 185 psFree(stats); 242 return false;186 goto DONE; 243 187 } 244 188 } else { 245 189 // we use a default FPA pixel scale of 1.0 246 190 if (!pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0)) { 247 psError( PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry for input FPA.");191 psError(psErrorCodeLast(), false, "Unable to read WCS astrometry for input FPA."); 248 192 psFree(view); 249 193 psFree(stats); 250 return false;194 goto DONE; 251 195 } 252 196 } … … 257 201 if (!cell->process || !cell->file_exists) { continue; } 258 202 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 259 return false; 203 psError(psErrorCodeLast(), false, "Unable to read files."); 204 goto DONE; 260 205 } 261 206 … … 266 211 while ((readout = pmFPAviewNextReadout(view, input->fpa, 1)) != NULL) { 267 212 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 268 return false; 213 psError(psErrorCodeLast(), false, "Unable to read files."); 214 goto DONE; 269 215 } 270 216 if (!readout->data_exists) { … … 283 229 284 230 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 285 return false; 231 psError(psErrorCodeLast(), false, "Unable to write files."); 232 goto DONE; 286 233 } 287 234 } 288 235 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 289 return false; 236 psError(psErrorCodeLast(), false, "Unable to write files."); 237 goto DONE; 290 238 } 291 239 } 292 240 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 293 return false; 241 psError(psErrorCodeLast(), false, "Unable to write files."); 242 goto DONE; 294 243 } 295 244 } … … 312 261 313 262 if (!pswarpPixelsLit(output, stats, config)) { 314 psError( PS_ERR_UNKNOWN, false, "Unable to calculate pixel regions.");263 psError(psErrorCodeLast(), false, "Unable to calculate pixel regions."); 315 264 psFree(cells); 316 265 psFree(view); 317 return false;266 goto DONE; 318 267 } 319 268 … … 349 298 350 299 if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) { 351 psError( PS_ERR_UNKNOWN, false, "Unable to average cell concepts.");300 psError(psErrorCodeLast(), false, "Unable to average cell concepts."); 352 301 psFree(stats); 353 302 psFree(cells); 354 303 psFree(view); 355 return false;304 goto DONE; 356 305 } 357 306 psFree(cells); … … 361 310 362 311 if (!psMetadataCopy(outFPA->concepts, input->fpa->concepts)) { 363 psError( PS_ERR_UNKNOWN, false, "Unable to copy FPA concepts from input to output.");312 psError(psErrorCodeLast(), false, "Unable to copy FPA concepts from input to output."); 364 313 psFree(stats); 365 314 psFree(view); 366 return false; 367 } 368 369 // Update ZP from the astrometry 370 { 371 psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP"); 372 item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP"); 373 } 315 goto DONE; 316 } 317 374 318 // Update ZP from the astrometry 375 319 { … … 388 332 pmHDU *skyHDU = pmHDUFromCell(cell); ///< HDU 389 333 if (!skyHDU) { 390 psError(PS _ERR_UNEXPECTED_NULL, false, "Unable to find skycell HDU.");334 psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU."); 391 335 psFree(view); 392 return false;336 goto DONE; 393 337 } 394 338 hdu->header = psMetadataCopy(hdu->header, skyHDU->header); … … 398 342 399 343 if (!pmAstromWriteWCS(hdu->header, outFPA, outChip, WCS_NONLIN_TOL)) { 400 psError( PS_ERR_UNKNOWN, false, "Unable to generate WCS header.");344 psError(psErrorCodeLast(), false, "Unable to generate WCS header."); 401 345 psFree(stats); 402 return false;346 goto DONE; 403 347 } 404 348 405 349 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 406 return false; 350 psError(psErrorCodeLast(), false, "Unable to write files."); 351 goto DONE; 407 352 } 408 353 409 354 // Done with the detector side of things 410 fileActivation(config, detectorFiles, false);411 fileActivation(config, independentFiles, false);355 pswarpFileActivation(config, detectorFiles, false); 356 pswarpFileActivation(config, independentFiles, false); 412 357 413 358 // We need a new PSF model for the warped frame. It would be good to generate this analytically, but … … 415 360 416 361 if (psMetadataLookupBool(&mdok, recipe, "PSF")) { 417 fileActivation(config, photFiles, true); 418 ioChecksBefore(config); 362 pswarpFileActivation(config, photFiles, true); 363 if (!pswarpIOChecksBefore(config)) { 364 psError(psErrorCodeLast(), false, "Unable to read files."); 365 goto DONE; 366 } 419 367 420 368 // supply the readout and fpa of interest to psphot … … 428 376 psArray *sources = psphotLoadPSFSources (config, view); 429 377 if (!sources) { 430 psError( PS_ERR_UNKNOWN, false, "No sources supplied to measure PSF");431 return false;378 psError(psErrorCodeLast(), false, "No sources supplied to measure PSF"); 379 goto DONE; 432 380 } 433 381 … … 498 446 DONE: 499 447 500 // Ensure everything is written out, at every level501 fileActivation(config, independentFiles, true);502 fileActivation(config, skycellFiles, true);503 ioChecksAfter(config);504 505 // Write out summary statistics506 if (stats) {507 psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",508 psTimerMark("pswarp"));509 510 const char *statsMDC = psMetadataConfigFormat(stats);511 if (!statsMDC) {512 psError(psErrorCodeLast(), false, "Unable to get statistics file.");513 psFree(stats);514 fclose(statsFile);515 return false;516 }517 psFree(stats);518 if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) {519 psError(PSWARP_ERR_IO, true, "Unable to write statistics file.");520 psFree(statsMDC);521 return false;522 }523 psFree(statsMDC);524 if (fclose(statsFile) == EOF) {525 psError(PSWARP_ERR_IO, true, "Unable to close statistics file.");526 return false;527 }528 pmConfigRunFilenameAddWrite(config, "STATS", statsName);529 }530 531 // Dump configuration532 psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");533 if (dump_file) {534 if (!pmConfigDump(config, dump_file)) {535 psError(psErrorCodeLast(), false, "Unable to dump configuration");536 return false;537 }538 }539 540 448 return true; 541 449 }
Note:
See TracChangeset
for help on using the changeset viewer.
