IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 11, 2007, 12:33:52 PM (19 years ago)
Author:
Paul Price
Message:

Plugging memory leaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppSim/src/ppSimLoop.c

    r14668 r14815  
    1919    psArray *stars = psArrayAllocEmpty (1);
    2020    if (type == PPSIM_TYPE_OBJECT) {
    21         ppSimLoadStars (stars, fpa, config);
     21        ppSimLoadStars (stars, fpa, config);
    2222    }
    2323
    2424    // Add random stars
    2525    if (type == PPSIM_TYPE_OBJECT) {
    26         ppSimMakeStars (stars, fpa, config, rng);
     26        ppSimMakeStars (stars, fpa, config, rng);
    2727    }
    2828
     
    3030    psArray *galaxies = psArrayAllocEmpty (1);
    3131    if (type == PPSIM_TYPE_OBJECT) {
    32         ppSimMakeGalaxies (galaxies, fpa, config, rng);
     32        ppSimMakeGalaxies (galaxies, fpa, config, rng);
    3333    }
    3434
     
    4040    // load any needed files (eg, input image, PSF)
    4141    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    42         psError(PS_ERR_UNKNOWN, false, "failed IO for fpa in ppSim\n");
    43         psFree(view);
    44         return false;
     42        psError(PS_ERR_UNKNOWN, false, "failed IO for fpa in ppSim\n");
     43        psFree(view);
     44        return false;
    4545    }
    4646
     
    5050    while ((chip = pmFPAviewNextChip(view, fpa, 1))) {
    5151
    52         // load any needed files (eg, input image, PSF)
    53         if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
     52        // load any needed files (eg, input image, PSF)
     53        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    5454            psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip);
    55             psFree (view);
    56             return false;
    57         }
     55            psFree (view);
     56            return false;
     57        }
    5858
    59         if (type == PPSIM_TYPE_OBJECT) {
    60             if (!ppSimSetPSF (chip, config)) {
    61                 psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip);
    62                 psFree (view);
    63                 return false;
    64             }
    65         }
     59        if (type == PPSIM_TYPE_OBJECT) {
     60            if (!ppSimSetPSF (chip, config)) {
     61                psError(PS_ERR_UNKNOWN, false, "failed IO for chip %d in ppSim\n", view->chip);
     62                psFree (view);
     63                return false;
     64            }
     65        }
    6666
    6767        pmCell *cell;                   // Cell from chip
    6868        while ((cell = pmFPAviewNextCell(view, fpa, 1))) {
    6969
    70             // check that we are able to work with this cell (readdir must be 1)
     70            // check that we are able to work with this cell (readdir must be 1)
    7171            int readdir = psMetadataLookupS32(NULL, cell->concepts, "CELL.READDIR"); // Read direction
    7272            if (readdir != 1) {
     
    7676            }
    7777
    78             // if no readout exists, generate a single readout (upgrade to allow multiple
    79             // readouts?)
    80             if (cell->readouts->n == 0) {
    81                 // Size, position and orientation of cell
    82                 int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning;
    83                 int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning;
     78            // if no readout exists, generate a single readout (upgrade to allow multiple
     79            // readouts?)
     80            if (cell->readouts->n == 0) {
     81                // Size, position and orientation of cell
     82                int numCols = psMetadataLookupS32(NULL, cell->concepts, "CELL.XSIZE") / binning;
     83                int numRows = psMetadataLookupS32(NULL, cell->concepts, "CELL.YSIZE") / binning;
    8484
    85                 // generate a new readout for this cell
     85                // generate a new readout for this cell
    8686                pmReadout *readout = pmReadoutAlloc(cell); // Readout within cell
    8787
    88                 // TO DO: Decide if cell is to be windowed, reduce numCols, numRows appropriately
     88                // TO DO: Decide if cell is to be windowed, reduce numCols, numRows appropriately
    8989                readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Signal in pixels
    9090                readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Noise in pixels
    9191
    92                 psImageInit (readout->image, 0.0);
    93                 psImageInit (readout->weight, 0.0);
    94             }
     92                psImageInit (readout->image, 0.0);
     93                psImageInit (readout->weight, 0.0);
    9594
    96             psVector *biasCols = ppSimMakeBiassec (cell, config);
     95                psFree(readout);        // Drop reference
     96            }
     97
     98            psVector *biasCols = ppSimMakeBiassec (cell, config);
    9799
    98100            for (int i = 0; i < cell->readouts->n; i++) {
    99101
    100                 pmReadout *readout = cell->readouts->data[i];
    101                 assert (readout);
     102                pmReadout *readout = cell->readouts->data[i];
     103                assert (readout);
    102104
    103                 // if we have not read in a weight or generated a fake image above, we need to
    104                 // build one here
    105                 if (!readout->weight) {
    106                     if (!pmReadoutGenerateWeight(readout, true)) {
    107                         psError (PS_ERR_UNKNOWN, false, "trouble creating weight");
    108                         return false;
    109                     }
    110                 }
     105                // if we have not read in a weight or generated a fake image above, we need to
     106                // build one here
     107                if (!readout->weight) {
     108                    if (!pmReadoutGenerateWeight(readout, true)) {
     109                        psError (PS_ERR_UNKNOWN, false, "trouble creating weight");
     110                        return false;
     111                    }
     112                }
    111113
    112114                psImage *expCorr = NULL; // Exposure correction per pixel, for adding objects
     
    115117                }
    116118
    117                 psVector *biasRows = ppSimMakeBias (readout, config, rng);
    118                 if (type == PPSIM_TYPE_BIAS) goto done;
    119        
    120                 ppSimMakeDark (readout, config);
    121                 if (type == PPSIM_TYPE_DARK) goto done;
     119                psVector *biasRows = ppSimMakeBias (readout, config, rng);
     120                if (type == PPSIM_TYPE_BIAS) goto done;
    122121
    123                 ppSimMakeSky (readout, expCorr, type, config);
    124                 if (type == PPSIM_TYPE_FLAT) goto done;
     122                ppSimMakeDark (readout, config);
     123                if (type == PPSIM_TYPE_DARK) goto done;
    125124
    126                 if (type == PPSIM_TYPE_OBJECT) {
    127                     ppSimInsertStars (readout, expCorr, stars, config);
    128                 }
     125                ppSimMakeSky (readout, expCorr, type, config);
     126                if (type == PPSIM_TYPE_FLAT) goto done;
    129127
    130                 if (type == PPSIM_TYPE_OBJECT) {
    131                     ppSimInsertGalaxies (readout, expCorr, galaxies, config);
    132                 }
     128                if (type == PPSIM_TYPE_OBJECT) {
     129                    ppSimInsertStars (readout, expCorr, stars, config);
     130                }
    133131
    134             done:
    135                 ppSimAddNoise(readout->image, readout->weight, cell, config, rng);
     132                if (type == PPSIM_TYPE_OBJECT) {
     133                    ppSimInsertGalaxies (readout, expCorr, galaxies, config);
     134                }
     135
     136                psFree(expCorr);
     137
     138            done:
     139                ppSimAddNoise(readout->image, readout->weight, cell, config, rng);
    136140                ppSimSaturate(readout, config);
    137141
    138                 ppSimAddOverscan (readout, config, biasCols, biasRows, rng);
     142                ppSimAddOverscan (readout, config, biasCols, biasRows, rng);
    139143                psFree(biasRows);
    140144
     
    145149            psFree(biasCols);
    146150
    147             ppSimUpdateConceptsCell (cell, config);
     151            ppSimUpdateConceptsCell (cell, config);
    148152
    149153            if (cell->hdu) {
     
    174178    }
    175179
     180    psFree(stars);
     181    psFree(galaxies);
     182
    176183    if (fpa->hdu) {
    177184        ppSimInitHeader(config, fpa, NULL, NULL);
Note: See TracChangeset for help on using the changeset viewer.