IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16946


Ignore:
Timestamp:
Mar 12, 2008, 10:30:21 AM (18 years ago)
Author:
Paul Price
Message:

Plugging memory leaks when PSF choosing fails.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotChoosePSF.c

    r16908 r16946  
    2222    pmPSFOptions *options = pmPSFOptionsAlloc ();
    2323
    24     // load user options from the recipe. no need to check existence -- they are 
     24    // load user options from the recipe. no need to check existence -- they are
    2525    // array to store candidate PSF stars
    2626    int NSTARS = psMetadataLookupS32 (&status, recipe, "PSF_MAX_NSTARS");
     
    4949    options->psfTrendMode = pmTrend2DModeFromString (psMetadataLookupStr (&status, recipe, "PSF.TREND.MODE"));
    5050    assert (status);
    51    
     51
    5252    options->psfTrendNx = psMetadataLookupS32 (&status, recipe, "PSF.TREND.NX");
    5353    assert (status);
     
    101101    } else {
    102102        if (item->type != PS_DATA_METADATA_MULTI) psAbort("missing PSF_MODEL selection");
    103         modelNames = psListToArray (item->data.list);
     103        modelNames = psListToArray (item->data.list);
    104104    }
    105105
    106106    // generate a psf model using the first selection
    107107    if (stars->n == 0) {
    108         // XXX optionally give up here
    109         psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
    110         psErrorStackPrint (stderr, "Using guess PSF model");
    111         psErrorClear ();
    112        
    113         // unset the PSFSTAR flags (none are used):
    114         for (int i = 0; i < sources->n; i++) {
    115             pmSource *source = sources->data[i];
    116             source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
    117         }
    118 
    119         // XXX set sxx, etc from FWHM in recipe
    120         pmPSF *psf = pmPSFBuildSimple (modelNames->data[0], 1.0, 1.0, 0.0, 1.0);
    121         psf->fieldNx = readout->image->numCols;
    122         psf->fieldNy = readout->image->numRows;
    123         psFree (modelNames);
    124 
    125         bool status = true;
    126         status &= psphotMakeFluxScale (readout->image, recipe, psf);
    127         status &= psphotPSFstats (readout, recipe, psf);
    128         if (!status) {
    129             psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
    130             psFree (psf);
    131             return NULL;
    132         }
    133 
    134         // XXX set DSX_MEAN, etc?
     108        // XXX optionally give up here
     109        psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
     110        psErrorStackPrint (stderr, "Using guess PSF model");
     111        psErrorClear ();
     112
     113        psFree(options);
     114
     115        // unset the PSFSTAR flags (none are used):
     116        for (int i = 0; i < sources->n; i++) {
     117            pmSource *source = sources->data[i];
     118            source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
     119        }
     120
     121        // XXX set sxx, etc from FWHM in recipe
     122        pmPSF *psf = pmPSFBuildSimple (modelNames->data[0], 1.0, 1.0, 0.0, 1.0);
     123        psf->fieldNx = readout->image->numCols;
     124        psf->fieldNy = readout->image->numRows;
     125        psFree (modelNames);
     126
     127        bool status = true;
     128        status &= psphotMakeFluxScale (readout->image, recipe, psf);
     129        status &= psphotPSFstats (readout, recipe, psf);
     130        if (!status) {
     131            psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
     132            psFree (psf);
     133            return NULL;
     134        }
     135
     136        // XXX set DSX_MEAN, etc?
    135137        return psf;
    136138    }
     
    171173    if (bestN < 0) {
    172174        psFree (models);
    173         psFree (stars);
    174 
    175         // XXX optionally give up here
    176         // generate a psf model using the first selection
    177         psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
    178         psErrorStackPrint (stderr, "Using guess PSF model");
    179         psErrorClear ();
    180        
    181         // unset the PSFSTAR flags (none are used):
    182         for (int i = 0; i < sources->n; i++) {
    183             pmSource *source = sources->data[i];
    184             source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
    185         }
    186 
    187         // XXX set sxx, etc from FWHM in recipe
    188         pmPSF *psf = pmPSFBuildSimple (modelNames->data[0], 1.0, 1.0, 0.0, 1.0);
    189         psf->fieldNx = readout->image->numCols;
    190         psf->fieldNy = readout->image->numRows;
    191         psFree (modelNames);
    192 
    193         bool status = true;
    194         status &= psphotMakeFluxScale (readout->image, recipe, psf);
    195         status &= psphotPSFstats (readout, recipe, psf);
    196         if (!status) {
    197             psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
    198             psFree (psf);
    199             return NULL;
    200         }
    201 
    202         // XXX set DSX_MEAN, etc?
     175        psFree (stars);
     176
     177        // XXX optionally give up here
     178        // generate a psf model using the first selection
     179        psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
     180        psErrorStackPrint (stderr, "Using guess PSF model");
     181        psErrorClear ();
     182
     183        psFree(options);
     184
     185        // unset the PSFSTAR flags (none are used):
     186        for (int i = 0; i < sources->n; i++) {
     187            pmSource *source = sources->data[i];
     188            source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
     189        }
     190
     191        // XXX set sxx, etc from FWHM in recipe
     192        pmPSF *psf = pmPSFBuildSimple (modelNames->data[0], 1.0, 1.0, 0.0, 1.0);
     193        psf->fieldNx = readout->image->numCols;
     194        psf->fieldNy = readout->image->numRows;
     195        psFree (modelNames);
     196
     197        bool status = true;
     198        status &= psphotMakeFluxScale (readout->image, recipe, psf);
     199        status &= psphotPSFstats (readout, recipe, psf);
     200        if (!status) {
     201            psError(PSPHOT_ERR_PSF, false, "Failed to fit any models when choosing PSF");
     202            psFree (psf);
     203            return NULL;
     204        }
     205
     206        // XXX set DSX_MEAN, etc?
    203207        return psf;
    204208    }
     
    280284        psError(PSPHOT_ERR_PSF, false, "Unable to construct residual table for PSF");
    281285        psFree (models);
     286        psFree(options);
    282287        return NULL;
    283288    }
     
    287292        psError(PSPHOT_ERR_PSF, false, "Unable to construct flux scale for PSF");
    288293        psFree (models);
     294        psFree(options);
    289295        return NULL;
    290296    }
     
    354360        pmSourcesWritePSFs (try->sources, "psfstars.dat");
    355361        pmSourcesWriteEXTs (try->sources, "extstars.dat", false);
    356         // XXX need alternative output function
     362        // XXX need alternative output function
    357363        // psMetadata *psfData = pmPSFtoMetadata (NULL, try->psf);
    358364        // psMetadataConfigWrite (psfData, "psfmodel.dat");
     
    369375    if (!psphotPSFstats (readout, recipe, psf)) {
    370376        psError(PSPHOT_ERR_PSF, false, "cannot measure PSF shape terms");
     377        psFree(options);
    371378        psFree(psf);
    372379        return NULL;
Note: See TracChangeset for help on using the changeset viewer.