Changeset 11255 for trunk/psModules/src/camera/pmFPAfileFitsIO.c
- Timestamp:
- Jan 23, 2007, 5:11:19 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAfileFitsIO.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAfileFitsIO.c
r10081 r11255 16 16 #include "pmFPAfile.h" 17 17 #include "pmFPAfileFitsIO.h" 18 #include "pmFPACopy.h" 19 20 pmFPA *pmFPAfileSuitableFPA(const pmFPAfile *file, const pmFPAview *view) 21 { 22 PS_ASSERT_PTR_NON_NULL(file, NULL); 23 PS_ASSERT_PTR_NON_NULL(view, NULL); 24 25 if (!file->format) { 26 return psMemIncrRefCounter(file->fpa); 27 } 28 29 // Need to change format 30 pmFPA *fpa = pmFPAConstruct(file->camera); 31 32 pmFPAview *phuView = pmFPAviewAlloc(0); // View corresponding to the PHU 33 *phuView = *view; // Copy contents 34 pmFPALevel phuLevel = pmFPAPHULevel(file->format); // Level for the PHU 35 switch (phuLevel) { 36 case PM_FPA_LEVEL_FPA: 37 phuView->chip = -1; 38 // Flow through 39 case PM_FPA_LEVEL_CHIP: 40 phuView->cell = -1; 41 // Flow through 42 case PM_FPA_LEVEL_CELL: 43 phuView->readout = -1; 44 break; 45 case PM_FPA_LEVEL_READOUT: 46 case PM_FPA_LEVEL_NONE: 47 default: 48 psAbort(PS_FILE_LINE, "Should never get here: bad phu level.\n"); 49 } 50 51 if (!pmFPAAddSourceFromView(fpa, phuView, file->format)) { 52 psError(PS_ERR_UNKNOWN, false, "Unable to insert HDU into FPA for writing.\n"); 53 psFree(fpa); 54 psFree(phuView); 55 return false; 56 } 57 psFree(phuView); 58 59 60 switch (phuLevel) { 61 case PM_FPA_LEVEL_FPA: 62 if (!pmFPACopy(fpa, file->fpa)) { 63 psError(PS_ERR_UNKNOWN, false, "Unable to copy FPA for format conversion.\n"); 64 return NULL; 65 } 66 return fpa; 67 case PM_FPA_LEVEL_CHIP: { 68 pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest 69 pmChip *srcChip = pmFPAviewThisChip(view, file->fpa); // Source chip 70 if (!pmChipCopy(chip, srcChip)) { 71 psError(PS_ERR_UNKNOWN, false, "Unable to copy chip for format conversion.\n"); 72 return false; 73 } 74 return fpa; 75 } 76 case PM_FPA_LEVEL_CELL: { 77 pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest 78 pmCell *srcCell = pmFPAviewThisCell(view, file->fpa); // Source cell 79 if (!pmCellCopy(cell, srcCell)) { 80 psError(PS_ERR_UNKNOWN, false, "Unable to copy cell for format conversion.\n"); 81 return false; 82 } 83 return fpa; 84 } 85 case PM_FPA_LEVEL_READOUT: 86 case PM_FPA_LEVEL_NONE: 87 default: 88 psAbort(PS_FILE_LINE, "Should never get here: bad phu level.\n"); 89 } 90 return NULL; 91 } 18 92 19 93 // given an already-opened fits file, read the table corresponding to the specified view … … 159 233 assert(file); 160 234 161 pmFPA *fpa = file->fpa; // FPA of interest162 235 psFits *fits = file->fits; // FITS file 163 164 // pmFPAWrite takes care of all PHUs as needed 165 if (view->chip == -1) { 166 return fpaWriteFunc(fpa, fits, NULL, false, true); 167 } 168 169 if (view->chip >= fpa->chips->n) { 170 psError(PS_ERR_IO, true, "Requested chip == %d >= fpa->chips->n == %ld", view->chip, fpa->chips->n); 171 return false; 172 } 173 pmChip *chip = fpa->chips->data[view->chip]; // Chip of interest 174 175 if (view->cell == -1) { 176 return chipWriteFunc(chip, fits, NULL, false, true); 177 } 178 179 if (view->cell >= chip->cells->n) { 180 psError(PS_ERR_IO, true, "Requested cell == %d >= chip->cells->n == %ld", view->cell, chip->cells->n); 181 return false; 182 } 183 pmCell *cell = chip->cells->data[view->cell]; // Cell of interest 184 185 if (view->readout == -1) { 186 return cellWriteFunc(cell, fits, NULL, false); 187 } 188 psError(PS_ERR_UNKNOWN, true, "Bad view: %d,%d", view->chip, view->cell); 236 PS_ASSERT_PTR_NON_NULL(fits, false); 237 238 pmFPA *fpa = pmFPAfileSuitableFPA(file, view); // FPA to write 239 240 switch (pmFPAviewLevel(view)) { 241 case PM_FPA_LEVEL_FPA: { 242 bool success = fpaWriteFunc(fpa, fits, NULL, false, true); 243 psFree(fpa); 244 return success; 245 } 246 case PM_FPA_LEVEL_CHIP: { 247 pmChip *chip = pmFPAviewThisChip(view, fpa); // Chip of interest 248 bool success = chipWriteFunc(chip, fits, NULL, false, true); 249 psFree(fpa); 250 return success; 251 } 252 case PM_FPA_LEVEL_CELL: { 253 pmCell *cell = pmFPAviewThisCell(view, fpa); // Cell of interest 254 bool success = cellWriteFunc(cell, fits, NULL, false); 255 psFree(fpa); 256 return success; 257 } 258 case PM_FPA_LEVEL_READOUT: 259 #if 0 // XXX disable readout write for now 260 261 { 262 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); // Readout of interest 263 if (changeFormat) 264 { 265 // No copy function defined for readouts! 266 psError(PS_ERR_UNKNOWN, false, "Unable to copy readout for format conversion on write.\n"); 267 return false; 268 } 269 if (view->nRows == 0) 270 { 271 return pmReadoutWrite(readout, fits, NULL, NULL); 272 } else 273 { 274 return pmReadoutWriteSegment(readout, fits, view->nRows, view->iRows, NULL, NULL); 275 } 276 } 277 #endif 278 case PM_FPA_LEVEL_NONE: 279 default: 280 psAbort(PS_FILE_LINE, "Should never reach here: invalid file level."); 281 } 282 189 283 return false; 190 191 // XXX disable readout write for now192 #if 0193 194 if (view->readout >= cell->readouts->n) {195 psError(PS_ERR_IO, true, "Requested readout == %d >= cell->readouts->n == %d",196 view->readout, cell->readouts->n);197 return false;198 }199 pmReadout *readout = cell->readouts->data[view->readout];200 201 if (view->nRows == 0) {202 pmReadoutWrite (readout, fits, NULL, NULL);203 } else {204 pmReadoutWriteSegment (readout, fits, view->nRows, view->iRows, NULL, NULL);205 }206 return true;207 #endif208 284 } 209 285
Note:
See TracChangeset
for help on using the changeset viewer.
