Changeset 7717 for trunk/psModules/src/camera/pmFPAWrite.c
- Timestamp:
- Jun 27, 2006, 7:12:19 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAWrite.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAWrite.c
r7618 r7717 1 1 #include <stdio.h> 2 2 #include <strings.h> 3 #include "pslib.h"3 #include <pslib.h> 4 4 5 5 #include "pmFPA.h" … … 73 73 74 74 // We can simply update an existing HDU 75 if (((hdu->phu || strcasecmp(hdu->extname, "PHU") == 0) && !psFitsMoveExtNum(fits, 0, false)) || 76 !psFitsMoveExtName(fits, hdu->extname)) { 77 psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname); 75 if (hdu->blankPHU && !psFitsMoveExtNum(fits, 0, false)) { 76 psError(PS_ERR_IO, false, "Unable to move to PHU\n"); 78 77 return false; 79 78 } … … 87 86 psFits *fits, // FITS file to which to write 88 87 psDB *db, // Database handle for "concepts" update 89 bool pixels // Write the pixels, or only the PHU header?88 bool blank // Write a blank PHU? 90 89 ) 91 90 { … … 98 97 } 99 98 100 bool success = true; // Success of writing 101 if ((!pixels && hdu->phu && !hdu->images) || // Data-less PHU 102 (pixels && (hdu->images || (!hdu->images && pmHDUGenerateForCell(cell) && hdu->images)))) { // Data 103 success &= pmConceptsWriteCell(cell, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | 104 PM_CONCEPT_SOURCE_DEFAULTS, false, NULL); 105 success &= pmHDUWrite(hdu, fits); 106 } 107 108 if (!success) { 109 psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n"); 110 return false; 111 } 112 99 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 100 // generate the HDU, but only copies the structure. 101 if (!hdu->blankPHU && !hdu->images) { 102 if (!pmHDUGenerateForCell(cell) || !hdu->images) { 103 psAbort(__func__, "Unable to generate HDU for cell --- likely programming error.\n"); 104 } 105 } 106 107 // We only write out a blank PHU if it's specifically requested. 108 bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank PHU? 109 bool writeImage = !hdu->blankPHU && hdu->images; // Write an image? 110 111 if (writeBlank || writeImage) { 112 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | 113 PM_CONCEPT_SOURCE_DEFAULTS; 114 if (!pmConceptsWriteCell(cell, source, false, NULL)) { 115 psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n"); 116 return false; 117 } 118 if (!pmHDUWrite(hdu, fits)) { 119 psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n"); 120 return false; 121 } 122 } 113 123 // No lower levels to which to recurse 114 124 115 return success;125 return true; 116 126 } 117 127 … … 120 130 psFits *fits, // FITS file to which to write 121 131 psDB *db, // Database handle for "concepts" update 122 bool pixels, // Write the pixels, or only the PHU header?132 bool blank, // Write a blank PHU? 123 133 bool recurse // Recurse to lower levels? 124 134 ) … … 129 139 pmHDU *hdu = chip->hdu; // The HDU 130 140 131 // XXXX this makes no sense to me at all: 132 // an image made up of only cells would not have 133 // any entries at this level, and could not be written out!!! 134 135 // if we have data at this level, try to write it out 141 // If we have data at this level, try to write it out 136 142 if (hdu) { 137 // generate the HDU if needed 138 if (pixels && !hdu->images) { 139 if (!pmHDUGenerateForChip(chip)) 140 psAbort ("pmFPAWrite", "error generating HDU"); 141 if (!hdu->images) 142 psAbort ("pmChipWrite", "programming error: failure generating HDU"); 143 } 144 145 // chip->hdu represents a blank data segment 146 bool blankSegment = !pixels && hdu->phu && !hdu->images; 147 148 // chip->hdu represents an image data segment 149 bool imageSegment = pixels && hdu->images; 150 151 if (blankSegment || imageSegment) { 152 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS; 143 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 144 // generate the HDU, but only copies the structure. 145 if (!blank && !hdu->blankPHU && !hdu->images) { 146 if (!pmHDUGenerateForChip(chip) || !hdu->images) { 147 psAbort (__func__, "Unable to generate HDU for chip --- likely programming error.\n"); 148 } 149 } 150 151 // We only write out a blank PHU if it's specifically requested. 152 bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank HDU? 153 bool writeImage = !hdu->blankPHU && hdu->images; // Write an image? 154 155 if (writeBlank || writeImage) { 156 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | 157 PM_CONCEPT_SOURCE_DEFAULTS; 153 158 if (!pmConceptsWriteChip(chip, source, false, true, NULL)) { 154 psError(PS_ERR_IO, false, "Unable to write Concepts for Chip.\n");159 psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n"); 155 160 return false; 156 161 } 157 162 if (!pmHDUWrite(hdu, fits)) { 158 psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");159 return false; 160 } 161 } 162 } 163 164 // XXX are we allowed to recurse if we have already written data at this level?163 psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n"); 164 return false; 165 } 166 } 167 } 168 169 // Recurse to lower level if specifically requested. 165 170 if (recurse) { 166 171 psArray *cells = chip->cells; // Array of cells 167 172 for (int i = 0; i < cells->n; i++) { 168 173 pmCell *cell = cells->data[i]; // The cell of interest 169 if (!pmCellWrite(cell, fits, db, pixels)) {174 if (!pmCellWrite(cell, fits, db, blank)) { 170 175 psError(PS_ERR_IO, false, "Unable to write Chip.\n"); 171 176 return false; … … 182 187 psFits *fits, // FITS file to which to write 183 188 psDB *db, // Database handle for "concepts" update 184 bool pixels, // Write the pixels, or only the PHU header?189 bool blank, // Write a blank PHU? 185 190 bool recurse // Recurse to lower levels? 186 191 ) … … 191 196 pmHDU *hdu = fpa->hdu; // The HDU 192 197 193 // XXXX this makes no sense to me at all: 194 // an image made up of only chips or cells would not have 195 // any entries at this level, and could not be written out!!! 196 197 // if we have data at this level, try to write it out 198 // If we have data at this level, try to write it out 198 199 if (hdu) { 199 200 // XXXXXXXXX this was extremely unclear. the conditions MUST be written more explicitly 201 // so someone else has a chance to understand it without massive reverse engineering!!!! 202 203 // generate the HDU if needed 204 if (pixels && !hdu->images) { 205 if (!pmHDUGenerateForFPA(fpa)) 206 psAbort ("pmFPAWrite", "error generating HDU"); 207 if (!hdu->images) 208 psAbort ("pmFPAWrite", "programming error: failure generating HDU"); 209 } 210 211 // fpa->hdu represents a blank data segment 212 bool blankSegment = !pixels && hdu->phu && !hdu->images; 213 214 // fpa->hdu represents an image data segment 215 bool imageSegment = pixels && hdu->images; 216 217 // if neither of these conditions is true, we probably need to recurse down to the next level and try again 218 if (blankSegment || imageSegment) { 219 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS; 200 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 201 // generate the HDU, but only copies the structure. 202 if (!blank && !hdu->blankPHU && !hdu->images) { 203 if (!pmHDUGenerateForFPA(fpa)) { 204 psAbort("pmFPAWrite", "error generating HDU"); 205 } 206 if (!hdu->images) { 207 psAbort("pmFPAWrite", "programming error: failure generating HDU"); 208 } 209 } 210 211 // We only write out a blank PHU if it's specifically requested. 212 bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank PHU? 213 bool writeImage = !hdu->blankPHU && hdu->images; // Write an image? 214 215 if (writeBlank || writeImage) { 216 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | 217 PM_CONCEPT_SOURCE_DEFAULTS; 220 218 if (!pmConceptsWriteFPA(fpa, source, true, NULL)) { 221 psError(PS_ERR_IO, false, "Unable to write Concepts for FPA.\n");219 psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n"); 222 220 return false; 223 221 } … … 229 227 } 230 228 231 // XXX what are the rules on when we allow recursion?229 // Recurse to lower levels if requested 232 230 if (recurse) { 233 231 psArray *chips = fpa->chips; // Array of chips 234 232 for (int i = 0; i < chips->n; i++) { 235 233 pmChip *chip = chips->data[i]; // The chip of interest 236 if (!pmChipWrite(chip, fits, db, pixels, true)) {234 if (!pmChipWrite(chip, fits, db, blank, true)) { 237 235 psError(PS_ERR_IO, false, "Unable to write FPA.\n"); 238 236 return false; … … 242 240 243 241 return true; 244 245 // summary: 246 // pmHDUWrite writes out the PHU header or the header + pixels 247 // we need to generate the HDU (why?) 248 // we call pmHDUWrite if: 249 // - the fpa->hdu represents a blank data segment (header w/ no pixels) 250 // - the fpa->hdu represents an image data segment (header w/ pixels) 251 } 242 }
Note:
See TracChangeset
for help on using the changeset viewer.
