IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 16, 2005, 5:18:39 PM (21 years ago)
Author:
Paul Price
Message:

Importing PAP code from phase 2. NOTE: Reverted files in detrend/ and imsubtract/ to a previous version. DO NOT merge these files back!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_051214/psModules/src/astrom/pmAstrometry.c

    r5739 r5795  
    1010* XXX: We should review the extent of the warning messages on these functions
    1111* when the transformations are not successful.
    12 * 
     12*
    1313* XXX: Should we implement non-linear cell->chip transforms?
    14 * 
    15 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    16 *  @date $Date: 2005-12-08 00:00:57 $
     14*
     15*  @version $Revision: 1.11.2.1 $ $Name: not supported by cvs2svn $
     16*  @date $Date: 2005-12-17 03:18:38 $
    1717*
    1818*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6060        psFree(readout->mask);
    6161        psFree(readout->weight);
    62         //
    63         // XXX: Not sure if this is the right way to do things.  Currently the psListAdd()
    64         // increase the memory reference counter to the list data.  So, we
    65         // iterate through the list, and decrement the reference counters.
    66         //
    67         if (1) {
    68             if ((readout->bias != NULL) && (readout->bias->head != NULL)) {
    69                 psListElem *tmpElem = (psListElem *) readout->bias->head;
    70                 while (NULL != tmpElem) {
    71                     psMemDecrRefCounter((psImage *) tmpElem->data);
    72                     tmpElem = tmpElem->next;
    73                 }
    74             }
    75         }
    76         psFree(readout->bias);
    7762        psFree(readout->analysis);
    7863        psFree(readout->parent);
     
    8873        psFree(cell->concepts);
    8974        psFree(cell->analysis);
     75        psFree(cell->camera);
    9076        //
    9177        // Set the parent to NULL in all cell->readouts before psFree(cell->readouts)
     
    10187        psFree(cell->readouts);
    10288        psFree(cell->parent);
    103         psFree(cell->private);
     89        psFree(cell->hdu);
    10490    }
    10591}
     
    125111        psFree(chip->cells);
    126112        psFree(chip->parent);
    127         psFree(chip->private);
     113        psFree(chip->hdu);
    128114    }
    129115}
     
    151137        }
    152138        psFree(fpa->chips);
    153         psFree(fpa->private);
     139        psFree(fpa->hdu);
    154140        psFree(fpa->phu);
    155141    }
    156142}
    157143
     144void p_pmHDUFree(p_pmHDU *hdu)
     145{
     146    if (hdu) {
     147        psFree(hdu->extname);
     148        psFree(hdu->header);
     149        psFree(hdu->images);
     150        psFree(hdu->masks);
     151        psFree(hdu->weights);
     152    }
     153}
     154
    158155// XXX: Verify these default values for row0, col0, rowBins, colBins
     156// PAP: These values may disappear in the future in favour of values in parent->concepts?
    159157pmReadout *pmReadoutAlloc(pmCell *cell)
    160158{
    161159    pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout));
    162160
    163     tmpReadout->col0 = -1;
    164     tmpReadout->row0 = -1;
    165     tmpReadout->colBins = -1;
    166     tmpReadout->rowBins = -1;
     161    tmpReadout->col0 = 0;
     162    tmpReadout->row0 = 0;
     163    tmpReadout->colBins = 0;
     164    tmpReadout->rowBins = 0;
    167165    tmpReadout->image = NULL;
    168166    tmpReadout->mask = NULL;
    169167    tmpReadout->weight = NULL;
    170     tmpReadout->bias = NULL;
    171168    tmpReadout->analysis = psMetadataAlloc();
    172169    tmpReadout->parent = cell;
     
    179176
    180177// XXX: Verify these default values for row0, col0.
     178// PAP: These values may disappear in the future in favour of values in the "concepts"?
    181179pmCell *pmCellAlloc(
    182180    pmChip *chip,
    183     psMetadata *cameradata,
    184     psString name)
     181    psMetadata *cameraData,
     182    const char *name)
    185183{
    186184    pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell));
    187185
    188     tmpCell->col0 = -1;
    189     tmpCell->row0 = -1;
     186    tmpCell->col0 = 0;
     187    tmpCell->row0 = 0;
    190188    tmpCell->toChip = NULL;
    191189    tmpCell->toFPA = NULL;
     
    196194        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CELL.NAME to metadata.\n");
    197195    }
    198     tmpCell->camera = cameradata;
    199     tmpCell->analysis = NULL;
     196    tmpCell->camera = psMemIncrRefCounter(cameraData);
     197    tmpCell->analysis = psMetadataAlloc();
    200198    tmpCell->readouts = psArrayAlloc(0);
    201     tmpCell->parent = chip;
     199    tmpCell->parent = psMemIncrRefCounter(chip);
    202200    if (chip != NULL) {
    203201        chip->cells = psArrayAdd(chip->cells, 1, (psPtr) tmpCell);
    204202    }
    205     tmpCell->valid = false;
    206     tmpCell->private = NULL;
     203    tmpCell->valid = true;              // All cells are valid by default
     204    tmpCell->hdu = NULL;
    207205
    208206    psMemSetDeallocator(tmpCell, (psFreeFunc) cellFree);
     
    211209
    212210// XXX: Verify these default values for row0, col0.
     211// PAP: row0, col0 may disappear in the future in favour of storing values in the "concepts".
    213212pmChip *pmChipAlloc(
    214213    pmFPA *fpa,
    215     psString name)
     214    const char *name)
    216215{
    217216    pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip));
    218217
    219     tmpChip->col0 = -1;
    220     tmpChip->row0 = -1;
     218    tmpChip->col0 = 0;
     219    tmpChip->row0 = 0;
    221220    tmpChip->toFPA = NULL;
    222221    tmpChip->fromFPA = NULL;
     
    226225        psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CHIP.NAME to metadata.\n");
    227226    }
    228     tmpChip->analysis = NULL;
     227    tmpChip->analysis = psMetadataAlloc();
    229228    tmpChip->cells = psArrayAlloc(0);
    230     tmpChip->parent = fpa;
     229    tmpChip->parent = psMemIncrRefCounter(fpa);
    231230    if (fpa != NULL) {
    232231        fpa->chips = psArrayAdd(fpa->chips, 1, (psPtr) tmpChip);
    233232    }
    234     tmpChip->valid = false;
    235     tmpChip->private = NULL;
     233    tmpChip->valid = true;              // Work on all chips, by default
     234    tmpChip->hdu = NULL;
    236235
    237236    psMemSetDeallocator(tmpChip, (psFreeFunc) chipFree);
     
    248247    tmpFPA->concepts = psMetadataAlloc();
    249248    tmpFPA->analysis = NULL;
    250     tmpFPA->camera = camera;
     249    tmpFPA->camera = psMemIncrRefCounter((psPtr)camera);
    251250    tmpFPA->chips = psArrayAlloc(0);
    252     tmpFPA->private = NULL;
     251    tmpFPA->hdu = NULL;
    253252    tmpFPA->phu = NULL;
    254253
    255254    psMemSetDeallocator(tmpFPA, (psFreeFunc) FPAFree);
    256255    return(tmpFPA);
     256}
     257
     258p_pmHDU *p_pmHDUAlloc(const char *extname)
     259{
     260    p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU));
     261    psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree);
     262
     263    hdu->extname = psStringCopy(extname);
     264    hdu->header = NULL;
     265    hdu->images = NULL;
     266    hdu->masks = NULL;
     267    hdu->weights = NULL;
     268
     269    return hdu;
    257270}
    258271
     
    800813}
    801814
     815
     816/*****************************************************************************
     817 *****************************************************************************/
     818
     819// Set cells within a chip to a specified validity
     820static bool setCellsValid(const pmChip *chip, // Chip of interest
     821                          bool valid    // Valid?
     822                         )
     823{
     824    PS_ASSERT_PTR_NON_NULL(chip, false);
     825
     826    psArray *cells = chip->cells;       // Component cells
     827    if (! cells) {
     828        return false;
     829    }
     830    for (int i = 0; i < cells->n; i++) {
     831        pmCell *tmpCell = cells->data[i]; // Cell of interest
     832        if (tmpCell) {
     833            tmpCell->valid = valid;
     834        }
     835    }
     836
     837    return true;
     838}
     839
    802840/*****************************************************************************
    803841 *****************************************************************************/
     
    807845{
    808846    PS_ASSERT_PTR_NON_NULL(fpa, false);
    809     if ((fpa->chips == NULL) || (chipNum >= fpa->chips->n)) {
     847
     848    psArray *chips = fpa->chips;        // Component chips
     849    if ((chips == NULL) || (chipNum >= chips->n)) {
    810850        return(false);
    811851    }
    812     psBool rc = true;
    813 
    814     for (psS32 i = 0 ; i < fpa->chips->n ; i++) {
    815         pmChip *tmpChip = (pmChip *) fpa->chips->data[i];
     852
     853    for (int i = 0 ; i < chips->n ; i++) {
     854        pmChip *tmpChip = (pmChip *) chips->data[i];
    816855        if (tmpChip == NULL) {
    817             rc = false;
     856            continue;
     857        }
     858        if (i == chipNum) {
     859            tmpChip->valid = true;
     860            setCellsValid(tmpChip, true);
    818861        } else {
    819             if (i == chipNum) {
    820                 tmpChip->valid = true;
    821             } else {
    822                 tmpChip->valid = false;
    823             }
    824         }
    825     }
    826 
    827     return(rc);
     862            tmpChip->valid = false;
     863            setCellsValid(tmpChip, false);
     864        }
     865
     866    }
     867
     868    return true;
    828869}
    829870
     
    831872/*****************************************************************************
    832873XXX: The SDRS is ambiguous on a few things:
    833     Whether or not the other chips should be set valid=true.
    834     Should we return the number of chip valid=true before or after they're set,
     874    Whether or not the other chips should be set valid=true. [PAP: No]
     875    Should we return the number of chip valid=true before or after they're set, [PAP: After]
    835876 *****************************************************************************/
    836877/**
    837  * 
     878 *
    838879 * pmFPAExcludeChip shall set valid to false only for the specified chip
    839880 * number (chipNum). In the event that the specified chip number does not exist
     
    841882 * The function shall return the number of chips within the fpa that have valid
    842883 * set to true.
    843  * 
     884 *
    844885 */
    845886int pmFPAExcludeChip(
     
    849890    PS_ASSERT_PTR_NON_NULL(fpa, false);
    850891
    851     if (fpa->chips == NULL) {
     892    psArray *chips = fpa->chips;        // Component chips
     893    if (chips == NULL) {
    852894        psLogMsg(__func__, PS_LOG_WARN, "WARNING: fpa->chips == NULL\n");
    853895        return(0);
    854896    }
    855     if ((chipNum >= fpa->chips->n) || (NULL == (pmChip *) fpa->chips->data[chipNum])) {
     897    if ((chipNum >= chips->n) || (NULL == (pmChip *) chips->data[chipNum])) {
    856898        psLogMsg(__func__, PS_LOG_WARN, "WARNING: the specified chip (%d) does not exist.\n", chipNum);
    857899        return(0);
    858900    }
    859901
    860     psS32 numChips = 0;
    861     for (psS32 i = 0 ; i < fpa->chips->n ; i++) {
    862         pmChip *tmpChip = (pmChip *) fpa->chips->data[i];
     902    int numChips = 0;                   // Number of valid chips
     903    for (int i = 0 ; i < chips->n ; i++) {
     904        pmChip *tmpChip = (pmChip *) chips->data[i]; // Chip of interest
    863905        if (tmpChip != NULL) {
    864906            if (i == chipNum) {
    865907                tmpChip->valid = false;
    866             } else {
    867                 tmpChip->valid = true;
     908                setCellsValid(tmpChip, false); // Wipe out the cell as well
     909            } else if (tmpChip->valid) {
    868910                numChips++;
    869911            }
Note: See TracChangeset for help on using the changeset viewer.