IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6852


Ignore:
Timestamp:
Apr 13, 2006, 4:43:25 PM (20 years ago)
Author:
Paul Price
Message:

Adding pmReadoutReadNext to read bits of a readout at a time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmFPARead.c

    r6840 r6852  
    5959//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    6060
    61 
    62 #if 0
    63 bool pmReadoutRead(pmReadout *readout,  // Readout to read into
    64                    psFits *fits,        // FITS file from which to read
    65                    int numSections      // Total number of sections
    66                    int section          // The section of interest
    67                   )
    68 {
    69     // This is very very different
    70 }
    71 #endif
     61// Read the next readout; return true if we read pixels in.
     62bool pmReadoutReadNext(pmReadout *readout, // Readout into which to read
     63                       psFits *fits,    // FITS file from which to read
     64                       int z,           // Readout number/plane; zero-offset indexing
     65                       int numRows      // The number of rows to read
     66                      )
     67{
     68    // Get the HDU and read the header
     69    pmCell *cell = readout->parent;     // The parent cell
     70    pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
     71    if (!hdu) {
     72        return false;
     73    }
     74
     75    if (!pmHDUReadHeader(hdu, fits)) {
     76        psError(PS_ERR_IO, false, "Unable to read HDU header!\n");
     77        return false;
     78    }
     79
     80    // Check the third dimension
     81    bool mdok = true;                   // Status of MD lookup
     82    int naxis = psMetadataLookupS32(&mdok, hdu->header, "NAXIS"); // The number of axes
     83    if (!mdok) {
     84        psError(PS_ERR_IO, true, "Unable to find NAXIS in header for extension %s\n", hdu->extname);
     85        return false;
     86    }
     87    if (naxis == 0) {
     88        // No pixels to read, as for a PHU.
     89        return false;
     90    }
     91    if (naxis < 2 || naxis > 3) {
     92        psError(PS_ERR_IO, true, "NAXIS in header of extension %s (= %d) is not valid.\n",
     93                hdu->extname, naxis);
     94        return false;
     95    }
     96    int naxis3 = 1;                     // The number of image planes
     97    if (naxis == 3) {
     98        naxis3 = psMetadataLookupS32(&mdok, hdu->header, "NAXIS3");
     99        if (!mdok) {
     100            psError(PS_ERR_IO, true, "Unable to find NAXIS3 in header for extension %s\n", hdu->extname);
     101            return false;
     102        }
     103    }
     104    if (z >= naxis3) {
     105        // Nothing to see here.  Move along.
     106        return false;
     107    }
     108
     109    // Get the size of the image plane
     110    int naxis1 = psMetadataLookupS32(&mdok, hdu->header, "NAXIS1"); // The number of columns
     111    if (!mdok) {
     112        psError(PS_ERR_IO, true, "Unable to find NAXIS1 in header for extension %s\n", hdu->extname);
     113        return false;
     114    }
     115    int naxis2 = psMetadataLookupS32(&mdok, hdu->header, "NAXIS2"); // The number of columns
     116    if (!mdok) {
     117        psError(PS_ERR_IO, true, "Unable to find NAXIS2 in header for extension %s\n", hdu->extname);
     118        return false;
     119    }
     120
     121    // Read the FITS image
     122    int offset = readout->row0;         // The row number to read
     123    if (readout->image) {
     124        offset += readout->image->numRows;
     125    }
     126    if (offset >= naxis2) {
     127        // We've read everything there is
     128        return false;
     129    }
     130    int upper = offset + numRows;       // The upper limit for the pixel read
     131    if (upper > naxis2) {
     132        upper = naxis2;
     133    }
     134    psRegion region = psRegionSet(0, naxis1, offset, upper); // Region to be read
     135    psImage *image = psFitsReadImage(fits, region, z); // The image
     136    if (readout->image) {
     137        psFree(readout->image);
     138    }
     139
     140    // Stick the image into the HDU and the readout
     141    if (!hdu->images) {
     142        hdu->images = psArrayAlloc(naxis3);
     143    }
     144    if (hdu->images->n != naxis3) {
     145        hdu->images = psArrayRealloc(hdu->images, naxis3);
     146    }
     147    if (hdu->images->data[z]) {
     148        psFree(hdu->images->data[z]);
     149    }
     150    hdu->images->data[z] = image;
     151    readout->image = psImageSubset(hdu->images->data[z], psRegionSet(0,0,0,0));
     152    readout->row0 = region.y0;
     153
     154    return true;
     155}
     156
    72157
    73158// Read in the cell, and allocate the readouts
Note: See TracChangeset for help on using the changeset viewer.