IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 18, 2006, 5:24:09 PM (20 years ago)
Author:
Paul Price
Message:

Adding pmReadoutWriteNext, which is to be used in concert with pmReadoutReadNext. Updated pmFPAWrite, pmChipWrite, pmCellWrite to optionally not write the pixels (i.e., PHU only), so that an output file should always have a PHU. This necessitated some small changes to the way the 'concepts' are written, in the case that they don't exist.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/astrom/pmFPAWrite.c

    r6872 r6896  
    55#include "pmFPA.h"
    66#include "pmHDU.h"
     7#include "pmHDUUtils.h"
    78#include "pmConcepts.h"
     9
     10
     11bool pmReadoutWriteNext(pmReadout *readout, // Readout to write
     12                        psFits *fits,   // FITS file to which to write
     13                        int z           // Image plane to write
     14                       )
     15{
     16    pmHDU *hdu = pmHDUFromReadout(readout); // The HDU to which to write
     17    psMetadata *header = hdu->header;   // The FITS header
     18    if (!header) {
     19        psError(PS_ERR_IO, true, "No FITS header available in the HDU.\n");
     20        return false;
     21    }
     22
     23    // We have to rely to a great extent on the FITS header, because otherwise we simply don't know how many
     24    // image planes there are (NAXIS3) or the size of the original image (NAXIS1, NAXIS2).
     25    bool mdok = true;                   // Status of MD lookup
     26    int naxis1 = psMetadataLookupS32(&mdok, header, "NAXIS1"); // Number of columns
     27    if (!mdok || naxis1 <= 0) {
     28        psError(PS_ERR_IO, true, "Can't find NAXIS1 in header.\n");
     29        return false;
     30    }
     31    int naxis2 = psMetadataLookupS32(&mdok, header, "NAXIS2"); // Number of rows
     32    if (!mdok || naxis2 <= 0) {
     33        psError(PS_ERR_IO, true, "Can't find NAXIS2 in header.\n");
     34        return false;
     35    }
     36    int naxis3 = psMetadataLookupS32(&mdok, header, "NAXIS3"); // Number of image planes
     37    if (!mdok || naxis3 <= 0) {
     38        naxis3 = 1;
     39    }
     40    if (z >= naxis3) {
     41        psError(PS_ERR_IO, true, "Specified a plane number (%d) greater than NAXIS3 allows.\n", z);
     42        return false;
     43    }
     44
     45    psImage *image = hdu->images->data[z]; // The image from the HDU to write
     46    if (readout->row0 == 0 && readout->col0 == 0 && z == 0) {
     47        // Then we can assume that nothing has been written to the FITS file for now
     48        if (naxis1 == image->numCols && naxis2 == image->numRows) {
     49            // We can write the whole lot at once
     50            return psFitsWriteImage(fits, header, image, z, hdu->extname);
     51        }
     52        // Create a dummy image so we can write something larger than we actually have
     53        psImage *dummy = psImageAlloc(naxis1, naxis2, image->type.type); // Dummy image
     54        psImageInit(dummy, 0);
     55        psImageOverlaySection(dummy, image, 0, 0, "=");
     56        bool result = psFitsWriteImage(fits, header, dummy, z, hdu->extname);
     57        psFree(dummy);
     58        return result;
     59    }
     60
     61    // We can simply update an existing HDU
     62    if (!psFitsMoveExtName(fits, hdu->extname)) {
     63        psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname);
     64        return false;
     65    }
     66    return psFitsUpdateImage(fits, image, readout->col0, readout->row0, z);
     67}
     68
     69
    870
    971
    1072bool pmCellWrite(pmCell *cell,          // Cell to write
    1173                 psFits *fits,          // FITS file to which to write
    12                  psDB *db               // Database handle for "concepts" update
     74                 psDB *db,              // Database handle for "concepts" update
     75                 bool pixels            // Write the pixels?
    1376                )
    1477{
     
    1780
    1881    pmHDU *hdu = cell->hdu;             // The HDU
    19     if (hdu && !pmHDUWrite(hdu, fits)) {
     82    if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) {
    2083        psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
    2184        return false;
     
    2891bool pmChipWrite(pmChip *chip,          // Chip to write
    2992                 psFits *fits,          // FITS file to which to write
    30                  psDB *db               // Database handle for "concepts" update
     93                 psDB *db,              // Database handle for "concepts" update
     94                 bool pixels            // Write the pixels?
    3195                )
    3296{
     
    3599
    36100    pmHDU *hdu = chip->hdu;             // The HDU
    37     if (hdu && !pmHDUWrite(hdu, fits)) {
     101    if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) {
    38102        psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
    39103        return false;
     
    41105
    42106    bool success = true;                // Success of writing
    43     psArray *cells = chip->cells;       // Array of cells
    44     for (int i = 0; i < cells->n; i++) {
    45         pmCell *cell = cells->data[i];  // The cell of interest
    46         success |= pmCellWrite(cell, fits, db);
     107    if (pixels) {
     108        psArray *cells = chip->cells;       // Array of cells
     109        for (int i = 0; i < cells->n; i++) {
     110            pmCell *cell = cells->data[i];  // The cell of interest
     111            success |= pmCellWrite(cell, fits, db, true);
     112        }
    47113    }
    48114
     
    55121bool pmFPAWrite(pmFPA *fpa,             // FPA to write
    56122                psFits *fits,           // FITS file to which to write
    57                 psDB *db                // Database handle for "concepts" update
     123                psDB *db,               // Database handle for "concepts" update
     124                bool pixels             // Write the pixels?
    58125               )
    59126{
     
    62129
    63130    pmHDU *hdu = fpa->hdu;              // The HDU
    64     if (hdu && !pmHDUWrite(hdu, fits)) {
     131    if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) {
    65132        psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n");
    66133        return false;
     
    68135
    69136    bool success = true;                // Success of writing
    70     psArray *chips = fpa->chips;        // Array of chips
    71     for (int i = 0; i < chips->n; i++) {
    72         pmChip *chip = chips->data[i];  // The chip of interest
    73         success |= pmChipWrite(chip, fits, db);
     137    if (pixels) {
     138        psArray *chips = fpa->chips;        // Array of chips
     139        for (int i = 0; i < chips->n; i++) {
     140            pmChip *chip = chips->data[i];  // The chip of interest
     141            success |= pmChipWrite(chip, fits, db, true);
     142        }
    74143    }
    75144
Note: See TracChangeset for help on using the changeset viewer.