Changeset 15168 for branches/pap_branch_070920/psLib/src/fits/psFits.c
- Timestamp:
- Oct 2, 2007, 5:01:45 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_070920/psLib/src/fits/psFits.c
r15111 r15168 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.71.2. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2007- 09-29 21:55:41$9 * @version $Revision: 1.71.2.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-10-03 03:01:45 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 81 81 bool psFitsClose(psFits* fits) 82 82 { 83 if (fits == NULL) { 84 psError(PS_ERR_BAD_PARAMETER_NULL, true, 85 _("The input psFits object can not NULL.")); 86 return false; 87 } 83 PS_ASSERT_FITS_NON_NULL(fits, false); 88 84 89 85 bool status = fitsClose(fits); … … 95 91 psFits* psFitsOpen(const char* name, const char* mode) 96 92 { 93 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 94 97 95 int status = 0; 98 96 fitsfile *fptr = NULL; /* Pointer to the FITS file */ 99 100 if (name == NULL) {101 psError(PS_ERR_BAD_PARAMETER_NULL, true,102 _("Specified filename can not be NULL."));103 return NULL;104 }105 97 106 98 /* check the mode to determine how to open/create file */ … … 131 123 if (access(name, F_OK) == 0) { 132 124 // file exists, delete old one first 133 remove 134 (name); 125 remove(name); 135 126 } 136 127 … … 140 131 (void)fits_create_file 141 132 #endif 142 (&fptr, 143 name, 144 &status); 133 (&fptr, name, &status); 145 134 if (fptr == NULL || status != 0) { 146 135 char fitsErr[MAX_STRING_LENGTH]; … … 157 146 (void)fits_open_file 158 147 #endif 159 (&fptr, 160 name, 161 iomode, 162 &status); 148 (&fptr, name, iomode, &status); 163 149 if (fptr == NULL || status != 0) { 164 150 char fitsErr[MAX_STRING_LENGTH]; … … 175 161 fits->writable = (iomode == READWRITE); 176 162 fits->extword = NULL; 163 fits->compression = true; 177 164 psMemSetDeallocator(fits,(psFreeFunc)fitsFree); 178 165 … … 180 167 } 181 168 182 psErrorCode p_psFitsError(const char* filename, 183 unsigned int lineno, 184 const char* func, 185 int status, 186 bool new, 187 const char *errorMsg, 188 ... 189 ) 169 psErrorCode p_psFitsError(const char* filename, unsigned int lineno, const char* func, int status, 170 bool new, const char *errorMsg, ...) 190 171 { 191 172 if (status == 0) { … … 211 192 static void psFitsCompressionFree(psFitsCompression *comp) 212 193 { 194 PS_ASSERT_PTR_NON_NULL(comp,); 213 195 psFree(comp->tilesize); 214 196 } … … 256 238 const char *extword) 257 239 { 258 PS_ASSERT_ PTR_NON_NULL(fits,false);240 PS_ASSERT_FITS_NON_NULL(fits, false); 259 241 PS_ASSERT_PTR_NON_NULL(extname, false); 260 242 PS_ASSERT_PTR_NON_NULL(extword, false); … … 301 283 const char* extname) 302 284 { 303 int status = 0; 304 305 if (fits == NULL) { 306 psError(PS_ERR_BAD_PARAMETER_NULL, true, 307 _("The input psFits object can not NULL.")); 308 return false; 309 } 310 311 if (extname == NULL) { 312 psError(PS_ERR_BAD_PARAMETER_NULL, true, 313 _("Specified extension name can not be NULL.")); 314 return false; 315 } 285 PS_ASSERT_FITS_NON_NULL(fits, false); 286 PS_ASSERT_STRING_NON_EMPTY(extname, false); 287 288 int status = 0; 316 289 317 290 if (fits->extword != NULL) { … … 336 309 bool relative) 337 310 { 338 if (fits == NULL) { 339 psError(PS_ERR_BAD_PARAMETER_NULL, true, 340 _("The input psFits object can not NULL.")); 341 return false; 342 } 311 PS_ASSERT_FITS_NON_NULL(fits, false); 343 312 344 313 int status = 0; … … 372 341 bool psFitsMoveLast(psFits* fits) 373 342 { 374 if (fits == NULL) { 375 psError(PS_ERR_BAD_PARAMETER_NULL, true, 376 _("The input psFits object can not NULL.")); 377 return false; 378 } 343 PS_ASSERT_FITS_NON_NULL(fits, false); 344 379 345 int size = psFitsGetSize(fits); 380 346 if (size == 0) { // empty file -- no action needed … … 387 353 int psFitsGetExtNum(const psFits* fits) 388 354 { 355 PS_ASSERT_FITS_NON_NULL(fits, false); 389 356 int hdunum; 390 391 if (fits == NULL) {392 psError(PS_ERR_BAD_PARAMETER_NULL, true,393 _("The input psFits object can not NULL."));394 return PS_FITS_TYPE_NONE;395 }396 397 398 357 return fits_get_hdu_num(fits->fd,&hdunum) - 1; 399 358 } … … 401 360 psString psFitsGetExtName(const psFits* fits) 402 361 { 403 if (fits == NULL) { 404 psError(PS_ERR_BAD_PARAMETER_NULL, true, 405 _("The input psFits object can not NULL.")); 406 return NULL; 407 } 362 PS_ASSERT_FITS_NON_NULL(fits, NULL); 408 363 409 364 int status = 0; … … 422 377 bool psFitsSetExtName(psFits* fits, const char* name) 423 378 { 424 if (fits == NULL) { 425 psError(PS_ERR_BAD_PARAMETER_NULL, true, 426 _("The input psFits object can not NULL.")); 427 return false; 428 } 429 430 if (name == NULL) { 431 psError(PS_ERR_BAD_PARAMETER_NULL, true, 432 _("Specified extension name can not be NULL.")); 433 return false; 434 } 379 PS_ASSERT_FITS_NON_NULL(fits, false); 380 PS_ASSERT_STRING_NON_EMPTY(name, false); 435 381 436 382 int status = 0; … … 454 400 bool relative) 455 401 { 456 if (fits == NULL) { 457 psError(PS_ERR_BAD_PARAMETER_NULL, true, 458 _("The input psFits object can not NULL.")); 459 return false; 460 } 402 PS_ASSERT_FITS_NON_NULL(fits, false); 461 403 462 404 if (! fits->writable) { … … 492 434 const char* extname) 493 435 { 494 if (fits == NULL) { 495 psError(PS_ERR_BAD_PARAMETER_NULL, true, 496 _("The input psFits object can not NULL.")); 497 return false; 498 } 436 PS_ASSERT_FITS_NON_NULL(fits, false); 437 PS_ASSERT_STRING_NON_EMPTY(extname, false); 499 438 500 439 if (! fits->writable) { … … 530 469 int psFitsGetSize(const psFits* fits) 531 470 { 532 if (fits == NULL) { 533 psError(PS_ERR_BAD_PARAMETER_NULL, true, 534 _("The input psFits object can not NULL.")); 535 return 0; 536 } 471 PS_ASSERT_FITS_NON_NULL(fits, 0); 537 472 538 473 int num = 0; … … 553 488 psFitsType psFitsGetExtType(const psFits* fits) 554 489 { 555 if (fits == NULL) { 556 psError(PS_ERR_BAD_PARAMETER_NULL, true, 557 _("The input psFits object can not NULL.")); 558 return PS_FITS_TYPE_NONE; 559 } 490 PS_ASSERT_FITS_NON_NULL(fits, PS_FITS_TYPE_NONE); 560 491 561 492 int status = 0; … … 582 513 bool psFitsTruncate(psFits* fits) 583 514 { 584 if (fits == NULL) { 585 psError(PS_ERR_BAD_PARAMETER_NULL, true, 586 _("The input psFits object can not NULL.")); 587 return PS_FITS_TYPE_NONE; 588 } 515 PS_ASSERT_FITS_NON_NULL(fits, NULL); 589 516 590 517 if (! fits->writable) { … … 623 550 ) 624 551 { 552 PS_ASSERT_FITS_NON_NULL(fits, false); 553 625 554 // convert psFitsCompressionType to cfitsio compression types 626 555 int comptype; … … 708 637 } 709 638 639 psFitsCompression *psFitsCompressionGet(psFits* fits) 640 { 641 PS_ASSERT_FITS_NON_NULL(fits, NULL); 642 643 int status = 0; // cfitsio status 644 645 psFitsCompressionType type = psFitsCompressionGetType(fits); 646 if (type < 0) { 647 psError(PS_ERR_UNKNOWN, false, "Unable to get compression type."); 648 return NULL; 649 } 650 651 psElemType tileType; // Type corresponding to "long" 652 if (sizeof(long) == sizeof(psS64)) { 653 tileType = PS_TYPE_S64; 654 } else if (sizeof(long) == sizeof(psS32)) { 655 tileType = PS_TYPE_S32; 656 } else { 657 psAbort("can't map (long) type to a psLib type"); 658 } 659 660 psVector *tiles = psVectorAlloc(3, tileType); // Tile sizes 661 if (fits_get_tile_dim(fits->fd, 3, (long*)tiles->data.U8, &status)) { 662 psFitsError(status, true, "Unable to get compression tile sizes."); 663 psFree(tiles); 664 return NULL; 665 } 666 667 int noisebits; // Noise bits for compression 668 if (fits_get_noise_bits(fits->fd, &noisebits, &status)) { 669 psFitsError(status, true, "Unable to get compression noise bits."); 670 psFree(tiles); 671 return NULL; 672 } 673 674 int hscale = 0, hsmooth = 0; // Scaling and smoothing for HCOMPRESS 675 676 #if FITS_HCOMP 677 if (fits_get_hcomp_scale(fits->fd, &hscale, &status)) { 678 psFitsError(status, true, "Unable to get HCOMPRESS scaling."); 679 psFree(tiles); 680 return NULL; 681 } 682 if (fits_get_hcomp_smooth(fits->fd, &hsmooth, &status)) { 683 psFitsError(status, true, "Unable to get HCOMPRESS smoothing."); 684 psFree(tiles); 685 return NULL; 686 } 687 #endif // FITS_HCOMP 688 689 psFitsCompression *compress = psFitsCompressionAlloc(type, tiles, noisebits, hscale, hsmooth); 690 psFree(tiles); // Drop reference 691 692 return compress; 693 } 694 695 psFitsCompressionType psFitsCompressionGetType(psFits* fits) 696 { 697 PS_ASSERT_FITS_NON_NULL(fits, -1); 698 699 int status = 0; // cfitsio status 700 int comptype = 0; // cfitsio compression type 701 if (fits_get_compression_type(fits->fd, &comptype, &status)) { 702 psFitsError(status, true, "Unable to get compression type."); 703 return -1; 704 } 705 706 psFitsCompressionType type; 707 switch (comptype) { 708 case 0: 709 type = PS_FITS_COMPRESS_NONE; 710 break; 711 case GZIP_1: 712 type = PS_FITS_COMPRESS_GZIP; 713 break; 714 case RICE_1: 715 type = PS_FITS_COMPRESS_RICE; 716 break; 717 case HCOMPRESS_1: 718 type = PS_FITS_COMPRESS_HCOMPRESS; 719 break; 720 case PLIO_1: 721 type = PS_FITS_COMPRESS_PLIO; 722 break; 723 default: 724 psError(PS_ERR_UNKNOWN, true, "cfitsio reports unknown compression type."); 725 return -1; 726 } 727 728 return type; 729 } 730 710 731 711 732 bool psFitsCompressionApply(
Note:
See TracChangeset
for help on using the changeset viewer.
