IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 19, 2013, 4:45:57 PM (13 years ago)
Author:
eugene
Message:

carry over changes from eam_branch/20130307

Location:
branches/eam_branches/ipp-20130419
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130419

  • branches/eam_branches/ipp-20130419/pswarp/src/pswarp.c

    r34800 r35421  
    1212
    1313#include "pswarp.h"
    14 #include "pswarpFileNames.h"
    1514
    1615int main (int argc, char **argv)
     
    2221    psphotInit();
    2322
    24     const char *statsName = NULL;       // Filename for statistics
    25     psMetadata *stats = NULL;           // Container for statistics
    26     FILE *statsFile = NULL;             // File stream for statistics
    27 
    2823    pmConfig *config = pswarpArguments(argc, argv);
    2924    if (!config) {
    30         goto DIE;
     25        pswarpCleanup(config, NULL);
    3126    }
     27
     28    pswarpStatsFile *statsFile = pswarpStatsFileOpen (config);
    3229
    3330    pswarpVersionPrint();
     
    3532    // load identify the data sources
    3633    if (!pswarpParseCamera(config)) {
    37         goto DIE;
     34        pswarpCleanup(config, statsFile);
    3835    }
    3936
    4037    if (!pswarpOptions(config)) {
    41         goto DIE;
     38        pswarpCleanup(config, statsFile);
    4239    }
    4340
    44     // load the skycell layout information
     41    // load the skycell layout information:
     42    //   read the output astrometry description
     43    //   generate the output pixels
     44    //   convert header astrometry to pmFPA astrometry structures
    4545    if (!pswarpDefine(config)) {
    46         goto DIE;
     46        pswarpCleanup(config, statsFile);
    4747    }
    48     if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) {
    49       if (!pswarpDefineBackground(config)) {
    50         goto DIE;
    51       }
    52     }
    53 
    54     // Open the statistics file
    55     bool mdok;                          ///< Status of MD lookup
    56     statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics
    57     if (mdok && statsName && strlen(statsName) > 0) {
    58         psString resolved = pmConfigConvertFilename(statsName, config, true, true);
    59         statsFile = fopen(resolved, "w");
    60         if (!statsFile) {
    61             psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
    62             psFree(resolved);
    63             goto DIE;
    64         }
    65         psFree(resolved);
    66         stats = psMetadataAlloc();
    67         psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
     48    if (!pswarpDefineBackground(config)) {
     49        pswarpCleanup(config, statsFile);
    6850    }
    6951
    7052    // load and warp
    71     if (!pswarpLoop(config, stats)) {
    72         goto DIE;
     53    if (!pswarpLoop(config, statsFile->md)) {
     54        pswarpCleanup(config, statsFile);
    7355    }
    74     if (psMetadataLookupBool(NULL,config->arguments,"BACKGROUND.MODEL")) {
    75       if (!pswarpLoopBackground(config, stats)) {
     56    if (!pswarpLoopBackground(config, statsFile->md)) {
    7657        fprintf(stderr,"Dying!\n");
    77         goto DIE;
    78       }
     58        pswarpCleanup(config, statsFile);
    7959    }
    8060
    8161    psLogMsg("pswarp", PS_LOG_INFO, "complete pswarp run: %f sec\n", psTimerMark("pswarp"));
     62    pswarpCleanup(config, statsFile);
     63}
    8264
    83 DIE:
    84     {
    85         psExit exitValue = pswarpExitCode(PS_EXIT_SUCCESS); // Exit code
    86 
    87         // Ensure everything is written out, at every level
    88         pswarpFileActivation(config, detectorFiles, true);
    89         pswarpFileActivation(config, skycellFiles, true);
    90         pswarpFileActivation(config, photFiles, true);
    91         pswarpFileActivation(config, independentFiles, true);
    92         if (!pswarpIOChecksAfter(config)) {
    93             psError(psErrorCodeLast(), false, "Unable to write files.");
    94             exitValue = pswarpExitCode(exitValue);
    95             pmFPAfileFreeSetStrict(false);
    96         }
    97 
    98         // Write out summary statistics
    99         if (stats && statsFile) {
    100             psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",
    101                              psTimerMark("pswarp"));
    102 
    103             const char *statsMDC = psMetadataConfigFormat(stats);
    104             if (!statsMDC) {
    105                 psError(psErrorCodeLast(), false, "Unable to get statistics file.");
    106                 exitValue = pswarpExitCode(exitValue);
    107             }
    108             psFree(stats);
    109             if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) {
    110                 psError(PSWARP_ERR_IO, true, "Unable to write statistics file.");
    111                 exitValue = pswarpExitCode(exitValue);
    112             }
    113             psFree(statsMDC);
    114             if (fclose(statsFile) == EOF) {
    115                 psError(PSWARP_ERR_IO, true, "Unable to close statistics file.");
    116                 exitValue = pswarpExitCode(exitValue);
    117             }
    118             pmConfigRunFilenameAddWrite(config, "STATS", statsName);
    119         }
    120 
    121         // Dump configuration
    122         psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG");
    123         if (dump_file) {
    124             if (!pmConfigDump(config, dump_file)) {
    125                 psError(psErrorCodeLast(), false, "Unable to dump configuration");
    126                 exitValue = pswarpExitCode(exitValue);
    127             }
    128         }
    129 
    130         psThreadPoolFinalize();
    131         psMemCheckCorruption(stderr, true);
    132 
    133         psFree(config);
    134 
    135         psTimerStop();
    136         pmVisualClose();
    137         pmModelClassCleanup();
    138         pmConceptsDone();
    139         pmConfigDone();
    140         psLibFinalize();
    141 
    142         exitValue = pswarpExitCode(exitValue);
    143         return exitValue;
    144     }
    145 }
     65// NOTE: pswarpCleanup calls exit
Note: See TracChangeset for help on using the changeset viewer.