IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2010, 3:55:49 PM (16 years ago)
Author:
eugene
Message:

update merges from trunk

Location:
branches/eam_branches/20100225
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225

  • branches/eam_branches/20100225/pswarp/src/pswarp.c

    r23195 r27517  
    1111 */
    1212
    13 # include "pswarp.h"
    14 
    15 static void usage (void) {
    16     fprintf(stderr, "USAGE: pswarp [-file image(s)] [-list imagelist] [options] (output) (skycell)\n");
    17     fprintf(stderr, "  options:\n");
    18     fprintf(stderr, "    [-astrom astrom.cmp] : provide an alternative astrometry calibration\n");
    19     fprintf(stderr, "    [-mask mask.fits] : provide a corresponding mask image\n");
    20     fprintf(stderr, "    [-variance variance.fits] : provide a corresponding variance image\n");
    21     psErrorStackPrint(stderr, "\n");
    22     exit (2);
    23 }
     13#include "pswarp.h"
     14#include "pswarpFileNames.h"
    2415
    2516int main (int argc, char **argv)
     
    2819
    2920    psLibInit(NULL);
    30 
    31     // model inits are needed in pmSourceIO
    32     // models defined in psphot/src/models are not available in psastro
    3321    pmModelClassInit();
    34 
    35     // init various psphot pieces (errors, models, threads)
    3622    psphotInit();
    3723
     24    const char *statsName = NULL;       // Filename for statistics
     25    psMetadata *stats = NULL;           // Container for statistics
     26    FILE *statsFile = NULL;             // File stream for statistics
     27
    3828    pmConfig *config = pswarpArguments(argc, argv);
    39     if (!config) usage();
     29    if (!config) {
     30        goto DIE;
     31    }
    4032
    4133    pswarpVersionPrint();
     
    4335    // load identify the data sources
    4436    if (!pswarpParseCamera(config)) {
    45         psErrorStackPrint(stderr, "error setting up the camera\n");
    46         exit(PS_EXIT_CONFIG_ERROR);
     37        goto DIE;
    4738    }
    4839
    4940    if (!pswarpOptions(config)) {
    50         psErrorStackPrint(stderr, "error parsing options\n");
    51         exit(PS_EXIT_SYS_ERROR);
     41        goto DIE;
    5242    }
    5343
    5444    // load the skycell layout information
    5545    if (!pswarpDefine(config)) {
    56         psErrorStackPrint(stderr, "error loading output definition\n");
    57         exit(PS_EXIT_CONFIG_ERROR);
     46        goto DIE;
     47    }
     48
     49    // Open the statistics file
     50    bool mdok;                          ///< Status of MD lookup
     51    statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics
     52    if (mdok && statsName && strlen(statsName) > 0) {
     53        psString resolved = pmConfigConvertFilename(statsName, config, true, true);
     54        statsFile = fopen(resolved, "w");
     55        if (!statsFile) {
     56            psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
     57            psFree(resolved);
     58            goto DIE;
     59        }
     60        psFree(resolved);
     61        stats = psMetadataAlloc();
     62        psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
    5863    }
    5964
    6065    // load and warp
    61     if (!pswarpLoop(config)) {
    62         psErrorStackPrint(stderr, "error warping data\n");
    63         exit(PS_EXIT_DATA_ERROR);
     66    if (!pswarpLoop(config, stats)) {
     67        goto DIE;
    6468    }
    6569
    66     psLogMsg("pswarp", 3, "complete pswarp run: %f sec\n", psTimerMark("pswarp"));
    67     pswarpCleanup(config);
    68     psLibFinalize();
    69     exit(PS_EXIT_SUCCESS);
     70    psLogMsg("pswarp", PS_LOG_INFO, "complete pswarp run: %f sec\n", psTimerMark("pswarp"));
     71
     72DIE:
     73    {
     74        psExit exitValue = pswarpExitCode(PS_EXIT_SUCCESS); // Exit code
     75
     76        // Ensure everything is written out, at every level
     77        pswarpFileActivation(config, detectorFiles, true);
     78        pswarpFileActivation(config, skycellFiles, true);
     79        pswarpFileActivation(config, photFiles, true);
     80        pswarpFileActivation(config, independentFiles, true);
     81        if (!pswarpIOChecksAfter(config)) {
     82            psError(psErrorCodeLast(), false, "Unable to write files.");
     83            exitValue = pswarpExitCode(exitValue);
     84            pmFPAfileFreeSetStrict(false);
     85        }
     86
     87        // Write out summary statistics
     88        if (stats) {
     89            psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",
     90                             psTimerMark("pswarp"));
     91
     92            const char *statsMDC = psMetadataConfigFormat(stats);
     93            if (!statsMDC) {
     94                psError(psErrorCodeLast(), false, "Unable to get statistics file.");
     95                exitValue = pswarpExitCode(exitValue);
     96            }
     97            psFree(stats);
     98            if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) {
     99                psError(PSWARP_ERR_IO, true, "Unable to write statistics file.");
     100                exitValue = pswarpExitCode(exitValue);
     101            }
     102            psFree(statsMDC);
     103            if (fclose(statsFile) == EOF) {
     104                psError(PSWARP_ERR_IO, true, "Unable to close statistics file.");
     105                exitValue = pswarpExitCode(exitValue);
     106            }
     107            pmConfigRunFilenameAddWrite(config, "STATS", statsName);
     108        }
     109
     110        // Dump configuration
     111        psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG");
     112        if (dump_file) {
     113            if (!pmConfigDump(config, dump_file)) {
     114                psError(psErrorCodeLast(), false, "Unable to dump configuration");
     115                exitValue = pswarpExitCode(exitValue);
     116            }
     117        }
     118
     119        psThreadPoolFinalize();
     120        psMemCheckCorruption(stderr, true);
     121
     122        psFree(config);
     123
     124        psTimerStop();
     125        pmVisualClose();
     126        pmModelClassCleanup();
     127        pmConceptsDone();
     128        pmConfigDone();
     129        psLibFinalize();
     130
     131        exitValue = pswarpExitCode(exitValue);
     132        return exitValue;
     133    }
    70134}
Note: See TracChangeset for help on using the changeset viewer.