Changeset 27126
- Timestamp:
- Mar 1, 2010, 4:48:52 PM (16 years ago)
- Location:
- trunk/pswarp/src
- Files:
-
- 1 added
- 4 edited
- 1 moved
-
Makefile.am (modified) (2 diffs)
-
pswarp.c (modified) (4 diffs)
-
pswarp.h (modified) (2 diffs)
-
pswarpExit.c (moved) (moved from trunk/pswarp/src/pswarpCleanup.c ) (6 diffs)
-
pswarpFiles.c (added)
-
pswarpLoop.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/Makefile.am
r23808 r27126 28 28 pswarp.c \ 29 29 pswarpArguments.c \ 30 pswarp Cleanup.c \30 pswarpExit.c \ 31 31 pswarpLoop.c \ 32 32 pswarpDefine.c \ … … 42 42 pswarpTransformSources.c \ 43 43 pswarpTransformTile.c \ 44 pswarpVersion.c 44 pswarpVersion.c \ 45 pswarpFiles.c 45 46 46 47 noinst_HEADERS = \ -
trunk/pswarp/src/pswarp.c
r27098 r27126 11 11 */ 12 12 13 # include "pswarp.h" 13 #include "pswarp.h" 14 #include "pswarpFileNames.h" 14 15 15 16 static void usage (void) { … … 30 31 pmModelClassInit(); 31 32 psphotInit(); 33 34 const char *statsName = NULL; // Filename for statistics 35 psMetadata *stats = NULL; // Container for statistics 36 FILE *statsFile = NULL; // File stream for statistics 32 37 33 38 pmConfig *config = pswarpArguments(argc, argv); … … 50 55 } 51 56 57 // Open the statistics file 58 bool mdok; ///< Status of MD lookup 59 statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics 60 if (mdok && statsName && strlen(statsName) > 0) { 61 psString resolved = pmConfigConvertFilename(statsName, config, true, true); 62 statsFile = fopen(resolved, "w"); 63 if (!statsFile) { 64 psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved); 65 psFree(resolved); 66 goto DIE; 67 } 68 psFree(resolved); 69 stats = psMetadataAlloc(); 70 psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0); 71 } 72 52 73 // load and warp 53 if (!pswarpLoop(config )) {74 if (!pswarpLoop(config, stats)) { 54 75 goto DIE; 55 76 } … … 58 79 59 80 DIE: 60 return pswarpCleanup(config); 81 { 82 psExit exitValue = pswarpExitCode(PS_EXIT_SUCCESS); // Exit code 83 84 // Ensure everything is written out, at every level 85 pswarpFileActivation(config, detectorFiles, true); 86 pswarpFileActivation(config, skycellFiles, true); 87 pswarpFileActivation(config, photFiles, true); 88 pswarpFileActivation(config, independentFiles, true); 89 if (!pswarpIOChecksAfter(config)) { 90 psError(psErrorCodeLast(), false, "Unable to write files."); 91 exitValue = pswarpExitCode(exitValue); 92 } 93 94 // Write out summary statistics 95 if (stats) { 96 psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion", 97 psTimerMark("pswarp")); 98 99 const char *statsMDC = psMetadataConfigFormat(stats); 100 if (!statsMDC) { 101 psError(psErrorCodeLast(), false, "Unable to get statistics file."); 102 exitValue = pswarpExitCode(exitValue); 103 } 104 psFree(stats); 105 if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) { 106 psError(PSWARP_ERR_IO, true, "Unable to write statistics file."); 107 exitValue = pswarpExitCode(exitValue); 108 } 109 psFree(statsMDC); 110 if (fclose(statsFile) == EOF) { 111 psError(PSWARP_ERR_IO, true, "Unable to close statistics file."); 112 exitValue = pswarpExitCode(exitValue); 113 } 114 pmConfigRunFilenameAddWrite(config, "STATS", statsName); 115 } 116 117 // Dump configuration 118 psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); 119 if (dump_file) { 120 if (!pmConfigDump(config, dump_file)) { 121 psError(psErrorCodeLast(), false, "Unable to dump configuration"); 122 exitValue = pswarpExitCode(exitValue); 123 } 124 } 125 126 psThreadPoolFinalize(); 127 psMemCheckCorruption(stderr, true); 128 129 psFree(config); 130 131 psTimerStop(); 132 pmVisualClose(); 133 pmModelClassCleanup(); 134 pmConceptsDone(); 135 pmConfigDone(); 136 psLibFinalize(); 137 138 exitValue = pswarpExitCode(exitValue); 139 return exitValue; 140 } 61 141 } -
trunk/pswarp/src/pswarp.h
r27096 r27126 80 80 bool pswarpParseCamera (pmConfig *config); 81 81 bool pswarpDefine (pmConfig *config); 82 bool pswarpLoop (pmConfig *config );83 psExit pswarp Cleanup (pmConfig *config);82 bool pswarpLoop (pmConfig *config, psMetadata *stats); 83 psExit pswarpExitCode(psExit exitValue); 84 84 bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config); 85 85 bool pswarpTransformSources(pmReadout *output, pmReadout *input, pmConfig *config); … … 129 129 /// Print version information 130 130 void pswarpVersionPrint(void); 131 132 /// Activate a list of files 133 /// 134 /// File list must be NULL-terminated 135 void pswarpFileActivation(pmConfig *config, // Configuration 136 char **files, // Files to turn on/off 137 bool state // Activation state 138 ); 139 140 141 // Run down the FPA hierarchy, checking files 142 bool pswarpIOChecksBefore(pmConfig *config // Configuration 143 ); 144 145 // Run up the FPA hierarchy, checking files 146 bool pswarpIOChecksAfter(pmConfig *config // Configuration 147 ); 148 -
trunk/pswarp/src/pswarpExit.c
r27118 r27126 1 /** @file pswarp Cleanup.c1 /** @file pswarpExit.c 2 2 * 3 3 * @brief … … 13 13 # include "pswarp.h" 14 14 15 psExit pswarpCleanup (pmConfig *config) 15 16 psExit pswarpExitCode(psExit exitValue) 16 17 { 17 psExit exitValue = PS_EXIT_SUCCESS; // Exit value for program 18 if (exitValue != PS_EXIT_SUCCESS) { 19 return exitValue; 20 } 21 18 22 psErrorCode errorCode = psErrorCodeLast(); // Error code 19 23 if (errorCode != PS_ERR_NONE) { … … 22 26 case PSWARP_ERR_UNKNOWN: 23 27 case PS_ERR_UNKNOWN: 24 exitValue = PS_EXIT_UNKNOWN_ERROR; 25 break; 28 return PS_EXIT_UNKNOWN_ERROR; 26 29 case PS_ERR_IO: 27 30 case PS_ERR_DB_CLIENT: … … 30 33 case PS_ERR_OS_CALL_FAILED: 31 34 case PSWARP_ERR_IO: 32 exitValue = PS_EXIT_SYS_ERROR; 33 break; 35 return PS_EXIT_SYS_ERROR; 34 36 case PS_ERR_BAD_PARAMETER_VALUE: 35 37 case PS_ERR_BAD_PARAMETER_TYPE: … … 38 40 case PSWARP_ERR_ARGUMENTS: 39 41 case PSWARP_ERR_CONFIG: 40 exitValue = PS_EXIT_CONFIG_ERROR; 41 break; 42 return PS_EXIT_CONFIG_ERROR; 42 43 case PSWARP_ERR_DATA: 43 44 case PSWARP_ERR_NO_OVERLAP: 44 exitValue = PS_EXIT_DATA_ERROR; 45 break; 45 return PS_EXIT_DATA_ERROR; 46 46 case PS_ERR_UNEXPECTED_NULL: 47 47 case PS_ERR_PROGRAMMING: … … 49 49 default: 50 50 // It's a programming error if we're not dealing with the error correctly 51 exitValue = PS_EXIT_PROG_ERROR; 52 break; 51 return PS_EXIT_PROG_ERROR; 53 52 } 54 53 } 55 54 56 psThreadPoolFinalize();57 psMemCheckCorruption(stderr, true);58 59 psFree(config);60 61 psTimerStop();62 pmVisualClose();63 pmModelClassCleanup();64 pmConceptsDone();65 pmConfigDone();66 psLibFinalize();67 68 55 return exitValue; 69 56 } 57 -
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.
