Changeset 10081 for trunk/psModules/src/camera/pmFPAWrite.c
- Timestamp:
- Nov 18, 2006, 1:43:28 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAWrite.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAWrite.c
r9983 r10081 14 14 15 15 #include "pmFPAWrite.h" 16 17 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 18 // Definitions 19 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 20 21 // Specify what to read 22 typedef enum { 23 FPA_WRITE_TYPE_IMAGE, // Write image 24 FPA_WRITE_TYPE_MASK, // Write mask 25 FPA_WRITE_TYPE_WEIGHT // Write weight map 26 } fpaWriteType; 27 28 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 29 // File-static (private) functions 30 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 31 32 // Return the appropriate image array for the given type 33 static psArray **appropriateImageArray(pmHDU *hdu, // HDU containing the image arrays 34 fpaWriteType type // Type to write 35 ) 36 { 37 switch (type) { 38 case FPA_WRITE_TYPE_IMAGE: 39 return &hdu->images; 40 case FPA_WRITE_TYPE_MASK: 41 return &hdu->masks; 42 case FPA_WRITE_TYPE_WEIGHT: 43 return &hdu->weights; 44 default: 45 psAbort(__func__, "Unknown write type: %x\n", type); 46 } 47 return NULL; 48 } 49 50 // Run the appropriate HDU write function 51 static bool appropriateWriteFunc(pmHDU *hdu, // HDU to write 52 psFits *fits, // FITS file to which to write 53 fpaWriteType type // Type to write 54 ) 55 { 56 switch (type) { 57 case FPA_WRITE_TYPE_IMAGE: 58 return pmHDUWrite(hdu, fits); 59 case FPA_WRITE_TYPE_MASK: 60 return pmHDUWriteMask(hdu, fits); 61 case FPA_WRITE_TYPE_WEIGHT: 62 return pmHDUWriteWeight(hdu, fits); 63 default: 64 psAbort(__func__, "Unknown write type: %x\n", type); 65 } 66 return false; 67 } 68 69 // Write a cell image/mask/weight 70 static bool cellWrite(pmCell *cell, // Cell to write 71 psFits *fits, // FITS file to which to write 72 psDB *db, // Database handle for "concepts" update 73 bool blank, // Write a blank PHU? 74 fpaWriteType type // Type to write 75 ) 76 { 77 assert(cell); 78 assert(fits); 79 80 psTrace ("pmFPAWrite", 5, "writing to Cell (%d)\n", blank); 81 82 pmHDU *hdu = cell->hdu; // The HDU 83 if (!hdu) { 84 return true; // We wrote every HDU that exists 85 } 86 87 psArray **imageArray = appropriateImageArray(hdu, type); // Array of images in the HDU 88 89 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 90 // generate the HDU, but only copies the structure. 91 if (!hdu->blankPHU && !*imageArray && (!pmHDUGenerateForCell(cell) || !*imageArray)) { 92 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell --- likely programming error.\n"); 93 return false; 94 } 95 96 // We only write out a blank PHU if it's specifically requested. 97 bool writeBlank = blank && hdu->blankPHU && !*imageArray; // Write a blank PHU? 98 bool writeImage = !blank && !hdu->blankPHU && *imageArray; // Write an image? 99 100 if (writeBlank || writeImage) { 101 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | 102 PM_CONCEPT_SOURCE_DEFAULTS; 103 if (!pmConceptsWriteCell(cell, source, false, NULL)) { 104 psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n"); 105 return false; 106 } 107 if (!appropriateWriteFunc(hdu, fits, type)) { 108 psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n"); 109 return false; 110 } 111 } 112 // No lower levels to which to recurse 113 114 return true; 115 } 116 117 // Write a chip image/mask/weight 118 static bool chipWrite(pmChip *chip, // Chip to write 119 psFits *fits, // FITS file to which to write 120 psDB *db, // Database handle for "concepts" update 121 bool blank, // Write a blank PHU? 122 bool recurse, // Recurse to lower levels? 123 fpaWriteType type // Type to write 124 ) 125 { 126 assert(chip); 127 assert(fits); 128 129 pmHDU *hdu = chip->hdu; // The HDU 130 131 psTrace ("pmFPAWrite", 5, "writing to Chip (%d, %d)\n", blank, recurse); 132 133 // If we have data at this level, try to write it out 134 if (hdu) { 135 psArray **imageArray = appropriateImageArray(hdu, type); // Array of images in HDU 136 137 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 138 // generate the HDU, but only copies the structure. 139 if (!blank && !hdu->blankPHU && !*imageArray && (!pmHDUGenerateForChip(chip) || !*imageArray)) { 140 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for chip --- likely programming error.\n"); 141 return false; 142 } 143 144 // We only write out a blank PHU if it's specifically requested. 145 bool writeBlank = blank && hdu->blankPHU && !*imageArray; // Write a blank HDU? 146 bool writeImage = !blank && !hdu->blankPHU && *imageArray; // Write an image? 147 148 if (writeBlank || writeImage) { 149 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | 150 PM_CONCEPT_SOURCE_DEFAULTS; 151 if (!pmConceptsWriteChip(chip, source, false, true, NULL)) { 152 psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n"); 153 return false; 154 } 155 if (!appropriateWriteFunc(hdu, fits, type)) { 156 psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n"); 157 return false; 158 } 159 } 160 } 161 162 // Recurse to lower level if specifically requested. 163 // XXX recursion implies blank == false (must be called on correct level?) 164 if (recurse) { 165 psArray *cells = chip->cells; // Array of cells 166 for (int i = 0; i < cells->n; i++) { 167 pmCell *cell = cells->data[i]; // The cell of interest 168 if (!cellWrite(cell, fits, db, false, type)) { 169 psError(PS_ERR_IO, false, "Unable to write Chip.\n"); 170 return false; 171 } 172 } 173 } 174 175 return true; 176 } 177 178 // Write an FPA image/mask/weight 179 static bool fpaWrite(pmFPA *fpa, // FPA to write 180 psFits *fits, // FITS file to which to write 181 psDB *db, // Database handle for "concepts" update 182 bool blank, // Write a blank PHU? 183 bool recurse, // Recurse to lower levels? 184 fpaWriteType type // Type to write 185 ) 186 { 187 assert(fpa); 188 assert(fits); 189 190 pmHDU *hdu = fpa->hdu; // The HDU 191 192 psTrace ("pmFPAWrite", 5, "writing to FPA (%d, %d)\n", blank, recurse); 193 194 // If we have data at this level, try to write it out 195 if (hdu) { 196 psArray **imageArray = appropriateImageArray(hdu, type); // Array of images in HDU 197 198 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 199 // generate the HDU, but only copies the structure. 200 if (!blank && !hdu->blankPHU && !*imageArray && (!pmHDUGenerateForFPA(fpa) || !*imageArray)) { 201 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for FPA --- likely programming error.\n"); 202 return false; 203 } 204 205 // We only write out a blank PHU if it's specifically requested. 206 bool writeBlank = blank && hdu->blankPHU && !*imageArray; // Write a blank PHU? 207 bool writeImage = !blank && !hdu->blankPHU && *imageArray; // Write an image? 208 209 if (writeBlank || writeImage) { 210 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | 211 PM_CONCEPT_SOURCE_DEFAULTS; 212 if (!pmConceptsWriteFPA(fpa, source, true, NULL)) { 213 psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n"); 214 return false; 215 } 216 if (!appropriateWriteFunc(hdu, fits, type)) { 217 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 218 return false; 219 } 220 } 221 } 222 223 // Recurse to lower levels if requested 224 if (recurse) { 225 psArray *chips = fpa->chips; // Array of chips 226 for (int i = 0; i < chips->n; i++) { 227 pmChip *chip = chips->data[i]; // The chip of interest 228 if (!chipWrite(chip, fits, db, false, true, type)) { 229 psError(PS_ERR_IO, false, "Unable to write FPA.\n"); 230 return false; 231 } 232 } 233 } 234 235 return true; 236 } 237 238 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 239 // Public functions 240 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 16 241 17 242 bool pmReadoutWriteNext(pmReadout *readout, psFits *fits, int z) … … 82 307 83 308 84 85 86 bool pmCellWrite(pmCell *cell, // Cell to write 87 psFits *fits, // FITS file to which to write 88 psDB *db, // Database handle for "concepts" update 89 bool blank // Write a blank PHU? 90 ) 309 bool pmCellWrite(pmCell *cell, psFits *fits, psDB *db, bool blank) 91 310 { 92 311 PS_ASSERT_PTR_NON_NULL(cell, false); 93 312 PS_ASSERT_PTR_NON_NULL(fits, false); 94 95 psTrace ("pmFPAWrite", 5, "writing to Cell (%d)\n", blank); 96 97 pmHDU *hdu = cell->hdu; // The HDU 98 if (!hdu) { 99 return true; // We wrote every HDU that exists 100 } 101 102 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 103 // generate the HDU, but only copies the structure. 104 if (!hdu->blankPHU && !hdu->images) { 105 if (!pmHDUGenerateForCell(cell) || !hdu->images) { 106 psAbort(__func__, "Unable to generate HDU for cell --- likely programming error.\n"); 107 } 108 } 109 110 // We only write out a blank PHU if it's specifically requested. 111 bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank PHU? 112 bool writeImage = !blank && !hdu->blankPHU && hdu->images; // Write an image? 113 114 if (writeBlank || writeImage) { 115 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | 116 PM_CONCEPT_SOURCE_DEFAULTS; 117 if (!pmConceptsWriteCell(cell, source, false, NULL)) { 118 psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n"); 119 return false; 120 } 121 if (!pmHDUWrite(hdu, fits)) { 122 psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n"); 123 return false; 124 } 125 } 126 // No lower levels to which to recurse 127 128 return true; 129 } 130 313 return cellWrite(cell, fits, db, blank, FPA_WRITE_TYPE_IMAGE); 314 } 131 315 132 316 bool pmChipWrite(pmChip *chip, psFits *fits, psDB *db, bool blank, bool recurse) … … 134 318 PS_ASSERT_PTR_NON_NULL(chip, false); 135 319 PS_ASSERT_PTR_NON_NULL(fits, false); 136 137 pmHDU *hdu = chip->hdu; // The HDU 138 139 psTrace ("pmFPAWrite", 5, "writing to Chip (%d, %d)\n", blank, recurse); 140 141 // If we have data at this level, try to write it out 142 if (hdu) { 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 = !blank && !hdu->blankPHU && hdu->images; // Write an image? 154 155 if (writeBlank || writeImage) { 156 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | 157 PM_CONCEPT_SOURCE_DEFAULTS; 158 if (!pmConceptsWriteChip(chip, source, false, true, NULL)) { 159 psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n"); 160 return false; 161 } 162 if (!pmHDUWrite(hdu, fits)) { 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. 170 // XXX recursion implies blank == false (must be called on correct level?) 171 if (recurse) { 172 psArray *cells = chip->cells; // Array of cells 173 for (int i = 0; i < cells->n; i++) { 174 pmCell *cell = cells->data[i]; // The cell of interest 175 if (!pmCellWrite(cell, fits, db, false)) { 176 psError(PS_ERR_IO, false, "Unable to write Chip.\n"); 177 return false; 178 } 179 } 180 } 181 182 return true; 183 } 184 185 320 return chipWrite(chip, fits, db, blank, recurse, FPA_WRITE_TYPE_IMAGE); 321 } 186 322 187 323 bool pmFPAWrite(pmFPA *fpa, psFits *fits, psDB *db, bool blank, bool recurse) … … 189 325 PS_ASSERT_PTR_NON_NULL(fpa, false); 190 326 PS_ASSERT_PTR_NON_NULL(fits, false); 191 192 pmHDU *hdu = fpa->hdu; // The HDU 193 194 psTrace ("pmFPAWrite", 5, "writing to FPA (%d, %d)\n", blank, recurse); 195 196 // If we have data at this level, try to write it out 197 if (hdu) { 198 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 199 // generate the HDU, but only copies the structure. 200 if (!blank && !hdu->blankPHU && !hdu->images) { 201 if (!pmHDUGenerateForFPA(fpa)) { 202 psAbort("pmFPAWrite", "error generating HDU"); 203 } 204 if (!hdu->images) { 205 psAbort("pmFPAWrite", "programming error: failure generating HDU"); 206 } 207 } 208 209 // We only write out a blank PHU if it's specifically requested. 210 bool writeBlank = blank && hdu->blankPHU && !hdu->images; // Write a blank PHU? 211 bool writeImage = !blank && !hdu->blankPHU && hdu->images; // Write an image? 212 213 if (writeBlank || writeImage) { 214 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | 215 PM_CONCEPT_SOURCE_DEFAULTS; 216 if (!pmConceptsWriteFPA(fpa, source, true, NULL)) { 217 psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n"); 218 return false; 219 } 220 if (!pmHDUWrite(hdu, fits)) { 221 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 222 return false; 223 } 224 } 225 } 226 227 // Recurse to lower levels if requested 228 if (recurse) { 229 psArray *chips = fpa->chips; // Array of chips 230 for (int i = 0; i < chips->n; i++) { 231 pmChip *chip = chips->data[i]; // The chip of interest 232 if (!pmChipWrite(chip, fits, db, false, true)) { 233 psError(PS_ERR_IO, false, "Unable to write FPA.\n"); 234 return false; 235 } 236 } 237 } 238 239 return true; 240 } 241 242 243 244 bool pmCellWriteMask(pmCell *cell, // Cell to write 245 psFits *fits, // FITS file to which to write 246 psDB *db // Database handle for "concepts" update 247 ) 327 return fpaWrite(fpa, fits, db, blank, recurse, FPA_WRITE_TYPE_IMAGE); 328 } 329 330 331 bool pmCellWriteMask(pmCell *cell, psFits *fits, psDB *db, bool blank) 248 332 { 249 333 PS_ASSERT_PTR_NON_NULL(cell, false); 250 334 PS_ASSERT_PTR_NON_NULL(fits, false); 251 252 pmHDU *hdu = cell->hdu; // The HDU 253 if (!hdu) { 254 return true; // We wrote every HDU that exists 255 } 256 257 psTrace ("pmFPAWrite", 5, "writing mask to Cell\n"); 258 259 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 260 // generate the HDU, but only copies the structure. 261 if (!hdu->blankPHU && !hdu->masks) { 262 if (!pmHDUGenerateForCell(cell) || !hdu->masks) { 263 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for cell --- likely programming error.\n"); 264 return false; 265 } 266 } 267 268 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | PM_CONCEPT_SOURCE_DEFAULTS; 269 if (!pmConceptsWriteCell(cell, source, false, NULL)) { 270 psError(PS_ERR_IO, false, "Unable to write concepts for cell.\n"); 271 return false; 272 } 273 if (!pmHDUWriteMask(hdu, fits)) { 274 psError(PS_ERR_IO, false, "Unable to write HDU for cell.\n"); 275 return false; 276 } 277 278 return true; 279 } 280 281 282 bool pmChipWriteMask(pmChip *chip, psFits *fits, psDB *db) 335 return cellWrite(cell, fits, db, blank, FPA_WRITE_TYPE_IMAGE); 336 } 337 338 bool pmChipWriteMask(pmChip *chip, psFits *fits, psDB *db, bool blank, bool recurse) 283 339 { 284 340 PS_ASSERT_PTR_NON_NULL(chip, false); 285 341 PS_ASSERT_PTR_NON_NULL(fits, false); 286 287 pmHDU *hdu = chip->hdu; // The HDU 288 if (!hdu) { 289 return true; // We wrote every HDU that exists 290 } 291 292 psTrace ("pmFPAWrite", 5, "writing mask to Chip\n"); 293 294 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 295 // generate the HDU, but only copies the structure. 296 if (!hdu->blankPHU && !hdu->masks) { 297 if (!pmHDUGenerateForChip(chip) || !hdu->masks) { 298 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for chip --- likely programming error.\n"); 299 return false; 300 } 301 } 302 303 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | PM_CONCEPT_SOURCE_DEFAULTS; 304 if (!pmConceptsWriteChip(chip, source, false, true, NULL)) { 305 psError(PS_ERR_IO, false, "Unable to write concepts for chip.\n"); 306 return false; 307 } 308 if (!pmHDUWriteMask(hdu, fits)) { 309 psError(PS_ERR_IO, false, "Unable to write HDU for chip.\n"); 310 return false; 311 } 312 313 return true; 314 } 315 316 317 318 bool pmFPAWriteMask(pmFPA *fpa, psFits *fits, psDB *db) 342 return chipWrite(chip, fits, db, blank, recurse, FPA_WRITE_TYPE_MASK); 343 } 344 345 bool pmFPAWriteMask(pmFPA *fpa, psFits *fits, psDB *db, bool blank, bool recurse) 319 346 { 320 347 PS_ASSERT_PTR_NON_NULL(fpa, false); 321 348 PS_ASSERT_PTR_NON_NULL(fits, false); 322 323 pmHDU *hdu = fpa->hdu; // The HDU 324 if (!hdu) { 325 return true; // We wrote every HDU that exists 326 } 327 328 psTrace ("pmFPAWrite", 5, "writing mask to FPA\n"); 329 330 // Generate the HDU if needed --- this is required after a pmFPACopy, or similar, which does not 331 // generate the HDU, but only copies the structure. 332 if (!hdu->blankPHU && !hdu->masks) { 333 if (!pmHDUGenerateForFPA(fpa) || !hdu->masks) { 334 psError(PS_ERR_UNKNOWN, false, "Unable to generate HDU for chip --- likely programming error.\n"); 335 return false; 336 } 337 } 338 339 pmConceptSource source = PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CELLS | PM_CONCEPT_SOURCE_DEFAULTS; 340 if (!pmConceptsWriteFPA(fpa, source, true, NULL)) { 341 psError(PS_ERR_IO, false, "Unable to write concepts for FPA.\n"); 342 return false; 343 } 344 if (!pmHDUWriteMask(hdu, fits)) { 345 psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n"); 346 return false; 347 } 348 349 return true; 350 } 351 349 return fpaWrite(fpa, fits, db, blank, recurse, FPA_WRITE_TYPE_MASK); 350 } 351 352 353 bool pmCellWriteWeight(pmCell *cell, psFits *fits, psDB *db, bool blank) 354 { 355 PS_ASSERT_PTR_NON_NULL(cell, false); 356 PS_ASSERT_PTR_NON_NULL(fits, false); 357 return cellWrite(cell, fits, db, blank, FPA_WRITE_TYPE_WEIGHT); 358 } 359 360 bool pmChipWriteWeight(pmChip *chip, psFits *fits, psDB *db, bool blank, bool recurse) 361 { 362 PS_ASSERT_PTR_NON_NULL(chip, false); 363 PS_ASSERT_PTR_NON_NULL(fits, false); 364 return chipWrite(chip, fits, db, blank, recurse, FPA_WRITE_TYPE_WEIGHT); 365 } 366 367 bool pmFPAWriteWeight(pmFPA *fpa, psFits *fits, psDB *db, bool blank, bool recurse) 368 { 369 PS_ASSERT_PTR_NON_NULL(fpa, false); 370 PS_ASSERT_PTR_NON_NULL(fits, false); 371 return fpaWrite(fpa, fits, db, blank, recurse, FPA_WRITE_TYPE_WEIGHT); 372 } 352 373 353 374
Note:
See TracChangeset
for help on using the changeset viewer.
