Changeset 6896
- Timestamp:
- Apr 18, 2006, 5:24:09 PM (20 years ago)
- Location:
- trunk/psModules/src/astrom
- Files:
-
- 7 edited
-
pmConceptsWrite.c (modified) (2 diffs)
-
pmFPA.c (modified) (2 diffs)
-
pmFPA.h (modified) (2 diffs)
-
pmFPARead.c (modified) (6 diffs)
-
pmFPAWrite.c (modified) (8 diffs)
-
pmFPAWrite.h (modified) (1 diff)
-
pmFPAfile.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/astrom/pmConceptsWrite.c
r6888 r6896 129 129 ) 130 130 { 131 if (!hdu->header) { 132 return false; 133 } 131 134 switch (item->type) { 132 135 case PS_DATA_STRING: … … 166 169 if (item->type == PS_DATA_LIST) { 167 170 psList *values = item->data.V; // List of outputs 171 if (values->n == 0) { 172 // Nothing to write 173 return false; 174 } 168 175 psList *keys = psStringSplit(keywords, " ,;"); // List of keywords 169 176 if (keys->n != values->n) { -
trunk/psModules/src/astrom/pmFPA.c
r6872 r6896 12 12 * XXX: Should we implement non-linear cell->chip transforms? 13 13 * 14 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-04-1 7 18:01:04$14 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-04-19 03:24:09 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 231 231 pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout)); 232 232 tmpReadout->row0 = 0; 233 tmpReadout->col0 = 0; 233 234 234 235 tmpReadout->image = NULL; -
trunk/psModules/src/astrom/pmFPA.h
r6872 r6896 7 7 * @author GLG, MHPCC 8 8 * 9 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-04-1 7 18:01:04$9 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-04-19 03:24:09 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 129 129 typedef struct 130 130 { 131 int row0; ///< Row offset; non-zero if reading in bit by bit 131 int col0; ///< Column offset; non-zero if reading in columns bit by bit 132 int row0; ///< Row offset; non-zero if reading in rows bit by bit 132 133 psImage *image; ///< Imaging area of readout 133 134 psImage *mask; ///< Mask of input image -
trunk/psModules/src/astrom/pmFPARead.c
r6894 r6896 34 34 return NULL; 35 35 } 36 psRegion region = psRegionSet(trimsec->x0, trimsec->x1, MAX(trimsec->y0 - readout->row0, 0), 37 MIN(trimsec->y1 - readout->row0, image->numRows)); 36 psRegion region = psRegionSet(MAX(trimsec->x0 - readout->col0, 0), // x0 37 MIN(trimsec->x1 - readout->col0, image->numCols), // x1 38 MAX(trimsec->y0 - readout->row0, 0), // y0 39 MIN(trimsec->y1 - readout->row0, image->numRows) // y1 40 ); 38 41 if (readout->image) { 39 42 psFree(readout->image); // Make way! … … 57 60 return NULL; 58 61 } 59 psRegion region = psRegionSet(biassec->x0, biassec->x1, MAX(biassec->y0 - readout->row0, 0), 60 MIN(biassec->y1 - readout->row0, image->numRows)); 62 psRegion region = psRegionSet(MAX(biassec->x0 - readout->col0, 0), // x0 63 MIN(biassec->x1 - readout->col0, image->numCols), // x1 64 MAX(biassec->y0 - readout->row0, 0), // y0 65 MIN(biassec->y1 - readout->row0, image->numRows) // y1 66 ); 61 67 psImage *overscan = psMemIncrRefCounter(psImageSubset(image, region)); 62 68 psListAdd(readout->bias, PS_LIST_TAIL, overscan); … … 76 82 psFits *fits, // FITS file from which to read 77 83 int z, // Readout number/plane; zero-offset indexing 78 int num Rows // The number of rows to read84 int numScans // The number of scans to read 79 85 ) 80 86 { … … 96 102 // Get the trim and bias sections 97 103 bool mdok = true; // Status of MD lookup 98 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); 104 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim sections 99 105 if (!mdok || !trimsec || psRegionIsBad(*trimsec)) { 100 106 psError(PS_ERR_IO, true, "CELL.TRIMSEC is not set.\n"); 101 107 return false; 102 108 } 103 psList *biassecs = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.BIASSEC"); 109 psList *biassecs = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.BIASSEC"); // Bias sections 104 110 if (!mdok || !biassecs) { 105 111 psError(PS_ERR_IO, true, "CELL.BIASSEC is not set.\n"); 112 return false; 113 } 114 int readdir = psMetadataLookupS32(&mdok, cell->concepts, "CELL.READDIR"); // Read direction 115 if (!mdok || readdir == 0 || (readdir != -1 && readdir != 1)) { 116 psError(PS_ERR_IO, true, "CELL.READDIR is not set to -1 or +1.\n"); 106 117 return false; 107 118 } … … 150 161 int offset = readout->row0; // The row number to read 151 162 if (readout->image) { 152 offset += readout->image->numRows; 153 } 154 if (offset >= naxis2) { 163 if (readdir > 0) { 164 // Reading rows 165 offset += readout->image->numRows; 166 } else { 167 // Reading columns 168 offset += readout->image->numCols; 169 } 170 } 171 if ((readdir > 0 && offset >= naxis2) || (readdir < 0 && offset > naxis1)) { 155 172 // We've read everything there is 156 173 return false; 157 174 } 158 int upper = offset + num Rows;// The upper limit for the pixel read159 if ( upper > naxis2) {175 int upper = offset + numScans; // The upper limit for the pixel read 176 if (readdir > 0 && upper > naxis2) { 160 177 upper = naxis2; 161 } 162 psRegion region = psRegionSet(0, naxis1, offset, upper); // Region to be read 178 } else if (readdir < 0 && upper > naxis1) { 179 upper = naxis1; 180 } 181 psRegion region = {0, 0, 0, 0}; // Region to be read 182 if (readdir > 0) { 183 region = psRegionSet(0, naxis1, offset, upper); // Read rows 184 } else { 185 region = psRegionSet(offset, upper, 0, naxis2); // Read columns 186 } 163 187 psImage *image = psFitsReadImage(fits, region, z); // The image 164 188 … … 177 201 hdu->images->data[z] = image; 178 202 readout->row0 = region.y0; 203 readout->col0 = region.x0; 179 204 readoutCarve(readout, image, trimsec, biassecs); 180 205 -
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 -
trunk/psModules/src/astrom/pmFPAWrite.h
r6872 r6896 5 5 #include "pmFPA.h" 6 6 7 bool pmReadoutWriteNext(pmReadout *readout, // Readout to write 8 psFits *fits, // FITS file to which to write 9 int z // Image plane to write 10 ); 7 11 8 12 bool pmCellWrite(pmCell *cell, // Cell to write 9 13 psFits *fits, // FITS file to which to write 10 psDB *db // Database handle for "concepts" update 14 psDB *db, // Database handle for "concepts" update 15 bool pixels // Write the pixels? 11 16 ); 12 17 bool pmChipWrite(pmChip *chip, // Chip to write 13 18 psFits *fits, // FITS file to which to write 14 psDB *db // Database handle for "concepts" update 19 psDB *db, // Database handle for "concepts" update 20 bool pixels // Write the pixels? 15 21 ); 16 22 bool pmFPAWrite(pmFPA *fpa, // FPA to write 17 23 psFits *fits, // FITS file to which to write 18 psDB *db // Database handle for "concepts" update 24 psDB *db, // Database handle for "concepts" update 25 bool pixels // Write the pixels? 19 26 ); 20 27 -
trunk/psModules/src/astrom/pmFPAfile.c
r6872 r6896 634 634 // pmFPAWrite takes care of all PHUs as needed 635 635 if (view->chip == -1) { 636 pmFPAWrite (fpa, fits, NULL );636 pmFPAWrite (fpa, fits, NULL, true); 637 637 return true; 638 638 } … … 660 660 661 661 if (view->cell == -1) { 662 pmChipWrite (chip, fits, NULL );662 pmChipWrite (chip, fits, NULL, true); 663 663 return true; 664 664 } … … 670 670 671 671 if (view->readout == -1) { 672 pmCellWrite (cell, fits, NULL );672 pmCellWrite (cell, fits, NULL, true); 673 673 return true; 674 674 }
Note:
See TracChangeset
for help on using the changeset viewer.
