Changeset 18767
- Timestamp:
- Jul 29, 2008, 11:40:36 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/psModules/src/camera/pmFPARead.c
r18210 r18767 45 45 46 46 // Return pointer to appropriate value for tracking scans 47 static int *readoutScansByType(pmReadout *readout, // Readout of interest48 fpaReadType type // Type of image47 static int readoutGetThisScan(pmReadout *readout, // Readout of interest 48 fpaReadType type // Type of image 49 49 ) 50 50 { 51 51 switch (type) { 52 52 case FPA_READ_TYPE_IMAGE: 53 return &readout->imageScan;53 return readout->thisImageScan; 54 54 case FPA_READ_TYPE_MASK: 55 return &readout->maskScan;55 return readout->thisMaskScan; 56 56 case FPA_READ_TYPE_WEIGHT: 57 return &readout->weightScan;57 return readout->thisWeightScan; 58 58 default: 59 59 psAbort("Unknown read type: %x\n", type); 60 60 } 61 } 62 63 // Return pointer to appropriate value for tracking scans 64 static int readoutSetLastScan(pmReadout *readout, // Readout of interest 65 fpaReadType type, // Type of image 66 int numScans // requested number of scans 67 ) 68 { 69 switch (type) { 70 case FPA_READ_TYPE_IMAGE: 71 readout->lastImageScan = readout->thisImageScan + numScans; 72 return readout->lastImageScan; 73 case FPA_READ_TYPE_MASK: 74 readout->lastMaskScan = readout->thisMaskScan + numScans; 75 return readout->lastMaskScan; 76 case FPA_READ_TYPE_WEIGHT: 77 readout->lastWeightScan = readout->thisWeightScan + numScans; 78 return readout->lastWeightScan; 79 default: 80 psAbort("Unknown read type: %x\n", type); 81 } 82 return false; 61 83 } 62 84 … … 134 156 } 135 157 136 137 // Determine readout scan properties: the next and last scans 138 // Requires that cellNumReadouts() has been called before (for header and concepts to have been read) 139 // In the process, adjusts the TRIMSEC 140 static bool readoutScanProperties(int *next, // Index of next scan 141 int *last, // Index of last scan 142 pmReadout *readout, // Readout of interest 143 int numScans, // Number of scans to read at a time 144 fpaReadType type, // Type of image 145 pmConfig *config // Configuration 158 // Does the current readout, with scans set for a new read, represent any real data, or is it 159 // beyond the end? Requires that cellNumReadouts() has been called before (for header and 160 // concepts to have been read) In the process, adjusts the TRIMSEC 161 static bool readoutHaveMoreScans(bool *result, // true : more data to read 162 pmReadout *readout, // Readout of interest 163 int numScans, // Number of scans to read at a time 164 fpaReadType type, // Type of image 165 pmConfig *config // Configuration 146 166 ) 147 167 { 148 assert(next); 149 assert(last); 168 assert(result); 150 169 assert(readout); 151 170 152 psImage *image = *readoutImageByType(readout, type); // Appropriate image from readout171 *result = false; 153 172 154 173 if (!pmConceptsReadCell(readout->parent, PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE, … … 163 182 PS_ASSERT_PTR_NON_NULL(cell, false); 164 183 pmHDU *hdu = pmHDUFromCell(cell); // HDU for data 184 165 185 bool mdok = true; // Status of MD lookup 166 186 psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim sections … … 195 215 // Calculate the segment offset and upper limit 196 216 if (numScans == 0) { 197 *next = (readdir == 1) ? trimsec->y0 : trimsec->x0; 198 } else { 199 *next = image ? *readoutScansByType(readout, type) + numScans : 0; 200 } 201 *last = (readdir == 1) ? trimsec->y1 : trimsec->x1; 202 217 // in the case of numScans == 0, we never call this funtion unless the data has not yet 218 // been read. thus, only if the delta is should we return false (ie, trimsec defines an empty region) 219 int thisScan = (readdir == 1) ? trimsec->y0 : trimsec->x0; 220 int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1; 221 *result = (lastScan > thisScan); 222 return true; 223 } 224 225 // allow multiple threads to read different segments into different readouts 226 // this thread may not have read a segment yet; but others have. trust readout->imageScan 227 228 // is the start scan of the read less than the last possible scan? 229 int thisScan = readoutGetThisScan(readout, type); 230 int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1; 231 232 *result = (lastScan > thisScan); 203 233 return true; 234 // XXX fold this and the above case together 204 235 } 205 236 … … 217 248 psImage *image = *readoutImageByType(readout, type); 218 249 250 // XXX this may not be the valid test in a multithread environment. consider a fileGroup of 251 // N readouts, but numScans set to 0. only the first should report that it requires data, 252 // even if all readouts lack the image pointer. 219 253 if (!image) { 220 254 return true; 221 } else if (numScans == 0) { 222 // Can only read the entire image once 255 } 256 257 // If we have already read an image, this result implies we are done (no more to read) 258 if (numScans == 0) { 223 259 return false; 224 260 } … … 235 271 } 236 272 237 int next; // Next position 238 int last; // Last position 239 if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) { 273 bool haveData; 274 if (!readoutHaveMoreScans(&haveData, readout, numScans, type, config)) { 240 275 psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties."); 241 276 return false; 242 277 } 243 278 244 return (next < last);279 return haveData; 245 280 } 246 281 … … 423 458 } 424 459 425 int next; // Next position 426 int last; // Last position 427 if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) { 460 bool haveData; 461 if (!readoutHaveMoreScans (&haveData, readout, type, numScans, config)) { 428 462 psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties."); 429 463 return false; 430 464 } 431 if ( next >= last) {465 if (!haveData) { 432 466 psError(PS_ERR_IO, true, "No more of the readout to read."); 433 467 return false; 434 468 } 469 435 470 436 471 pmHDU *hdu = pmHDUFromCell(cell); // The HDU … … 459 494 } 460 495 461 462 463 496 // Check the third dimension 464 497 int naxis = psMetadataLookupS32(&mdok, hdu->header, "NAXIS"); // The number of axes … … 478 511 } 479 512 480 // Update number of scansread481 int *scansTracker = readoutScansByType(readout, type); // Tracker for how many scans have been read482 *scansTracker = next;483 if ( next== 0) {513 // Determine the numbe of scans to read 514 int thisScan = readoutGetThisScan(readout, type); 515 int lastScan = readoutSetLastScan (readout, type, numScans); 516 if (thisScan == 0) { 484 517 overlap = 0; 485 518 } 486 next-= overlap;519 thisScan -= overlap; 487 520 488 521 // Calculate limits, adjust readout->row0,col0 … … 491 524 if (readdir == 1) { 492 525 // Reading rows 493 readout->row0 = next;526 readout->row0 = thisScan; 494 527 readout->col0 = trimsec->x0; 495 528 if (numScans == 0) { … … 498 531 } else { 499 532 // Reading cols 500 readout->col0 = next;533 readout->col0 = thisScan; 501 534 readout->row0 = trimsec->y0; 502 535 if (numScans == 0) { … … 504 537 } 505 538 } 506 int upper = next + numScans + overlap; // Upper limit to next section507 539 508 540 // Blow away existing data. … … 510 542 psFree(*image); 511 543 *image = NULL; 512 *image = readoutReadComponent(*image, fits, trimsec, readdir, next, upper, z, bad, pixelTypes[type]);544 *image = readoutReadComponent(*image, fits, trimsec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]); 513 545 514 546 // Read overscans only for "image" type --- weights and masks shouldn't record overscans … … 528 560 psRegion *biassec = NULL; // Bias section from iteration 529 561 while ((biassec = psListGetAndIncrement(biassecsIter))) { 530 psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, next, upper, z, 531 bad, pixelTypes[type]); // The bias 562 psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]); // The bias 532 563 psListAdd(readout->bias, PS_LIST_TAIL, bias); 533 564 psFree(bias); // Drop reference
Note:
See TracChangeset
for help on using the changeset viewer.
