Changeset 6734 for branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c
- Timestamp:
- Mar 30, 2006, 10:08:30 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmFPACopy.c
r6720 r6734 117 117 *xSize = MAX(trimsec->x1, *xSize); 118 118 *ySize = MAX(trimsec->y1, *ySize); 119 } else { 120 psFree(cellsIter); 121 return false; 119 122 } 120 123 psList *biassecs = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.BIASSEC"); // Bias sections … … 126 129 *xSize = MAX(biassec->x1, *xSize); 127 130 *ySize = MAX(biassec->y1, *ySize); 131 } else { 132 psFree(biassecsIter); 133 psFree(cellsIter); 134 return false; 128 135 } 129 136 } … … 133 140 psFree(cellsIter); 134 141 135 return (*xSize == 0 || *ySize == 0);142 return (*xSize != 0 && *ySize != 0); 136 143 } 137 144 … … 145 152 switch (readdir) { 146 153 case 1: // Read direction is rows 147 region = psRegionSet(*position, image->row0, *position + image->numCols,154 region = psRegionSet(*position, *position + image->numCols, image->row0, 148 155 image->row0 + image->numRows); 149 156 *position += image->numCols; 150 157 break; 151 158 case 2: // Read direction is columns 152 region = psRegionSet(image->col0, *position, image->col0 + image->numCols,159 region = psRegionSet(image->col0, image->col0 + image->numCols, *position, 153 160 *position + image->numRows); 154 161 *position += image->numRows; … … 209 216 int numCells = targets->n; // Number of cells 210 217 int cellNum = 0; // The cell number 211 int position ;// Position on the image218 int position = 0; // Position on the image 212 219 bool mdok = true; // Status of MD lookup 213 220 … … 218 225 while ((target = psListGetAndIncrement(targetsIter)) && (source = psListGetAndIncrement(sourcesIter)) && 219 226 !done) { 220 if (cellNum < numCells/2) {227 if (cellNum <= numCells/2 - 1) { 221 228 doBiasSections(&position, target, source); 229 cellNum++; 222 230 } else { 223 231 done = true; … … 249 257 250 258 // A final run through to do the RHS biases 251 psListIteratorSet(targetsIter, numCells/2);252 psListIteratorSet(sourcesIter, numCells/2);259 psListIteratorSet(targetsIter, cellNum); 260 psListIteratorSet(sourcesIter, cellNum); 253 261 while ((target = psListGetAndIncrement(targetsIter)) && (source = psListGetAndIncrement(sourcesIter))) { 254 262 doBiasSections(&position, target, source); … … 299 307 // Get the size of the HDU, either from existing trimsec and biassec, or generate these and try again 300 308 int xSize = 0, ySize = 0; // Size of HDU 301 if (!sizeHDU(&xSize, &ySize, targetCells) || !(generateTrimBias(targetCells, sourceCells) && 309 #if 1 310 311 if (!sizeHDU(&xSize, &ySize, targetCells) && !(generateTrimBias(targetCells, sourceCells) && 302 312 sizeHDU(&xSize, &ySize, targetCells))) { 303 313 psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n"); 304 314 return false; 305 315 } 316 #else 317 if (!sizeHDU(&xSize, &ySize, targetCells)) { 318 if (generateTrimBias(targetCells, sourceCells)) { 319 if (!sizeHDU(&xSize, &ySize, targetCells)) { 320 psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n"); 321 return false; 322 } 323 } else { 324 psError(PS_ERR_IO, true, "Unable to determine size of HDU!\n"); 325 return false; 326 } 327 } 328 #endif 306 329 307 330 hdu->images = psArrayAlloc(numReadouts); … … 314 337 return true; 315 338 } 316 317 318 #define UPDATE_CASE(TYPENAME,TYPE) \319 case TYPENAME: targetItem->data.TYPE = sourceItem->data.TYPE; \320 break;321 322 // Update a particular "concept" for the target cell from the source cell323 static bool updateConcept(pmCell *target, // Target cell324 const pmCell *source, // Source cell325 const char *concept // Concept name326 )327 {328 psMetadataItem *targetItem = psMetadataLookup(target->concepts, concept); // Concept from the target329 psMetadataItem *sourceItem = psMetadataLookup(source->concepts, concept); // Concept from the source330 331 switch (targetItem->type) {332 UPDATE_CASE(PS_TYPE_S32, S32);333 UPDATE_CASE(PS_TYPE_F32, F32);334 UPDATE_CASE(PS_TYPE_F64, F64);335 UPDATE_CASE(PS_DATA_STRING, V);336 default:337 psLogMsg(__func__, PS_LOG_WARN, "Unsupported type (%x) for concept %s --- ignored.\n",338 targetItem->type, concept);339 return false;340 }341 return true;342 }343 344 339 345 340 // Copy pixels from a target image to a source image, with flips … … 386 381 return false; 387 382 } 383 384 #if 1 385 // Copy any headers 386 if (target->hdu && !target->hdu->phu) { 387 pmHDU *sourceHDU = pmHDUFromFPA(source); 388 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header); 389 } 390 #endif 388 391 389 392 int numChips = 0; // Number of chips copied … … 400 403 } 401 404 405 // Update the concepts 406 psMetadataCopy(target->concepts, source->concepts); 407 402 408 return numChips; 403 409 } … … 417 423 return false; 418 424 } 425 426 #if 1 427 // Copy any headers 428 if (target->hdu && !target->hdu->phu) { 429 pmHDU *sourceHDU = pmHDUFromChip(source); 430 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header); 431 } 432 #endif 419 433 420 434 int numCells = 0; // Number of cells copied … … 431 445 } 432 446 447 // Update the concepts 448 psMetadataCopy(target->concepts, source->concepts); 449 433 450 return numCells; 434 451 … … 442 459 assert(source); 443 460 444 psArray *targetReadouts = target->readouts; // The target readouts445 461 psArray *sourceReadouts = source->readouts; // The source readouts 446 if (targetReadouts->n != sourceReadouts->n) { 447 psError(PS_ERR_IO, true, "Number of source readouts (%d) differs from the number of target readouts " 448 "(%d)\n", sourceReadouts->n, targetReadouts->n); 449 return false; 450 } 451 int numReadouts = targetReadouts->n; // Number of readouts copied 462 int numReadouts = sourceReadouts->n; // Number of readouts copied 463 464 #if 1 465 // Copy any headers 466 if (target->hdu && !target->hdu->phu) { 467 pmHDU *sourceHDU = pmHDUFromCell(source); 468 target->hdu->header = psMetadataCopy(target->hdu->header, sourceHDU->header); 469 } 470 #endif 452 471 453 472 pmHDU *hdu = pmHDUFromCell(target); // The target HDU; we need to fix this up 454 if (! hdu->images) {473 if (!hdu->images) { 455 474 generateHDU(target, source); 456 475 } 457 458 // Need to check CELL.X0, CELL.Y0, CELL.XBIN, CELL.YBIN should be unchanged; we can check this by 459 // setting the values and leaving it to the pmConceptWrite functions to do the checking against the 460 // camera configuration when it comes time to write them out. 461 updateConcept(target, source, "CELL.X0"); 462 updateConcept(target, source, "CELL.Y0"); 463 updateConcept(target, source, "CELL.XBIN"); 464 updateConcept(target, source, "CELL.YBIN"); 476 if (!hdu->header) { 477 hdu->header = psMetadataAlloc(); 478 } 465 479 466 480 // Need to check/change CELL.XPARITY and CELL.YPARITY 467 481 bool xFlip = (psMetadataLookupS32(NULL, target->concepts, "CELL.XPARITY") != 468 psMetadataLookupS32(NULL, target->concepts, "CELL.XPARITY")); // Switch parity in x?482 psMetadataLookupS32(NULL, source->concepts, "CELL.XPARITY")); // Switch parity in x? 469 483 bool yFlip = (psMetadataLookupS32(NULL, target->concepts, "CELL.YPARITY") != 470 psMetadataLookupS32(NULL, target->concepts, "CELL.YPARITY")); // Switch parity in y?484 psMetadataLookupS32(NULL, source->concepts, "CELL.YPARITY")); // Switch parity in y? 471 485 472 486 bool mdok = true; // Status of MD lookup … … 482 496 } 483 497 484 for (int i = 0; i < targetReadouts->n; i++) {498 for (int i = 0; i < numReadouts; i++) { 485 499 pmReadout *sourceReadout = sourceReadouts->data[i]; // The source readout 486 500 psImage *sourceImage = sourceReadout->image; // The source image 487 pmReadout *targetReadout = targetReadouts->data[i]; // The target readout501 pmReadout *targetReadout = pmReadoutAlloc(target); // The target readout; this adds it to the cell 488 502 if (sourceImage->numCols != trimsec->x1 - trimsec->x0 || 489 503 sourceImage->numRows != trimsec->y1 - trimsec->y0) { … … 500 514 psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator 501 515 psRegion *biassec = NULL; // Bias section from iteration 502 while ((biassec = psListGetAndIncrement(biassecsIter))) { 516 psListIterator *biasIter = psListIteratorAlloc(sourceReadout->bias, PS_LIST_HEAD, false); // Iterator 517 psImage *bias = NULL; // Bias image from iteration 518 while ((biassec = psListGetAndIncrement(biassecsIter)) && (bias = psListGetAndIncrement(biasIter))) { 503 519 if (psRegionIsBad(*biassec)) { 504 520 psString biassecString = psRegionToString(*biassec); // String for bias section … … 507 523 continue; 508 524 } 509 if ( sourceImage->numCols != biassec->x1 - biassec->x0 ||510 sourceImage->numRows != biassec->y1 - biassec->y0) {525 if (bias->numCols != biassec->x1 - biassec->x0 || 526 bias->numRows != biassec->y1 - biassec->y0) { 511 527 psString biassecString = psRegionToString(*biassec); // String with the bias section 512 528 psLogMsg(__func__, PS_LOG_WARN, "Source image size (%dx%d) for readout %d doesn't match " 513 "CELL.BIASSEC for target (%s) -- ignored.\n", sourceImage->numCols,514 sourceImage->numRows, i,biassecString);529 "CELL.BIASSEC for target (%s) -- ignored.\n", bias->numCols, bias->numRows, i, 530 biassecString); 515 531 psFree(biassecString); 516 532 } else { 517 copyPixels(hdu->images->data[i], sourceImage, *biassec, xFlip, yFlip);518 psImage * bias = psMemIncrRefCounter(psImageSubset(hdu->images->data[i], *biassec));519 psListAdd(targetReadout->bias, PS_LIST_TAIL, bias);520 psFree( bias);// Drop reference533 copyPixels(hdu->images->data[i], bias, *biassec, xFlip, yFlip); 534 psImage *newBias = psMemIncrRefCounter(psImageSubset(hdu->images->data[i], *biassec)); 535 psListAdd(targetReadout->bias, PS_LIST_TAIL, newBias); 536 psFree(newBias); // Drop reference 521 537 } 522 538 } 523 539 psFree(biassecsIter); 524 540 psFree(biasIter); 541 } 542 543 // Copy the remaining "concepts" over 544 psMetadataIterator *conceptsIter = psMetadataIteratorAlloc(source->concepts, PS_LIST_HEAD, NULL); 545 psMetadataItem *conceptItem = NULL; // Item from iteration 546 while ((conceptItem = psMetadataGetAndIncrement(conceptsIter))) { 547 psString name = conceptItem->name; // Name of concept 548 if (strcmp(name, "CELL.TRIMSEC") != 0 && strcmp(name, "CELL.BIASSEC") != 0 && 549 strcmp(name, "CELL.XPARITY") != 0 && strcmp(name, "CELL.YPARITY") != 0) { 550 psMetadataAddItem(target->concepts, conceptItem, PS_LIST_TAIL, PS_META_REPLACE); 551 } 552 } 553 554 // Need to update CELL.X0 and CELL.Y0 if we flipped 555 if (xFlip) { 556 psMetadataItem *xZero = psMetadataLookup(target->concepts, "CELL.X0"); // CELL.X0 557 pmReadout *readout = target->readouts->data[0]; // A representative readout 558 xZero->data.S32 -= readout->image->numCols - 1; 559 } 560 if (yFlip) { 561 psMetadataItem *yZero = psMetadataLookup(target->concepts, "CELL.Y0"); // CELL.Y0 562 pmReadout *readout = target->readouts->data[0]; // A representative readout 563 yZero->data.S32 -= readout->image->numRows - 1; 525 564 } 526 565
Note:
See TracChangeset
for help on using the changeset viewer.
