IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6379


Ignore:
Timestamp:
Feb 7, 2006, 8:52:03 PM (20 years ago)
Author:
eugene
Message:

extensive cleanup of memory handling : no more leaks!

Location:
trunk/psphot/src
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/Makefile.am

    r6311 r6379  
    3131        psphotModelGroupInit.c  \
    3232        psphotGrowthCurve.c     \
     33        psphotCleanup.c         \
    3334        psphotEvalPSF.c         \
    3435        psphotEvalFLT.c         \
  • trunk/psphot/src/pmCellSetMask.c

    r6311 r6379  
    11# include "psphot.h"
    22
     3// 2006.02.04 : no leaks
    34bool pmCellSetMask (pmCell *cell, psMetadata *recipe) {
    45   
  • trunk/psphot/src/pmModelFitSet.c

    r5828 r6379  
    1818
    1919    return true;
     20}
     21
     22void pmModelFitSetClear (void) {
     23
     24    psFree (onePar);
     25    psFree (oneDeriv);
     26    return;
    2027}
    2128
  • trunk/psphot/src/pmSourceFitSet.c

    r5993 r6379  
    105105    for (psS32 i = 0; i < source->pixels->numRows; i++) {
    106106        for (psS32 j = 0; j < source->pixels->numCols; j++) {
     107            // skip masked points
    107108            if (source->mask->data.U8[i][j]) {
    108109                continue;
    109110            }
     111            // skip zero-weight points
     112            if (source->weight->data.F32[i][j] == 0) {
     113                continue;
     114            }
    110115            psVector *coord = psVectorAlloc(2, PS_TYPE_F32);
    111116
     
    115120            x->data[nPix] = (psPtr *) coord;
    116121            y->data.F32[nPix] = source->pixels->data.F32[i][j];
    117 
    118122            // psMinimizeLMChi2 takes wt = 1/dY^2
    119             if (source->weight->data.F32[i][j] == 0) {
    120                 continue;
    121             }
    122123            yErr->data.F32[nPix] = 1.0 / source->weight->data.F32[i][j];
    123124            nPix++;
     
    131132        psFree (y);
    132133        psFree (yErr);
     134        psFree (params);
     135        psFree (dparams);
     136        psFree (paramMask);
    133137        return(false);
    134138    }
     
    180184            dparams->data.F32[i] = delta->data.F64[i];
    181185        }
     186        psFree (delta);
    182187    }
    183188
     
    217222    psFree(covar);
    218223    psFree(paramMask);
     224    psFree(params);
     225    psFree(dparams);
     226    psFree(params_min);
     227    psFree(params_max);
     228    psFree(beta_lim);
     229
     230    // free static memory used by pmModelFitSet
     231    pmModelFitSetClear ();
    219232
    220233    rc = (onPic && fitStatus);
  • trunk/psphot/src/psModulesUtils.c

    r6311 r6379  
    180180
    181181  if (config == NULL) return;
     182  psFree (config->site);
     183  psFree (config->camera);
     184  psFree (config->recipe);
     185  psFree (config->arguments);
     186  psFree (config->options);
     187  psFree (config->database);
    182188  return;
    183189}
     
    202208
    203209  if (file == NULL) return;
     210  psFree (file->phu);
     211  psFree (file->filename);
     212  psFree (file->fpa);
     213  psFitsClose (file->fits);
    204214  return;
    205215}
  • trunk/psphot/src/psSparse.c

    r5654 r6379  
    7070        tSj->data.S32[i]  = Sj->data.S32[j];
    7171    }
     72    psFree (index);
    7273    psFree (Aij);
    7374    psFree (Si);
  • trunk/psphot/src/psphot.c

    r6311 r6379  
    2222
    2323    psLogMsg ("psphot", 3, "complete psphot run: %f sec\n", psTimerMark ("complete"));
     24
     25    psFree (input);
     26    psFree (config);
     27    psphotCleanup ();
     28
    2429    exit (0);
    2530}
  • trunk/psphot/src/psphot.h

    r6311 r6379  
    1313# include "psModulesUtils.h"
    1414# include "psSparse.h"
    15 #include "pmFPAConstruct.h"
     15# include "pmFPAConstruct.h"
     16# include "pmConcepts.h"
    1617
    1718# define PSPHOT_RECIPE "PSPHOT"
     
    2728bool            psphotReadout (pmReadout *readout, psMetadata *config);
    2829bool            ppImageLoadPixels (ppFile *input, psDB *db, int chipNum, int cellNum);
     30void            psphotCleanup (void);
    2931
    3032// psphotReadout functions
     
    8991char           *psphotSplitName (psMetadata *header);
    9092void            psphotOutputPrep (ppFile *file, ppConfig *config);
     93void            psphotOutputCleanup (void);
    9194char           *psphotNameSubstitute (char *input, char *replace, char *key);
    9295
     
    103106psF32           pmModelFitSet (psVector *deriv, const psVector *params, const psVector *x);
    104107bool            pmModelFitSetInit (pmModelType type);
     108void            pmModelFitSetClear (void);
    105109
    106110//  functions to support the source fitting process
  • trunk/psphot/src/psphotApResid.c

    r6056 r6379  
    11# include "psphot.h"
     2static char DEFAULT_OPTION[] = "SKYBIAS";
    23
    34// measure the aperture residual statistics
     
    6970    // APTREND options : NONE SKYBIAS XY_LIN XY_QUAD SKY_XY_LIN FULL
    7071    char *ApTrendOption = psMetadataLookupPtr (&status, config, "APTREND");
    71     if (!status) ApTrendOption = psStringCopy ("SKYBIAS");
     72    if (!status) ApTrendOption = DEFAULT_OPTION;
    7273
    7374    // 3hi/1lo sigma clipping on the rflux vs metric fit
     
    190191        psf->ApTrend  = psVectorChiClipFitPolynomial4D (psf->ApTrend, stats, mask, PSFTRY_MASK_ALL, apResid, dMag, xPos, yPos, r2rflux, flux);
    191192    }
    192 
    193 # if (1)
    194     psPolynomial4D *poly = psf->ApTrend;
    195     for (int nt = 0; nt <= poly->nT; nt++) {
    196         for (int nz = 0; nz <= poly->nZ; nz++) {
    197             for (int ny = 0; ny <= poly->nY; ny++) {
    198                 for (int nx = 0; nx <= poly->nX; nx++) {
    199                     if (poly->mask[nx][ny][nz][nt]) continue;
    200                     fprintf (stderr, "%d %d %d %d : %22.15g\n", nx, ny, nz, nt, poly->coeff[nx][ny][nz][nt]);
    201                 }
    202             }
    203         }
    204     }
    205 # endif
    206193
    207194    // construct the fitted values and the residuals
     
    256243              1e6*psf->ApTrend->coeff[0][2][0][0]);
    257244
    258     // psFree (stats);
    259     // psFree (mask);
    260     // psFree (rflux);
    261     // psFree (apResid);
    262 
     245    psFree (mask);
     246    psFree (xPos);
     247    psFree (yPos);
     248    psFree (flux);
     249    psFree (r2rflux);
     250    psFree (apResid);
     251    psFree (dMag);
     252
     253    psFree (fit);
     254    psFree (resid);
     255    psFree (stats);
     256    psFree (residStats);
    263257    return true;
    264258}
  • trunk/psphot/src/psphotArguments.c

    r6311 r6379  
    2727    if ((N = psArgumentGet (*argc, argv, "-mask"))) {
    2828        psArgumentRemove (N, argc, argv);
    29         psMetadataAddStr (config->arguments, PS_LIST_TAIL, "MASK_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     29        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "MASK_IMAGE", PS_META_REPLACE, "", argv[N]);
    3030        psArgumentRemove (N, argc, argv);
    3131    }
     
    3434    if ((N = psArgumentGet (*argc, argv, "-weight"))) {
    3535        psArgumentRemove (N, argc, argv);
    36         psMetadataAddStr (config->arguments, PS_LIST_TAIL, "WEIGHT_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     36        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "WEIGHT_IMAGE", PS_META_REPLACE, "", argv[N]);
    3737        psArgumentRemove (N, argc, argv);
    3838    }
     
    4141    if ((N = psArgumentGet (*argc, argv, "-resid"))) {
    4242        psArgumentRemove (N, argc, argv);
    43         psMetadataAddStr (config->arguments, PS_LIST_TAIL, "RESID_IMAGE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     43        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "RESID_IMAGE", PS_META_REPLACE, "", argv[N]);
    4444        psArgumentRemove (N, argc, argv);
    4545    }
     
    4848    if ((N = psArgumentGet (*argc, argv, "-chip"))) {
    4949        psArgumentRemove (N, argc, argv);
    50         psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_META_REPLACE, "", psStringCopy(argv[N]));
     50        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTION", PS_META_REPLACE, "", argv[N]);
    5151        psArgumentRemove (N, argc, argv);
    5252    }
     
    6565        if ((N = psArgumentGet (*argc, argv, "-model"))) {
    6666            psArgumentRemove (N, argc, argv);
    67             psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", psStringCopy (argv[N]));
     67            psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODEL", 0, "", argv[N]);
    6868            psArgumentRemove (N, argc, argv);
    6969        }
     
    7272        if ((N = psArgumentGet (*argc, argv, "-fitmode"))) {
    7373            psArgumentRemove (N, argc, argv);
    74             psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", psStringCopy (argv[N]));
     74            psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_MODE", 0, "", argv[N]);
    7575            psArgumentRemove (N, argc, argv);
    7676        }
    7777        if ((N = psArgumentGet (*argc, argv, "-fitset"))) {
    7878            psArgumentRemove (N, argc, argv);
    79             psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", psStringCopy (argv[N]));
     79            psMetadataAddStr (config->arguments, PS_LIST_TAIL, "TEST_FIT_SET", 0, "", argv[N]);
    8080            psArgumentRemove (N, argc, argv);
    8181        }
     
    8888    if ((N = psArgumentGet (*argc, argv, "-psf"))) {
    8989        psArgumentRemove (N, argc, argv);
    90         psMetadataAddStr (config->options, PS_LIST_TAIL, "PSF_INPUT_FILE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     90        psMetadataAddStr (config->options, PS_LIST_TAIL, "PSF_INPUT_FILE", PS_META_REPLACE, "", argv[N]);
    9191        psArgumentRemove (N, argc, argv);
    9292    }
     
    9595    if ((N = psArgumentGet (*argc, argv, "-photcode"))) {
    9696        psArgumentRemove (N, argc, argv);
    97         psMetadataAddStr (config->options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     97        psMetadataAddStr (config->options, PS_LIST_TAIL, "PHOTCODE", PS_META_REPLACE, "", argv[N]);
    9898        psArgumentRemove (N, argc, argv);
    9999    }
     
    102102    if ((N = psArgumentGet (*argc, argv, "-break"))) {
    103103        psArgumentRemove (N, argc, argv);
    104         psMetadataAddStr (config->options, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", psStringCopy(argv[N]));
     104        psMetadataAddStr (config->options, PS_LIST_TAIL, "BREAK_POINT", PS_META_REPLACE, "", argv[N]);
    105105        psArgumentRemove (N, argc, argv);
    106106    }
     
    109109    if ((N = psArgumentGet (*argc, argv, "-fitmode"))) {
    110110        psArgumentRemove (N, argc, argv);
    111         psMetadataAddStr (config->options, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", psStringCopy(argv[N]));
     111        psMetadataAddStr (config->options, PS_LIST_TAIL, "FITMODE", PS_META_REPLACE, "", argv[N]);
    112112        psArgumentRemove (N, argc, argv);
    113113    }
     
    116116    if ((N = psArgumentGet (*argc, argv, "-region"))) {
    117117        psArgumentRemove (N, argc, argv);
    118         psMetadataAddStr (config->options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", psStringCopy(argv[N]));
     118        psMetadataAddStr (config->options, PS_LIST_TAIL, "ANALYSIS_REGION", 0, "", argv[N]);
    119119        psArgumentRemove (N, argc, argv);
    120120    }
  • trunk/psphot/src/psphotBasicDeblend.c

    r6319 r6379  
    11# include "psphot.h"
    22
    3 // 2006.02.02 : no leaks? (creates source->blend entries)
    4 // XXX if I free sources, I still have 54 leaks?
     3// 2006.02.07 : no leaks
    54bool psphotBasicDeblend (psArray *sources, psMetadata *config, psStats *sky) {
    65
     
    3534    // this results in an index of increasing SN
    3635
    37     // temporary array for overlapping objects we find
    38     psArray *overlap = psArrayAlloc (100);
    39 
    4036    // examine sources in decreasing SN order
    4137    for (int i = sources->n - 1; i >= 0; i--) {
     
    4541        if (source->mode & PM_SOURCE_BLEND) continue;
    4642
     43        // temporary array for overlapping objects we find
     44        // XXX psArrayAlloc should set ->n to 0 *and* all objects to NULL
     45        // XXX I need a psArrayEmpty function to free the elements without the array
     46        // XXX then, I could allocate 'overlap' once outside the loop and only
     47        // XXX clear at the end of each loop
     48        psArray *overlap = psArrayAlloc (100);
    4749        overlap->n = 0;
    4850
     
    7375        }
    7476
     77        if (overlap->n == 0) {
     78            psFree (overlap);
     79            continue;
     80        }
     81
     82        // this source has overlapping neighbors, check for actual blends
    7583        // generate source contour (1/4 peak counts)
    76         if (overlap->n > 0) {
    77             // set the threshold based on user inputs
    78             threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky;
    79             threshold = PS_MAX (threshold, minThreshold);
     84        // set the threshold based on user inputs
     85        threshold = FRACTION * (source->peak->counts - source->moments->Sky) + source->moments->Sky;
     86        threshold = PS_MAX (threshold, minThreshold);
    8087
    81             // generate a basic contour (set of x,y coordinates at-or-below flux level)
    82             psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold);
    83             if (contour == NULL) continue;
     88        // generate a basic contour (set of x,y coordinates at-or-below flux level)
     89        psArray *contour = pmSourceContour_EAM (source->pixels, source->peak->x, source->peak->y, threshold);
     90        if (contour == NULL) {
     91            psFree (overlap);
     92            continue;
     93        }
    8494
    85             // the source contour consists of two vectors, xv and yv.  the contour is
    86             // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]).  both
    87             // coordinate pairs have the same yv[] value, with xv[i] corresponding to
    88             // the left boundary and xv[i+1] corresponding to the right boundary
     95        // the source contour consists of two vectors, xv and yv.  the contour is
     96        // a series of coordinate pairs, (xv[i],yv[i]) & (xv[i+1],yv[i+1]).  both
     97        // coordinate pairs have the same yv[] value, with xv[i] corresponding to
     98        // the left boundary and xv[i+1] corresponding to the right boundary
    8999
    90             psVector *xv = contour->data[0];
    91             psVector *yv = contour->data[1];
    92             for (int k = 0; k < overlap->n; k++) {
    93                 testSource = overlap->data[k];
    94                 if (testSource->peak->counts > source->peak->counts) continue;
    95                 for (int j = 0; j < xv->n; j+=2) {
    96                     if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue;
    97                     if (xv->data.F32[j+0] > testSource->peak->x) break;
    98                     if (xv->data.F32[j+1] < testSource->peak->x) break;
     100        psVector *xv = contour->data[0];
     101        psVector *yv = contour->data[1];
     102        for (int k = 0; k < overlap->n; k++) {
     103            testSource = overlap->data[k];
     104            if (testSource->peak->counts > source->peak->counts) continue;
     105            for (int j = 0; j < xv->n; j+=2) {
     106                if (fabs(yv->data.F32[j] - testSource->peak->y) > 0.5) continue;
     107                if (xv->data.F32[j+0] > testSource->peak->x) break;
     108                if (xv->data.F32[j+1] < testSource->peak->x) break;
    99109
    100                     testSource->mode |= PM_SOURCE_BLEND;
     110                testSource->mode |= PM_SOURCE_BLEND;
    101111
    102                     // add this to the list of source->blends
    103                     if (source->blends == NULL) {
    104                         source->blends = psArrayAlloc (16);
    105                         source->blends->n = 0;
    106                     }
    107                     psArrayAdd (source->blends, 16, testSource);
     112                // add this to the list of source->blends
     113                if (source->blends == NULL) {
     114                    source->blends = psArrayAlloc (16);
     115                    source->blends->n = 0;
     116                }
    108117
    109                     Nblend ++;
    110                     j = xv->n;
    111                 }
    112             } 
    113             psFree (contour);
    114         }
     118                psArrayAdd (source->blends, 16, testSource);
     119
     120                Nblend ++;
     121                j = xv->n;
     122            }
     123        } 
     124        psFree (overlap);
     125        psFree (contour);
    115126    }
    116127    psLogMsg ("psphot.deblend", 3, "identified %d blended objects (%f sec)\n", Nblend, psTimerMark ("psphot"));
    117128
    118     char *breakPt = psMetadataLookupPtr (&status, config, "BREAK_POINT");
     129    char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT");
    119130    if (!strcasecmp (breakPt, "DEBLEND")) exit (0);
    120131
    121132    psFree (SN);
    122133    psFree (index);
    123     psFree (overlap);
    124    
    125134    return true;
    126135}
  • trunk/psphot/src/psphotBlendFit.c

    r6056 r6379  
    3030        psTrace ("psphot.blend", 5, "trying source at %f, %f\n", source->moments->x, source->moments->y);
    3131
     32        // try fitting PSFs, then try extended sources
    3233        if (psphotFitBlend (readout, source)) continue;
    3334        if (psphotFitBlob (readout, source, sources)) continue;
  • trunk/psphot/src/psphotChoosePSF.c

    r6117 r6379  
    11# include "psphot.h"
    22
     3// 2006.02.07 : no leaks!
    34// try PSF models and select best option
    45pmPSF *psphotChoosePSF (psMetadata *config, psArray *sources, psStats *skystats) {
     
    89    pmPSFtry       *try   = NULL;
    910    psArray        *stars = NULL;
    10     psMetadataItem *item  = NULL;
    1111
    1212    psTimerStart ("psphot");
     
    3737    psMetadataItem *mdi = psMetadataLookup (config, "PSF_MODEL");
    3838    if (mdi == NULL) psAbort ("psphotChoosePSF", "missing PSF_MODEL selection");
     39
    3940    if (mdi->type == PS_DATA_STRING) {
    4041        list = psListAlloc(NULL);
     
    5152    psListIterator *iter = psListIteratorAlloc (list, PS_LIST_HEAD, FALSE);
    5253    for (int i = 0; i < models->n; i++) {
    53 
    54         item = psListGetAndIncrement (iter);
     54        // XXX psListGetAndIncrement does not increment ref counter!?
     55        // XXX if it did, i should free 'item' below
     56        psMetadataItem *item = psListGetAndIncrement (iter);
    5557        modelName = item->data.V;
    56 
    5758        models->data[i] = pmPSFtryModel (stars, modelName, RADIUS);
    58         psFree (modelName);
    59         psFree (item);
     59        // psFree (item);
    6060    }
    6161    psFree (iter);
     
    9898    psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid);
    9999
    100     char *breakPt = psMetadataLookupPtr (&status, config, "BREAK_POINT");
     100    char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT");
    101101    if (!strcasecmp (breakPt, "PSFFIT")) exit (0);
    102102
  • trunk/psphot/src/psphotEnsemblePSF.c

    r6056 r6379  
    11# include "psphot.h"
    22
     3// 2006.02.07 : no leaks!
     4// fit all reasonable sources with the linear PSF model
    35bool psphotEnsemblePSF (pmReadout *readout, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) {
    46
     
    68    float x;
    79    float y;
     10    float f;
    811
    912    psTimerStart ("psphot");
     
    2831    bool UseAnalysisRegion = false;
    2932    psRegion AnalysisRegion = {0, 0, 0, 0};
    30     char *region = psMetadataLookupPtr (&status, config, "ANALYSIS_REGION");
     33    char *region = psMetadataLookupStr (&status, config, "ANALYSIS_REGION");
    3134    if (status) {
    3235        UseAnalysisRegion = true;
     
    126129        index->data.U32[models->n] = i;
    127130        psArrayAdd (models, 100, otSource);
     131        psFree (otSource);
    128132    }
    129133    psLogMsg ("psphot.emsemble", 4, "built models: %f (%d objects)\n", psTimerMark ("psphot"), sources->n);
    130134   
    131     float f;
    132 
    133135    // fill out the sparse matrix
    134136    psSparse *sparse = psSparseAlloc (models->n, 100);
     
    173175        pmSource *Mi = models->data[i];
    174176
    175         Fi->modelPSF = Mi->modelPSF;
     177        // need to increment counter so we can free models here and sources above
     178        Fi->modelPSF = psMemCopy (Mi->modelPSF);
    176179
    177180        // assign linearly-fitted normalization
     
    183186        Fi->mode |= PM_SOURCE_TEMPSUB;
    184187    }
    185 
    186     // XXX EAM : need to free up many things here
     188    psFree (index);
     189    psFree (sparse);
     190    psFree (models);
     191    psFree (norm);
    187192
    188193    psLogMsg ("psphot.emsemble", 3, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot"));
  • trunk/psphot/src/psphotFindPeaks.c

    r6320 r6379  
    3939
    4040    // optional dump of all peak data
    41     char *output = psMetadataLookupPtr (&status, config, "PEAKS_OUTPUT_FILE");
     41    char *output = psMetadataLookupStr (&status, config, "PEAKS_OUTPUT_FILE");
    4242    if (status && (output != NULL) && (output[0])) {
    4343        pmPeaksWriteText (peaks, output);
    44         psFree (output);
    4544    }
    46      
    4745    psLogMsg ("psphot", 3, "%d peaks: %f sec\n", peaks->n, psTimerMark ("psphot"));
    4846
    49     char *breakPt = psMetadataLookupPtr (&status, config, "BREAK_POINT");
     47    char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT");
    5048    if (!strcasecmp (breakPt, "PEAKS")) exit (0);
    5149
  • trunk/psphot/src/psphotFitGalaxies.c

    r6056 r6379  
    1414    float EXT_MIN_SN       = psMetadataLookupF32 (&status, config, "EXT_MIN_SN");
    1515    float EXT_MOMENTS_RAD  = psMetadataLookupF32 (&status, config, "EXT_MOMENTS_RADIUS");
    16     char       *modelName  = psMetadataLookupPtr (&status, config, "EXT_MODEL");
     16    char       *modelName  = psMetadataLookupStr (&status, config, "EXT_MODEL");
    1717    pmModelType modelType  = pmModelSetType (modelName);
    1818
  • trunk/psphot/src/psphotFullFit.c

    r6056 r6379  
    1919
    2020    // extended source model descriptions
    21     char         *modelNameEXT = psMetadataLookupPtr (&status, config, "EXT_MODEL");
     21    char         *modelNameEXT = psMetadataLookupStr (&status, config, "EXT_MODEL");
    2222    pmModelType   modelTypeEXT = pmModelSetType (modelNameEXT);
    2323
  • trunk/psphot/src/psphotGrowthCurve.c

    r6311 r6379  
    6262    psLogMsg ("psphot.growth", 4, "GrowthCurve : apLoss : %f\n", psf->growth->apLoss);
    6363   
     64    psFree (view);
     65    psFree (image);
     66    psFree (mask);
     67    psFree (model);
     68    psFree (modelRef);
     69
    6470    return true;
    6571}
  • trunk/psphot/src/psphotImageLoop.c

    r6311 r6379  
    3232        if (! chip->process) { continue; }
    3333
    34         if (imageLoadDepth == PP_LOAD_CHIP) {
     34        if (imageLoadDepth == PP_LOAD_CHIP) {
    3535            psTrace(__func__, 1, "Loading pixels for chip %d...\n", i);
    3636            ppImageLoadPixels(file, config->database, i, -1);
     
    4747                ppImageLoadPixels(file, config->database, i, j);
    4848            }
    49 
     49           
    5050            // XXX optional mask and weight input image should be loaded here?
    5151            // this sets the weight map and basic mask applying CELL.BAD and CELL.SATURATION
     
    6161                // run a single-model test if desired
    6262                psphotModelTest (readout, config->arguments, config->recipe);
    63 
    6463                psphotReadout (readout, config->recipe);
    6564                psphotOutput (readout, config->arguments);
  • trunk/psphot/src/psphotLoadPixels.c

    r6117 r6379  
    2424        }
    2525    }
    26 
     26   
    2727    // Read in the input pixels
    2828    if (! pmFPARead(input->fpa, input->fits, input->phu, db)) {
     
    3030        exit(EXIT_FAILURE);
    3131    }
     32
    3233    return true;
    3334}
  • trunk/psphot/src/psphotModelTest.c

    r6311 r6379  
    11# include "psphot.h"
    22# include "psEllipse.h"
     3static char DEFAULT_MODE[] = "EXT";
    34
    45bool psphotModelTest (pmReadout *readout, psMetadata *arguments, psMetadata *recipe) {
     
    1718
    1819    // what fitting mode to use?
    19     char *psfModeWord = psMetadataLookupPtr (&status, arguments, "TEST_FIT_MODE");
     20    char *psfModeWord = psMetadataLookupStr (&status, arguments, "TEST_FIT_MODE");
    2021    if (!status) {
    21         psfModeWord = psStringCopy ("EXT");
     22        psfModeWord = DEFAULT_MODE;
    2223    }
    2324    bool psfMode = !strcasecmp (psfModeWord, "PSF");
     
    2526    // in psfMode, psf sets the model type
    2627    if (psfMode) {
    27         char *psfFile = psMetadataLookupPtr (&status, arguments, "PSF_INPUT_FILE");
     28        char *psfFile = psMetadataLookupStr (&status, arguments, "PSF_INPUT_FILE");
    2829        if (!status) psAbort ("psphotModelTest", "PSF_INPUT_FILE not supplied");
    2930        psMetadata *psfData = psMetadataConfigParse (NULL, &Nfail, psfFile, FALSE);
     
    3233    } else {
    3334        // find the model: supplied by user or first in the PSF_MODEL list
    34         char *modelName  = psMetadataLookupPtr (&status, arguments, "TEST_FIT_MODEL");
     35        char *modelName  = psMetadataLookupStr (&status, arguments, "TEST_FIT_MODEL");
    3536        if (modelName == NULL) {
    3637            // get the list pointers for the PSF_MODEL entries
     
    153154    psImageKeepCircle (source->mask, xObj, yObj, RADIUS, "OR", PSPHOT_MASK_MARKED);
    154155
    155     char *fitset = psMetadataLookupPtr (&status, arguments, "TEST_FIT_SET");
     156    char *fitset = psMetadataLookupStr (&status, arguments, "TEST_FIT_SET");
    156157    if (status) {
    157158        status = psphotFitSet (source, model, fitset, psfMode);
  • trunk/psphot/src/psphotOutput.c

    r6311 r6379  
    1212static char *extRoot    = NULL;
    1313
     14void psphotOutputCleanup () {
     15
     16    psFree (outputRoot);
     17    psFree (outputName);
     18    psFree (outputMode);
     19    psFree (outputFormat);
     20    psFree (extNumberFormat);
     21    psFree (extNameKey);
     22    psFree (extRoot);
     23    return;
     24}
     25
    1426void psphotOutputPrep (ppFile *file, ppConfig *config) {
    1527
    1628    bool status;
    1729
    18     outputRoot   = psMetadataLookupPtr (&status, config->arguments, "OUTPUT_ROOT");
     30    outputRoot      = psMetadataLookupStr (&status, config->arguments, "OUTPUT_ROOT");
    1931    if (!status) psAbort ("psphot", "output file not specified");
    2032
    21     outputName   = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_NAME");
    22     outputMode   = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_MODE");
    23     outputFormat = psMetadataLookupPtr (&status, config->recipe, "OUTPUT_FORMAT");
     33    outputName      = psMetadataLookupStr (&status, config->recipe, "OUTPUT_NAME");
     34    outputMode      = psMetadataLookupStr (&status, config->recipe, "OUTPUT_MODE");
     35    outputFormat    = psMetadataLookupStr (&status, config->recipe, "OUTPUT_FORMAT");
    2436
    2537    // rules to construct output names
    26     extNumberFormat = psMetadataLookupPtr (&status, config->recipe, "EXTNUMBER_FORMAT");
    27     extNameKey      = psMetadataLookupPtr (&status, config->recipe, "EXTNAME");
    28     extRoot         = psMetadataLookupPtr (&status, config->recipe, "EXTROOT");
     38    extNumberFormat = psMetadataLookupStr (&status, config->recipe, "EXTNUMBER_FORMAT");
     39    extNameKey      = psMetadataLookupStr (&status, config->recipe, "EXTNAME");
     40    extRoot         = psMetadataLookupStr (&status, config->recipe, "EXTROOT");
    2941
    3042    if (extNumberFormat == NULL) {
     
    6375    }
    6476
     77    // save so freeing config will not drop these references
     78    psMemCopy (outputRoot);
     79    psMemCopy (outputName);
     80    psMemCopy (outputMode);
     81    psMemCopy (outputFormat);
     82    psMemCopy (extNumberFormat);
     83    psMemCopy (extNameKey);
     84    psMemCopy (extRoot);
     85
    6586    return;
    6687}
     
    79100
    80101    // find the extname:
    81     char *extNameVal = psMetadataLookupPtr (&status, header, extNameKey);
     102    char *extNameVal = psMetadataLookupStr (&status, header, extNameKey);
    82103           
    83104    extNameWord = extNameVal;
     
    157178    if (!strcasecmp (outputMode, "SPLIT")) {
    158179        outputFile = psphotSplitName (header);
    159     } else {
    160         // construct appropriate extname
    161         psAbort ("psphotOutput", "programming error");
    162     }
    163    
    164     fprintf (stderr, "output file: %s\n", outputFile);
    165     return;
    166 
    167     char *psfFile    = psMetadataLookupPtr (&status, arguments, "PSF_OUTPUT_FILE");
    168     char *psfSample  = psMetadataLookupPtr (&status, arguments, "PSF_SAMPLE_FILE");
    169     char *residImage = psMetadataLookupPtr (&status, arguments, "RESID_IMAGE");
     180    }
     181
     182    char *psfFile    = psMetadataLookupStr (&status, arguments, "PSF_OUTPUT_FILE");
     183    char *psfSample  = psMetadataLookupStr (&status, arguments, "PSF_SAMPLE_FILE");
     184    char *residImage = psMetadataLookupStr (&status, arguments, "RESID_IMAGE");
    170185
    171186    if (psfSample != NULL) psphotSamplePSFs (psf, readout->image, psfSample);
     
    183198    if (outputFormat == NULL) {
    184199        psLogMsg ("output", 3, "no data output format selected");
     200        psFree (outputFile);
    185201        return;
    186202    }
    187203    if (!strcasecmp (outputFormat, "SX")) {
    188204        pmSourcesWriteSX (sources, outputFile);
     205        psFree (outputFile);
    189206        return;
    190207    }
    191208    if (!strcasecmp (outputFormat, "OBJ")) {
    192209        pmSourcesWriteOBJ (sources, outputFile);
     210        psFree (outputFile);
    193211        return;
    194212    }
    195213    if (!strcasecmp (outputFormat, "CMP")) {
    196214        pmSourcesWriteCMP (sources, outputFile, header);
     215        psFree (outputFile);
    197216        return;
    198217    }
    199218    if (!strcasecmp (outputFormat, "CMF")) {
    200219        pmSourcesWriteCMF (sources, outputFile, header);
     220        psFree (outputFile);
    201221        return;
    202222    }
    203223    if (!strcasecmp (outputFormat, "TEXT")) {
    204224        pmSourcesWriteText (sources, outputFile);
     225        psFree (outputFile);
    205226        return;
    206227    }
     
    610631    }
    611632    fclose (f);
     633    psFree (empty);
    612634    return true;
    613635}
     
    746768
    747769    // optional dump of all rough source data
    748     char *output = psMetadataLookupPtr (&status, config, "MOMENTS_OUTPUT_FILE");
     770    char *output = psMetadataLookupStr (&status, config, "MOMENTS_OUTPUT_FILE");
    749771    if (!status) return false;
    750772    if (output == NULL) return false;
     
    752774
    753775    pmMomentsWriteText (sources, output);
    754     psFree (output);
    755776    return true;
    756777}
  • trunk/psphot/src/psphotParseCamera.c

    r6311 r6379  
    66      if (ITEM == NULL) { \
    77        psMetadataAdd##TYPE (CONFIG, PS_LIST_TAIL, NAME, 0, COMMENT, VALUE); \
    8       } else { psFree (ITEM); } }
     8      } }
    99
     10// 2006.02.07 : no leaks!
    1011ppFile *psphotParseCamera (ppConfig *config) {
    1112
    1213    ppFile *input = ppFileAlloc ();
    1314
    14     input->filename = psMemIncrRefCounter(psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE"));
     15    input->filename = psMetadataLookupStr(NULL, config->arguments, "INPUT_FILE");
     16    psMemCopy (input->filename); // keep for external use
    1517
    1618    // Open the input image
     
    5355    while ((item = psMetadataGetAndIncrement (iter)) != NULL) {
    5456        psMetadataAddItem (config->recipe, item, PS_LIST_TAIL, PS_META_REPLACE);
    55         psFree (item);
    5657    }
    5758    psFree (iter);
  • trunk/psphot/src/psphotReadout.c

    r6319 r6379  
    11# include "psphot.h"
    22
    3 # define MEM_0 psMemId ID = psMemGetId ();
    4 # define MEM_1(A) \
    5     psTimerStop ();\
    6     if (A != NULL) { psFree (A); } \
    7     fprintf (stderr, "found %d leaks\n", psMemCheckLeaks (ID, NULL, NULL, false));\
    8     exit (1);
    9 
     3// XXX 2006.02.07 : no leaks!
    104bool psphotReadout (pmReadout *readout, psMetadata *config) {
    115
     
    4135
    4236    // use bright stellar objects to measure PSF
    43     MEM_0;
    4437    psf = psphotChoosePSF (config, sources, sky);
    45     MEM_1(psf);
    4638
    4739    // XXX change FITMODE to a string
     
    8072    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SKY.MEAN",  PS_DATA_F32,     "psphot sky mean", sky->sampleMean);
    8173    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SKY.SIGMA", PS_DATA_F32,     "psphot sky stdev", sky->sampleStdev);
     74
     75    // free up the local copies of the data
     76    psFree (psf);
     77    psFree (sky);
     78    psFree (model);
     79    psFree (peaks);
     80    psFree (sources);
     81
    8282    return true;
    8383}
  • trunk/psphot/src/psphotRoughClass.c

    r6320 r6379  
    1515    psphotDumpMoments (config, sources);
    1616
    17     char *breakPt = psMetadataLookupPtr (&status, config, "BREAK_POINT");
     17    char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT");
    1818    if (!strcasecmp (breakPt, "CLASS")) exit (0);
    1919
  • trunk/psphot/src/psphotSourceFits.c

    r6056 r6379  
    5454
    5555    // extended source model descriptions
    56     char *modelNameEXT = psMetadataLookupPtr (&status, config, "EXT_MODEL");
     56    char *modelNameEXT = psMetadataLookupStr (&status, config, "EXT_MODEL");
    5757    modelTypeEXT = pmModelSetType (modelNameEXT);
    5858    psphotInitRadiusEXT (config, sky, modelTypeEXT);
     
    7777    psTrace ("psphot.blend", 5, "trying blob...\n");
    7878
     79    // this temporary source is used as a place-holder by the psphotEval functions below
    7980    pmSource *tmpSrc = pmSourceAlloc ();
    8081
     
    8990    chiDBL = ONE->chisq / ONE->nDOF;
    9091
     92    psFree (tmpSrc); // XXX should I keep / save the flags set in the eval functions?
     93
    9194    if (okEXT && okDBL) {
    9295        psTrace ("psphot.blend", 5, "blob chisq: %f vs %f\n", chiEXT, chiDBL);
     
    98101    if (okEXT && !okDBL) goto keepEXT;
    99102    if (!okEXT && okDBL) goto keepDBL;
     103
     104    // both models failed; reject them both
     105    psFree (EXT);
     106    psFree (DBL);
    100107    return false;
    101108
    102109keepEXT:
    103110    // sub EXT
     111    psFree (DBL);
    104112    pmSourceSubModel (source->pixels, source->mask, EXT, false, false);
    105113    psTrace ("psphot.blend", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[2], EXT->params->data.F32[3]);
     
    113121keepDBL:
    114122    // sub DLB
     123    psFree (EXT);
    115124    pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[0], false, false);
    116125    pmSourceSubModel (source->pixels, source->mask, (pmModel *) DBL->data[1], false, false);
     
    120129    source->mode |=  PM_SOURCE_SUBTRACTED;
    121130    source->mode &= ~PM_SOURCE_TEMPSUB;
    122 
    123     // save new model
    124     // tmpSrc->modelPSF = (pmModel *) modelSet->data[1];
    125     // psArrayAdd (sources, 100, tmpSrc);
    126131
    127132    return true;
     
    205210        return status;
    206211    }
    207 
    208212    psTrace ("psphot.blend", 5, "trying blend...\n");
    209213
     
    225229    psArrayAdd (sourceSet, 16, source);
    226230
     231    // counter to track the blend elements used in the fit
     232    psVector *index  = psVectorAlloc (source->blends->n + 1, PS_TYPE_S32);
     233    index->data.S32[0] = -1; // first element corresponds to the primary source
     234
    227235    for (int i = 0; i < source->blends->n; i++) {
    228236        pmSource *blend = source->blends->data[i];
     
    237245        pmModel *model = blend->modelPSF;
    238246
    239         for (psS32 i = 0; i < model->params->n; i++) {
    240             model->params->data.F32[i] = PSF->params->data.F32[i];
    241             model->dparams->data.F32[i] = PSF->dparams->data.F32[i];
     247        for (int j = 0; j < model->params->n; j++) {
     248            model->params->data.F32[j] = PSF->params->data.F32[j];
     249            model->dparams->data.F32[j] = PSF->dparams->data.F32[j];
    242250        }
    243251
     
    247255
    248256        // add this blend to the list
     257        index->data.S32[modelSet->n] = i;
    249258        psArrayAdd (modelSet, 16, model);
    250259        psArrayAdd (sourceSet, 16, blend);
     
    261270        pmModel *model = modelSet->data[i];
    262271
     272        // if we skip this one, free the corresponding blend entry model
    263273        if (!psphotEvalPSF (src, model)) {
    264             psFree (model);
    265             src->modelPSF = NULL;
     274            int n = index->data.S32[i];
     275            pmSource *blend = source->blends->data[n];
     276            psFree (blend->modelPSF);
     277            blend->modelPSF = NULL;
    266278            continue;
    267279        }
     
    272284        src->mode &= ~PM_SOURCE_TEMPSUB;
    273285    }
     286    psFree (index);
     287    psFree (modelSet);
     288    psFree (sourceSet);
    274289
    275290    // evaluate the primary object
     
    281296    psTrace ("psphot.blend", 5, "fitted primary as PSF\n");
    282297    pmSourceSubModel (source->pixels, source->mask, PSF, false, false);
     298    psFree (source->modelPSF);
    283299    source->modelPSF = PSF;
    284300    source->mode |=  PM_SOURCE_SUBTRACTED;
  • trunk/psphot/src/psphotSourceStats.c

    r6320 r6379  
    6363    psLogMsg ("psphot", 3, "%d moments: %f sec\n", sources->n, psTimerMark ("psphot"));
    6464
    65     char *breakPt = psMetadataLookupPtr (&status, config, "BREAK_POINT");
     65    char *breakPt = psMetadataLookupStr (&status, config, "BREAK_POINT");
    6666    if (!strcasecmp (breakPt, "STATS")) exit (0);
    6767
Note: See TracChangeset for help on using the changeset viewer.