IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27075


Ignore:
Timestamp:
Feb 25, 2010, 10:58:13 AM (16 years ago)
Author:
Paul Price
Message:

Ensure files are closed when exiting with an error. Moved target PSF to its own file so that it can be closed independently of the images (they share data_exists, which need to have multiple states if they're on the same file).

Location:
trunk/ppStack/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStack/src/ppStack.c

    r27004 r27075  
    5555
    5656
    57      // Common code for the death.
    58 die:
    59     psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark(TIMER_NAME));
    60     psTimerStop();
     57 die:
     58    // Common code for the death.
     59    {
     60        psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
     61        psErrorCode errorCode = psErrorCodeLast(); // Error code
     62        if (errorCode != PS_ERR_NONE) {
     63            psErrorStackPrint(stderr, "Unable to perform stack.");
     64            switch (errorCode) {
     65              case PPSTACK_ERR_UNKNOWN:
     66              case PS_ERR_UNKNOWN:
     67                exitValue = PS_EXIT_UNKNOWN_ERROR;
     68                break;
     69              case PS_ERR_IO:
     70              case PS_ERR_DB_CLIENT:
     71              case PS_ERR_DB_SERVER:
     72              case PS_ERR_BAD_FITS:
     73              case PS_ERR_OS_CALL_FAILED:
     74              case PPSTACK_ERR_IO:
     75                exitValue = PS_EXIT_SYS_ERROR;
     76                break;
     77              case PS_ERR_BAD_PARAMETER_VALUE:
     78              case PS_ERR_BAD_PARAMETER_TYPE:
     79              case PS_ERR_BAD_PARAMETER_NULL:
     80              case PS_ERR_BAD_PARAMETER_SIZE:
     81              case PPSTACK_ERR_ARGUMENTS:
     82              case PPSTACK_ERR_CONFIG:
     83                exitValue = PS_EXIT_CONFIG_ERROR;
     84                break;
     85              case PPSTACK_ERR_PSF:
     86              case PPSTACK_ERR_REJECTED:
     87              case PPSTACK_ERR_DATA:
     88                exitValue = PS_EXIT_DATA_ERROR;
     89                break;
     90              case PS_ERR_UNEXPECTED_NULL:
     91              case PS_ERR_PROGRAMMING:
     92              case PPSTACK_ERR_NOT_IMPLEMENTED:
     93              case PPSTACK_ERR_PROG:
     94              default:
     95                // It's a programming error if we're not dealing with the error correctly
     96                exitValue = PS_EXIT_PROG_ERROR;
     97                break;
     98            }
     99        }
    61100
    62     psFree(config);
    63     pmModelClassCleanup();
    64     pmConfigDone();
    65     psLibFinalize();
    66     pmVisualClose();
     101        // Ensure everything closes
     102        ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true);
     103        ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true);
     104        ppStackFileActivation(config, PPSTACK_FILES_COMBINE, true);
     105        ppStackFileActivation(config, PPSTACK_FILES_PHOT, true);
     106        if (!ppStackFilesIterateUp(config)) {
     107            psErrorStackPrint(stderr, "Unable to close files.");
     108        }
    67109
    68     psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
    69     psErrorCode errorCode = psErrorCodeLast(); // Error code
    70     if (errorCode != PS_ERR_NONE) {
    71         psErrorStackPrint(stderr, "Unable to perform stack.");
    72         switch (errorCode) {
    73           case PPSTACK_ERR_UNKNOWN:
    74           case PS_ERR_UNKNOWN:
    75             exitValue = PS_EXIT_UNKNOWN_ERROR;
    76             break;
    77           case PS_ERR_IO:
    78           case PS_ERR_DB_CLIENT:
    79           case PS_ERR_DB_SERVER:
    80           case PS_ERR_BAD_FITS:
    81           case PS_ERR_OS_CALL_FAILED:
    82           case PPSTACK_ERR_IO:
    83             exitValue = PS_EXIT_SYS_ERROR;
    84             break;
    85           case PS_ERR_BAD_PARAMETER_VALUE:
    86           case PS_ERR_BAD_PARAMETER_TYPE:
    87           case PS_ERR_BAD_PARAMETER_NULL:
    88           case PS_ERR_BAD_PARAMETER_SIZE:
    89           case PPSTACK_ERR_ARGUMENTS:
    90           case PPSTACK_ERR_CONFIG:
    91             exitValue = PS_EXIT_CONFIG_ERROR;
    92             break;
    93           case PPSTACK_ERR_PSF:
    94           case PPSTACK_ERR_REJECTED:
    95           case PPSTACK_ERR_DATA:
    96             exitValue = PS_EXIT_DATA_ERROR;
    97             break;
    98           case PS_ERR_UNEXPECTED_NULL:
    99           case PS_ERR_PROGRAMMING:
    100           case PPSTACK_ERR_NOT_IMPLEMENTED:
    101           case PPSTACK_ERR_PROG:
    102           default:
    103             // It's a programming error if we're not dealing with the error correctly
    104             exitValue = PS_EXIT_PROG_ERROR;
    105             break;
    106         }
     110        psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark(TIMER_NAME));
     111        psTimerStop();
     112
     113        psFree(config);
     114        pmModelClassCleanup();
     115        pmConfigDone();
     116        psLibFinalize();
     117        pmVisualClose();
     118
     119        exit(exitValue);
    107120    }
    108 
    109     exit(exitValue);
    110121}
    111122
  • trunk/ppStack/src/ppStack.h

    r27004 r27075  
    1313// Mask values for inputs
    1414typedef enum {
     15    PPSTACK_MASK_NONE   = 0x00,         // Nothing wrong
    1516    PPSTACK_MASK_CAL    = 0x01,         // Photometric calibration failed
    1617    PPSTACK_MASK_PSF    = 0x02,         // PSF measurement failed
  • trunk/ppStack/src/ppStackCamera.c

    r27004 r27075  
    284284
    285285    if (havePSFs) {
    286         pmFPAfile *targetPSF = pmFPAfileDefineOutput(config, output->fpa, "PPSTACK.TARGET.PSF");
     286        pmFPA *psfFPA = pmFPAConstruct(config->camera, config->cameraName); // FPA to contain PSF
     287        if (!psfFPA) {
     288            psError(psErrorCodeLast(), false, "Unable to construct an FPA from camera configuration.");
     289            return false;
     290        }
     291        pmFPAfile *targetPSF = pmFPAfileDefineOutput(config, psfFPA, "PPSTACK.TARGET.PSF");
    287292        if (!targetPSF) {
    288293            psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSTACK.TARGET.PSF"));
    289294            return false;
    290295        }
     296        psFree(psfFPA);
    291297        if (targetPSF->type != PM_FPA_FILE_PSF) {
    292298            psError(PPSTACK_ERR_CONFIG, true, "PPSTACK.TARGET.PSF is not of type PSF");
  • trunk/ppStack/src/ppStackLoop.c

    r27004 r27075  
    99#include "ppStack.h"
    1010#include "ppStackLoop.h"
     11
     12/// Print a summary of the inputs, and return the number of good inputs
     13static int stackSummary(const ppStackOptions *options, // Stack options, with input mask
     14                        const char *place              // Place in code
     15    )
     16{
     17    int numGood = 0;                // Number of good inputs
     18    psString summary = NULL;        // Summary of images
     19    for (int i = 0; i < options->num; i++) {
     20        char *reason;               // Reason for rejecting
     21        switch (options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
     22          case PPSTACK_MASK_NONE:
     23            reason = "Good";
     24            numGood++;
     25            break;
     26          case PPSTACK_MASK_CAL:
     27            reason = "Calibration failed";
     28            break;
     29          case PPSTACK_MASK_PSF:
     30            reason = "PSF measurement failed";
     31            break;
     32          case PPSTACK_MASK_MATCH:
     33            reason = "PSF matching failed";
     34            break;
     35          case PPSTACK_MASK_CHI2:
     36            reason = "PSF matching chi^2 deviant";
     37            break;
     38          case PPSTACK_MASK_REJECT:
     39            reason = "Rejection exceeded threshold";
     40            break;
     41          default:
     42            psAbort("Unrecognised mask value: %x", options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
     43        }
     44        psStringAppend(&summary, "Image %d: %s\n", i, reason);
     45    }
     46    psLogMsg("ppStack", PS_LOG_INFO, "Summary of images for %s:\n%s", place, summary);
     47    psFree(summary);
     48
     49    return numGood;
     50}
     51
     52
    1153
    1254bool ppStackLoop(pmConfig *config)
     
    5395    ppStackMemDump("convolve");
    5496
     97    // Ensure sufficient inputs
     98    {
     99        int numGood = stackSummary(options, "initial combination");
     100        psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
     101        bool safe = psMetadataLookupBool(NULL, recipe, "SAFE"); // Be safe when combining
     102        if (safe && numGood <= 1) {
     103            psError(PPSTACK_ERR_REJECTED, true, "Insufficient inputs for combination with safety on");
     104            return false;
     105        }
     106    }
    55107
    56108    // Start threading
     
    94146    ppStackMemDump("reject");
    95147
     148    // Check inputs
     149    {
     150        int numGood = stackSummary(options, "final combination");
     151        if (numGood <= 0) {
     152            psError(PPSTACK_ERR_REJECTED, true, "Insufficient inputs for combination");
     153            return false;
     154        }
     155    }
    96156
    97157    // Final combination
  • trunk/ppStack/src/ppStackPrepare.c

    r27004 r27075  
    282282        psLogMsg("ppStack", PS_LOG_INFO, "Target seeing FWHM: %f\n", options->targetSeeing);
    283283
    284         pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSTACK.OUTPUT"); // Output chip
     284        pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPSTACK.TARGET.PSF"); // Output chip
    285285        psMetadataAddPtr(outChip->analysis, PS_LIST_TAIL, "PSPHOT.PSF", PS_DATA_UNKNOWN,
    286286                         "Target PSF", options->psf);
  • trunk/ppStack/src/ppStackReject.c

    r27004 r27075  
    171171    psFree(options->regions); options->regions = NULL;
    172172
    173     if (numRejected >= num - 1) {
     173    if (numRejected >= num) {
    174174        psError(PPSTACK_ERR_REJECTED, true, "All inputs completely rejected; unable to proceed.");
    175175        return false;
Note: See TracChangeset for help on using the changeset viewer.