IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 12, 2007, 11:50:07 AM (19 years ago)
Author:
Paul Price
Message:

Asserting on file types.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageParseCamera.c

    r12820 r12824  
    55# include "ppImage.h"
    66
    7 ppImageOptions *ppImageParseCamera (pmConfig *config) {
    8 
     7ppImageOptions *ppImageParseCamera(pmConfig *config)
     8{
    99    bool status = false;
    1010
     
    1515        return NULL;
    1616    }
     17    if (input->type != PM_FPA_FILE_IMAGE) {
     18        psError(PS_ERR_IO, true, "PPIMAGE.INPUT is not of type IMAGE");
     19        return NULL;
     20    }
    1721
    1822    // if MASK or WEIGHT was supplied on command line, bind files to 'input'
    1923    // the mask and weight will be mosaicked with the image
    20     pmFPAfileBindFromArgs (NULL, input, config, "PPIMAGE.INPUT.MASK",   "MASK");
    21     pmFPAfileBindFromArgs (NULL, input, config, "PPIMAGE.INPUT.WEIGHT", "WEIGHT");
     24    pmFPAfile *inputMask = pmFPAfileBindFromArgs(NULL, input, config, "PPIMAGE.INPUT.MASK", "INPUT.MASK");
     25    if (inputMask && inputMask->type != PM_FPA_FILE_MASK) {
     26        psError(PS_ERR_IO, true, "PPIMAGE.INPUT.MASK is not of type MASK");
     27        return NULL;
     28    }
     29
     30    pmFPAfile *inputWeight = pmFPAfileBindFromArgs(NULL, input, config, "PPIMAGE.INPUT.WEIGHT", "INPUT.WEIGHT");
     31    if (inputWeight && inputWeight->type != PM_FPA_FILE_WEIGHT) {
     32        psError(PS_ERR_IO, true, "PPIMAGE.INPUT.WEIGHT is not of type WEIGHT");
     33        return NULL;
     34    }
    2235
    2336    // add recipe options supplied on command line
     
    3548        pmFPAfileDefineFromConf  (&status, config, "PPIMAGE.BIAS");
    3649        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.BIAS", input->fpa, PM_DETREND_TYPE_BIAS);
    37         if (!status) {
    38             psError (PS_ERR_IO, false, "can't find a bias image source");
     50        pmFPAfile *bias = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.BIAS");
     51        if (!status || !bias) {
     52            psError (PS_ERR_IO, false, "Can't find a bias image source");
     53            psFree(options);
     54            return NULL;
     55        }
     56        if (bias->type != PM_FPA_FILE_IMAGE) {
     57            psError(PS_ERR_IO, true, "PPIMAGE.BIAS is not of type IMAGE");
     58            psFree(options);
    3959            return NULL;
    4060        }
     
    4565        pmFPAfileDefineFromConf  (&status, config, "PPIMAGE.DARK");
    4666        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.DARK", input->fpa, PM_DETREND_TYPE_DARK);
    47         if (!status) {
    48             psError (PS_ERR_IO, false, "can't find a dark image source");
     67        pmFPAfile *dark = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.DARK");
     68        if (!status || !dark) {
     69            psError (PS_ERR_IO, false, "Can't find a dark image source");
     70            psFree(options);
     71            return NULL;
     72        }
     73        if (dark->type != PM_FPA_FILE_IMAGE) {
     74            psError(PS_ERR_IO, true, "PPIMAGE.DARK is not of type IMAGE");
     75            psFree(options);
    4976            return NULL;
    5077        }
     
    5582        pmFPAfileDefineFromConf  (&status, config, "PPIMAGE.MASK");
    5683        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.MASK", input->fpa, PM_DETREND_TYPE_MASK);
    57         if (!status) {
    58             psError (PS_ERR_IO, false, "can't find a mask image source");
     84        pmFPAfile *mask = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.MASK");
     85        if (!status || !mask) {
     86            psError (PS_ERR_IO, false, "Can't find a mask image source");
     87            psFree(options);
     88            return NULL;
     89        }
     90        if (mask->type != PM_FPA_FILE_MASK) {
     91            psError(PS_ERR_IO, true, "PPIMAGE.MASK is not of type MASK");
     92            psFree(options);
    5993            return NULL;
    6094        }
     
    6599        pmFPAfileDefineFromConf  (&status, config, "PPIMAGE.SHUTTER");
    66100        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.SHUTTER", input->fpa, PM_DETREND_TYPE_SHUTTER);
    67         if (!status) {
    68             psError (PS_ERR_IO, false, "can't find a shutter image source");
     101        pmFPAfile *shutter = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.SHUTTER");
     102        if (!status || !shutter) {
     103            psError (PS_ERR_IO, false, "Can't find a shutter image source");
     104            psFree(options);
     105            return NULL;
     106        }
     107        if (shutter->type != PM_FPA_FILE_IMAGE) {
     108            psError(PS_ERR_IO, true, "PPIMAGE.SHUTTER is not of type IMAGE");
     109            psFree(options);
    69110            return NULL;
    70111        }
     
    81122        psErrorClear();
    82123        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.FLAT", input->fpa, PM_DETREND_TYPE_FLAT);
    83         if (!status) {
    84             psError (PS_ERR_IO, false, "can't find a flat image source");
     124        pmFPAfile *flat = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.FLAT");
     125        if (!status || !flat) {
     126            psError (PS_ERR_IO, false, "Can't find a flat image source");
     127            psFree(options);
     128            return NULL;
     129        }
     130        if (flat->type != PM_FPA_FILE_IMAGE) {
     131            psError(PS_ERR_IO, true, "PPIMAGE.FLAT is not of type IMAGE");
     132            psFree(options);
    85133            return NULL;
    86134        }
     
    95143        if (!status || !filter || strlen(filter) == 0) {
    96144            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FPA.FILTER.\n");
     145            psFree(options);
    97146            return NULL;
    98147        }
     
    114163            filters = psMemIncrRefCounter(mdi->data.list);
    115164        } else {
    116             psAbort("invalid type for FRINGE.FILTERS");
     165            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     166                    "FRINGE.FILTERS in recipe %s is not of type METADATA", RECIPE_NAME);
     167            psFree(options);
     168            return NULL;
    117169        }
    118170
     
    135187        pmFPAfileDefineFromConf  (&status, config, "PPIMAGE.FRINGE");
    136188        pmFPAfileDefineFromDetDB (&status, config, "PPIMAGE.FRINGE", input->fpa, PM_DETREND_TYPE_FRINGE_IMAGE);
    137         if (!status) {
    138             psError (PS_ERR_IO, false, "can't find a fringe image source");
     189        pmFPAfile *fringe = psMetadataLookupPtr(NULL, config->files, "PPIMAGE.FRINGE");
     190        if (!status || !fringe) {
     191            psError (PS_ERR_IO, false, "Can't find a fringe image source");
     192            psFree(options);
     193            return NULL;
     194        }
     195        if (fringe->type != PM_FPA_FILE_FRINGE) {
     196            psError(PS_ERR_IO, true, "PPIMAGE.FRINGE is not of type FRINGE");
     197            psFree(options);
    139198            return NULL;
    140199        }
     
    148207        return NULL;
    149208    }
     209    if (output->type != PM_FPA_FILE_IMAGE) {
     210        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT is not of type IMAGE");
     211        psFree(options);
     212        return NULL;
     213    }
    150214    pmFPAfile *outMask = pmFPAfileDefineOutput(config, input->fpa, "PPIMAGE.OUTPUT.MASK");
    151215    if (!outMask) {
     
    154218        return NULL;
    155219    }
     220    if (outMask->type != PM_FPA_FILE_MASK) {
     221        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.MASK is not of type MASK");
     222        psFree(options);
     223        return NULL;
     224    }
    156225    pmFPAfile *outWeight = pmFPAfileDefineOutput(config, input->fpa, "PPIMAGE.OUTPUT.WEIGHT");
    157226    if (!outWeight) {
     
    160229        return NULL;
    161230    }
     231    if (outWeight->type != PM_FPA_FILE_WEIGHT) {
     232        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.WEIGHT is not of type WEIGHT");
     233        psFree(options);
     234        return NULL;
     235    }
     236
    162237    // XXX should these be bound explicitly to the output->fpa rather than the input->fpa?
    163238    pmFPAfile *byChip = pmFPAfileDefineChipMosaic(config, input->fpa, "PPIMAGE.OUTPUT.CHIP");
     
    167242        return NULL;
    168243    }
     244    if (byChip->type != PM_FPA_FILE_IMAGE) {
     245        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.CHIP is not of type IMAGE");
     246        psFree(options);
     247        return NULL;
     248    }
    169249    pmFPAfile *byFPA1 = pmFPAfileDefineFPAMosaic(config, input->fpa, "PPIMAGE.OUTPUT.FPA1");
    170250    if (!byFPA1) {
     
    173253        return NULL;
    174254    }
     255    if (byFPA1->type != PM_FPA_FILE_IMAGE) {
     256        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.FPA1 is not of type IMAGE");
     257        psFree(options);
     258        return NULL;
     259    }
    175260    pmFPAfile *byFPA2 = pmFPAfileDefineFPAMosaic(config, input->fpa, "PPIMAGE.OUTPUT.FPA2");
    176261    if (!byFPA2) {
     
    179264        return NULL;
    180265    }
     266    if (byFPA2->type != PM_FPA_FILE_IMAGE) {
     267        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.FPA2 is not of type IMAGE");
     268        psFree(options);
     269        return NULL;
     270    }
    181271
    182272    // For photometry, we operate on the chip-mosaicked image
    183273    // we create a copy of the mosaicked image for psphot so we can write out a clean image
    184274    if (options->doPhotom) {
    185         pmFPAfile *psphotInput = pmFPAfileDefineFromFPA (config, byChip->fpa, 1, 1, "PSPHOT.INPUT");
    186         PS_ASSERT (psphotInput, false);
    187 
    188         // this file is just used as a carrier;
    189         // actual output files (eg, PSPHOT.RESID) are defined below
    190         psphotInput->save = false;
    191 
    192         // define associated psphot input/output files
    193         if (!psphotDefineFiles (config, psphotInput)) {
    194             psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
    195             return false;
    196         }
     275        pmFPAfile *psphotInput = pmFPAfileDefineFromFPA (config, byChip->fpa, 1, 1, "PSPHOT.INPUT");
     276        PS_ASSERT (psphotInput, false);
     277
     278        // this file is just used as a carrier;
     279        // actual output files (eg, PSPHOT.RESID) are defined below
     280        psphotInput->save = false;
     281
     282        // define associated psphot input/output files
     283        if (!psphotDefineFiles (config, psphotInput)) {
     284            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psphot");
     285            return false;
     286        }
    197287    }
    198288
    199289    // For photometry, we operate on the chip-mosaicked image
    200290    if (options->doAstromChip || options->doAstromMosaic) {
    201         if (!options->doPhotom) {
    202             psError (PSASTRO_ERR_CONFIG, false, "photometry mode is not selected; it is required for astrometry");
    203             return false;
    204         }
    205 
    206         pmFPAfile *psphotOutput = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
    207         PS_ASSERT (psphotOutput, false);
    208 
    209         pmFPAfile *psastroInput = pmFPAfileDefineInput (config, psphotOutput->fpa, "PSASTRO.INPUT");
    210         PS_ASSERT (psastroInput, false);
    211         psastroInput->mode = PM_FPA_MODE_REFERENCE;
    212 
    213         // define associated psphot input/output files
    214         if (!psastroDefineFiles (config, psastroInput)) {
    215             psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psastro");
    216             return false;
    217         }
     291        if (!options->doPhotom) {
     292            psError (PSASTRO_ERR_CONFIG, false, "photometry mode is not selected; it is required for astrometry");
     293            return false;
     294        }
     295
     296        pmFPAfile *psphotOutput = psMetadataLookupPtr (&status, config->files, "PSPHOT.OUTPUT");
     297        PS_ASSERT (psphotOutput, false);
     298
     299        pmFPAfile *psastroInput = pmFPAfileDefineInput (config, psphotOutput->fpa, "PSASTRO.INPUT");
     300        PS_ASSERT (psastroInput, false);
     301        psastroInput->mode = PM_FPA_MODE_REFERENCE;
     302
     303        // define associated psphot input/output files
     304        if (!psastroDefineFiles (config, psastroInput)) {
     305            psError(PSPHOT_ERR_CONFIG, false, "Trouble defining the additional input/output files for psastro");
     306            return false;
     307        }
    218308    }
    219309
     
    234324        return NULL;
    235325    }
     326    if (bin1->type != PM_FPA_FILE_IMAGE) {
     327        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.BIN1 is not of type IMAGE");
     328        psFree(options);
     329        return NULL;
     330    }
    236331
    237332    pmFPAfile *bin2 = pmFPAfileDefineFromFPA (config, byChip->fpa, options->xBin2, options->yBin2, "PPIMAGE.BIN2");
     
    241336        return NULL;
    242337    }
     338    if (bin2->type != PM_FPA_FILE_IMAGE) {
     339        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.BIN2 is not of type IMAGE");
     340        psFree(options);
     341        return NULL;
     342    }
    243343
    244344    // bin1 and bin2 are used as carriers: input for byFPA1, byFPA2
     
    252352        return NULL;
    253353    }
     354    if (jpg1->type != PM_FPA_FILE_JPEG) {
     355        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.JPEG1 is not of type JPEG");
     356        psFree(options);
     357        return NULL;
     358    }
    254359    pmFPAfile *jpg2 = pmFPAfileDefineOutput (config, byFPA2->fpa, "PPIMAGE.JPEG2");
    255360    if (!jpg2) {
    256361        psError(PS_ERR_IO, false, _("Unable to generate new file from PPIMAGE.JPEG2"));
     362        psFree(options);
     363        return NULL;
     364    }
     365    if (jpg2->type != PM_FPA_FILE_JPEG) {
     366        psError(PS_ERR_IO, true, "PPIMAGE.OUTPUT.JPEG2 is not of type JPEG");
    257367        psFree(options);
    258368        return NULL;
     
    274384            if (! pmFPASelectChip(input->fpa, chipNum, false)) {
    275385                psError(PS_ERR_IO, false, "Chip number %d doesn't exist in camera.\n", chipNum);
     386                psFree(options);
    276387                return false;
    277388            }
     
    293404
    294405    if (psTraceGetLevel("ppImage.config") > 0) {
    295         // Get a look inside all the files.
    296         psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL); // Iterator
    297         psMetadataItem *item;               // Item from iteration
    298         fprintf(stderr, "Files:\n");
    299         while ((item = psMetadataGetAndIncrement(filesIter))) {
    300             pmFPAfile *file = item->data.V; // File of interest
    301             fprintf(stderr, "%s: %p %p %p (%p) %p\n", file->name,
    302                     file->src, file->fpa,
    303                     file->camera, file->fpa->camera, file->format);
    304         }
    305         psFree(filesIter);
     406        // Get a look inside all the files.
     407        psMetadataIterator *filesIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, NULL); // Iterator
     408        psMetadataItem *item;               // Item from iteration
     409        fprintf(stderr, "Files:\n");
     410        while ((item = psMetadataGetAndIncrement(filesIter))) {
     411            pmFPAfile *file = item->data.V; // File of interest
     412            fprintf(stderr, "%s: %p %p %p (%p) %p\n", file->name,
     413                    file->src, file->fpa,
     414                    file->camera, file->fpa->camera, file->format);
     415        }
     416        psFree(filesIter);
    306417    }
    307418
Note: See TracChangeset for help on using the changeset viewer.