IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18854


Ignore:
Timestamp:
Aug 1, 2008, 10:40:59 AM (18 years ago)
Author:
Paul Price
Message:

Catching !model to avoid SEGV.

File:
1 edited

Legend:

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

    r14963 r18854  
    1414
    1515    pmTrend2D *trend = pmTrend2DAlloc (PM_TREND_MAP, image, Nx, Ny, stats);
    16    
     16
    1717    psVector *xPts = psVectorAlloc (Nx*Ny, PS_TYPE_F32);
    1818    psVector *yPts = psVectorAlloc (Nx*Ny, PS_TYPE_F32);
     
    2020
    2121    int Npts = 0;
     22    bool success = true;                // Function succeeded?
    2223
    23     // generate a set of test normalized PSF fluxes filling the grid 
     24    // generate a set of test normalized PSF fluxes filling the grid
    2425    for (int ix = 0; ix < Nx; ix++) {
    25         for (int iy = 0; iy < Ny; iy++) {
    26            
    27             float x = psImageBinningGetFineX (trend->map->binning, ix + 0.5);
    28             float y = psImageBinningGetFineY (trend->map->binning, iy + 0.5);
     26        for (int iy = 0; iy < Ny; iy++) {
    2927
    30             // create normalized model object at xc,yc
    31             pmModel *model = pmModelFromPSFforXY (psf, x, y, 1.0);
     28            float x = psImageBinningGetFineX (trend->map->binning, ix + 0.5);
     29            float y = psImageBinningGetFineY (trend->map->binning, iy + 0.5);
    3230
    33             // measure the fitMag for this model
    34             float fitSum = model->modelFlux (model->params);
    35             assert (fitSum > 0);
    36             assert (isfinite(fitSum));
     31            // create normalized model object at xc,yc
     32            pmModel *model = pmModelFromPSFforXY (psf, x, y, 1.0);
     33            if (!model) {
     34                psError(PS_ERR_UNKNOWN, false, "Unable to generate model for grid point %d,%d", ix, iy);
     35                success = false;
     36                goto DONE;
     37            }
    3738
    38             xPts->data.F32[Npts] = x;
    39             yPts->data.F32[Npts] = y;
    40             fPts->data.F32[Npts] = fitSum;
    41             Npts ++;
    42             assert (Npts <= xPts->nalloc);
    43             psFree (model);
    44         }
     39            // measure the fitMag for this model
     40            float fitSum = model->modelFlux (model->params);
     41            assert (fitSum > 0);
     42            assert (isfinite(fitSum));
     43
     44            xPts->data.F32[Npts] = x;
     45            yPts->data.F32[Npts] = y;
     46            fPts->data.F32[Npts] = fitSum;
     47            Npts ++;
     48            assert (Npts <= xPts->nalloc);
     49            psFree (model);
     50        }
    4551    }
    4652    xPts->n = Npts;
    4753    yPts->n = Npts;
    4854    fPts->n = Npts;
    49    
    50     // XXX test for errors here
    51     pmTrend2DFit (trend, NULL, 0xff, xPts, yPts, fPts, NULL);
    52    
     55
     56    if (!pmTrend2DFit (trend, NULL, 0xff, xPts, yPts, fPts, NULL)) {
     57        psError(PS_ERR_UNKNOWN, false, "Unable to fit trend");
     58        success = false;
     59        goto DONE;
     60    }
     61
    5362    // XXX do something useful to measure residual statistics
    5463
    55     psf->FluxScale = trend;
     64    psf->FluxScale = psMemIncrRefCounter(trend);
    5665
    57     psFree (xPts);
    58     psFree (yPts);
    59     psFree (fPts);
    60     psFree (stats);
     66 DONE:
     67    psFree(xPts);
     68    psFree(yPts);
     69    psFree(fPts);
     70    psFree(stats);
     71    psFree(trend);
    6172
    62     return true;
     73    return success;
    6374}
Note: See TracChangeset for help on using the changeset viewer.