Changeset 6896 for trunk/psModules/src/astrom/pmFPAWrite.c
- Timestamp:
- Apr 18, 2006, 5:24:09 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/astrom/pmFPAWrite.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/astrom/pmFPAWrite.c
r6872 r6896 5 5 #include "pmFPA.h" 6 6 #include "pmHDU.h" 7 #include "pmHDUUtils.h" 7 8 #include "pmConcepts.h" 9 10 11 bool 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 8 70 9 71 10 72 bool pmCellWrite(pmCell *cell, // Cell to write 11 73 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? 13 76 ) 14 77 { … … 17 80 18 81 pmHDU *hdu = cell->hdu; // The HDU 19 if (hdu && !pmHDUWrite(hdu, fits)) {82 if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) { 20 83 psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n"); 21 84 return false; … … 28 91 bool pmChipWrite(pmChip *chip, // Chip to write 29 92 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? 31 95 ) 32 96 { … … 35 99 36 100 pmHDU *hdu = chip->hdu; // The HDU 37 if (hdu && !pmHDUWrite(hdu, fits)) {101 if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) { 38 102 psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n"); 39 103 return false; … … 41 105 42 106 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 } 47 113 } 48 114 … … 55 121 bool pmFPAWrite(pmFPA *fpa, // FPA to write 56 122 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? 58 125 ) 59 126 { … … 62 129 63 130 pmHDU *hdu = fpa->hdu; // The HDU 64 if (hdu && !pmHDUWrite(hdu, fits)) {131 if (hdu && ((!pixels && hdu->phu) || pixels) && !pmHDUWrite(hdu, fits)) { 65 132 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 66 133 return false; … … 68 135 69 136 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 } 74 143 } 75 144
Note:
See TracChangeset
for help on using the changeset viewer.
