Changeset 6514
- Timestamp:
- Mar 3, 2006, 4:39:39 PM (20 years ago)
- File:
-
- 1 edited
-
branches/rel10_ifa/psLib/src/fits/psFitsImage.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psLib/src/fits/psFitsImage.c
r6513 r6514 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1.10. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-03-04 0 1:54:42$9 * @version $Revision: 1.1.10.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-03-04 02:39:39 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 25 25 #include "psTrace.h" 26 26 #include "psVector.h" 27 27 #include "psFitsImage.h" 28 28 #include "psFitsHeader.h" 29 29 … … 257 257 } 258 258 259 output = psImageAlloc(lastPixel[0]-firstPixel[0]+1, lastPixel[1]-firstPixel[1]+1, datatype);259 psImage *output = psImageAlloc(lastPixel[0]-firstPixel[0]+1, lastPixel[1]-firstPixel[1]+1, datatype); 260 260 261 261 // n.b., this assumes contiguous image buffer … … 278 278 int nAxis = 0; // Number of axes 279 279 long nAxes[3]; // Number of pixels on each axis 280 int status = 0; // cfitsio status value 281 char fitsErr[80] = ""; // CFITSIO error message string 280 282 281 283 if (fits == NULL) { … … 327 329 psMetadata* header, 328 330 const psImage* input, 329 int numZPlanes) 331 int numZPlanes, 332 const char *extname) 330 333 { 331 334 … … 373 376 psMetadataAddF64(header, PS_LIST_TAIL, "BSCALE", PS_META_REPLACE, "Pixel value scale", 1.0); 374 377 psMetadataAddF64(header, PS_LIST_TAIL, "BZERO", PS_META_REPLACE, "Pixel value offset", bZero); 378 psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "Extension name", extname); 375 379 } 376 380 … … 381 385 psFitsWriteHeader(header, (psPtr)fits); 382 386 } else { 387 // Write the necessary headers manually 383 388 fits_write_key_dbl(fits->fd, "BZERO", bZero, 12, "Pixel Value Offset", &status); 384 389 fits_write_key_dbl(fits->fd, "BSCALE", 1.0, 12, "Pixel Value Scale", &status); 390 // Regrettably have to cast away "const" on extname 391 fits_write_key_str(fits->fd, "EXTNAME", (char *)extname, "Extension name", &status); 392 385 393 } 386 394 … … 438 446 if (input->n == 0) { 439 447 psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_EMPTY); 440 return fal ase;448 return false; 441 449 } 442 450 443 451 if (input->n == 1) { 444 452 // The problem reduces to one already solved 445 return psFitsWriteImage(fits, header, input->data[0], extname);453 return psFitsWriteImage(fits, header, input->data[0], 1, extname); 446 454 } 447 455 448 456 // Check that all images are of the same size 449 { 450 psImage *image = input->data[0];// First image off the array 451 int numCols = image->numCols; // Number of columns 452 int numRows = image->numRows; // Number of rows 453 for (int i = 1; i < input->n; i++) 454 { 455 image = input->data[i]; 456 if (image->numCols != numCols || image->numRows != numRows) { 457 psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_SIZE_DIFFER); 458 return false; 459 } 457 psImage *testImage = input->data[0];// First image off the array 458 int numCols = testImage->numCols; // Number of columns 459 int numRows = testImage->numRows; // Number of rows 460 for (int i = 1; i < input->n; i++) { 461 testImage = input->data[i]; 462 if (testImage->numCols != numCols || testImage->numRows != numRows) { 463 psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_SIZE_DIFFER); 464 return false; 460 465 } 461 466 } … … 472 477 psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS2", PS_META_REPLACE, "Number of rows", numRows) && 473 478 psMetadataAddS32(headerCopy, PS_LIST_HEAD, "NAXIS3", PS_META_REPLACE, "Number of image planes", 474 i mages->n);479 input->n); 475 480 if (! update) { 476 psError(PS_ERR_UNKNOWN, false, psFits_METADATA_ADD_FAILED, "NAXIS, NAXIS1, NAXIS2, NAXIS3"); 481 psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_METADATA_ADD_FAILED, 482 "NAXIS, NAXIS1, NAXIS2, NAXIS3"); 477 483 psFree(headerCopy); 478 484 return false; 479 485 } 480 486 481 // Now we can safely write the images out 482 for (int i = 0; i < images->n; i++) { 483 if (! psFitsWriteImage(fits, headerCopy, images->data[i], i, extname)) { 487 // Now we can safely write the images out. 488 // The first is an psFitsImageWrite to create the extension. 489 // The next are psFitsImageUpdate to write into the extension. 490 if (! psFitsWriteImage(fits, headerCopy, input->data[0], input->n, extname)) { 491 psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_WRITE_PLANE_FAILED, 0); 492 psFree(headerCopy); 493 return false; 494 } 495 psFree(headerCopy); // Free, or drop reference 496 497 for (int i = 1; i < input->n; i++) { 498 if (! psFitsUpdateImage(fits, input->data[i], 0, 0, i)) { 484 499 psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_WRITE_PLANE_FAILED, i); 485 psFree(headerCopy);486 500 return false; 487 501 } 488 502 } 489 503 490 psFree(headerCopy); // Free, or drop reference491 492 504 return true; 493 505 } 494 506 495 496 497 507 bool psFitsUpdateImage(psFits* fits, 498 508 const psImage* input, 499 psRegion region,509 int x0, int y0, 500 510 int z) 501 511 { … … 572 582 long lastPixel[3]; 573 583 574 firstPixel[0] = region.x0 + 1;575 firstPixel[1] = region.y0 + 1;584 firstPixel[0] = x0 + 1; 585 firstPixel[1] = y0 + 1; 576 586 firstPixel[2] = z + 1; 577 587 578 if (region.x1 > 0) { 579 lastPixel[0] = region.x1; 580 } else { 581 lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0 582 } 583 if (region.y1 > 0) { 584 lastPixel[1] = region.y1; 585 } else { 586 lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0 587 } 588 lastPixel[0] = firstPixel[0] + input->numCols; 589 lastPixel[1] = firstPixel[1] + input->numRows; 588 590 lastPixel[2] = z + 1; 589 591 … … 594 596 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 595 597 "Specified region [%d:%d,%d:%d], is not valid given the %dx%d FITS image.", 596 region.y0,region.y1-1,region.x0,region.x1-1);598 x0, x0 + input->numCols, y0, y0 + input->numRows, nAxes[0], nAxes[1]); 597 599 return false; 598 600 … … 633 635 } 634 636 637 bool psFitsUpdateImageCube(psFits *fits, const psArray *input, int x0, int y0) 638 { 639 if (fits == NULL) { 640 psError(PS_ERR_BAD_PARAMETER_NULL, true, 641 PS_ERRORTEXT_psFits_NULL); 642 return false; 643 } 644 645 if (input == NULL) { 646 psError(PS_ERR_BAD_PARAMETER_NULL, true, 647 PS_ERRORTEXT_psFits_IMAGE_NULL); 648 return false; 649 } 650 651 if (input->n == 0) { 652 psError(PS_ERR_BAD_PARAMETER_SIZE, true, PS_ERRORTEXT_psFits_ARRAY_EMPTY); 653 return false; 654 } 655 656 for (int i = 0; i < input->n; i++) { 657 if (! psFitsUpdateImage(fits, input->data[i], x0, y0, i)) { 658 psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psFits_UPDATE_PLANE_FAILED, i); 659 return false; 660 } 661 } 662 663 return true; 664 }
Note:
See TracChangeset
for help on using the changeset viewer.
