IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26982


Ignore:
Timestamp:
Feb 17, 2010, 5:36:13 PM (16 years ago)
Author:
Paul Price
Message:

Being better about errors and their mapping to exit codes.

Location:
trunk/ppSub/src
Files:
16 edited

Legend:

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

    r26899 r26982  
    2424int main(int argc, char *argv[])
    2525{
    26 
    27 # if 0
    2826    psLibInit(NULL);
    29     pmVisualSetVisual(true);
    30     for (int order = 2; order < 11; order ++) {
    31         pmSubtractionDeconvolutionTest (order);
    32     }
    33     psLibFinalize();
    34     exit (1);
    35 # endif
    36 
    37     psExit exitValue = PS_EXIT_SUCCESS; // Exit value
    3827    psTimerStart("ppSub");
    39     psLibInit(NULL);
    4028
    4129    ppSubData *data = NULL;             // Processing data
    4230    pmConfig *config = pmConfigRead(&argc, argv, PPSUB_RECIPE); // Configuration
    4331    if (!config) {
    44         psErrorStackPrint(stderr, "Error reading configuration.");
    45         exitValue = PS_EXIT_CONFIG_ERROR;
    4632        goto die;
    4733    }
     
    5036
    5137    if (!pmModelClassInit()) {
    52         psErrorStackPrint(stderr, "Error initialising model classes.\n");
    53         exitValue = PS_EXIT_PROG_ERROR;
     38        psError(PPSUB_ERR_PROG, false, "Unable to initialise model classes.");
    5439        psFree(config);
    5540        goto die;
     
    5742
    5843    if (!psphotInit()) {
    59         psErrorStackPrint(stderr, "Error initialising psphot.\n");
    60         exitValue = PS_EXIT_PROG_ERROR;
     44        psError(PPSUB_ERR_PROG, false, "Error initialising psphot.");
    6145        psFree(config);
    6246        goto die;
     
    6650
    6751    if (!ppSubArguments(argc, argv, data)) {
    68         psErrorStackPrint(stderr, "Error reading arguments.\n");
    69         exitValue = PS_EXIT_CONFIG_ERROR;
     52        psError(PPSUB_ERR_ARGUMENTS, false, "Error reading arguments.");
    7053        goto die;
    7154    }
    7255
    7356    if (!ppSubCamera(data)) {
    74         psErrorStackPrint(stderr, "Error setting up camera.\n");
    75         exitValue = PS_EXIT_CONFIG_ERROR;
    7657        goto die;
    7758    }
    7859
    7960    if (!ppSubLoop(data)) {
    80         psErrorStackPrint(stderr, "Error performing subtraction.\n");
    81         exitValue = PS_EXIT_SYS_ERROR;
    8261        goto die;
    8362    }
     
    8766    psTimerStop();
    8867
    89     psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
    90     if (dump_file) {
    91         if (!pmConfigDump(data->config, dump_file)) {
    92             psErrorStackPrint(stderr, "Unable to dump configuration.\n");
    93             exitValue = PS_EXIT_SYS_ERROR;
     68    if (data) {
     69        psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "-dumpconfig");
     70        if (dump_file) {
     71            if (!pmConfigDump(data->config, dump_file)) {
     72                psError(PPSUB_ERR_IO, false, "Unable to dump configuration.");
     73            }
    9474        }
     75        psFree(data);
    9576    }
    96     psFree(data);
    9777
    9878    pmVisualClose(); //close plot windows, if -visual is set
     
    10181    psLibFinalize();
    10282
     83    psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
     84    psErrorCode errorCode = psErrorCodeLast(); // Error code
     85    if (errorCode != PS_ERR_NONE) {
     86        psErrorStackPrint(stderr, "Unable to perform subtraction.");
     87        switch (errorCode) {
     88          case PPSUB_ERR_UNKNOWN:
     89          case PS_ERR_UNKNOWN:
     90            exitValue = PS_EXIT_UNKNOWN_ERROR;
     91            break;
     92          case PS_ERR_IO:
     93          case PS_ERR_DB_CLIENT:
     94          case PS_ERR_DB_SERVER:
     95          case PS_ERR_BAD_FITS:
     96          case PS_ERR_OS_CALL_FAILED:
     97          case PPSUB_ERR_IO:
     98            exitValue = PS_EXIT_SYS_ERROR;
     99            break;
     100          case PS_ERR_BAD_PARAMETER_VALUE:
     101          case PS_ERR_BAD_PARAMETER_TYPE:
     102          case PS_ERR_BAD_PARAMETER_NULL:
     103          case PS_ERR_BAD_PARAMETER_SIZE:
     104          case PPSUB_ERR_ARGUMENTS:
     105          case PPSUB_ERR_CONFIG:
     106            exitValue = PS_EXIT_CONFIG_ERROR;
     107            break;
     108          case PPSUB_ERR_DATA:
     109          case PPSUB_ERR_NO_OVERLAP:
     110            exitValue = PS_EXIT_DATA_ERROR;
     111            break;
     112          case PS_ERR_UNEXPECTED_NULL:
     113          case PS_ERR_PROGRAMMING:
     114          case PPSUB_ERR_NOT_IMPLEMENTED:
     115          case PPSUB_ERR_PROG:
     116          default:
     117            // It's a programming error if we're not dealing with the error correctly
     118            exitValue = PS_EXIT_PROG_ERROR;
     119            break;
     120        }
     121    }
     122
    103123    exit(exitValue);
    104124}
  • trunk/ppSub/src/ppSubBackground.c

    r26899 r26982  
    4343        // Create the background model
    4444        if (!psphotModelBackgroundReadoutFileIndex(config, view, "PPSUB.OUTPUT", 0)) {
    45             psError(PS_ERR_UNKNOWN, false, "Unable to model background");
     45            psError(psErrorCodeLast(), false, "Unable to model background");
    4646            psFree(view);
    4747            return false;
     
    5050        modelRO = pmFPAfileThisReadout(config->files, view, "PSPHOT.BACKMDL");
    5151        if (!modelRO) {
    52             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find background model");
     52            psError(psErrorCodeLast(), false, "Unable to find background model");
    5353            psFree(view);
    5454            return false;
  • trunk/ppSub/src/ppSubCamera.c

    r26899 r26982  
    4545
    4646    if (!status) {
    47         psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     47        psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
    4848        return false;
    4949    }
     
    5252        file = pmFPAfileDefineFromRun(&status, bind, config, filerule); // File to return
    5353        if (!status) {
    54             psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     54            psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
    5555            return NULL;
    5656        }
     
    6464
    6565    if (file->type != fileType) {
    66         psError(PS_ERR_UNKNOWN, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
     66        psError(PPSUB_ERR_CONFIG, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
    6767        return NULL;
    6868    }
     
    8484        pmFPAfileDefineOutput(config, template->fpa, filerule);
    8585    if (!file) {
    86         psError(PS_ERR_IO, false, _("Unable to generate output file from %s"), filerule);
     86        psError(psErrorCodeLast(), false, _("Unable to generate output file from %s"), filerule);
    8787        return NULL;
    8888    }
    8989    if (file->type != fileType) {
    90         psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
     90        psError(PPSUB_ERR_CONFIG, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
    9191        return NULL;
    9292    }
     
    109109    pmFPAfile *file = pmFPAfileDefineFromRun(&status, bind, config, filerule); // File to return
    110110    if (!status) {
    111         psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     111        psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
    112112        return NULL;
    113113    }
     
    121121        file = pmFPAfileDefineOutput(config, bind ? bind->fpa : NULL, filerule);
    122122        if (!status) {
    123             psError(PS_ERR_UNKNOWN, false, "Failed to load file definition for %s", filerule);
     123            psError(psErrorCodeLast(), false, "Failed to load file definition for %s", filerule);
    124124            return false;
    125125        }
     
    135135
    136136    if (file->type != fileType) {
    137         psError(PS_ERR_UNKNOWN, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
     137        psError(PPSUB_ERR_CONFIG, true, "%s is not of type %s", filerule, pmFPAfileStringFromType(fileType));
    138138        return NULL;
    139139    }
     
    154154    pmFPAfile *input = defineInputFile(&success, config, NULL, "PPSUB.INPUT", "INPUT", PM_FPA_FILE_IMAGE);
    155155    if (!success) {
    156         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.INPUT");
     156        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.INPUT");
    157157        return false;
    158158    }
     
    160160    defineInputFile(&success, config, input, "PPSUB.INPUT.MASK", "INPUT.MASK", PM_FPA_FILE_MASK);
    161161    if (!success) {
    162         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.INPUT.MASK");
     162        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.INPUT.MASK");
    163163        return false;
    164164    }
     
    166166    pmFPAfile *inVar = defineInputFile(&success, config, input, "PPSUB.INPUT.VARIANCE", "INPUT.VARIANCE", PM_FPA_FILE_VARIANCE);
    167167    if (!success) {
    168         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.INPUT.VARIANCE");
     168        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.INPUT.VARIANCE");
    169169        return false;
    170170    }
     
    172172    defineInputFile(&success, config, NULL, "PPSUB.INPUT.SOURCES", "INPUT.SOURCES", PM_FPA_FILE_CMF);
    173173    if (!success) {
    174         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.INPUT.SOURCES");
     174        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.INPUT.SOURCES");
    175175        return false;
    176176    }
     
    179179    pmFPAfile *ref = defineInputFile(&success, config, NULL, "PPSUB.REF", "REF", PM_FPA_FILE_IMAGE);
    180180    if (!success) {
    181         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.REF");
     181        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF");
    182182        return false;
    183183    }
     
    185185    defineInputFile(&success, config, ref, "PPSUB.REF.MASK", "REF.MASK", PM_FPA_FILE_MASK);
    186186    if (!success) {
    187         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.REF.MASK");
     187        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF.MASK");
    188188        return false;
    189189    }
     
    191191    pmFPAfile *refVar = defineInputFile(&success, config, ref, "PPSUB.REF.VARIANCE", "REF.VARIANCE", PM_FPA_FILE_VARIANCE);
    192192    if (!success) {
    193         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.REF.VARIANCE");
     193        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF.VARIANCE");
    194194        return false;
    195195    }
     
    197197    defineInputFile(&success, config, NULL, "PPSUB.REF.SOURCES", "REF.SOURCES", PM_FPA_FILE_CMF);
    198198    if (!success) {
    199         psError(PS_ERR_IO, false, "Failed to build FPA from PPSUB.REF.SOURCES");
     199        psError(psErrorCodeLast(), false, "Failed to build FPA from PPSUB.REF.SOURCES");
    200200        return false;
    201201    }
     
    204204    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSUB_RECIPE); // Recipe for ppSim
    205205    if (!recipe) {
    206         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find recipe %s", PPSUB_RECIPE);
     206        psError(PPSUB_ERR_CONFIG, false, "Unable to find recipe %s", PPSUB_RECIPE);
    207207        return false;
    208208    }
     
    227227                                             PM_FPA_FILE_MASK);
    228228    if (!inConvImage || !inConvMask) {
    229         psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     229        psError(psErrorCodeLast(), false, "Unable to define output files");
    230230        return false;
    231231    }
     
    238238                                                PM_FPA_FILE_VARIANCE);
    239239        if (!inConvVar) {
    240             psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     240            psError(psErrorCodeLast(), false, "Unable to define output files");
    241241            return false;
    242242        }
     
    251251                                              PM_FPA_FILE_MASK);
    252252    if (!refConvImage || !refConvMask) {
    253         psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     253        psError(psErrorCodeLast(), false, "Unable to define output files");
    254254        return false;
    255255    }
     
    262262                                                 PM_FPA_FILE_VARIANCE);
    263263        if (!refConvVar) {
    264             psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     264            psError(psErrorCodeLast(), false, "Unable to define output files");
    265265            return false;
    266266        }
     
    274274    pmFPAfile *outMask = defineOutputFile(config, output, false, "PPSUB.OUTPUT.MASK", PM_FPA_FILE_MASK);
    275275    if (!output || !outMask) {
    276         psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     276        psError(psErrorCodeLast(), false, "Unable to define output files");
    277277        return false;
    278278    }
     
    283283                                             PM_FPA_FILE_VARIANCE);
    284284        if (!outVar) {
    285             psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     285            psError(psErrorCodeLast(), false, "Unable to define output files");
    286286            return false;
    287287        }
     
    296296                                              PM_FPA_FILE_MASK);
    297297        if (!inverse || !invMask) {
    298             psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     298            psError(psErrorCodeLast(), false, "Unable to define output files");
    299299            return false;
    300300        }
     
    305305                                                 PM_FPA_FILE_VARIANCE);
    306306            if (!invVar) {
    307                 psError(PS_ERR_UNKNOWN, false, "Unable to define output files");
     307                psError(psErrorCodeLast(), false, "Unable to define output files");
    308308                return false;
    309309            }
     
    316316    pmFPAfile *jpeg1 = pmFPAfileDefineOutput(config, NULL, "PPSUB.OUTPUT.JPEG1");
    317317    if (!jpeg1) {
    318         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.JPEG1"));
     318        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSUB.OUTPUT.JPEG1"));
    319319        return false;
    320320    }
    321321    if (jpeg1->type != PM_FPA_FILE_JPEG) {
    322         psError(PS_ERR_IO, true, "PPSUB.OUTPUT.JPEG1 is not of type JPEG");
     322        psError(psErrorCodeLast(), true, "PPSUB.OUTPUT.JPEG1 is not of type JPEG");
    323323        return false;
    324324    }
     
    326326    pmFPAfile *jpeg2 = pmFPAfileDefineOutput(config, NULL, "PPSUB.OUTPUT.JPEG2");
    327327    if (!jpeg2) {
    328         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.JPEG2"));
     328        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSUB.OUTPUT.JPEG2"));
    329329        return false;
    330330    }
    331331    if (jpeg2->type != PM_FPA_FILE_JPEG) {
    332         psError(PS_ERR_IO, true, "PPSUB.OUTPUT.JPEG2 is not of type JPEG");
     332        psError(psErrorCodeLast(), true, "PPSUB.OUTPUT.JPEG2 is not of type JPEG");
    333333        return false;
    334334    }
     
    338338    pmFPAfile *jpeg3 = pmFPAfileDefineOutput(config, NULL, "PPSUB.OUTPUT.RESID.JPEG");
    339339    if (!jpeg3) {
    340         psError(PS_ERR_IO, false, _("Unable to generate output file from PPSUB.OUTPUT.RESID.JPEG"));
     340        psError(psErrorCodeLast(), false, _("Unable to generate output file from PPSUB.OUTPUT.RESID.JPEG"));
    341341        return false;
    342342    }
    343343    if (jpeg3->type != PM_FPA_FILE_JPEG) {
    344         psError(PS_ERR_IO, true, "PPSUB.OUTPUT.RESID.JPEG is not of type JPEG");
     344        psError(psErrorCodeLast(), true, "PPSUB.OUTPUT.RESID.JPEG is not of type JPEG");
    345345        return false;
    346346    }
     
    360360        pmFPAfile *psphot = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.INPUT");
    361361        if (!psphot) {
    362             psError(PS_ERR_IO, false, "Failed to build FPA from PSPHOT.INPUT");
     362            psError(psErrorCodeLast(), false, "Failed to build FPA from PSPHOT.INPUT");
    363363            return false;
    364364        }
    365365        if (psphot->type != PM_FPA_FILE_IMAGE) {
    366             psError(PS_ERR_IO, true, "PSPHOT.INPUT is not of type IMAGE");
     366            psError(psErrorCodeLast(), true, "PSPHOT.INPUT is not of type IMAGE");
    367367            return false;
    368368        }
     
    374374        pmFPAfile *psf = pmFPAfileDefineFromFPA(config, output->fpa, 1, 1, "PSPHOT.PSF.LOAD");
    375375        if (!psf) {
    376             psError(PS_ERR_IO, false, "Failed to build FPA from PSPHOT.PSF.LOAD");
     376            psError(psErrorCodeLast(), false, "Failed to build FPA from PSPHOT.PSF.LOAD");
    377377            return false;
    378378        }
    379379        if (psf->type != PM_FPA_FILE_PSF) {
    380             psError(PS_ERR_IO, true, "PSPHOT.PSF.LOAD is not of type PSF");
     380            psError(psErrorCodeLast(), true, "PSPHOT.PSF.LOAD is not of type PSF");
    381381            return false;
    382382        }
     
    384384
    385385        if (!psphotDefineFiles(config, psphot)) {
    386             psError(PS_ERR_UNKNOWN, false, "Unable to set up psphot files.");
     386            psError(psErrorCodeLast(), false, "Unable to set up psphot files.");
    387387            return false;
    388388        }
     
    395395                                                 PM_FPA_FILE_CMF);
    396396        if (!outSources) {
    397             psError(PS_ERR_UNKNOWN, false, "Unable to set up output source file.");
     397            psError(psErrorCodeLast(), false, "Unable to set up output source file.");
    398398            return false;
    399399        }
     
    404404                                                     PM_FPA_FILE_CMF);
    405405            if (!invSources) {
    406                 psError(PS_ERR_UNKNOWN, false, "Unable to set up inverse source file.");
     406                psError(psErrorCodeLast(), false, "Unable to set up inverse source file.");
    407407                return false;
    408408            }
  • trunk/ppSub/src/ppSubDefineOutput.c

    r26899 r26982  
    5555
    5656    if (!kernels) {
    57         hdu = pmHDUFromCell(refConv->parent);
     57        hdu = pmHDUFromCell(refConv->parent);
    5858        analysis = refConv->analysis;
    5959        kernels = psMetadataLookupPtr(&mdok, analysis, PM_SUBTRACTION_ANALYSIS_KERNEL);
    6060    }
    6161    if (!kernels) {
    62         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find SUBTRACTION.KERNEL");
     62        psError(PPSUB_ERR_UNKNOWN, true, "Unable to find SUBTRACTION.KERNEL");
    6363        psFree(outRO);
    6464        return false;
  • trunk/ppSub/src/ppSubErrorCodes.dat

    r23740 r26982  
    1010DATA                    Problem in data values
    1111NO_OVERLAP              No overlap between input and skycell
     12PROG                    Programming error
  • trunk/ppSub/src/ppSubLoop.c

    r26899 r26982  
    4343
    4444    if (!ppSubSetMasks(config)) {
    45         psError(PS_ERR_UNKNOWN, false, "Unable to set masks.");
     45        psError(psErrorCodeLast(), false, "Unable to set masks.");
    4646        return false;
    4747    }
    4848
    4949    if (!ppSubMatchPSFs(data)) {
    50         psError(PS_ERR_UNKNOWN, false, "Unable to match PSFs.");
     50        psError(psErrorCodeLast(), false, "Unable to match PSFs.");
    5151        return false;
    5252    }
     
    5757    // generate the residual stamp grid for visualization
    5858    if (!ppSubResidualSampleJpeg(config)) {
    59         psError(PS_ERR_UNKNOWN, false, "Unable to update.");
     59        psError(psErrorCodeLast(), false, "Unable to update.");
    6060        return false;
    6161    }
     
    7171
    7272    if (!ppSubLowThreshold(data)) {
    73         psError(PS_ERR_UNKNOWN, false, "Unable to threshold images.");
     73        psError(psErrorCodeLast(), false, "Unable to threshold images.");
    7474        return false;
    7575    }
     
    8282
    8383    if (!ppSubDefineOutput("PPSUB.OUTPUT", config)) {
    84         psError(PS_ERR_UNKNOWN, false, "Unable to define output.");
     84        psError(psErrorCodeLast(), false, "Unable to define output.");
    8585        return false;
    8686    }
    8787
    8888    if (!data->quality && !ppSubMakePSF(data)) {
    89         psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
     89        psError(psErrorCodeLast(), false, "Unable to generate PSF.");
    9090        return false;
    9191    }
    9292
    9393    if (!ppSubReadoutSubtract(config)) {
    94         psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.");
     94        psError(psErrorCodeLast(), false, "Unable to subtract images.");
    9595        return false;
    9696    }
     
    104104    // Higher order background subtraction using psphot
    105105    if (!ppSubBackground(config)) {
    106         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
     106        psError(psErrorCodeLast(), false, "Unable to subtract background.");
    107107        return false;
    108108    }
     
    110110    // Perform Variance correction (rescale within a modest range)
    111111    if (!ppSubVarianceRescale(config)) {
    112         psError(PS_ERR_UNKNOWN, false, "Unable to rescale variance.");
     112        psError(psErrorCodeLast(), false, "Unable to rescale variance.");
    113113        return false;
    114114    }
     
    120120
    121121    if (!data->quality && !ppSubReadoutPhotometry("PPSUB.OUTPUT", data)) {
    122         psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
     122        psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    123123        return false;
    124124    }
     
    131131    // Perform statistics on the cell
    132132    if (!ppSubReadoutStats(data)) {
    133         psError(PS_ERR_UNKNOWN, false, "Unable to collect statistics");
     133        psError(psErrorCodeLast(), false, "Unable to collect statistics");
    134134        return false;
    135135    }
     
    137137    // generate the binned image used to write the jpeg
    138138    if (!ppSubReadoutJpeg(config)) {
    139         psError(PS_ERR_UNKNOWN, false, "Unable to update.");
     139        psError(psErrorCodeLast(), false, "Unable to update.");
    140140        return false;
    141141    }
     
    149149
    150150        if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config)) {
    151             psError(PS_ERR_UNKNOWN, false, "Unable to define inverse.");
     151            psError(psErrorCodeLast(), false, "Unable to define inverse.");
    152152            return false;
    153153        }
    154154
    155155        if (!ppSubReadoutInverse(config)) {
    156             psError(PS_ERR_UNKNOWN, false, "Unable to invert images.");
     156            psError(psErrorCodeLast(), false, "Unable to invert images.");
    157157            return false;
    158158        }
     
    170170
    171171        if (!data->quality && !ppSubReadoutPhotometry("PPSUB.INVERSE", data)) {
    172             psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
     172            psError(psErrorCodeLast(), false, "Unable to perform photometry.");
    173173            return false;
    174174        }
  • trunk/ppSub/src/ppSubMakePSF.c

    r26899 r26982  
    5959    pmFPAfile *photFile = psMetadataLookupPtr(&mdok, config->files, "PSPHOT.INPUT"); // Photometry file
    6060    if (!pmFPACopy(photFile->fpa, minuendFile->fpa)) {
    61         psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for photometry");
     61        psError(PPSUB_ERR_CONFIG, false, "Unable to copy FPA for photometry");
    6262        psFree(view);
    6363        return false;
  • trunk/ppSub/src/ppSubMatchPSFs.c

    r26974 r26982  
    5656    psAssert(photFile, "Need photometry file.");
    5757    if (!pmFPACopy(photFile->fpa, ro->parent->parent->parent)) {
    58         psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for photometry");
     58        psError(PPSUB_ERR_CONFIG, false, "Unable to copy FPA for photometry");
    5959        return false;
    6060    }
     
    170170    if (!pmSubtractionParamsScale(kernelSize, stampSize, kernelWidths, inFWHM, refFWHM,
    171171                                  scaleRef, scaleMin, scaleMax)) {
    172         psError(PS_ERR_UNKNOWN, false, "Unable to scale parameters.");
     172        psError(PPSUB_ERR_DATA, false, "Unable to scale parameters.");
    173173        return false;
    174174    }
     
    236236        psFree(lists);
    237237        if (!detections->allSources) {
    238             psError(PS_ERR_UNKNOWN, false, "Unable to merge source lists");
     238            psError(PPSUB_ERR_DATA, false, "Unable to merge source lists");
    239239            psFree(detections);
    240240            return false;
     
    262262    pmSubtractionKernelsType type = pmSubtractionKernelsTypeFromString(typeStr); // Type of kernel
    263263    if (type == PM_SUBTRACTION_KERNEL_NONE) {
    264         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unrecognised kernel type: %s", typeStr);
     264        psError(PPSUB_ERR_ARGUMENTS, true, "Unrecognised kernel type: %s", typeStr);
    265265        return false;
    266266    }
     
    319319            break;
    320320          default:
    321             psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Invalid value for -convolve");
     321            psError(PPSUB_ERR_ARGUMENTS, false, "Invalid value for -convolve");
    322322            return false;
    323323        }
     
    325325
    326326    if (!subScaleKernel(data, widths, &size, &footprint)) {
    327         psError(PS_ERR_UNKNOWN, false, "Unable to scale kernel parameters");
     327        psError(PPSUB_ERR_DATA, false, "Unable to scale kernel parameters");
    328328        return false;
    329329    }
     
    391391            return true;
    392392        } else {
    393             psError(PS_ERR_UNKNOWN, false, "Unable to match images.");
     393            psError(PPSUB_ERR_DATA, false, "Unable to match images.");
    394394            return false;
    395395        }
  • trunk/ppSub/src/ppSubReadoutInverse.c

    r24255 r26982  
    3434    pmHDU *invHDU = invFPA->hdu;          // Inverse HDU
    3535    if (!pmAstromWriteWCS(invHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
    36         psError(PS_ERR_UNKNOWN, false, "Unable to write WCS astrometry to PPSUB.INVERSE.");
     36        psError(psErrorCodeLast(), false, "Unable to write WCS astrometry to PPSUB.INVERSE.");
    3737        return false;
    3838    }
    3939    // Read from newly written astrometry so that it exists in the "inverse" FPA (for sources)
    4040    if (!pmAstromReadWCS(invFPA, invChip, invHDU->header, 1.0)) {
    41         psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry.");
     41        psError(psErrorCodeLast(), false, "Unable to read WCS astrometry.");
    4242        return false;
    4343    }
  • trunk/ppSub/src/ppSubReadoutJpeg.c

    r26899 r26982  
    3333    pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    3434    if (!pmReadoutRebin(ro1, outRO, maskBad, bin1, bin1)) {
    35         psError(PS_ERR_UNKNOWN, false, "Unable to bin output (1st binning)");
     35        psError(PPSUB_ERR_DATA, false, "Unable to bin output (1st binning)");
    3636        psFree(ro1);
    3737        psFree(ro2);
     
    3939    }
    4040    if (!pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
    41         psError(PS_ERR_UNKNOWN, false, "Unable to bin output (2nd binning)");
     41        psError(PPSUB_ERR_DATA, false, "Unable to bin output (2nd binning)");
    4242        psFree(ro1);
    4343        psFree(ro2);
  • trunk/ppSub/src/ppSubReadoutPhotometry.c

    r26899 r26982  
    5353    pmFPAfile *inFile = psMetadataLookupPtr(&mdok, config->files, name); // Input file
    5454    if (!pmFPACopy(photFile->fpa, inFile->fpa)) {
    55         psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for photometry");
     55        psError(PPSUB_ERR_CONFIG, false, "Unable to copy FPA for photometry");
    5656        psFree(view);
    5757        return false;
     
    111111    if (!data->quality) {
    112112        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.DETECTIONS")) {
    113             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.DETECTIONS");
     113            psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.DETECTIONS");
    114114            return false;
    115115        }
    116116        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, "PSPHOT.HEADER")) {
    117             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy PSPHOT.HEADER");
     117            psError(PPSUB_ERR_PROG, false, "Unable to copy PSPHOT.HEADER");
    118118            return false;
    119119        }
    120120        if (!psMetadataCopySingle(inRO->analysis, photRO->analysis, PM_DETEFF_ANALYSIS)) {
    121             psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to copy Detection Efficiency");
     121            psError(PPSUB_ERR_PROG, false, "Unable to copy Detection Efficiency");
    122122            return false;
    123123        }
  • trunk/ppSub/src/ppSubReadoutStats.c

    r23939 r26982  
    2323    pmFPAfile *output = psMetadataLookupPtr(NULL, config->files, "PPSUB.OUTPUT"); // Output file
    2424    if (!output) {
    25         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find file PPSUB.OUTPUT.\n");
     25        psError(PPSUB_ERR_PROG, true, "Unable to find file PPSUB.OUTPUT.\n");
    2626        return false;
    2727    }
  • trunk/ppSub/src/ppSubReadoutSubtract.c

    r24862 r26982  
    7171    pmFPA *outFPA = outFile->fpa;       // Output FPA
    7272    if (!pmConceptsCopyFPA(outFPA, inFPA, true, true)) {
    73         psError(PS_ERR_UNKNOWN, false, "Unable to copy concepts from input to output.");
     73        psError(PPSUB_ERR_CONFIG, false, "Unable to copy concepts from input to output.");
    7474        psFree(outRO);
    7575        psFree(view);
     
    8484    psFree(view);
    8585    if (!outHDU || !inHDU) {
    86         psError(PS_ERR_UNKNOWN, false, "Unable to find HDU at FPA level to copy astrometry.");
     86        psError(PPSUB_ERR_PROG, true, "Unable to find HDU at FPA level to copy astrometry.");
    8787        return false;
    8888    }
    8989    if (!pmAstromReadWCS(outFPA, outChip, inHDU->header, 1.0)) {
    90         psError(PS_ERR_UNKNOWN, false, "Unable to read WCS astrometry from input FPA.");
     90        psError(psErrorCodeLast(), false, "Unable to read WCS astrometry from input FPA.");
    9191        return false;
    9292    }
    9393    if (!pmAstromWriteWCS(outHDU->header, outFPA, outChip, WCS_TOLERANCE)) {
    94         psError(PS_ERR_UNKNOWN, false, "Unable to write WCS astrometry to output FPA.");
     94        psError(psErrorCodeLast(), false, "Unable to write WCS astrometry to output FPA.");
    9595        return false;
    9696    }
  • trunk/ppSub/src/ppSubSetMasks.c

    r23740 r26982  
    2828    psImageMaskType maskValue, markValue; // Mask values
    2929    if (!pmConfigMaskSetBits(&maskValue, &markValue, config)) {
    30         psError(PS_ERR_UNKNOWN, false, "Unable to determine mask value.");
     30        psError(PPSUB_ERR_CONFIG, false, "Unable to determine mask value.");
    3131        return false;
    3232    }
    3333
    3434    // Set the mask bits needed by psphot (in psphot recipe)
    35     psphotSetMaskRecipe (config, maskValue, markValue);
     35    psphotSetMaskRecipe(config, maskValue, markValue);
    3636
    3737    // Look up recipe values
     
    7979    // Mask the NAN values
    8080    if (!pmReadoutMaskNonfinite(inRO, satValue)) {
    81         psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in input.");
     81        psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in input.");
    8282        return false;
    8383    }
    8484    if (!pmReadoutMaskNonfinite(refRO, satValue)) {
    85         psError(PS_ERR_UNKNOWN, false, "Unable to mask non-finite pixels in reference.");
     85        psError(PPSUB_ERR_DATA, false, "Unable to mask non-finite pixels in reference.");
    8686        return false;
    8787    }
     
    9494    psImageInterpolateMode interpMode = psImageInterpolateModeFromString(interpModeStr); // Interp
    9595    if (interpMode == PS_INTERPOLATE_NONE) {
    96         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unknown interpolation mode: %s", interpModeStr);
     96        psError(PPSUB_ERR_CONFIG, false, "Unknown interpolation mode: %s", interpModeStr);
    9797        return false;
    9898    }
     
    104104    // Interpolate over bad pixels, so the bad pixels don't explode
    105105    if (!pmReadoutInterpolateBadPixels(inRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
    106         psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for input image.");
     106        psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for input image.");
    107107        return false;
    108108    }
    109109    if (!pmReadoutInterpolateBadPixels(refRO, maskVal, interpMode, poorFrac, maskPoor, maskBad)) {
    110         psError(PS_ERR_UNKNOWN, false, "Unable to interpolate bad pixels for reference image.");
     110        psError(PPSUB_ERR_DATA, false, "Unable to interpolate bad pixels for reference image.");
    111111        return false;
    112112    }
  • trunk/ppSub/src/ppSubThreshold.c

    r26899 r26982  
    4545    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS);                               // Random number generator
    4646    if (!psImageBackground(stats, NULL, subImage, subMask, maskIgnore, rng)) {
    47         psError(PS_ERR_UNKNOWN, false, "Unable to determine threshold.");
     47        psError(PPSUB_ERR_DATA, false, "Unable to determine threshold.");
    4848        psFree(rng);
    4949        psFree(stats);
     
    9797    pmReadout *in = pmFPAfileThisReadout(config->files, view, "PPSUB.INPUT.CONV"); // Input image
    9898    if (!in) {
    99         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find readout.");
     99        psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout.");
    100100        return false;
    101101    }
     
    103103    pmReadout *ref = pmFPAfileThisReadout(config->files, view, "PPSUB.REF.CONV"); // Reference image
    104104    if (!ref) {
    105         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find readout.");
     105        psError(PPSUB_ERR_UNKNOWN, false, "Unable to find readout.");
    106106        return false;
    107107    }
     
    114114        psRegion *region = regItem->data.V; // Region of interest
    115115        if (!lowThreshold(in, thresh, maskVal, maskThresh, region, "input convolved image")) {
    116             psError(PS_ERR_UNKNOWN, false, "Unable to threshold input image.");
     116            psError(psErrorCodeLast(), false, "Unable to threshold input image.");
    117117            return false;
    118118        }
    119119        if (!lowThreshold(ref, thresh, maskVal, maskThresh, region, "reference convolved image")) {
    120             psError(PS_ERR_UNKNOWN, false, "Unable to threshold input image.");
     120            psError(psErrorCodeLast(), false, "Unable to threshold input image.");
    121121            return false;
    122122        }
  • trunk/ppSub/src/ppSubVarianceRescale.c

    r25374 r26982  
    3535    int num = psMetadataLookupS32(&mdok, recipe, "RENORM.NUM");
    3636    if (!mdok) {
    37         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.NUM is not set in the recipe");
     37        psError(PPSUB_ERR_ARGUMENTS, true, "RENORM.NUM is not set in the recipe");
    3838        return false;
    3939    }
    4040    float minValid = psMetadataLookupF32(&mdok, recipe, "RENORM.MIN");
    4141    if (!mdok) {
    42         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.MIN is not set in the recipe");
     42        psError(PPSUB_ERR_ARGUMENTS, true, "RENORM.MIN is not set in the recipe");
    4343        return false;
    4444    }
    4545    float maxValid = psMetadataLookupF32(&mdok, recipe, "RENORM.MAX");
    4646    if (!mdok) {
    47         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "RENORM.MAX is not set in the recipe");
     47        psError(PPSUB_ERR_ARGUMENTS, true, "RENORM.MAX is not set in the recipe");
    4848        return false;
    4949    }
Note: See TracChangeset for help on using the changeset viewer.