IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 22, 2005, 4:54:52 PM (21 years ago)
Author:
Paul Price
Message:

Working under pslib-0.7.0, but don't have the inner loop behaving yet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/phase2/pmFPA.c

    r4820 r5104  
    11#include <stdio.h>
    22#include <string.h>
     3#include <assert.h>
    34#include "pslib.h"
    45#include "psAdditionals.h"
     
    67#include "pmFPA.h"
    78
    8 
    99//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1010// Allocators
    1111//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1212
    13 pmFPA *pmFPAAlloc(const psMetadata *camera, // Camera configuration
    14                   psDB *db              // Database
     13p_pmHDU *p_pmHDUAlloc(const char *extname)
     14{
     15    p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU));
     16    psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree);
     17
     18    hdu->extname = extname;
     19    hdu->pixels = NULL;
     20    hdu->header = NULL;
     21
     22    return hdu;
     23}
     24
     25void p_pmHDUFree(p_pmHDU *hdu)
     26{
     27    psFree(hdu->pixels);
     28    psFree(hdu->header);
     29}
     30
     31pmFPA *pmFPAAlloc(const psMetadata *camera // Camera configuration
    1532    )
    1633{
    1734    pmFPA *fpa = psAlloc(sizeof(pmFPA));// The FPA
    18     psMemSetDeallocator(fpa, (psFreeFcn)p_pmFPAFree);
     35    psMemSetDeallocator(fpa, (psFreeFunc)p_pmFPAFree);
    1936
    2037    // Fill in the components
     
    2340    fpa->projection = NULL;
    2441
    25     fpa->values = psMetadataAlloc();
    26 //    fpa->camera = psMemIncrRefCounter((psPtr)camera);
    27     fpa->db = db;
     42    fpa->concepts = psMetadataAlloc();
     43    fpa->camera = psMemIncrRefCounter((psPtr)camera);
    2844    fpa->chips = psArrayAlloc(0);
    2945
    30     fpa->extname = NULL;
    31     fpa->pixels = NULL;
    32     fpa->header = NULL;
     46    fpa->private = NULL;
    3347
    3448    return fpa;
     
    4155    psFree(fpa->projection);
    4256
    43     psFree(fpa->values);
     57    psFree(fpa->concepts);
    4458    psFree((psPtr)fpa->camera);
    45     psFree(fpa->db);
    4659    psFree(fpa->chips);
    4760
    48     psFree(fpa->pixels);
    49     psFree(fpa->header);
     61    psFree(fpa->private);
    5062}
    5163
     
    5567{
    5668    pmChip *chip = psAlloc(sizeof(pmChip)); // The chip
    57     psMemSetDeallocator(chip, (psFreeFcn)p_pmChipFree);
     69    psMemSetDeallocator(chip, (psFreeFunc)p_pmChipFree);
    5870
    5971    // Push onto the array of chips
     
    6779    chip->fromFPA = NULL;
    6880
    69     chip->values = psMetadataAlloc();
    70 //    chip->parent = psMemIncrRefCounter(fpa);
     81    chip->concepts = psMetadataAlloc();
    7182    chip->cells = psArrayAlloc(0);
    72 
    73     chip->extname = NULL;
    74     chip->pixels = NULL;
    75     chip->header = NULL;
    76 
    77     psMetadataAddStr(chip->values, PS_LIST_HEAD, "CHIP.NAME", "Chip name added at pmChipAlloc", name);
     83    chip->parent = fpa;                 // We don't increment the reference counter on this --- it's a
     84                                        // "hidden" link.  If we increment the reference counter, we get stuck
     85                                        // in a circle.
     86    chip->valid = true;   
     87
     88    chip->private = NULL;
     89
     90    psMetadataAddStr(chip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, "Chip name added at pmChipAlloc", name);
    7891
    7992    return chip;
     
    8598    psFree(chip->fromFPA);
    8699
    87     psFree(chip->values);
     100    psFree(chip->concepts);
    88101    psFree(chip->cells);
    89 //    psFree(chip->parent);
    90 
    91     psFree(chip->pixels);
    92     psFree(chip->header);
     102
     103    psFree(chip->private);
     104
     105    // We don't free the parent member, since that would generate a circular call.  We don't increment the
     106    // reference counter when we add it, anyway, so that's OK.
    93107}
    94108
    95109pmCell *pmCellAlloc(pmChip *chip,       // Chip to which the cell belongs
    96                     psMetadata *values, // Initial values for concepts
     110                    psMetadata *cameraData, // Camera data
    97111                    psString name       // Name of cell
    98112    )
    99113{
    100114    pmCell *cell = psAlloc(sizeof(pmCell)); // The cell
    101     psMemSetDeallocator(cell, (psFreeFcn)p_pmCellFree);
     115    psMemSetDeallocator(cell, (psFreeFunc)p_pmCellFree);
    102116
    103117    // Push onto the array of chips
     
    114128    cell->toSky = NULL;
    115129
    116     cell->values = psMemIncrRefCounter(values);
     130    cell->concepts = psMetadataAlloc();
     131    psMetadataAddStr(cell->concepts, PS_LIST_HEAD, "CELL.NAME", 0, "Cell name added at pmCellAlloc", name);
     132    cell->camera = psMemIncrRefCounter(cameraData);
     133
    117134    cell->readouts = psArrayAlloc(0);
    118 //    cell->parent = psMemIncrRefCounter(chip);
    119 
    120     cell->extname = NULL;
    121     cell->pixels = NULL;
    122     cell->header = NULL;
    123 
    124     psMetadataAddStr(cell->values, PS_LIST_HEAD, "CELL.NAME", "Cell name added at pmCellAlloc", name);
     135    cell->parent = chip;                // We don't increment the reference counter on this --- it's a
     136                                        // "hidden" link.  If we increment the reference counter, we get stuck
     137                                        // in a circle.
     138    cell->valid = true;
     139
     140    cell->private = NULL;
    125141
    126142    return cell;
     
    135151    psFree(cell->toSky);
    136152
    137     psFree(cell->values);
     153    psFree(cell->concepts);
     154    psFree(cell->camera);
    138155    psFree(cell->readouts);
    139 //    psFree(cell->parent);
    140 
    141     psFree(cell->pixels);
    142     psFree(cell->header);
     156
     157    psFree(cell->private);
     158
     159    // We don't free the parent member, since that would generate a circular call.  We don't increment the
     160    // reference counter when we add it, anyway, so that's OK.
    143161}
    144162
    145163pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs
    146                           int readoutNum, // Number of the readout
    147164                          psImage *image, // The pixels
    148165                          psList *overscans, // The overscan images
     
    151168{
    152169    pmReadout *readout = psAlloc(sizeof(pmReadout));
    153     psMemSetDeallocator(readout, (psFreeFcn)p_pmReadoutFree);
    154     psArray *readouts = cell->readouts;
    155     if (readoutNum >= readouts->nalloc) {
    156         readouts = psArrayRealloc(readouts, readoutNum);
    157         cell->readouts = readouts;
    158     }
    159     readouts->data[readoutNum] = readout;
     170    psMemSetDeallocator(readout, (psFreeFunc)p_pmReadoutFree);
     171    cell->readouts = psArrayAdd(cell->readouts, 0, readout);
    160172   
    161173    // Set the components
    162     readout->image = image;
    163     readout->overscans = overscans;
     174    readout->image = psMemIncrRefCounter(image);
     175    readout->mask = NULL;
     176    readout->overscans = psMemIncrRefCounter(overscans);
    164177   
    165     readout->values = psMetadataAlloc();
     178    //readout->concepts = psMetadataAlloc();
    166179   
    167180    *(int*)&readout->col0 = col0;
     
    178191{
    179192    psFree(readout->image);
     193    psFree(readout->mask);
    180194    psFree(readout->overscans);
    181     psFree(readout->values);
    182 }
     195    //psFree(readout->concepts);
     196}
     197
     198
     199//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     200// Select and Exclude chips
     201//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     202
     203bool pmFPASelectChip(pmFPA *fpa, int chipNum)
     204{
     205    assert(fpa);
     206
     207    if (chipNum < 0 || chipNum > fpa->chips->n) {
     208        return false;
     209    }
     210    psArray *chips = fpa->chips;        // Component chips
     211    for (int i = 0; i < chips->n; i++) {
     212        pmChip *chip = chips->data[i];  // The chip of interest
     213        if (i == chipNum) {
     214            psTrace(__func__, 5, "Marking chip %d valid.\n", i);
     215            chip->valid = true;
     216            psArray *cells = chip->cells; // Component cells
     217            for (int j = 0; j < cells->n; j++) {
     218                pmCell *cell = cells->data[j]; // Cell of interest
     219                cell->valid = true;
     220            }
     221        } else {
     222            psTrace(__func__, 5, "Marking chip %d invalid.\n", i);
     223            chip->valid = false;
     224            psArray *cells = chip->cells; // Component cells
     225            for (int j = 0; j < cells->n; j++) {
     226                pmCell *cell = cells->data[j]; // Cell of interest
     227                cell->valid = false;
     228            }
     229        }
     230    }
     231    return true;
     232}
     233
     234int pmFPAExcludeChip(pmFPA *fpa, int chipNum)
     235{
     236    assert(fpa);
     237
     238    if (chipNum < 0 || chipNum > fpa->chips->n) {
     239        psLogMsg(__func__, PS_LOG_WARN, "Invalid chip number: %d\n", chipNum);
     240    }
     241    int numValid = 0;                   // Number of valid chips
     242    psArray *chips = fpa->chips;        // Component chips
     243    for (int i = 0; i < chips->n; i++) {
     244        pmChip *chip = chips->data[i];  // The chip of interest
     245        if (i == chipNum) {
     246            psTrace(__func__, 5, "Marking chip %d invalid.\n", i);
     247            chip->valid = false;
     248            psArray *cells = chip->cells; // Component cells
     249            for (int j = 0; j < cells->n; j++) {
     250                pmCell *cell = cells->data[j]; // Cell of interest
     251                cell->valid = false;
     252            }
     253        } else if (chip->valid) {
     254            numValid++;
     255        }
     256    }
     257
     258    psTrace(__func__, 5, "%d valid chips in fpa.\n", numValid);
     259    return numValid;
     260}
Note: See TracChangeset for help on using the changeset viewer.