IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 14, 2011, 1:05:28 PM (15 years ago)
Author:
watersc1
Message:

Merge of trunk back into branch.

Location:
branches/czw_branch/20101203
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/ppStack/src/ppStackCleanup.c

    r27427 r30631  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
     1#include "ppStack.h"
    42
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <ppStats.h>
    9 
    10 #include "ppStack.h"
    11 #include "ppStackLoop.h"
    12 
    13 
    14 bool ppStackCleanup(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config)
     3// ppStackCleanupFiles
     4bool ppStackCleanupFiles(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config, ppStackFileList stackFiles, ppStackFileList photFiles, bool closeJPEGs)
    155{
    166    psAssert(stack, "Require stack");
     
    188    psAssert(config, "Require configuration");
    199
    20     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    21     psAssert(recipe, "We've thrown an error on this before.");
    22 
    23 #if 0
    24     // Ensure masked regions really look masked
    25     {
    26         psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad
    27         psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
    28         if (!pmReadoutMaskApply(options->outRO, maskBad)) {
    29             psWarning("Unable to apply mask");
    30         }
    31     }
    32 #endif
    33 
    34     // Generate binned JPEGs
    35     {
    36         int bin1 = psMetadataLookupS32(NULL, recipe, "BIN1"); // First binning level
    37         int bin2 = psMetadataLookupS32(NULL, recipe, "BIN2"); // Second binning level
    38 
    39         // Target cells
    40         pmFPAview *view = pmFPAviewAlloc(0); // View to cells of interest
    41         view->chip = view->cell = 0;
    42         pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG1");
    43         pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG2");
    44         psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
    45         psFree(view);
    46 
    47         pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    48         if (!pmReadoutRebin(ro1, options->outRO, maskValue, bin1, bin1) ||
    49             !pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
    50             psError(PPSTACK_ERR_DATA, false, "Unable to bin output.");
    51             psFree(ro1);
    52             psFree(ro2);
    53             return false;
    54         }
    55         psFree(ro1);
    56         psFree(ro2);
    57     }
    58 
    59     // Statistics on output
    60     if (options->stats) {
    61         psTrace("ppStack", 1, "Gathering statistics on stacked image....\n");
    62         psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad
    63         psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
    64 
    65         pmFPAview *view = pmFPAviewAlloc(0); // View to readout
    66         view->chip = view->cell = view->readout = 0;
    67 
    68         ppStatsFPA(options->stats, options->outRO->parent->parent->parent, view, maskBad, config);
    69 
    70         psFree(view);
    71     }
    72 
    7310    if (!ppStackFilesIterateUp(config)) {
    7411        psError(psErrorCodeLast(), false, "Unable to close files.");
    7512        return false;
    7613    }
    77     ppStackFileActivation(config, PPSTACK_FILES_STACK, false);
    78     ppStackFileActivation(config, PPSTACK_FILES_PHOT, false);
     14    ppStackFileActivation(config, stackFiles, false);
     15    ppStackFileActivation(config, photFiles, false);
    7916
    8017    // Ensure files are freed
    81     {
    82         options->outRO->data_exists = false;
    83         options->outRO->parent->data_exists = false;
    84         options->outRO->parent->parent->data_exists = false;
    85         psFree(options->outRO);
    86         options->outRO = NULL;
     18    options->outRO->data_exists = false;
     19    options->outRO->parent->data_exists = false;
     20    options->outRO->parent->parent->data_exists = false;
     21    psFree(options->outRO);
     22    options->outRO = NULL;
    8723
    88         options->expRO->data_exists = false;
    89         options->expRO->parent->data_exists = false;
    90         options->expRO->parent->parent->data_exists = false;
    91         psFree(options->expRO);
    92         options->expRO = NULL;
     24    options->expRO->data_exists = false;
     25    options->expRO->parent->data_exists = false;
     26    options->expRO->parent->parent->data_exists = false;
     27    psFree(options->expRO);
     28    options->expRO = NULL;
    9329
     30    for (int i = 0; i < options->num; i++) {
     31        pmCellFreeData(options->cells->data[i]);
     32    }
     33
     34    if (closeJPEGs) {
     35        // XXX move these close / free operations to the jpeg creation function
    9436        pmFPAview *view = pmFPAviewAlloc(0);// Pointer into FPA hierarchy
    9537        view->chip = view->cell = 0;        // pmFPAviewFreeData doesn't want to deal with readouts
     
    11860    return true;
    11961}
     62
     63bool ppStackCleanup (pmConfig *config, ppStackOptions *options) {
     64
     65    psExit exitValue = ppStackExitCode(PS_EXIT_SUCCESS); // Exit code
     66
     67    // Ensure everything closes
     68    if (config) {
     69        ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true);
     70        ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true);
     71        ppStackFileActivation(config, PPSTACK_FILES_STACK, true);
     72        ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true);
     73        ppStackFileActivation(config, PPSTACK_FILES_PHOT, true);
     74        if (!ppStackFilesIterateUp(config)) {
     75            psError(psErrorCodeLast(), false, "Unable to close files.");
     76            exitValue = ppStackExitCode(exitValue);
     77            pmFPAfileFreeSetStrict(false);
     78        }
     79    }
     80
     81    // Write out summary statistics
     82    if (options && options->stats) {
     83
     84        psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, "Bad data quality flag", options->quality);
     85        psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_STACK", 0, "Total time", psTimerClear("PPSTACK_TOTAL"));
     86
     87        const char *statsMDC = psMetadataConfigFormat(options->stats);
     88        if (!statsMDC || strlen(statsMDC) == 0) {
     89            psError(PS_ERR_IO, false, "Unable to get statistics MDC file.");
     90            exitValue = ppStackExitCode(exitValue);
     91            exit(exitValue);
     92        }
     93        if (fprintf(options->statsFile, "%s", statsMDC) != strlen(statsMDC)) {
     94            psError(PS_ERR_IO, false, "Unable to write statistics MDC file.");
     95            exitValue = ppStackExitCode(exitValue);
     96            exit(exitValue);
     97        }
     98        psFree(statsMDC);
     99        if (fclose(options->statsFile) == EOF) {
     100            psError(PS_ERR_IO, false, "Unable to close statistics MDC file.");
     101            exitValue = ppStackExitCode(exitValue);
     102            exit(exitValue);
     103        }
     104        options->statsFile = NULL;
     105        pmConfigRunFilenameAddWrite(config, "STATS", psMetadataLookupStr(NULL, config->arguments, "STATS"));
     106    }
     107    psFree(options);
     108
     109    // Dump configuration
     110    bool mdok;                                                                    // Status of MD lookup
     111    psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config
     112    if (dump && !pmConfigDump(config, dump)) {
     113        psError(psErrorCodeLast(), false, "Unable to dump configuration.");
     114        exitValue = ppStackExitCode(exitValue);
     115    }
     116
     117    psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark("PPSTACK"));
     118    psTimerStop();
     119
     120    psFree(config);
     121    pmModelClassCleanup();
     122    pmConfigDone();
     123    psLibFinalize();
     124    pmVisualClose();
     125    pmVisualCleanup ();
     126
     127    exitValue = ppStackExitCode(exitValue);
     128    exit(exitValue);
     129}
Note: See TracChangeset for help on using the changeset viewer.