Changeset 27126 for trunk/pswarp/src/pswarpLoop.c
- Timestamp:
- Mar 1, 2010, 4:48:52 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/pswarp/src/pswarpLoop.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpLoop.c
r27101 r27126 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 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 42 psFree(view); 43 return false; 44 } 45 view->chip = 0; 46 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 47 psFree(view); 48 return false; 49 } 50 view->cell = 0; 51 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 52 psFree(view); 53 return false; 54 } 55 psFree(view); 56 return true; 57 } 58 59 /** 60 * Run up the FPA hierarchy, checking files 61 */ 62 static bool ioChecksAfter(pmConfig *config ///< Configuration 63 ) 64 { 65 pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking 66 view->chip = view->cell = 0; 67 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 68 psFree(view); 69 return false; 70 } 71 view->cell = -1; 72 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 73 psFree(view); 74 return false; 75 } 76 view->chip = -1; 77 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 78 psFree(view); 79 return false; 80 } 81 psFree(view); 82 return true; 83 } 84 85 86 /** 87 * Loop over the inputs, warp them to the output skycell and then write out the output. 88 */ 89 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) 90 24 { 91 25 bool status; 26 bool mdok; // Status of MD lookup 92 27 93 28 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, 94 "SKYCELL.CAMERA"); // /<Name of camera for skycell29 "SKYCELL.CAMERA"); // Name of camera for skycell 95 30 pmConfigCamerasCull(config, skyCamera); 96 31 pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG"); 97 98 32 99 33 // load the recipe … … 143 77 psFree (view); 144 78 145 bool mdok; ///< Status of MD lookup146 const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics147 psMetadata *stats = NULL; ///< Container for statistics148 FILE *statsFile = NULL; ///< File stream for statistics149 if (mdok && statsName && strlen(statsName) > 0) {150 psString resolved = pmConfigConvertFilename(statsName, config, true, true);151 statsFile = fopen(resolved, "w");152 if (!statsFile) {153 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);154 psFree(resolved);155 return false;156 }157 psFree(resolved);158 stats = psMetadataAlloc();159 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);160 }161 79 162 80 // Turn all skycell files on to generate them, and then turn them off for the loop over the input images 163 81 // the input, which is in a different format. 164 82 { 165 fileActivation(config, detectorFiles, false);166 fileActivation(config, photFiles, false);167 fileActivation(config, independentFiles, false);168 fileActivation(config, skycellFiles, true);169 if (! ioChecksBefore(config)) {83 pswarpFileActivation(config, detectorFiles, false); 84 pswarpFileActivation(config, photFiles, false); 85 pswarpFileActivation(config, independentFiles, false); 86 pswarpFileActivation(config, skycellFiles, true); 87 if (!pswarpIOChecksBefore(config)) { 170 88 psError(psErrorCodeLast(), false, "Unable to read files."); 171 return false;172 } 173 fileActivation(config, skycellFiles, false);89 goto DONE; 90 } 91 pswarpFileActivation(config, skycellFiles, false); 174 92 } 175 93 … … 183 101 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 184 102 psError(psErrorCodeLast(), false, "Unable to read files."); 185 return false;103 goto DONE; 186 104 } 187 105 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { … … 190 108 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 191 109 psError(psErrorCodeLast(), false, "Unable to read files."); 192 return false;110 goto DONE; 193 111 } 194 112 pmCell *cell; … … 199 117 !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 200 118 psError(psErrorCodeLast(), false, "Unable to read files."); 201 return false;119 goto DONE; 202 120 } 203 121 } 204 122 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 205 123 psError(psErrorCodeLast(), false, "Unable to write files."); 206 return false;124 goto DONE; 207 125 } 208 126 } 209 127 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) { 210 128 psError(psErrorCodeLast(), false, "Unable to write files."); 211 return false;212 } 213 psFree(view); 214 215 fileActivation(config, detectorFiles, true);129 goto DONE; 130 } 131 psFree(view); 132 133 pswarpFileActivation(config, detectorFiles, true); 216 134 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 217 135 } … … 238 156 psFree(view); 239 157 psFree(stats); 240 return false;158 goto DONE; 241 159 } 242 160 } … … 247 165 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 248 166 psError(psErrorCodeLast(), false, "Unable to read files."); 249 return false;167 goto DONE; 250 168 } 251 169 … … 256 174 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 257 175 psError(psErrorCodeLast(), false, "Unable to read files."); 258 return false;176 goto DONE; 259 177 } 260 178 … … 266 184 psFree(view); 267 185 psFree(stats); 268 return false;186 goto DONE; 269 187 } 270 188 } else { … … 274 192 psFree(view); 275 193 psFree(stats); 276 return false;194 goto DONE; 277 195 } 278 196 } … … 284 202 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) { 285 203 psError(psErrorCodeLast(), false, "Unable to read files."); 286 return false;204 goto DONE; 287 205 } 288 206 … … 294 212 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { 295 213 psError(psErrorCodeLast(), false, "Unable to read files."); 296 return false;214 goto DONE; 297 215 } 298 216 if (!readout->data_exists) { … … 312 230 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 313 231 psError(psErrorCodeLast(), false, "Unable to write files."); 314 return false;232 goto DONE; 315 233 } 316 234 } 317 235 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 318 236 psError(psErrorCodeLast(), false, "Unable to write files."); 319 return false;237 goto DONE; 320 238 } 321 239 } 322 240 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 323 241 psError(psErrorCodeLast(), false, "Unable to write files."); 324 return false;242 goto DONE; 325 243 } 326 244 } … … 346 264 psFree(cells); 347 265 psFree(view); 348 return false;266 goto DONE; 349 267 } 350 268 … … 384 302 psFree(cells); 385 303 psFree(view); 386 return false;304 goto DONE; 387 305 } 388 306 psFree(cells); … … 395 313 psFree(stats); 396 314 psFree(view); 397 return false;315 goto DONE; 398 316 } 399 317 … … 421 339 psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU."); 422 340 psFree(view); 423 return false;341 goto DONE; 424 342 } 425 343 hdu->header = psMetadataCopy(hdu->header, skyHDU->header); … … 431 349 psError(psErrorCodeLast(), false, "Unable to generate WCS header."); 432 350 psFree(stats); 433 return false;351 goto DONE; 434 352 } 435 353 436 354 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 437 355 psError(psErrorCodeLast(), false, "Unable to write files."); 438 return false;356 goto DONE; 439 357 } 440 358 441 359 // Done with the detector side of things 442 fileActivation(config, detectorFiles, false);443 fileActivation(config, independentFiles, false);360 pswarpFileActivation(config, detectorFiles, false); 361 pswarpFileActivation(config, independentFiles, false); 444 362 445 363 // We need a new PSF model for the warped frame. It would be good to generate this analytically, but … … 447 365 448 366 if (psMetadataLookupBool(&mdok, recipe, "PSF")) { 449 fileActivation(config, photFiles, true);450 if (! ioChecksBefore(config)) {367 pswarpFileActivation(config, photFiles, true); 368 if (!pswarpIOChecksBefore(config)) { 451 369 psError(psErrorCodeLast(), false, "Unable to read files."); 452 return false;370 goto DONE; 453 371 } 454 372 … … 464 382 if (!sources) { 465 383 psError(psErrorCodeLast(), false, "No sources supplied to measure PSF"); 466 return false;384 goto DONE; 467 385 } 468 386 … … 533 451 DONE: 534 452 535 // Ensure everything is written out, at every level536 fileActivation(config, independentFiles, true);537 fileActivation(config, skycellFiles, true);538 if (!ioChecksAfter(config)) {539 psError(psErrorCodeLast(), false, "Unable to write files.");540 return false;541 }542 543 // Write out summary statistics544 if (stats) {545 psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",546 psTimerMark("pswarp"));547 548 const char *statsMDC = psMetadataConfigFormat(stats);549 if (!statsMDC) {550 psError(psErrorCodeLast(), false, "Unable to get statistics file.");551 psFree(stats);552 fclose(statsFile);553 return false;554 }555 psFree(stats);556 if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) {557 psError(PSWARP_ERR_IO, true, "Unable to write statistics file.");558 psFree(statsMDC);559 return false;560 }561 psFree(statsMDC);562 if (fclose(statsFile) == EOF) {563 psError(PSWARP_ERR_IO, true, "Unable to close statistics file.");564 return false;565 }566 pmConfigRunFilenameAddWrite(config, "STATS", statsName);567 }568 569 // Dump configuration570 psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");571 if (dump_file) {572 if (!pmConfigDump(config, dump_file)) {573 psError(psErrorCodeLast(), false, "Unable to dump configuration");574 return false;575 }576 }577 578 453 return true; 579 454 }
Note:
See TracChangeset
for help on using the changeset viewer.
