Changeset 6767 for trunk/psLib/src/fits/psFitsImage.c
- Timestamp:
- Apr 4, 2006, 9:52:55 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsImage.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsImage.c
r5511 r6767 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $10 * @date $Date: 200 5-11-14 22:18:30$9 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-04-04 19:52:42 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 16 16 17 17 #include "psFits.h" 18 #include "psFitsImage.h" 18 19 #include "string.h" 19 20 #include "psError.h" … … 292 293 psMetadata* header, 293 294 const psImage* input, 294 int numZPlanes) 295 int numZPlanes, 296 const char* extname) 297 { 298 // this is equivalent to insert after the last HDU 299 300 psFitsMoveLast(fits); 301 return psFitsInsertImage(fits,header,input,numZPlanes,extname,true); 302 } 303 304 bool psFitsInsertImage(psFits* fits, 305 psMetadata* header, 306 const psImage* input, 307 int numZPlanes, 308 const char* extname, 309 bool after) 295 310 { 296 311 … … 330 345 } 331 346 332 fits_create_img(fits->fd, bitPix, naxis, naxes, &status); 347 int chdu = psFitsGetExtNum(fits); 348 int hdus = psFitsGetSize(fits); 349 if (! after) { 350 if (chdu == 0) { 351 // set status to signal fits_insert_img to insert a new primary HDU 352 status = PREPEND_PRIMARY; 353 } else if (hdus > 0) { 354 // move back one to perform an insert after the previous HDU 355 psFitsMoveExtNum(fits, -1, true); 356 } 357 } 358 359 if (hdus == 0) { 360 status = 0; 361 fits_create_img(fits->fd, bitPix, naxis, naxes, &status); 362 363 } else { 364 fits_insert_img(fits->fd, bitPix, naxis, naxes, &status); 365 } 333 366 334 367 if (bZero != 0) { // set the bscale/bzero … … 339 372 340 373 // write the header, if any. 374 if (extname != NULL) { 375 psFitsSetExtName(fits,extname); 376 } 377 341 378 if (header != NULL) { 342 psFitsWriteHeader(header, (psPtr)fits); 379 if (extname != NULL) { 380 psMetadataAddStr(header,PS_LIST_TAIL,"EXTNAME", 381 PS_META_REPLACE, 382 "Extenion Name", 383 extname); 384 } 385 386 psFitsWriteHeader(header, fits); 343 387 } 344 388 … … 378 422 bool psFitsUpdateImage(psFits* fits, 379 423 const psImage* input, 380 psRegion region, 424 int x0, 425 int y0, 381 426 int z) 382 427 { … … 453 498 long lastPixel[3]; 454 499 455 firstPixel[0] = region.x0 + 1;456 firstPixel[1] = region.y0 + 1;500 firstPixel[0] = x0 + 1; 501 firstPixel[1] = y0 + 1; 457 502 firstPixel[2] = z + 1; 458 503 459 if (region.x1 > 0) { 460 lastPixel[0] = region.x1; 461 } else { 462 lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0 463 } 464 if (region.y1 > 0) { 465 lastPixel[1] = region.y1; 466 } else { 467 lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0 468 } 504 lastPixel[0] = x0 + numCols; 505 lastPixel[1] = y0 + numRows; 469 506 lastPixel[2] = z + 1; 470 507 … … 474 511 lastPixel[1] < 1 || lastPixel[1] > nAxes[1]) { 475 512 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 476 "Specified region [%d:%d,%d:%d], is not valid given the %dx%d FITS image.", 477 region.y0,region.y1-1,region.x0,region.x1-1); 478 return false; 479 480 } 481 482 int dx = lastPixel[0] - firstPixel[0]; 483 int dy = lastPixel[1] - firstPixel[1]; 484 if (dx > numCols || 485 dy > numRows) { 486 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 487 "The region [%d:%d,%d:%d], is not valid given the input %dx%d image.", 488 firstPixel[1]-1,lastPixel[1]-1, 489 firstPixel[0]-1,lastPixel[0]-1, 490 numCols, numRows); 491 return false; 492 } 493 494 psImage* subset; 495 if (dx != numCols || dy != numRows) { 496 // the input image needs to be subsetted 497 subset = psImageSubset((psImage*)input, psRegionSet(0,dx+1,0,dy+1)); 498 } else { 499 subset = psMemIncrRefCounter((psImage*)input); 500 } 501 502 fits_write_subset(fits->fd, dataType, firstPixel, lastPixel, subset->data.V[0], &status); 513 "Input image [size of %ix%i] at position (%i,%i) does not all lay in the %ix%i FITS image.", 514 numCols, numRows, 515 x0, y0, 516 nAxes[0], nAxes[1]); 517 return false; 518 } 519 520 fits_write_subset(fits->fd, dataType, firstPixel, lastPixel, input->data.V[0], &status); 503 521 504 522 if ( status != 0) {
Note:
See TracChangeset
for help on using the changeset viewer.
