IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4694


Ignore:
Timestamp:
Aug 1, 2005, 2:21:14 PM (21 years ago)
Author:
Paul Price
Message:

Rough draft of pmFPAMorph working

Location:
trunk/archive/scripts/src
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/Makefile

    r4309 r4694  
    88BUILD_TARGET = test_pmFPAfromHeader
    99
    10 READ_OBJS = test_pmFPARead.o pmCameraFromHeader.o pmFPARead.o papFocalPlane.o psAdditionals.o papStuff.o
     10READ_OBJS = test_pmFPARead.o pmCameraFromHeader.o pmFPARead.o papFocalPlane.o psAdditionals.o papStuff.o \
     11                pmFPAConstruct.o pmFPAMorph.o pmFPAWrite.o
    1112READ_TARGET = test_pmFPARead
    1213
  • trunk/archive/scripts/src/megacam_raw.config

    r4395 r4694  
    125125# Default PS concepts that may be specified by value
    126126DEFAULTS        METADATA
     127        CELL.READDIR            S32     1               # Cell is read in x direction
    127128        CELL.BAD                S32     0
     129#       CELL.YPARITY    S32     1
     130# This doesn't work, yet.
    128131        CELL.YPARITY_DEPEND     STR     CHIP.NAME
    129132        CELL.YPARITY    METADATA
  • trunk/archive/scripts/src/megacam_splice.config

    r4395 r4694  
    8888# Default PS concepts that may be specified by value
    8989DEFAULTS        METADATA
     90        CELL.READDIR            S32     1               # Cell is read in x direction
    9091        CELL.BAD                S32     0
    9192        CELL.XPARITY            S32     1
  • trunk/archive/scripts/src/papFocalPlane.c

    r4386 r4694  
    254254}
    255255
    256 psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell
    257                                const char *chipName, // The name of the chip
    258                                const char *cellName, // The name of the cell
     256psMetadataItem *psCellGetValue(papCell *cell, // The cell
    259257                               const char *valueName // Name of value
    260258                               )
    261259{
    262     psTrace(__func__, 3, "Trying to retrieve %s for %s:%s...\n", valueName, chipName, cellName);
    263 
    264     bool mdStatus = true;               // Status of MD lookup
    265     papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
    266     if (!mdStatus) {
    267         psError(PS_ERR_IO, false, "Unable to find chip named %s\n", chipName);
    268         return NULL;
    269     }
    270     papCell *cell = psMetadataLookupCell(&mdStatus, chip->cells, cellName); // The cell
    271     if (!mdStatus) {
    272         psError(PS_ERR_IO, false, "Unable to find cell named %s in chip %s\n", cellName, chipName);
    273         return NULL;
    274     }
     260    psTrace(__func__, 3, "Trying to retrieve %s...\n", valueName);
     261
     262    papChip *chip = cell->parent;       // The chip
     263    papFPA *fpa = chip->parent;         // The FPA
    275264
    276265    // Try cache, headers, database, defaults in order
     
    293282}
    294283
    295 float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell
    296                         const char *chipName, // The name of the chip
    297                         const char *cellName, // The name of the cell
     284float psCellGetValueF32(papCell *cell, // The cell
    298285                        const char *valueName // Name of value
    299286                        )
    300287{
    301288    float value = NAN;                  // Result
    302     psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
    303     if (! item) {
    304         psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
     289    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
     290    if (! item) {
     291        psError(PS_ERR_IO, true, "Unable to find value %s in cell.\n", valueName);
    305292    } else if (item->type != PS_META_F32) {
    306         psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not F32.\n", valueName, chipName,
    307                 cellName);
     293        psError(PS_ERR_IO, true, "Metadata item type for %s is not F32.\n", valueName);
    308294    } else {
    309295        value = item->data.F32;
     
    313299}
    314300
    315 int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell
    316                       const char *chipName, // The name of the chip
    317                       const char *cellName, // The name of the cell
     301int psCellGetValueS32(papCell *cell, // The cell
    318302                      const char *valueName // Name of value
    319303    )
    320304{
    321305    int value = 0;                      // Result
    322     psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
    323     if (! item) {
    324         psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
     306    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
     307    if (! item) {
     308        psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName);
    325309    } else if (item->type != PS_META_S32) {
    326         psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not S32.\n", valueName, chipName,
    327                 cellName);
     310        psError(PS_ERR_IO, true, "Metadata item type for %s is not S32.\n", valueName);
    328311    } else {
    329312        value = item->data.S32;
     
    334317
    335318
    336 double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell
    337                          const char *chipName, // The name of the chip
    338                          const char *cellName, // The name of the cell
     319double psCellGetValueF64(papCell *cell, // The cell
    339320                         const char *valueName // Name of value
    340321                         )
    341322{
    342323    double value = NAN;                 // Result
    343     psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
    344     if (! item) {
    345         psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
     324    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
     325    if (! item) {
     326        psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName);
    346327    } else if (item->type != PS_META_F64) {
    347         psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not F64.\n", valueName, chipName,
    348                 cellName);
     328        psError(PS_ERR_IO, true, "Metadata item type for %s is not F64.\n", valueName);
    349329    } else {
    350330        value = item->data.F64;
     
    355335
    356336
    357 psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell
    358                               const char *chipName, // The name of the chip
    359                               const char *cellName, // The name of the cell
     337psString psCellGetValueString(papCell *cell, // The cell
    360338                              const char *valueName // Name of value
    361339    )
    362340{
    363341    psString value = NULL;              // Result
    364     psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
    365     if (! item) {
    366         psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);
     342    psMetadataItem *item = psCellGetValue(cell, valueName); // The item
     343    if (! item) {
     344        psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName);
    367345    } else if (item->type != PS_META_STR) {
    368         psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not STR.\n", valueName, chipName,
    369                 cellName);
     346        psError(PS_ERR_IO, true, "Metadata item type for %s is not STR.\n", valueName);
    370347    } else {
    371348        value = item->data.V;
     
    394371    fpa->camera = psMemIncrRefCounter((psPtr)camera);
    395372    fpa->db = db;
    396     fpa->chips = psMetadataAlloc();
    397 
     373    fpa->chips = psArrayAlloc(0);
     374
     375    fpa->extname = NULL;
    398376    fpa->pixels = NULL;
    399377    fpa->header = NULL;
     
    418396
    419397papChip *papChipAlloc(papFPA *fpa,      // FPA to which the chip belongs
    420                       const char *name  // Name of the chip
     398                      psString name     // Chip name
    421399    )
    422400{
     
    424402    psMemSetDeallocator(chip, (psFreeFcn)p_papChipFree);
    425403
    426     // Push onto the FPA
    427     psMetadataAdd(fpa->chips, PS_LIST_TAIL, name, PS_META_CHIP, "Chip added on allocation", chip);
     404    // Push onto the array of chips
     405    fpa->chips = psArrayAdd(fpa->chips, 0, chip);
    428406
    429407    // Fill in the components
     
    435413
    436414    chip->values = psMetadataAlloc();
    437     chip->cells = psMetadataAlloc();
    438 
     415    chip->parent = psMemIncrRefCounter(fpa);
     416    chip->cells = psArrayAlloc(0);
     417
     418    chip->extname = NULL;
    439419    chip->pixels = NULL;
    440420    chip->header = NULL;
    441421
    442     psMetadataAdd(chip->values, PS_LIST_TAIL, "CHIP.NAME", PS_META_STR, "Name of the chip",
    443                   psStringCopy(name));
     422    psMetadataAddStr(chip->values, PS_LIST_HEAD, "CHIP.NAME", "Chip name added at papChipAlloc", name);
    444423
    445424    return chip;
     
    453432    psFree(chip->values);
    454433    psFree(chip->cells);
     434    psFree(chip->parent);
    455435
    456436    psFree(chip->pixels);
     
    459439
    460440papCell *papCellAlloc(papChip *chip,    // Chip to which the cell belongs
    461                       const char *name, // Name of the cell
    462                       int nReadouts     // Number of readouts contained
     441                      psString name     // Name of cell
    463442    )
    464443{
     
    466445    psMemSetDeallocator(cell, (psFreeFcn)p_papCellFree);
    467446
    468     // Push onto the chip
    469     psMetadataAdd(chip->cells, PS_LIST_TAIL, name, PS_META_CELL, "Cell added on allocation", cell);
     447    // Push onto the array of chips
     448    chip->cells = psArrayAdd(chip->cells, 0, cell);
    470449
    471450    // Fill in components
     
    480459
    481460    cell->values = psMetadataAlloc();
    482     cell->readouts = psArrayAlloc(nReadouts);
    483 
     461    cell->readouts = psArrayAlloc(0);
     462    cell->parent = psMemIncrRefCounter(chip);
     463
     464    cell->extname = NULL;
    484465    cell->pixels = NULL;
    485466    cell->header = NULL;
    486467
    487     psMetadataAdd(cell->values, PS_LIST_TAIL, "CELL.NAME", PS_META_STR, "Name of the cell",
    488                   psStringCopy(name));
     468    psMetadataAddStr(cell->values, PS_LIST_HEAD, "CELL.NAME", "Cell name added at papCellAlloc", name);
    489469
    490470    return cell;
     
    501481    psFree(cell->values);
    502482    psFree(cell->readouts);
     483    psFree(cell->parent);
    503484
    504485    psFree(cell->pixels);
  • trunk/archive/scripts/src/papFocalPlane.h

    r4386 r4694  
    1818    const psMetadata *camera;           // Camera configuration
    1919    psDB *db;                           // Database
    20     psMetadata *chips;                  // The chips (referred to by name)
     20    psArray *chips;                     // The chips
    2121    // FITS data
     22    const char *extname;                // Extension name, if it corresponds to this level
    2223    psArray *pixels;                    // The pixel data, if it corresponds to this level
    2324    psMetadata *header;                 // The FITS header, if it corresponds to this level
     
    3334    // Information
    3435    psMetadata *values;                 // Important values (cached)
    35     psMetadata *cells;                  // The cells (referred to by name)
     36    psArray *cells;                     // The cells (referred to by name)
     37    papFPA *parent;                     // Parent FPA
    3638    // FITS data
     39    const char *extname;                // Extension name, if it corresponds to this level
    3740    psArray *pixels;                    // The pixel data, if it corresponds to this level
    3841    psMetadata *header;                 // The FITS header, if it corresponds to this level
     
    5255    psMetadata *values;                 // Important values (cached)
    5356    psArray *readouts;                  // The readouts (referred to by number)
     57    papChip *parent;                    // Parent chip
    5458    // FITS data
     59    const char *extname;                // Extension name, if it corresponds to this level
    5560    psArray *pixels;                    // The pixel data, if it corresponds to this level
    5661    psMetadata *header;                 // The FITS header, if it corresponds to this level
     
    7479
    7580// Look for a particular value for a given cell (referred to by FPA+chip+cell)
    76 psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell
    77                                const char *chipName, // The name of the chip
    78                                const char *cellName, // The name of the cell
     81psMetadataItem *psCellGetValue(papCell *cell, // The cell
    7982                               const char *valueName // Name of value
    8083    );
    8184
    8285// Type-specific functions provided as a convenience to the user
    83 float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell
    84                         const char *chipName, // The name of the chip
    85                         const char *cellName, // The name of the cell
     86float psCellGetValueF32(papCell *cell, // The cell
    8687                        const char *valueName // Name of value
    8788                        );
    88 int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell
    89                       const char *chipName, // The name of the chip
    90                       const char *cellName, // The name of the cell
     89int psCellGetValueS32(papCell *cell, // The cell
    9190                      const char *valueName // Name of value
    9291                      );
    93 double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell
    94                          const char *chipName, // The name of the chip
    95                          const char *cellName, // The name of the cell
     92double psCellGetValueF64(papCell *cell, // The cell
    9693                         const char *valueName // Name of value
    9794                         );
    98 psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell
    99                               const char *chipName, // The name of the chip
    100                               const char *cellName, // The name of the cell
     95psString psCellGetValueString(papCell *cell, // The cell
    10196                              const char *valueName // Name of value
    10297                              );
     
    110105
    111106papChip *papChipAlloc(papFPA *fpa,      // FPA to which the chip belongs
    112                     const char *name    // Name of the chip
     107                      psString name     // Name of chip
    113108    );
    114109void p_papChipFree(papChip *chip);
    115110
    116111papCell *papCellAlloc(papChip *chip,    // Chip to which the cell belongs
    117                       const char *name, // Name of the cell
    118                       int nReadouts     // Number of readouts contained
     112                      psString name     // Name of cell
    119113    );
    120114void p_papCellFree(papCell *cell);
  • trunk/archive/scripts/src/papmodule.h

    r4386 r4694  
    22
    33#include "pmCameraFromHeader.h"
     4#include "pmFPAConstruct.h"
    45#include "pmFPARead.h"
    56#include "papStuff.h"
    67#include "psAdditionals.h"
    78#include "papFocalPlane.h"
     9#include "pmFPAMorph.h"
     10#include "pmFPAWrite.h"
  • trunk/archive/scripts/src/pmFPAConstruct.c

    r4594 r4694  
    8181            // Extensions are chips; Content contains a list of cells
    8282            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    83                 const char *extName = contentItem->name; // The name of the extension
    84                 papChip *chip = papChipAlloc(fpa); // The chip
     83                psString extName = contentItem->name; // The name of the extension
     84                papChip *chip = papChipAlloc(fpa, extName); // The chip
    8585                chip->extname = extName;// Mark chip to receive FITS data
    8686                if (contentItem->type != PS_META_STR) {
     
    9797                while (cellName = psListGetAndIncrement(cellNamesIter)) {
    9898                    // Get the cell data
    99                     papCell *cell = papCellAlloc(chip); // The cell
     99                    papCell *cell = papCellAlloc(chip, cellName); // The cell
    100100                    psMetadata *cellData = getCellData(camera, cellName);
    101101                    metadataCopy(cell->values, cellData);
     
    109109            psMetadata *chips = psMetadataAlloc(); // Given a chip name, holds the chip number
    110110            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    111                 const char *extName = contentItem->name; // The name of the extension
     111                psString extName = contentItem->name; // The name of the extension
    112112                psTrace(__func__, 1, "Getting %s....\n", extName);
    113113
     
    122122                    psLogMsg(__func__, PS_LOG_WARN, "Unable to read contents of %s: ignored.\n", extName);
    123123                } else {
    124                     const char *chipName = psListGet(contents, 0); // The name of the chip
    125                     const char *cellType = psListGet(contents, 1); // The type of cell
     124                    psString chipName = psListGet(contents, 0); // The name of the chip
     125                    psString cellType = psListGet(contents, 1); // The type of cell
    126126                    psTrace(__func__, 7, "Extension is cell of type %s, from chip %s\n", cellType,
    127127                            chipName);
     
    129129                    papChip *chip = psMetadataLookupChip(&mdStatus, chips, chipName); // The chip
    130130                    if (! mdStatus && ! chip) {
    131                         chip = papChipAlloc(fpa);
     131                        chip = papChipAlloc(fpa, chipName);
    132132                        psMetadataAdd(chips, PS_LIST_TAIL, chipName, PS_META_CHIP, "", chip);
    133133                    }
     
    135135                    psArray *images = NULL;
    136136                    psMetadata *header = NULL;
    137                     papCell *cell = papCellAlloc(chip); // The cell
     137                    papCell *cell = papCellAlloc(chip, extName); // The cell
    138138                    cell->extname = extName; // Mark cell to receive FITS data
    139139                    psMetadata *cellData = getCellData(camera, cellType);
     
    147147            fpa->extname = "PHU";
    148148            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    149                 const char *chipName = contentItem->name; // The name of the chip
     149                psString chipName = contentItem->name; // The name of the chip
    150150
    151151                if (contentItem->type != PS_META_STR) {
     
    154154                    continue;
    155155                }
    156                 const char *content = contentItem->data.V; // The content of the extension
     156                psString content = contentItem->data.V; // The content of the extension
    157157                psTrace(__func__, 5, "Component cells are: %s\n", content);
    158                 papChip *chip = papChipAlloc(fpa); // The chip
     158                papChip *chip = papChipAlloc(fpa, chipName); // The chip
    159159                psList *cellNames = papSplit(content, ", "); // Split the list of cells
    160160                psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false);
     
    162162                while (cellName = psListGetAndIncrement(cellNamesIter)) {
    163163                    psTrace(__func__, 7, "Processing cell %s....\n", cellName);
    164                     papCell *cell = papCellAlloc(chip); // The cell
     164                    papCell *cell = papCellAlloc(chip, cellName); // The cell
    165165                    psMetadata *cellData = getCellData(camera, cellName);
    166166                    metadataCopy(cell->values, cellData);
     
    179179    } else if (strncmp(phuType, "CHIP", 4) == 0) {
    180180        // The FITS file contains a single chip only
    181         papChip *chip = papChipAlloc(fpa); // The chip
     181        psString chipName = psStringCopy("CHIP"); // Name for chip
     182        papChip *chip = papChipAlloc(fpa, chipName); // The chip
    182183
    183184        if (strncmp(extType, "NONE", 4) == 0) {
     
    193194            psList *cellNames = papSplit(contents, " ,"); // Names of cells
    194195            psListIterator *cellIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); // Iterator
    195             const char *cellName = NULL;
     196            psString cellName = NULL;
    196197            while (cellName = psListGetAndIncrement(cellIter)) {
    197                 papCell *cell = papCellAlloc(chip); // The cell
     198                papCell *cell = papCellAlloc(chip, cellName); // The cell
    198199                psMetadata *cellData = getCellData(camera, cellName);
    199200                metadataCopy(cell->values, cellData);
     
    219220            psMetadataItem *contentItem = NULL; // Item from metadata
    220221            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    221                 const char *extName = contentItem->name; // The name of the extension
    222 
    223                 psMemCheckCorruption(true);
    224                
    225                 psTrace(__func__, 1, "Getting %s....\n", extName);
    226 
     222                psString extName = contentItem->name; // The name of the extension
    227223                // Content is a cell type
    228224                if (contentItem->type != PS_META_STR) {
     
    233229                }
    234230                const char *cellType = contentItem->data.V; // The type of cell
    235                 psTrace(__func__, 2, "Cell type is %s\n", cellType);
     231                psTrace(__func__, 5, "Cell type is %s\n", cellType);
    236232                psArray *images = NULL;
    237233                psMetadata *header = NULL;
    238                 papCell *cell = papCellAlloc(chip); // The cell
     234                papCell *cell = papCellAlloc(chip, extName); // The cell
    239235                cell->extname = extName; // Mark cell to receive FITS data
    240236                psMetadata *cellData = getCellData(camera, cellType);
     
    266262{
    267263    psTrace(__func__, 0, "FPA:\n");
    268     if (fpa->pixels) {
    269         psTrace(__func__, 1, "---> FPA contains pixels.\n");
     264    if (fpa->extname) {
     265        psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa->extname);
     266        if (! fpa->pixels) {
     267            psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa->extname);
     268        }
    270269    }
    271270
     
    275274        psTrace(__func__, 1, "Chip: %d\n", i);
    276275        papChip *chip = chips->data[i]; // The chip
    277         if (chip->pixels) {
    278             psTrace(__func__, 2, "---> Chip contains pixels.\n");
     276        if (chip->extname) {
     277            psTrace(__func__, 2, "---> Chip is extension %s.\n", chip->extname);
     278            if (! chip->pixels) {
     279                psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip->extname);
     280            }
    279281        }
    280282        // Iterate over the chip
     
    283285            psTrace(__func__, 2, "Cell: %d\n", j);
    284286            papCell *cell = cells->data[j]; // The cell
    285             if (cell->pixels) {
    286                 psTrace(__func__, 3, "---> Cell contains pixels.\n");
     287            if (cell->extname) {
     288                psTrace(__func__, 3, "---> Cell is extension %s.\n", cell->extname);
     289                if (! cell->pixels) {
     290                    psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell->extname);
     291                }
    287292            }
    288293            psMetadataPrint(cell->values, 3);
     
    292297                papReadout *readout = readouts->data[k]; // The readout
    293298                psImage *image = readout->image; // The image
    294                 psTrace(__func__, 4, "Image: [%d:%d,%d:%d]\n", image->col0, image->col0 +
    295                         image->numCols, image->row0, image->row0 + image->numRows);
     299                psTrace(__func__, 4, "Image: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 +
     300                        image->numCols, image->row0, image->row0 + image->numRows, image->numCols,
     301                        image->numRows);
    296302                psList *overscans = readout->overscans; // The list of overscans
    297303                psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false);
    298304                while (image = psListGetAndIncrement(overscansIter)) {
    299                     psTrace(__func__, 4, "Overscan: [%d:%d,%d:%d]\n", image->col0, image->col0 +
    300                             image->numCols, image->row0, image->row0 + image->numRows);
     305                    psTrace(__func__, 4, "Overscan: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 +
     306                            image->numCols, image->row0, image->row0 + image->numRows, image->numCols,
     307                            image->numRows);
    301308                }
    302309                psFree(overscansIter);
  • trunk/archive/scripts/src/pmFPARead.c

    r4386 r4694  
    55#include "papStuff.h"
    66#include "papFocalPlane.h"
     7#include "pmFPARead.h"
    78
    89// NOTE: Need to deal with header inheritance
     
    1112// File-static functions
    1213//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    13 
    14 // Copy metadata elements into another metadata
    15 static void metadataCopy(psMetadata *to, // Metadata to which to copy
    16                          psMetadata *from // Metdata from which to copy
    17     )
    18 {
    19     psMetadataIterator *mdIter = psMetadataIteratorAlloc(from, PS_LIST_HEAD, NULL); // Iterator for the MD
    20     psMetadataItem *item = NULL;        // Item from the metadata
    21     while (item = psMetadataGetAndIncrement(mdIter)) {
    22         psTrace(__func__, 9, "Adding %s to metadata...\n", item->name);
    23         if (! psMetadataAddItem(to, item, PS_LIST_TAIL, PS_META_REPLACE)) {
    24             psLogMsg(__func__, PS_LOG_WARN, "Unable to add item (%s: %s) to metadata: ignored\n", item->name,
    25                      item->comment);
    26         }
    27     }
    28     psFree(mdIter);
    29 }
    30 
    31 // Read data for a particular cell from the camera configuration
    32 static psMetadata *getCellData(const psMetadata *camera, // The camera configuration
    33                                const char *cellName // The name of the cell
    34     )
    35 {
    36     bool status = true;                 // Result of MD lookup
    37     psMetadata *cells = psMetadataLookupMD(&status, camera, "CELLS"); // The CELLS
    38     if (! status) {
    39         psError(PS_ERR_IO, false, "Unable to determine CELLS of camera.\n");
    40         return NULL;
    41     }
    42 
    43     psMetadata *cellData = psMetadataLookupMD(&status, cells, cellName); // The data for the particular cell
    44     if (! status) {
    45         psError(PS_ERR_IO, false, "Unable to find specs for cell %s: ignored\n", cellName);
    46         return NULL;
    47     } else {
    48         return cellData;
    49     }
    50 }
    5114
    5215// Read a FITS extension into a chip
     
    5720    )
    5821{
     22    psTrace(__func__, 7, "Moving to extension %s...\n", extName);
    5923    if (strncmp(extName, "PHU", 3) == 0) {
    6024        if (!psFitsMoveExtNum(fits, 0, false)) {
     
    6630        return false;
    6731    }
     32    psTrace(__func__, 7, "Reading header....\n");
    6833    *header = psFitsReadHeader(*header, fits);
     34    if (! *header) {
     35        psError(PS_ERR_IO, false, "Unable to read FITS header!\n");
     36        return false;
     37    }
     38
     39    psTrace(__func__, 7, "Checking NAXIS....\n");
    6940    bool mdStatus = false;
    7041    int nAxis = psMetadataLookupS32(&mdStatus, *header, "NAXIS");
     
    7748                 "anyway.\n");
    7849    }
     50    psTrace(__func__, 9, "NAXIS = %d\n", nAxis);
    7951
    8052    int numPlanes = 1;                  // Number of planes
     
    8961
    9062    // Read each plane into the array
     63    psTrace(__func__, 7, "Reading %d planes into array....\n", numPlanes);
    9164    *images = psArrayAlloc(numPlanes); // Array of images
    9265    for (int i = 0; i < numPlanes; i++) {
    93         (*images)->data[i] = psFitsReadImage((*images)->data[i], fits, region, 0);
     66        psTrace(__func__, 9, "Reading plane %d\n", i);
     67        psMemCheckCorruption(true);
     68        (*images)->data[i] = psFitsReadImage(NULL, fits, region, i);
     69        psTrace(__func__, 10, "Done\n");
    9470        if (! (*images)->data[i]) {
    9571            psError(PS_ERR_IO, false, "Unable to read image for extension %s, plane %d\n", extName, i);
     
    11995                    region.y1);
    12096            numFound++;
     97            // Convert from FITS standard to PS standard
     98            region.x0 -= 1;
     99            region.y0 -= 1;
     100            // We don't touch the x1 and y1 values because they aren't included by psImageSubset.
    121101            psImage *subImage = psImageSubset(image, region);
    122102            psListAdd(list, PS_LIST_TAIL, subImage);
     
    166146                // We have the region: [x0:x1,y0:y1]
    167147                psRegion region = psRegionFromString(regionString);
     148                // Convert from FITS standard to PS standard
     149                region.x0 -= 1;
     150                region.y0 -= 1;
     151                // We don't touch the x1 and y1 values because they aren't included by psImageSubset.
    168152                psImage *subImage = psImageSubset(image, region);
    169153                psListAdd(subImages, PS_LIST_TAIL, subImage);
     
    251235//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    252236
    253 papFPA *pmFPARead(psFits *fits, // A FITS file
    254                   const psMetadata *camera, // The camera configuration
    255                   psDB *db              // Database
    256     )
    257 {
    258     papFPA *fpa = papFPAAlloc(camera, db); // The FPA to fill out
    259     bool mdStatus = true;               // Status from metadata lookups
    260     const char *phuType = psMetadataLookupString(&mdStatus, camera, "PHU"); // What is the PHU?
    261     const char *extType = psMetadataLookupString(&mdStatus, camera, "EXTENSIONS"); // What's in the extensions?
    262     if (strncmp(phuType, "FPA", 3) == 0) {
    263         // The FITS file contains an entire FPA
    264 
    265         psMetadata *contents = psMetadataLookupMD(&mdStatus, camera, "CONTENTS"); // The CONTENTS
    266         if (! mdStatus) {
    267             psError(PS_ERR_IO, false, "Unable to determine CONTENTS of camera.\n");
    268             psFree(fpa);
    269             return NULL;
    270         }
    271 
    272         // Set up iteration over the contents
    273         psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL);
    274         psMetadataItem *contentItem = NULL; // Item from the metadata
    275 
    276         if (strncmp(extType, "CHIP", 4) == 0) {
    277             // Extensions are chips; Content contains a list of cells
    278             while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    279                 const char *extName = contentItem->name; // The name of the extension
    280                 papChip *chip = papChipAlloc(fpa, extName); // The chip
    281                 readExtension(&(chip->pixels), &(chip->header), fits, extName);
    282                 if (contentItem->type != PS_META_STR) {
    283                     psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
    284                              contentItem->type);
    285                 } else {
    286                     const char *content = contentItem->data.V; // The content of the extension
    287                     psTrace(__func__, 7, "Content of %s is: %s\n", extName, content);
    288                     psList *cellNames = papSplit(content, " ,"); // A list of the component cells
    289                     psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, NULL);
    290                     char *cellName = NULL; // The name of a cell
    291                     while (cellName = psListGetAndIncrement(cellNamesIter)) {
    292                         // Get the cell data
    293                         papCell *cell = papCellAlloc(chip, cellName, ((psArray*)chip->pixels)->n); // The cell
    294                         psMetadata *cellData = getCellData(camera, cellName);
    295                         metadataCopy(cell->values, cellData);
    296                         portionCell(cell, chip->pixels, chip->header);
    297                     }
    298                     psFree(cellNamesIter);
    299                     psFree(cellNames);
     237bool pmFPARead(papFPA *fpa,             // FPA to read into
     238               psFits *fits             // FITS file from which to read
     239    )
     240{
     241    psArray *pixels = NULL;             // Current pixels from FITS file (array of images)
     242    psMetadata *header = NULL;          // Current header from FITS file
     243
     244    psTrace(__func__, 1, "Working on FPA...\n");
     245    if (fpa->extname) {
     246        psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", fpa->extname);
     247        if (! readExtension(&fpa->pixels, &fpa->header, fits, fpa->extname)) {
     248            psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", fpa->extname);
     249            return false;
     250        }
     251        pixels = fpa->pixels;
     252        header = fpa->header;
     253    }
     254
     255    psArray *chips = fpa->chips;        // Array of chips
     256    // Iterate over the FPA
     257    for (int i = 0; i < chips->n; i++) {
     258        papChip *chip = chips->data[i]; // The chip
     259        psTrace(__func__, 2, "Working on chip %d...\n", i);
     260        if (chip->extname) {
     261            psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", chip->extname, i);
     262            if (! readExtension(&chip->pixels, &chip->header, fits, chip->extname)) {
     263                psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", chip->extname);
     264                return false;
     265            }
     266            pixels = chip->pixels;
     267            header = chip->header;
     268        }
     269        // Iterate over the chip
     270        psArray *cells = chip->cells;   // Array of cells
     271        for (int j = 0; j < cells->n; j++) {
     272            papCell *cell = cells->data[j]; // The cell
     273            psTrace(__func__, 3, "Working on cell %d...\n", j);
     274            if (cell->extname) {
     275                psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", cell->extname, j);
     276                if (! readExtension(&cell->pixels, &cell->header, fits, cell->extname)) {
     277                    psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", cell->extname);
     278                    return false;
    300279                }
    301             }
    302 
    303         } else if (strncmp(extType, "CELL", 4) == 0) {
    304             // Extensions are cells; Content contains a chip name and cell type
    305             psMetadata *chipNumbers = psMetadataAlloc(); // Given a chip name, holds the chip number
    306             while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    307                 const char *extName = contentItem->name; // The name of the extension
    308                 psTrace(__func__, 1, "Getting %s....\n", extName);
    309 
    310                 if (contentItem->type != PS_META_STR) {
    311                     psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
    312                              contentItem->type);
    313                 } else {
    314                     const char *content = contentItem->data.V; // The content of the extension
    315                     psList *contents = papSplit(content, ": "); // Split the name from the type
    316                     if (contents->size != 2) {
    317                         psLogMsg(__func__, PS_LOG_WARN, "Unable to read contents of %s: ignored.\n", extName);
    318                     } else {
    319                         const char *chipName = psListGet(contents, 0); // The name of the chip
    320                         const char *cellType = psListGet(contents, 1); // The type of cell
    321                         psTrace(__func__, 7, "Extension is cell of type %s, from chip %s\n", cellType,
    322                                 chipName);
    323 
    324                         papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
    325                         if (! mdStatus && ! chip) {
    326                             chip = papChipAlloc(fpa, chipName);
    327                         }
    328                         // The cell
    329                         psArray *images = NULL;
    330                         psMetadata *header = NULL;
    331                         psTrace(__func__, 7, "Reading extension %s\n", extName);
    332                         readExtension(&images, &header, fits, extName);
    333                         psTrace(__func__, 7, "Allocating cell %s\n", cellType);
    334                         papCell *cell = papCellAlloc(chip, cellType, images->n); // The cell
    335                         cell->pixels = images;
    336                         cell->header = header;
    337                         psMetadata *cellData = getCellData(camera, cellType);
    338                         metadataCopy(cell->values, cellData);
    339                         psTrace(__func__, 7, "Portioning cell....\n");
    340                         portionCell(cell, cell->pixels, cell->header);
    341                         psTrace(__func__, 7, "Done.\n");
    342                     }
    343                 }
    344             }
    345 
    346         } else if (strncmp(extType, "NONE", 4) == 0) {
    347             // No extensions; Content contains metadata, each entry is a chip with its component cells
    348             readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU");
    349             while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    350                 const char *chipName = contentItem->name; // The name of the chip
    351 
    352                 if (contentItem->type != PS_META_STR) {
    353                     psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
    354                              contentItem->type);
    355                 } else {
    356                     const char *content = contentItem->data.V; // The content of the extension
    357                     papChip *chip = papChipAlloc(fpa, content); // The chip
    358                     psList *cellNames = papSplit(content, ", "); // Split the list of cells
    359                     psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false);
    360                     char *cellName = NULL; // Name of the cell
    361                     while (cellName = psListGetAndIncrement(cellNamesIter)) {
    362                         papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell
    363                         psMetadata *cellData = getCellData(camera, cellName);
    364                         metadataCopy(cell->values, cellData);
    365                         portionCell(cell, fpa->pixels, fpa->header);
    366                     }
    367                     psFree(cellNamesIter);
    368                 }
    369             }
    370 
    371         } else {
    372             psError(PS_ERR_IO, false, "EXTENSIONS in camera definition is not CHIP, CELL or NONE.\n");
    373             psFree(fpa);
    374             return NULL;
    375         } // Type of extension
    376 
    377         psFree(contentsIter);
    378 
    379     } else if (strncmp(phuType, "CHIP", 4) == 0) {
    380         // The FITS file contains a single chip only
    381         papChip *chip = papChipAlloc(fpa, "CHIP"); // The chip
    382        
    383         if (strncmp(extType, "NONE", 4) == 0) {
    384             // There are no extensions --- only the PHU
    385             readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU");
    386 
    387             const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS");
    388             if (! mdStatus) {
    389                 psError(PS_ERR_IO, false, "Unable to determine CONTENTS of camera.\n");
    390                 psFree(fpa);
    391                 return NULL;
    392             }
    393             psList *cellNames = papSplit(contents, " ,"); // Names of cells
    394             psListIterator *cellIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); // Iterator
    395             const char *cellName = NULL;
    396             while (cellName = psListGetAndIncrement(cellIter)) {
    397                 papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell
    398                 psMetadata *cellData = getCellData(camera, cellName);
    399                 metadataCopy(cell->values, cellData);
    400                 portionCell(cell, fpa->pixels, fpa->header);
    401             }
    402             psFree(cellIter);
    403         } else if (strncmp(extType, "CELL", 4) == 0) {
    404             // Extensions are cells
    405             psMetadata *contents = psMetadataLookupMD(&mdStatus, camera, "CONTENTS"); // The CONTENTS
    406             if (! mdStatus) {
    407                 psError(PS_ERR_IO, false, "Unable to determine CONTENTS of camera.\n");
    408                 psFree(fpa);
    409                 return NULL;
    410             }
    411            
    412             if (strncmp(extType, "CELL", 4) != 0) {
    413                 psLogMsg(__func__, PS_LOG_WARN, "EXTENSIONS in camera definition is %s, but PHU is CHIP.\n"
    414                          "EXTENSIONS assumed to be CELL.\n", extType);
    415             }
    416 
    417             // Iterate through the contents
    418             psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL);
    419             psMetadataItem *contentItem = NULL; // Item from metadata
    420             while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    421                 const char *extName = contentItem->name; // The name of the extension
    422 
    423                 psMemCheckCorruption(true);
    424                
    425                 psTrace(__func__, 1, "Getting %s....\n", extName);
    426 
    427                 // Content is a cell type
    428                 if (contentItem->type != PS_META_STR) {
    429                     psLogMsg(__func__, PS_LOG_WARN,
    430                              "CONTENT metadata for extension %s is not of type string, but %x --- ignored\n",
    431                              extName, contentItem->type);
    432                 } else {
    433                     const char *cellType = contentItem->data.V; // The type of cell
    434                     psTrace(__func__, 2, "Cell type is %s\n", cellType);
    435                     psArray *images = NULL;
    436                     psMetadata *header = NULL;
    437                     readExtension(&images, &header, fits, extName);
    438                     papCell *cell = papCellAlloc(chip, extName, images->n); // The cell
    439                     cell->pixels = images;
    440                     cell->header = header;
    441                     psMetadata *cellData = getCellData(camera, cellType);
    442                     metadataCopy(cell->values, cellData);
    443                     portionCell(cell, cell->pixels, cell->header);
    444                 }
    445             } // Iterating through contents
    446             psFree(contentsIter);
    447 
    448         } else {
    449             psError(PS_ERR_IO, false, "EXTENSIONS in camera definition is neither CELL or NONE.\n");
    450             psFree(fpa);
    451             return NULL;
    452         }
    453 
    454     } else {
    455         psError(PS_ERR_IO, true,
    456                 "The PHU type specified in the camera configuration (%s) is not FPA or CHIP.\n",
    457                 phuType);
    458         psFree(fpa);
    459         return NULL;
    460     }
    461 
    462     return fpa;
    463 }
    464 
    465 void pmFPAPrint(papFPA *fpa             // FPA to print
    466     )
    467 {
    468     // Print out the focal plane
    469     psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa->chips, PS_LIST_HEAD, NULL); // Iterator for FPA
    470     psMetadataItem *fpaItem = NULL;     // Item from metadata
    471     psTrace("pmFPARead", 0, "FPA:\n");
    472     if (fpa->pixels) {
    473         psTrace("pmFPARead", 1, "---> FPA contains pixels.\n");
    474     }
    475     while (fpaItem = psMetadataGetAndIncrement(fpaIter)) {
    476         if (fpaItem->type != PS_META_CHIP) {
    477             psError(PS_ERR_IO, false, "FPA content is not a chip.\n");
    478         } else {
    479             psTrace("pmFPARead", 1, "Chip: %s\n", fpaItem->name);
    480             papChip *chip = fpaItem->data.V; // The chip
    481             if (chip->pixels) {
    482                 psTrace("pmFPARead", 2, "---> Chip contains pixels.\n");
    483             }
    484             // Iterator for chip
    485             psMetadataIterator *chipIter = psMetadataIteratorAlloc(chip->cells, PS_LIST_HEAD, NULL);
    486             psMetadataItem *chipItem = NULL; // Item from metadata
    487             while (chipItem = psMetadataGetAndIncrement(chipIter)) {
    488                 if (chipItem->type != PS_META_CELL) {
    489                     psError(PS_ERR_IO, false, "Chip content is not a cell.\n");
    490                 } else {
    491                     psTrace("pmFPARead", 2, "Cell: %s\n", chipItem->name);
    492                     papCell *cell = chipItem->data.V; // The cell
    493                     if (cell->pixels) {
    494                         psTrace("pmFPARead", 3, "---> Cell contains pixels.\n");
    495                     }
    496                     // Iterator for cell values
    497                     psMetadataIterator *cellIter = psMetadataIteratorAlloc(cell->values, PS_LIST_HEAD, NULL);
    498                     psMetadataItem *cellItem = NULL; // Item from metadata
    499                     while (cellItem = psMetadataGetAndIncrement(cellIter)) {
    500                         switch(cellItem->type) {
    501                           case PS_META_STR:
    502                             psTrace("pmFPARead", 3, "%s: %s\n", cellItem->name, cellItem->data.V);
    503                             break;
    504                           case PS_META_F32:
    505                             psTrace("pmFPARead", 3, "%s: %f\n", cellItem->name, cellItem->data.F32);
    506                             break;
    507                           case PS_META_S32:
    508                             psTrace("pmFPARead", 3, "%s: %d\n", cellItem->name, cellItem->data.S32);
    509                             break;
    510                           case PS_META_META:
    511                             psTrace("pmFPARead", 3, "%s:\n", cellItem->name);
    512                             psMetadataPrint(cellItem->data.V, 4);
    513                             break;
    514                           default:
    515                             psError(PS_ERR_IO, false, "Unknown type for cell (%x).\n", cellItem->type);
    516                         }
    517                     } // Iterating through cell
    518                     psFree(cellIter);
    519 
    520                     // Iterator for cell
    521                     psTrace("pmFPARead", 3, "Readouts:\n");
    522                     psArray *readouts = cell->readouts; // The readouts
    523                     for (int i = 0; i < readouts->n; i++) {
    524                         papReadout *readout = readouts->data[i]; // The readout
    525                         psImage *image = readout->image; // The image
    526                         psTrace("pmFPARead", 4, "Image: [%d:%d,%d:%d]\n", image->col0, image->col0 +
    527                                 image->numCols, image->row0, image->row0 + image->numRows);
    528                         psList *overscans = readout->overscans; // The list of overscans
    529                         psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false);
    530                         while (image = psListGetAndIncrement(overscansIter)) {
    531                             psTrace("pmFPARead", 4, "Overscan: [%d:%d,%d:%d]\n", image->col0, image->col0 +
    532                                 image->numCols, image->row0, image->row0 + image->numRows);
    533                         }
    534                         psFree(overscansIter);
    535                     }
    536                 }
    537             } // Iterating through chip
    538             psFree(chipIter);
    539         }
    540     } // Iterating through FPA
    541     psFree(fpaIter);
    542 }
     280                pixels = cell->pixels;
     281                header = cell->header;
     282            }
     283
     284            psTrace(__func__, 5, "Allocating readouts and extracting overscans etc for chip %d cell %d...\n",
     285                    i, j);
     286            portionCell(cell, pixels, header);
     287        }
     288    }
     289
     290    return true;
     291}
  • trunk/archive/scripts/src/pmFPARead.h

    r4386 r4694  
    44#include "papFocalPlane.h"
    55
    6 // Read the contents of a FITS file (format specified by the camera configuration) into memory
    7 papFPA *pmFPARead(psFits *fits, // A FITS file
    8                   const psMetadata *camera, // The camera configuration
    9                   psDB *db              // Database handle
    10     );
    11 
    12 // Print out the FPA
    13 void pmFPAPrint(papFPA *fpa             // FPA to print
    14     );
     6bool pmFPARead(papFPA *fpa,             // FPA to read into
     7               psFits *fits             // FITS file from which to read
     8               );
    159
    1610#endif
  • trunk/archive/scripts/src/test_pmFPARead.c

    r4395 r4694  
    2626
    2727    (void)psTraceSetLevel(".", 0);
     28    (void)psTraceSetLevel("readExtension", 10);
    2829    (void)psTraceSetLevel("readMultipleRegions", 0);
    2930    (void)psTraceSetLevel("portions", 0);
    30     (void)psTraceSetLevel("pmFPARead", 10);
     31    (void)psTraceSetLevel("pmFPAPrint", 10);
    3132    (void)psTraceSetLevel("pmFPAfromHeader", 10);
    3233    (void)psTraceSetLevel("pmCameraFromHeader", 10);
    33 
     34    (void)psTraceSetLevel("pmFPAMorph", 10);
     35    (void)psTraceSetLevel("spliceCells", 10);
    3436
    3537
     
    5355    psMetadata *camera = pmCameraFromHeader(header, ipprc);
    5456
    55     papFPA *fpa = pmFPARead(fits, camera, NULL);
     57    papFPA *fpa = pmFPAConstruct(camera, NULL);
     58
     59    // Cut off a lot of the chips so I can fit things in memory
     60    {
     61        psArray *chips = fpa->chips;
     62        papChip *chip = chips->data[0];
     63        psFree(chips);
     64        chips = psArrayAlloc(1);
     65        chips->data[0] = chip;
     66    }
     67
     68    (void)pmFPARead(fpa, fits);
    5669    (void)pmFPAPrint(fpa);
    5770
    58     printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.XPARITY"),
    59            psCellGetValueS32(fpa, "ccd15", "right", "CELL.XPARITY"));
    60     printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.YPARITY"),
    61            psCellGetValueS32(fpa, "ccd15", "right", "CELL.YPARITY"));
    62     printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.YPARITY"),
    63            psCellGetValueS32(fpa, "ccd15", "right", "CELL.YPARITY"));
     71    // Morph to a splice image
     72    psMetadata *newCamera = psMetadataConfigParse(NULL, &badLines, "megacam_splice.config", true);
     73    papFPA *newfpa = pmFPAConstruct(newCamera, NULL);
     74
     75    // Cut off a lot of the chips so I can fit things in memory
     76    {
     77        psArray *chips = newfpa->chips;
     78        papChip *chip = chips->data[0];
     79        psFree(chips);
     80        chips = psArrayAlloc(1);
     81        chips->data[0] = chip;
     82    }
     83
     84    pmFPAPrint(newfpa);
     85    pmFPAMorph(newfpa, fpa, 0, 0);
     86    pmFPAPrint(newfpa);
     87
     88#if 0
     89    // Write out
     90    psFits *newfits = psFitsAlloc("test.fits");
     91    pmFPAWrite(fits, newfpa);
     92    psFree(newfits);
     93#endif
     94
     95#if 1
     96    psArray *chips = newfpa->chips;
     97    for (int i = 0; i < chips->n; i++) {
     98        papChip *chip = chips->data[i]; // Chip of interest
     99        psArray *cells = chip->cells;   // Array of cells
     100
     101        if (chip->extname) {
     102            psFits *fp = psFitsAlloc(chip->extname);
     103            psFitsWriteImage(fp, chip->header, chip->pixels->data[i], i);
     104            psFree(fp);
     105        }
     106
     107        for (int j = 0; j < cells->n; j++) {
     108            papCell *cell = cells->data[j]; // Cell of interest
     109
     110            if (cell->extname) {
     111                psFits *fp = psFitsAlloc(cell->extname);
     112                psFitsWriteImage(fp, cell->header, cell->pixels->data[i], i);
     113                psFree(fp);
     114            }
     115        }
     116    }
     117#endif
     118
     119    psFree(newfpa);
     120    psFree(newCamera);
    64121
    65122    // Tidy up
Note: See TracChangeset for help on using the changeset viewer.