Changeset 7530
- Timestamp:
- Jun 12, 2006, 4:40:32 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAWrite.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAWrite.c
r7469 r7530 128 128 129 129 pmHDU *hdu = chip->hdu; // The HDU 130 if (!hdu) { 131 return true; // We wrote every HDU that exists 132 } 133 134 bool success = true; // Success of writing 135 if ((!pixels && hdu->phu && !hdu->images) || // Data-less PHU 136 (pixels && (hdu->images || (!hdu->images && pmHDUGenerateForChip(chip) && hdu->images)))) { // Data 137 success &= pmConceptsWriteChip(chip, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | 138 PM_CONCEPT_SOURCE_DEFAULTS, false, true, NULL); 139 success &= pmHDUWrite(hdu, fits); 140 } 141 142 if (!success) { 143 psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n"); 144 return false; 145 } 146 130 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 136 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; 153 if (!pmConceptsWriteChip(chip, source, false, true, NULL)) { 154 psError(PS_ERR_IO, false, "Unable to write Concepts for Chip.\n"); 155 return false; 156 } 157 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? 147 165 if (recurse) { 148 166 psArray *cells = chip->cells; // Array of cells 149 167 for (int i = 0; i < cells->n; i++) { 150 168 pmCell *cell = cells->data[i]; // The cell of interest 151 success &= pmCellWrite(cell, fits, db, pixels); 152 } 153 } 154 155 return success; 169 if (!pmCellWrite(cell, fits, db, pixels)) { 170 psError(PS_ERR_IO, false, "Unable to write Chip.\n"); 171 return false; 172 } 173 } 174 } 175 176 return true; 156 177 } 157 178 … … 169 190 170 191 pmHDU *hdu = fpa->hdu; // The HDU 171 if (!hdu) { 172 return true; // We wrote every HDU that exists 173 } 174 175 bool success = true; // Success of writing 176 if ((!pixels && hdu->phu && !hdu->images) || // Data-less PHU 177 (pixels && (hdu->images || (!hdu->images && pmHDUGenerateForFPA(fpa) && hdu->images)))) { // Data 178 success &= pmConceptsWriteFPA(fpa, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | 179 PM_CONCEPT_SOURCE_DEFAULTS, true, NULL); 180 success &= pmHDUWrite(hdu, fits); 181 } 182 183 if (!success) { 184 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 185 return false; 186 } 187 192 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 (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; 220 if (!pmConceptsWriteFPA(fpa, source, true, NULL)) { 221 psError(PS_ERR_IO, false, "Unable to write Concepts for FPA.\n"); 222 return false; 223 } 224 if (!pmHDUWrite(hdu, fits)) { 225 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 226 return false; 227 } 228 } 229 } 230 231 // XXX what are the rules on when we allow recursion? 188 232 if (recurse) { 189 233 psArray *chips = fpa->chips; // Array of chips 190 234 for (int i = 0; i < chips->n; i++) { 191 235 pmChip *chip = chips->data[i]; // The chip of interest 192 success &= pmChipWrite(chip, fits, db, pixels, true); 193 } 194 } 195 196 return success; 197 } 198 236 if (!pmChipWrite(chip, fits, db, pixels, true)) { 237 psError(PS_ERR_IO, false, "Unable to write FPA.\n"); 238 return false; 239 } 240 } 241 } 242 243 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 }
Note:
See TracChangeset
for help on using the changeset viewer.
