IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15250


Ignore:
Timestamp:
Oct 8, 2007, 5:10:05 PM (19 years ago)
Author:
Paul Price
Message:

Reading the table row by row in order to avoid memory fragmentation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceIO_PS1_DEV_1.c

    r15243 r15250  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2007-10-08 18:52:49 $
     5 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2007-10-09 03:10:05 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6666    for (i = 0; i < sources->n; i++) {
    6767        pmSource *source = (pmSource *) sources->data[i];
    68         source->seq = i;
     68        source->seq = i;
    6969
    7070        // no difference between PSF and non-PSF model
     
    166166    assert (modelType > -1);
    167167
    168     psArray *table = psFitsReadTable (fits);
    169168    // validate a single row of the table (must match SMP)
    170169
    171     // XXX test return values 
     170    // XXX test return values
    172171
    173172    // XXX we have a memory problem, which is illustrated here: if I allocate the sources array
     
    178177    // return (fooSources);
    179178
    180     psArray *sources = psArrayAlloc (table->n);
     179
     180    // We get the size of the table, and allocate the array of sources first because the table is large and
     181    // ephemeral --- when the table gets blown away, whatever is allocated after the table is read.  In fact,
     182    // it's better to read the table row by row.
     183    long numSources = psFitsTableSize(fits); // Number of sources in table
     184    psArray *sources = psArrayAlloc(numSources); // Array of sources, to return
    181185
    182186    // convert the table to the pmSource entries
    183187    // XXX need to chooose PSF vs EXT, based on type?
    184     for (int i = 0; i < table->n; i++) {
     188    for (int i = 0; i < numSources; i++) {
     189        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
     190
    185191        pmSource *source = pmSourceAlloc ();
    186192        pmModel *model = pmModelAlloc (modelType);
     
    191197        PAR = model->params->data.F32;
    192198        dPAR = model->dparams->data.F32;
    193 
    194         psMetadata *row = table->data[i];
    195199
    196200        PAR[PM_PAR_XPOS]  = psMetadataLookupF32 (&status, row, "X_PSF");
     
    225229
    226230        source->mode      = psMetadataLookupU16 (&status, row, "FLAGS");
    227         assert (status);
     231        assert (status);
    228232
    229233        // XXX other values saved but not loaded?
     
    232236
    233237        sources->data[i] = source;
    234     }
    235     psFree (table);
    236     return (sources);
     238        psFree(row);
     239    }
     240
     241    return sources;
    237242}
Note: See TracChangeset for help on using the changeset viewer.