Changeset 2962
- Timestamp:
- Jan 12, 2005, 12:17:02 PM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 20 edited
-
psLib.kdevelop.pcs (modified) ( previous)
-
psLib.kdevses (modified) (2 diffs)
-
src/dataIO/Makefile (modified) (1 diff)
-
src/dataIO/psFileUtilsErrors.dat (modified) (3 diffs)
-
src/dataIO/psFileUtilsErrors.h (modified) (4 diffs)
-
src/dataIO/psFits.c (modified) (9 diffs)
-
src/dataIO/psFits.h (modified) (10 diffs)
-
src/dataManip/psMatrixVectorArithmetic.c (modified) (3 diffs)
-
src/dataManip/psMatrixVectorArithmetic.h (modified) (2 diffs)
-
src/fileUtils/Makefile (modified) (1 diff)
-
src/fileUtils/psFileUtilsErrors.dat (modified) (3 diffs)
-
src/fileUtils/psFileUtilsErrors.h (modified) (4 diffs)
-
src/fileUtils/psFits.c (modified) (9 diffs)
-
src/fileUtils/psFits.h (modified) (10 diffs)
-
src/fits/psFits.c (modified) (9 diffs)
-
src/fits/psFits.h (modified) (10 diffs)
-
src/image/psImageIO.c (modified) (4 diffs)
-
src/pslib.h (modified) (2 diffs)
-
test/dataIO/Makefile (modified) (2 diffs)
-
test/fileUtils/Makefile (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/psLib.kdevses
r2925 r2962 2 2 <!DOCTYPE KDevPrjSession> 3 3 <KDevPrjSession> 4 <DocsAndViews NumberOfDocuments="0" /> 4 <DocsAndViews NumberOfDocuments="3" > 5 <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/test/fileUtils/tst_psFits.c" > 6 <View0 Type="Source" /> 7 </Doc0> 8 <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.h" > 9 <View0 Type="Source" /> 10 </Doc1> 11 <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/fileUtils/psFits.c" > 12 <View0 line="318" Type="Source" /> 13 </Doc2> 14 </DocsAndViews> 5 15 <pluginList> 6 16 <kdevbookmarks> … … 11 21 </bookmarks> 12 22 </kdevbookmarks> 13 <kdevsubversion>14 <subversion recurseresolve="1" recurserelocate="1" recursemerge="1" recursecommit="1" base="" recursepropget="1" recurseswitch="1" recurseupdate="1" recursepropset="1" recursediff="1" recurserevert="1" forcemove="1" recursecheckout="1" forceremove="1" recurseadd="1" recurseproplist="1" forcemerge="1" />15 </kdevsubversion>16 23 <kdevvalgrind> 17 24 <executable path="" params="" /> -
trunk/psLib/src/dataIO/Makefile
r2375 r2962 8 8 -I.. -I../image -I../astronomy -DSER7_FILE="\"$(SER7_FILE)\"" -DTAIUTC_FILE="\"$(TAIUTC_FILE)\"" 9 9 10 SRC_OBJS = psLookupTable.o 10 SRC_OBJS = psLookupTable.o \ 11 psFits.o 11 12 12 13 OBJS = $(addprefix makedir/,$(SRC_OBJS)) -
trunk/psLib/src/dataIO/psFileUtilsErrors.dat
r2806 r2962 10 10 psLookupTable_PARSE_VALUE Unable to parse string, %s on line %lld. 11 11 psLookupTable_PARSE_TYPE Unable to parse type, %s on line %lld. 12 psLookupTable_PARSE_GENERAL Unable to read lookup table item, %s on line %lld 12 psLookupTable_PARSE_GENERAL Unable to read lookup table item, %s on line %lld 13 13 psLookupTable_INTERPOLATE_HIGH High index too big, %d. 14 14 psLookupTable_INTERPOLATE_LOW Low index too small, %d. … … 19 19 psFits_FILENAME_INVALID Could not open file,'%s'.\nCFITSIO Error: %s 20 20 psFits_FILENAME_NULL Specified filename can not be NULL. 21 psFits_EXTNAME_NULL Specified extension name can not be NULL. 21 22 psFits_EXTNAME_INVALID Could not find HDU '%s' in file %s.\nCFITSIO Error: %s 22 23 psFits_EXTNUM_INVALID Could not find HDU #%d in file %s.\nCFITSIO Error: %s … … 40 41 psFits_METADATA_NULL The input psMetadata was NULL. Need a non-NULL psMetadata for operation to be performed. 41 42 psFits_METADATA_PTYPE_UNSUPPORTED A metadata item's primative type, %d, is not supported. 42 psFits_ROW_INVALID Specified row, %d, is not valid for current table of %d rows. 43 psFits_ROW_INVALID Specified row, %d, is not valid for current table of %d rows. 43 44 psFits_GET_TABLE_ELEMENT Failed to retrieve table element (%d,%d).\nCFITSIO Error: %s 44 45 psFits_FIND_COLUMN Specified column, %s, was not found.\nCFITSIO Error: %s 45 46 psFits_GET_COLTYPE Could not determine the datatype of the table column.\nCFITSIO Error: %s 46 47 psFits_TABLE_READ_COL Failed to read table column.\nCFITSIO Error: %s 48 psFits_DATATYPE_UNKNOWN Could not determine image data type.\nCFITSIO Error: %s 49 psFits_IMAGE_DIM_UNKNOWN Could not determine image dimensions.\nCFITSIO Error: %s 50 psFits_IMAGE_DIMENSION_UNSUPPORTED Image number of dimensions, %d, is not valid. Only two or three dimensions supported for FITS I/O. 51 psFits_IMAGE_SIZE_UNKNOWN Could not determine image size.\nCFITSIO Error: %s 52 psFits_FITS_TYPE_UNSUPPORTED FITS image type, BITPIX=%d, is not supported. 53 psFits_READ_FAILED Reading FITS file failed.\nCFITSIO Error: %s 47 54 # -
trunk/psLib/src/dataIO/psFileUtilsErrors.h
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 33 33 #define PS_ERRORTEXT_psLookupTable_PARSE_VALUE "Unable to parse string, %s on line %lld." 34 34 #define PS_ERRORTEXT_psLookupTable_PARSE_TYPE "Unable to parse type, %s on line %lld." 35 #define PS_ERRORTEXT_psLookupTable_PARSE_GENERAL "Unable to read lookup table item, %s on line %lld "35 #define PS_ERRORTEXT_psLookupTable_PARSE_GENERAL "Unable to read lookup table item, %s on line %lld" 36 36 #define PS_ERRORTEXT_psLookupTable_INTERPOLATE_HIGH "High index too big, %d." 37 37 #define PS_ERRORTEXT_psLookupTable_INTERPOLATE_LOW "Low index too small, %d." … … 41 41 #define PS_ERRORTEXT_psFits_FILENAME_INVALID "Could not open file,'%s'.\nCFITSIO Error: %s" 42 42 #define PS_ERRORTEXT_psFits_FILENAME_NULL "Specified filename can not be NULL." 43 #define PS_ERRORTEXT_psFits_EXTNAME_NULL "Specified extension name can not be NULL." 43 44 #define PS_ERRORTEXT_psFits_EXTNAME_INVALID "Could not find HDU '%s' in file %s.\nCFITSIO Error: %s" 44 45 #define PS_ERRORTEXT_psFits_EXTNUM_INVALID "Could not find HDU #%d in file %s.\nCFITSIO Error: %s" … … 62 63 #define PS_ERRORTEXT_psFits_METADATA_NULL "The input psMetadata was NULL. Need a non-NULL psMetadata for operation to be performed." 63 64 #define PS_ERRORTEXT_psFits_METADATA_PTYPE_UNSUPPORTED "A metadata item's primative type, %d, is not supported." 64 #define PS_ERRORTEXT_psFits_ROW_INVALID "Specified row, %d, is not valid for current table of %d rows. "65 #define PS_ERRORTEXT_psFits_ROW_INVALID "Specified row, %d, is not valid for current table of %d rows." 65 66 #define PS_ERRORTEXT_psFits_GET_TABLE_ELEMENT "Failed to retrieve table element (%d,%d).\nCFITSIO Error: %s" 66 67 #define PS_ERRORTEXT_psFits_FIND_COLUMN "Specified column, %s, was not found.\nCFITSIO Error: %s" 67 68 #define PS_ERRORTEXT_psFits_GET_COLTYPE "Could not determine the datatype of the table column.\nCFITSIO Error: %s" 68 69 #define PS_ERRORTEXT_psFits_TABLE_READ_COL "Failed to read table column.\nCFITSIO Error: %s" 70 #define PS_ERRORTEXT_psFits_DATATYPE_UNKNOWN "Could not determine image data type.\nCFITSIO Error: %s" 71 #define PS_ERRORTEXT_psFits_IMAGE_DIM_UNKNOWN "Could not determine image dimensions.\nCFITSIO Error: %s" 72 #define PS_ERRORTEXT_psFits_IMAGE_DIMENSION_UNSUPPORTED "Image number of dimensions, %d, is not valid. Only two or three dimensions supported for FITS I/O." 73 #define PS_ERRORTEXT_psFits_IMAGE_SIZE_UNKNOWN "Could not determine image size.\nCFITSIO Error: %s" 74 #define PS_ERRORTEXT_psFits_FITS_TYPE_UNSUPPORTED "FITS image type, BITPIX=%d, is not supported." 75 #define PS_ERRORTEXT_psFits_READ_FAILED "Reading FITS file failed.\nCFITSIO Error: %s" 69 76 //~End 70 77 -
trunk/psLib/src/dataIO/psFits.c
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 196 196 } 197 197 198 psFits* psFitsAlloc(const char* name, ///< the FITS file name 199 bool readwrite) ///< if TRUE, the file is open for read/write. 198 psFits* psFitsAlloc(const char* name) 200 199 { 201 200 int status = 0; … … 207 206 return NULL; 208 207 } 209 210 int iomode = (readwrite) ? READWRITE : READONLY;211 208 212 209 /* Open/Create the FITS file */ 213 210 if (access(name, F_OK) == 0) { // file exists 214 (void)fits_open_file(&fptr, name, iomode, &status); 211 (void)fits_open_file(&fptr, name, READWRITE, &status); 212 if (fptr == NULL) { // if failed, try openning as just read-only 213 status = 0; 214 (void)fits_open_file(&fptr, name, READONLY, &status); 215 } 215 216 if (fptr == NULL || status != 0) { 216 217 char fitsErr[MAX_STRING_LENGTH]; … … 221 222 return NULL; 222 223 } 223 } else { // file does not exist 224 } else { // file does not exist, so create. 224 225 (void)fits_create_file(&fptr, name, &status); 225 226 if (fptr == NULL || status != 0) { … … 253 254 } 254 255 256 if (extname == NULL) { 257 psError(PS_ERR_BAD_PARAMETER_NULL, true, 258 PS_ERRORTEXT_psFits_EXTNAME_NULL); 259 return false; 260 } 261 255 262 256 263 if (fits_movnam_hdu(fits->p_fd, ANY_HDU, (char*)extname, 0, &status) != 0) { … … 317 324 } 318 325 319 return hdutype -1;326 return hdutype; 320 327 } 321 328 … … 339 346 } 340 347 return psStringCopy(name); 348 } 349 350 bool psFitsSetExtName(psFits* fits, const char* name) 351 { 352 if (fits == NULL) { 353 psError(PS_ERR_BAD_PARAMETER_NULL, true, 354 PS_ERRORTEXT_psFits_NULL); 355 return false; 356 } 357 358 if (name == NULL) { 359 psError(PS_ERR_BAD_PARAMETER_NULL, true, 360 PS_ERRORTEXT_psFits_EXTNAME_NULL); 361 return false; 362 } 363 364 int status = 0; 365 366 if (fits_update_key_str(fits->p_fd, "EXTNAME", (char*)name, NULL, &status) != 0) { 367 char fitsErr[MAX_STRING_LENGTH]; 368 (void)fits_get_errstatus(status, fitsErr); 369 psError(PS_ERR_IO, true, 370 PS_ERRORTEXT_psFits_WRITE_FAILED, 371 fits->filename, fitsErr); 372 return false; 373 } 374 375 return true; 341 376 } 342 377 … … 540 575 } 541 576 577 psImage* psFitsReadImage(psImage* output, // a psImage to recycle. 578 psFits* fits, // the psFits object 579 psRegion region, // the region in the FITS image to read 580 int z) // the z-plane in the FITS image cube to read 581 { 582 psS32 status = 0; /* CFITSIO file vars */ 583 psS32 nAxis = 0; 584 psS32 anynull = 0; 585 psS32 bitPix = 0; /* Pixel type */ 586 long nAxes[3]; 587 long firstPixel[3]; /* lower-left corner of image subset */ 588 long lastPixel[3]; /* upper-right corner of image subset */ 589 long increment[3]; /* increment for image subset */ 590 char fitsErr[80] = ""; /* CFITSIO error message string */ 591 psS32 fitsDatatype = 0; 592 psS32 datatype = 0; 593 594 if (fits == NULL) 595 { 596 psError(PS_ERR_BAD_PARAMETER_NULL, true, 597 PS_ERRORTEXT_psFits_NULL); 598 psFree(output); 599 return NULL; 600 } 601 602 // check to see if we even are positioned on an image HDU 603 int hdutype; 604 if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) 605 { 606 char fitsErr[MAX_STRING_LENGTH]; 607 (void)fits_get_errstatus(status, fitsErr); 608 psError(PS_ERR_IO, true, 609 PS_ERRORTEXT_psFits_GET_HDU_TYPE_FAILED, 610 fitsErr); 611 return NULL; 612 } 613 if (hdutype != IMAGE_HDU) 614 { 615 psError(PS_ERR_IO, true, 616 PS_ERRORTEXT_psFits_NOT_IMAGE_TYPE); 617 return NULL; 618 } 619 620 /* Get the data type 'bitPix' from the FITS image */ 621 if (fits_get_img_equivtype(fits->p_fd, &bitPix, &status) != 0) 622 { 623 fits_get_errstatus(status, fitsErr); 624 psError(PS_ERR_IO, true, 625 PS_ERRORTEXT_psFits_DATATYPE_UNKNOWN, 626 fitsErr); 627 psFree(output); 628 return NULL; 629 } 630 631 /* Get the dimensions 'nAxis' from the FITS image */ 632 if (fits_get_img_dim(fits->p_fd, &nAxis, &status) != 0) 633 { 634 (void)fits_get_errstatus(status, fitsErr); 635 psError(PS_ERR_IO, true, 636 PS_ERRORTEXT_psFits_IMAGE_DIM_UNKNOWN, 637 fitsErr); 638 psFree(output); 639 return NULL; 640 } 641 642 /* Validate the number of axis */ 643 if ((nAxis < 2) || (nAxis > 3)) 644 { 645 psError(PS_ERR_IO, true, 646 PS_ERRORTEXT_psFits_IMAGE_DIMENSION_UNSUPPORTED, 647 nAxis); 648 psFree(output); 649 return NULL; 650 } 651 652 /* Get the Image size from the FITS file */ 653 if (fits_get_img_size(fits->p_fd, nAxis, nAxes, &status) != 0) 654 { 655 (void)fits_get_errstatus(status, fitsErr); 656 psError(PS_ERR_IO, true, 657 PS_ERRORTEXT_psFits_IMAGE_SIZE_UNKNOWN, 658 fitsErr); 659 psFree(output); 660 return NULL; 661 } 662 663 firstPixel[0] = region.x0 + 1; 664 firstPixel[1] = region.y0 + 1; 665 firstPixel[2] = z + 1; 666 667 if (region.x1 > 0) 668 { 669 lastPixel[0] = region.x1; 670 } else 671 { 672 lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0 673 } 674 if (region.y1 > 0) 675 { 676 lastPixel[1] = region.y1; 677 } else 678 { 679 lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0 680 } 681 lastPixel[2] = z + 1; 682 683 increment[0] = 1; 684 increment[1] = 1; 685 increment[2] = 1; 686 687 switch (bitPix) 688 { 689 case BYTE_IMG: 690 datatype = PS_TYPE_U8; 691 fitsDatatype = TBYTE; 692 break; 693 case SBYTE_IMG: 694 datatype = PS_TYPE_S8; 695 fitsDatatype = TSBYTE; 696 break; 697 case USHORT_IMG: 698 datatype = PS_TYPE_U16; 699 fitsDatatype = TUSHORT; 700 break; 701 case SHORT_IMG: 702 datatype = PS_TYPE_S16; 703 fitsDatatype = TSHORT; 704 break; 705 case ULONG_IMG: 706 datatype = PS_TYPE_U32; 707 fitsDatatype = TUINT; 708 break; 709 case LONG_IMG: 710 datatype = PS_TYPE_S32; 711 fitsDatatype = TINT; 712 break; 713 case LONGLONG_IMG: 714 datatype = PS_TYPE_S64; 715 fitsDatatype = TLONGLONG; 716 break; 717 case FLOAT_IMG: 718 datatype = PS_TYPE_F32; 719 fitsDatatype = TFLOAT; 720 break; 721 case DOUBLE_IMG: 722 datatype = PS_TYPE_F64; 723 fitsDatatype = TDOUBLE; 724 break; 725 default: 726 psError(PS_ERR_IO, true, 727 PS_ERRORTEXT_psFits_FITS_TYPE_UNSUPPORTED, 728 bitPix); 729 psFree(output); 730 return NULL; 731 } 732 733 output = psImageRecycle(output, 734 lastPixel[0]-firstPixel[0]+1, 735 lastPixel[1]-firstPixel[1]+1, 736 datatype); 737 738 // n.b., this assumes contiguous image buffer 739 if (fits_read_subset(fits->p_fd, fitsDatatype, firstPixel, lastPixel, increment, 740 NULL, output->data.V[0], &anynull, &status) != 0) 741 { 742 psFree(output); 743 (void)fits_get_errstatus(status, fitsErr); 744 psError(PS_ERR_IO, true, 745 PS_ERRORTEXT_psFits_READ_FAILED, 746 fitsErr); 747 return NULL; 748 } 749 750 return output; 751 752 } 753 542 754 bool psFitsWriteImage(psFits* fits, 543 755 const psMetadata* header, … … 594 806 } 595 807 596 long firstPixel = (numZPlanes-1)*numRows*numCols; // start write in last z-plane597 598 808 if (input->parent == NULL) { // if no parent, assume that the image data is contiguous 599 809 fits_write_img(fits->p_fd, 600 810 dataType, // datatype 601 firstPixel, // writing to the first z-plane811 1, // writing to the first z-plane 602 812 numCols*numRows, // number of elements to write, i.e., the whole image 603 813 input->data.V[0], // the data 604 814 &status); 605 815 } else { // image data may not be contiguous; write one row at a time 816 int firstPixel = 1; 606 817 for (int row = 0; row < numRows; row++) { 607 818 fits_write_img(fits->p_fd, -
trunk/psLib/src/dataIO/psFits.h
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 37 37 38 38 /** FITS file object. 39 * 39 * 40 40 * This object should be considered opaque to the user; no item in this 41 41 * struct should be accessed directly. … … 51 51 /** Opens a FITS file and allocates the associated psFits object. 52 52 * 53 * @return psFits* new psFits object for the FITS files specified or 53 * @return psFits* new psFits object for the FITS files specified or 54 54 * NULL if the open of the FITS file failed 55 55 */ 56 56 psFits* psFitsAlloc( 57 const char* name, ///< the FITS file name 58 bool readwrite ///< if TRUE, the file is open for read/write. 57 const char* name ///< the FITS file name 59 58 ); 60 59 … … 89 88 /** Get the current extension name. 90 89 * 91 * @return int Current HDU name of the psFits file or NULL if an 90 * @return int Current HDU name of the psFits file or NULL if an 92 91 * error occurred. 93 92 */ … … 96 95 ); 97 96 97 /** Set the current extension's name 98 * 99 * @return bool TRUE if the extension was successfully set, otherwise FALSE. 100 */ 101 bool psFitsSetExtName( 102 psFits* fits, ///< the psFits object 103 const char* name ///< the extension name 104 ); 105 98 106 /** Get the total number of HDUs in the FITS file. 99 107 * 100 * @return int The total number of HDUs in the FITS file or < 0 if an 108 * @return int The total number of HDUs in the FITS file or < 0 if an 101 109 * error occurred. 102 110 */ … … 107 115 /** Get the extension type of the current HDU. 108 116 * 109 * @return psFitsType The type of the current HDU. If PS_FITS_TYPE_UNKNOWN, 117 * @return psFitsType The type of the current HDU. If PS_FITS_TYPE_UNKNOWN, 110 118 * the type could not be determined. 111 119 */ … … 151 159 * @return psImage* the read image or NULL if there was an error. 152 160 */ 153 psImage* psFitsReadImage Section(161 psImage* psFitsReadImage( 154 162 psImage* out, ///< a psImage to recycle. 155 163 psFits* fits, ///< the psFits object … … 182 190 * PS_FITS_TYPE_BINARY_TABLE or PS_FITS_TYPE_ASCII_TABLE. 183 191 * 184 * @return psArray* Array of data items for the specified column or NULL 192 * @return psArray* Array of data items for the specified column or NULL 185 193 * if an error occurred. 186 194 */ … … 207 215 * @return psArray* Array of psMetadata items, which contains the output 208 216 * data items of each row. 209 * 217 * 210 218 * @see psFitsReadTableRow 211 219 */ … … 218 226 * 219 227 * @return bool TRUE if the write was successful, otherwise FALSE 220 * 228 * 221 229 * @see psFitsReadTableRow 222 230 */ -
trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
r2702 r2962 29 29 * @author Ross Harman, MHPCC 30 30 * 31 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $32 * @date $Date: 200 4-12-11 03:06:31 $31 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 32 * @date $Date: 2005-01-12 22:17:01 $ 33 33 * 34 34 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 377 377 // Preprocessor macro function to create arithmetic function operation name 378 378 #define BINARY_OP(DIM1,DIM2,OUT,IN1,OP,IN2) \ 379 if(!strncmp(OP, "+", 1)) { \ 379 if(!strncmp(OP, "=", 1)) { \ 380 BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i2,IN2); \ 381 } else if(!strncmp(OP, "+", 1)) { \ 380 382 BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i1 + *i2,IN2); \ 381 383 } else if(!strncmp(OP, "-", 1)) { \ … … 384 386 BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i1 * *i2,IN2); \ 385 387 } else if(!strncmp(OP, "/", 1)) { \ 386 BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i1 / *i2,IN2); \388 BINARY_TYPE(DIM1,DIM2,OUT,IN1,*i1 / *i2,IN2); \ 387 389 } else if(!strncmp(OP, "^", 1)) { \ 388 390 if(PS_IS_PSELEMTYPE_COMPLEX(IN1->type)) { \ -
trunk/psLib/src/dataManip/psMatrixVectorArithmetic.h
r2204 r2962 30 30 * @author Ross Harman, MHPCC 31 31 * 32 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $33 * @date $Date: 200 4-10-27 00:57:31 $32 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 33 * @date $Date: 2005-01-12 22:17:01 $ 34 34 * 35 35 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 49 49 * out = in1 op in2, 50 50 * 51 * Where op is: " +", "-", "*", "/", "^", "min", or "max"51 * Where op is: "=", "+", "-", "*", "/", "^", "min", or "max" 52 52 * 53 * This function only supports vector-vector or image-image oper tions.53 * This function only supports vector-vector or image-image operations. 54 54 * 55 55 * @return psType* : Pointer to either psImage or psVector. -
trunk/psLib/src/fileUtils/Makefile
r2375 r2962 8 8 -I.. -I../image -I../astronomy -DSER7_FILE="\"$(SER7_FILE)\"" -DTAIUTC_FILE="\"$(TAIUTC_FILE)\"" 9 9 10 SRC_OBJS = psLookupTable.o 10 SRC_OBJS = psLookupTable.o \ 11 psFits.o 11 12 12 13 OBJS = $(addprefix makedir/,$(SRC_OBJS)) -
trunk/psLib/src/fileUtils/psFileUtilsErrors.dat
r2806 r2962 10 10 psLookupTable_PARSE_VALUE Unable to parse string, %s on line %lld. 11 11 psLookupTable_PARSE_TYPE Unable to parse type, %s on line %lld. 12 psLookupTable_PARSE_GENERAL Unable to read lookup table item, %s on line %lld 12 psLookupTable_PARSE_GENERAL Unable to read lookup table item, %s on line %lld 13 13 psLookupTable_INTERPOLATE_HIGH High index too big, %d. 14 14 psLookupTable_INTERPOLATE_LOW Low index too small, %d. … … 19 19 psFits_FILENAME_INVALID Could not open file,'%s'.\nCFITSIO Error: %s 20 20 psFits_FILENAME_NULL Specified filename can not be NULL. 21 psFits_EXTNAME_NULL Specified extension name can not be NULL. 21 22 psFits_EXTNAME_INVALID Could not find HDU '%s' in file %s.\nCFITSIO Error: %s 22 23 psFits_EXTNUM_INVALID Could not find HDU #%d in file %s.\nCFITSIO Error: %s … … 40 41 psFits_METADATA_NULL The input psMetadata was NULL. Need a non-NULL psMetadata for operation to be performed. 41 42 psFits_METADATA_PTYPE_UNSUPPORTED A metadata item's primative type, %d, is not supported. 42 psFits_ROW_INVALID Specified row, %d, is not valid for current table of %d rows. 43 psFits_ROW_INVALID Specified row, %d, is not valid for current table of %d rows. 43 44 psFits_GET_TABLE_ELEMENT Failed to retrieve table element (%d,%d).\nCFITSIO Error: %s 44 45 psFits_FIND_COLUMN Specified column, %s, was not found.\nCFITSIO Error: %s 45 46 psFits_GET_COLTYPE Could not determine the datatype of the table column.\nCFITSIO Error: %s 46 47 psFits_TABLE_READ_COL Failed to read table column.\nCFITSIO Error: %s 48 psFits_DATATYPE_UNKNOWN Could not determine image data type.\nCFITSIO Error: %s 49 psFits_IMAGE_DIM_UNKNOWN Could not determine image dimensions.\nCFITSIO Error: %s 50 psFits_IMAGE_DIMENSION_UNSUPPORTED Image number of dimensions, %d, is not valid. Only two or three dimensions supported for FITS I/O. 51 psFits_IMAGE_SIZE_UNKNOWN Could not determine image size.\nCFITSIO Error: %s 52 psFits_FITS_TYPE_UNSUPPORTED FITS image type, BITPIX=%d, is not supported. 53 psFits_READ_FAILED Reading FITS file failed.\nCFITSIO Error: %s 47 54 # -
trunk/psLib/src/fileUtils/psFileUtilsErrors.h
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 33 33 #define PS_ERRORTEXT_psLookupTable_PARSE_VALUE "Unable to parse string, %s on line %lld." 34 34 #define PS_ERRORTEXT_psLookupTable_PARSE_TYPE "Unable to parse type, %s on line %lld." 35 #define PS_ERRORTEXT_psLookupTable_PARSE_GENERAL "Unable to read lookup table item, %s on line %lld "35 #define PS_ERRORTEXT_psLookupTable_PARSE_GENERAL "Unable to read lookup table item, %s on line %lld" 36 36 #define PS_ERRORTEXT_psLookupTable_INTERPOLATE_HIGH "High index too big, %d." 37 37 #define PS_ERRORTEXT_psLookupTable_INTERPOLATE_LOW "Low index too small, %d." … … 41 41 #define PS_ERRORTEXT_psFits_FILENAME_INVALID "Could not open file,'%s'.\nCFITSIO Error: %s" 42 42 #define PS_ERRORTEXT_psFits_FILENAME_NULL "Specified filename can not be NULL." 43 #define PS_ERRORTEXT_psFits_EXTNAME_NULL "Specified extension name can not be NULL." 43 44 #define PS_ERRORTEXT_psFits_EXTNAME_INVALID "Could not find HDU '%s' in file %s.\nCFITSIO Error: %s" 44 45 #define PS_ERRORTEXT_psFits_EXTNUM_INVALID "Could not find HDU #%d in file %s.\nCFITSIO Error: %s" … … 62 63 #define PS_ERRORTEXT_psFits_METADATA_NULL "The input psMetadata was NULL. Need a non-NULL psMetadata for operation to be performed." 63 64 #define PS_ERRORTEXT_psFits_METADATA_PTYPE_UNSUPPORTED "A metadata item's primative type, %d, is not supported." 64 #define PS_ERRORTEXT_psFits_ROW_INVALID "Specified row, %d, is not valid for current table of %d rows. "65 #define PS_ERRORTEXT_psFits_ROW_INVALID "Specified row, %d, is not valid for current table of %d rows." 65 66 #define PS_ERRORTEXT_psFits_GET_TABLE_ELEMENT "Failed to retrieve table element (%d,%d).\nCFITSIO Error: %s" 66 67 #define PS_ERRORTEXT_psFits_FIND_COLUMN "Specified column, %s, was not found.\nCFITSIO Error: %s" 67 68 #define PS_ERRORTEXT_psFits_GET_COLTYPE "Could not determine the datatype of the table column.\nCFITSIO Error: %s" 68 69 #define PS_ERRORTEXT_psFits_TABLE_READ_COL "Failed to read table column.\nCFITSIO Error: %s" 70 #define PS_ERRORTEXT_psFits_DATATYPE_UNKNOWN "Could not determine image data type.\nCFITSIO Error: %s" 71 #define PS_ERRORTEXT_psFits_IMAGE_DIM_UNKNOWN "Could not determine image dimensions.\nCFITSIO Error: %s" 72 #define PS_ERRORTEXT_psFits_IMAGE_DIMENSION_UNSUPPORTED "Image number of dimensions, %d, is not valid. Only two or three dimensions supported for FITS I/O." 73 #define PS_ERRORTEXT_psFits_IMAGE_SIZE_UNKNOWN "Could not determine image size.\nCFITSIO Error: %s" 74 #define PS_ERRORTEXT_psFits_FITS_TYPE_UNSUPPORTED "FITS image type, BITPIX=%d, is not supported." 75 #define PS_ERRORTEXT_psFits_READ_FAILED "Reading FITS file failed.\nCFITSIO Error: %s" 69 76 //~End 70 77 -
trunk/psLib/src/fileUtils/psFits.c
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 196 196 } 197 197 198 psFits* psFitsAlloc(const char* name, ///< the FITS file name 199 bool readwrite) ///< if TRUE, the file is open for read/write. 198 psFits* psFitsAlloc(const char* name) 200 199 { 201 200 int status = 0; … … 207 206 return NULL; 208 207 } 209 210 int iomode = (readwrite) ? READWRITE : READONLY;211 208 212 209 /* Open/Create the FITS file */ 213 210 if (access(name, F_OK) == 0) { // file exists 214 (void)fits_open_file(&fptr, name, iomode, &status); 211 (void)fits_open_file(&fptr, name, READWRITE, &status); 212 if (fptr == NULL) { // if failed, try openning as just read-only 213 status = 0; 214 (void)fits_open_file(&fptr, name, READONLY, &status); 215 } 215 216 if (fptr == NULL || status != 0) { 216 217 char fitsErr[MAX_STRING_LENGTH]; … … 221 222 return NULL; 222 223 } 223 } else { // file does not exist 224 } else { // file does not exist, so create. 224 225 (void)fits_create_file(&fptr, name, &status); 225 226 if (fptr == NULL || status != 0) { … … 253 254 } 254 255 256 if (extname == NULL) { 257 psError(PS_ERR_BAD_PARAMETER_NULL, true, 258 PS_ERRORTEXT_psFits_EXTNAME_NULL); 259 return false; 260 } 261 255 262 256 263 if (fits_movnam_hdu(fits->p_fd, ANY_HDU, (char*)extname, 0, &status) != 0) { … … 317 324 } 318 325 319 return hdutype -1;326 return hdutype; 320 327 } 321 328 … … 339 346 } 340 347 return psStringCopy(name); 348 } 349 350 bool psFitsSetExtName(psFits* fits, const char* name) 351 { 352 if (fits == NULL) { 353 psError(PS_ERR_BAD_PARAMETER_NULL, true, 354 PS_ERRORTEXT_psFits_NULL); 355 return false; 356 } 357 358 if (name == NULL) { 359 psError(PS_ERR_BAD_PARAMETER_NULL, true, 360 PS_ERRORTEXT_psFits_EXTNAME_NULL); 361 return false; 362 } 363 364 int status = 0; 365 366 if (fits_update_key_str(fits->p_fd, "EXTNAME", (char*)name, NULL, &status) != 0) { 367 char fitsErr[MAX_STRING_LENGTH]; 368 (void)fits_get_errstatus(status, fitsErr); 369 psError(PS_ERR_IO, true, 370 PS_ERRORTEXT_psFits_WRITE_FAILED, 371 fits->filename, fitsErr); 372 return false; 373 } 374 375 return true; 341 376 } 342 377 … … 540 575 } 541 576 577 psImage* psFitsReadImage(psImage* output, // a psImage to recycle. 578 psFits* fits, // the psFits object 579 psRegion region, // the region in the FITS image to read 580 int z) // the z-plane in the FITS image cube to read 581 { 582 psS32 status = 0; /* CFITSIO file vars */ 583 psS32 nAxis = 0; 584 psS32 anynull = 0; 585 psS32 bitPix = 0; /* Pixel type */ 586 long nAxes[3]; 587 long firstPixel[3]; /* lower-left corner of image subset */ 588 long lastPixel[3]; /* upper-right corner of image subset */ 589 long increment[3]; /* increment for image subset */ 590 char fitsErr[80] = ""; /* CFITSIO error message string */ 591 psS32 fitsDatatype = 0; 592 psS32 datatype = 0; 593 594 if (fits == NULL) 595 { 596 psError(PS_ERR_BAD_PARAMETER_NULL, true, 597 PS_ERRORTEXT_psFits_NULL); 598 psFree(output); 599 return NULL; 600 } 601 602 // check to see if we even are positioned on an image HDU 603 int hdutype; 604 if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) 605 { 606 char fitsErr[MAX_STRING_LENGTH]; 607 (void)fits_get_errstatus(status, fitsErr); 608 psError(PS_ERR_IO, true, 609 PS_ERRORTEXT_psFits_GET_HDU_TYPE_FAILED, 610 fitsErr); 611 return NULL; 612 } 613 if (hdutype != IMAGE_HDU) 614 { 615 psError(PS_ERR_IO, true, 616 PS_ERRORTEXT_psFits_NOT_IMAGE_TYPE); 617 return NULL; 618 } 619 620 /* Get the data type 'bitPix' from the FITS image */ 621 if (fits_get_img_equivtype(fits->p_fd, &bitPix, &status) != 0) 622 { 623 fits_get_errstatus(status, fitsErr); 624 psError(PS_ERR_IO, true, 625 PS_ERRORTEXT_psFits_DATATYPE_UNKNOWN, 626 fitsErr); 627 psFree(output); 628 return NULL; 629 } 630 631 /* Get the dimensions 'nAxis' from the FITS image */ 632 if (fits_get_img_dim(fits->p_fd, &nAxis, &status) != 0) 633 { 634 (void)fits_get_errstatus(status, fitsErr); 635 psError(PS_ERR_IO, true, 636 PS_ERRORTEXT_psFits_IMAGE_DIM_UNKNOWN, 637 fitsErr); 638 psFree(output); 639 return NULL; 640 } 641 642 /* Validate the number of axis */ 643 if ((nAxis < 2) || (nAxis > 3)) 644 { 645 psError(PS_ERR_IO, true, 646 PS_ERRORTEXT_psFits_IMAGE_DIMENSION_UNSUPPORTED, 647 nAxis); 648 psFree(output); 649 return NULL; 650 } 651 652 /* Get the Image size from the FITS file */ 653 if (fits_get_img_size(fits->p_fd, nAxis, nAxes, &status) != 0) 654 { 655 (void)fits_get_errstatus(status, fitsErr); 656 psError(PS_ERR_IO, true, 657 PS_ERRORTEXT_psFits_IMAGE_SIZE_UNKNOWN, 658 fitsErr); 659 psFree(output); 660 return NULL; 661 } 662 663 firstPixel[0] = region.x0 + 1; 664 firstPixel[1] = region.y0 + 1; 665 firstPixel[2] = z + 1; 666 667 if (region.x1 > 0) 668 { 669 lastPixel[0] = region.x1; 670 } else 671 { 672 lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0 673 } 674 if (region.y1 > 0) 675 { 676 lastPixel[1] = region.y1; 677 } else 678 { 679 lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0 680 } 681 lastPixel[2] = z + 1; 682 683 increment[0] = 1; 684 increment[1] = 1; 685 increment[2] = 1; 686 687 switch (bitPix) 688 { 689 case BYTE_IMG: 690 datatype = PS_TYPE_U8; 691 fitsDatatype = TBYTE; 692 break; 693 case SBYTE_IMG: 694 datatype = PS_TYPE_S8; 695 fitsDatatype = TSBYTE; 696 break; 697 case USHORT_IMG: 698 datatype = PS_TYPE_U16; 699 fitsDatatype = TUSHORT; 700 break; 701 case SHORT_IMG: 702 datatype = PS_TYPE_S16; 703 fitsDatatype = TSHORT; 704 break; 705 case ULONG_IMG: 706 datatype = PS_TYPE_U32; 707 fitsDatatype = TUINT; 708 break; 709 case LONG_IMG: 710 datatype = PS_TYPE_S32; 711 fitsDatatype = TINT; 712 break; 713 case LONGLONG_IMG: 714 datatype = PS_TYPE_S64; 715 fitsDatatype = TLONGLONG; 716 break; 717 case FLOAT_IMG: 718 datatype = PS_TYPE_F32; 719 fitsDatatype = TFLOAT; 720 break; 721 case DOUBLE_IMG: 722 datatype = PS_TYPE_F64; 723 fitsDatatype = TDOUBLE; 724 break; 725 default: 726 psError(PS_ERR_IO, true, 727 PS_ERRORTEXT_psFits_FITS_TYPE_UNSUPPORTED, 728 bitPix); 729 psFree(output); 730 return NULL; 731 } 732 733 output = psImageRecycle(output, 734 lastPixel[0]-firstPixel[0]+1, 735 lastPixel[1]-firstPixel[1]+1, 736 datatype); 737 738 // n.b., this assumes contiguous image buffer 739 if (fits_read_subset(fits->p_fd, fitsDatatype, firstPixel, lastPixel, increment, 740 NULL, output->data.V[0], &anynull, &status) != 0) 741 { 742 psFree(output); 743 (void)fits_get_errstatus(status, fitsErr); 744 psError(PS_ERR_IO, true, 745 PS_ERRORTEXT_psFits_READ_FAILED, 746 fitsErr); 747 return NULL; 748 } 749 750 return output; 751 752 } 753 542 754 bool psFitsWriteImage(psFits* fits, 543 755 const psMetadata* header, … … 594 806 } 595 807 596 long firstPixel = (numZPlanes-1)*numRows*numCols; // start write in last z-plane597 598 808 if (input->parent == NULL) { // if no parent, assume that the image data is contiguous 599 809 fits_write_img(fits->p_fd, 600 810 dataType, // datatype 601 firstPixel, // writing to the first z-plane811 1, // writing to the first z-plane 602 812 numCols*numRows, // number of elements to write, i.e., the whole image 603 813 input->data.V[0], // the data 604 814 &status); 605 815 } else { // image data may not be contiguous; write one row at a time 816 int firstPixel = 1; 606 817 for (int row = 0; row < numRows; row++) { 607 818 fits_write_img(fits->p_fd, -
trunk/psLib/src/fileUtils/psFits.h
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 37 37 38 38 /** FITS file object. 39 * 39 * 40 40 * This object should be considered opaque to the user; no item in this 41 41 * struct should be accessed directly. … … 51 51 /** Opens a FITS file and allocates the associated psFits object. 52 52 * 53 * @return psFits* new psFits object for the FITS files specified or 53 * @return psFits* new psFits object for the FITS files specified or 54 54 * NULL if the open of the FITS file failed 55 55 */ 56 56 psFits* psFitsAlloc( 57 const char* name, ///< the FITS file name 58 bool readwrite ///< if TRUE, the file is open for read/write. 57 const char* name ///< the FITS file name 59 58 ); 60 59 … … 89 88 /** Get the current extension name. 90 89 * 91 * @return int Current HDU name of the psFits file or NULL if an 90 * @return int Current HDU name of the psFits file or NULL if an 92 91 * error occurred. 93 92 */ … … 96 95 ); 97 96 97 /** Set the current extension's name 98 * 99 * @return bool TRUE if the extension was successfully set, otherwise FALSE. 100 */ 101 bool psFitsSetExtName( 102 psFits* fits, ///< the psFits object 103 const char* name ///< the extension name 104 ); 105 98 106 /** Get the total number of HDUs in the FITS file. 99 107 * 100 * @return int The total number of HDUs in the FITS file or < 0 if an 108 * @return int The total number of HDUs in the FITS file or < 0 if an 101 109 * error occurred. 102 110 */ … … 107 115 /** Get the extension type of the current HDU. 108 116 * 109 * @return psFitsType The type of the current HDU. If PS_FITS_TYPE_UNKNOWN, 117 * @return psFitsType The type of the current HDU. If PS_FITS_TYPE_UNKNOWN, 110 118 * the type could not be determined. 111 119 */ … … 151 159 * @return psImage* the read image or NULL if there was an error. 152 160 */ 153 psImage* psFitsReadImage Section(161 psImage* psFitsReadImage( 154 162 psImage* out, ///< a psImage to recycle. 155 163 psFits* fits, ///< the psFits object … … 182 190 * PS_FITS_TYPE_BINARY_TABLE or PS_FITS_TYPE_ASCII_TABLE. 183 191 * 184 * @return psArray* Array of data items for the specified column or NULL 192 * @return psArray* Array of data items for the specified column or NULL 185 193 * if an error occurred. 186 194 */ … … 207 215 * @return psArray* Array of psMetadata items, which contains the output 208 216 * data items of each row. 209 * 217 * 210 218 * @see psFitsReadTableRow 211 219 */ … … 218 226 * 219 227 * @return bool TRUE if the write was successful, otherwise FALSE 220 * 228 * 221 229 * @see psFitsReadTableRow 222 230 */ -
trunk/psLib/src/fits/psFits.c
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 196 196 } 197 197 198 psFits* psFitsAlloc(const char* name, ///< the FITS file name 199 bool readwrite) ///< if TRUE, the file is open for read/write. 198 psFits* psFitsAlloc(const char* name) 200 199 { 201 200 int status = 0; … … 207 206 return NULL; 208 207 } 209 210 int iomode = (readwrite) ? READWRITE : READONLY;211 208 212 209 /* Open/Create the FITS file */ 213 210 if (access(name, F_OK) == 0) { // file exists 214 (void)fits_open_file(&fptr, name, iomode, &status); 211 (void)fits_open_file(&fptr, name, READWRITE, &status); 212 if (fptr == NULL) { // if failed, try openning as just read-only 213 status = 0; 214 (void)fits_open_file(&fptr, name, READONLY, &status); 215 } 215 216 if (fptr == NULL || status != 0) { 216 217 char fitsErr[MAX_STRING_LENGTH]; … … 221 222 return NULL; 222 223 } 223 } else { // file does not exist 224 } else { // file does not exist, so create. 224 225 (void)fits_create_file(&fptr, name, &status); 225 226 if (fptr == NULL || status != 0) { … … 253 254 } 254 255 256 if (extname == NULL) { 257 psError(PS_ERR_BAD_PARAMETER_NULL, true, 258 PS_ERRORTEXT_psFits_EXTNAME_NULL); 259 return false; 260 } 261 255 262 256 263 if (fits_movnam_hdu(fits->p_fd, ANY_HDU, (char*)extname, 0, &status) != 0) { … … 317 324 } 318 325 319 return hdutype -1;326 return hdutype; 320 327 } 321 328 … … 339 346 } 340 347 return psStringCopy(name); 348 } 349 350 bool psFitsSetExtName(psFits* fits, const char* name) 351 { 352 if (fits == NULL) { 353 psError(PS_ERR_BAD_PARAMETER_NULL, true, 354 PS_ERRORTEXT_psFits_NULL); 355 return false; 356 } 357 358 if (name == NULL) { 359 psError(PS_ERR_BAD_PARAMETER_NULL, true, 360 PS_ERRORTEXT_psFits_EXTNAME_NULL); 361 return false; 362 } 363 364 int status = 0; 365 366 if (fits_update_key_str(fits->p_fd, "EXTNAME", (char*)name, NULL, &status) != 0) { 367 char fitsErr[MAX_STRING_LENGTH]; 368 (void)fits_get_errstatus(status, fitsErr); 369 psError(PS_ERR_IO, true, 370 PS_ERRORTEXT_psFits_WRITE_FAILED, 371 fits->filename, fitsErr); 372 return false; 373 } 374 375 return true; 341 376 } 342 377 … … 540 575 } 541 576 577 psImage* psFitsReadImage(psImage* output, // a psImage to recycle. 578 psFits* fits, // the psFits object 579 psRegion region, // the region in the FITS image to read 580 int z) // the z-plane in the FITS image cube to read 581 { 582 psS32 status = 0; /* CFITSIO file vars */ 583 psS32 nAxis = 0; 584 psS32 anynull = 0; 585 psS32 bitPix = 0; /* Pixel type */ 586 long nAxes[3]; 587 long firstPixel[3]; /* lower-left corner of image subset */ 588 long lastPixel[3]; /* upper-right corner of image subset */ 589 long increment[3]; /* increment for image subset */ 590 char fitsErr[80] = ""; /* CFITSIO error message string */ 591 psS32 fitsDatatype = 0; 592 psS32 datatype = 0; 593 594 if (fits == NULL) 595 { 596 psError(PS_ERR_BAD_PARAMETER_NULL, true, 597 PS_ERRORTEXT_psFits_NULL); 598 psFree(output); 599 return NULL; 600 } 601 602 // check to see if we even are positioned on an image HDU 603 int hdutype; 604 if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) 605 { 606 char fitsErr[MAX_STRING_LENGTH]; 607 (void)fits_get_errstatus(status, fitsErr); 608 psError(PS_ERR_IO, true, 609 PS_ERRORTEXT_psFits_GET_HDU_TYPE_FAILED, 610 fitsErr); 611 return NULL; 612 } 613 if (hdutype != IMAGE_HDU) 614 { 615 psError(PS_ERR_IO, true, 616 PS_ERRORTEXT_psFits_NOT_IMAGE_TYPE); 617 return NULL; 618 } 619 620 /* Get the data type 'bitPix' from the FITS image */ 621 if (fits_get_img_equivtype(fits->p_fd, &bitPix, &status) != 0) 622 { 623 fits_get_errstatus(status, fitsErr); 624 psError(PS_ERR_IO, true, 625 PS_ERRORTEXT_psFits_DATATYPE_UNKNOWN, 626 fitsErr); 627 psFree(output); 628 return NULL; 629 } 630 631 /* Get the dimensions 'nAxis' from the FITS image */ 632 if (fits_get_img_dim(fits->p_fd, &nAxis, &status) != 0) 633 { 634 (void)fits_get_errstatus(status, fitsErr); 635 psError(PS_ERR_IO, true, 636 PS_ERRORTEXT_psFits_IMAGE_DIM_UNKNOWN, 637 fitsErr); 638 psFree(output); 639 return NULL; 640 } 641 642 /* Validate the number of axis */ 643 if ((nAxis < 2) || (nAxis > 3)) 644 { 645 psError(PS_ERR_IO, true, 646 PS_ERRORTEXT_psFits_IMAGE_DIMENSION_UNSUPPORTED, 647 nAxis); 648 psFree(output); 649 return NULL; 650 } 651 652 /* Get the Image size from the FITS file */ 653 if (fits_get_img_size(fits->p_fd, nAxis, nAxes, &status) != 0) 654 { 655 (void)fits_get_errstatus(status, fitsErr); 656 psError(PS_ERR_IO, true, 657 PS_ERRORTEXT_psFits_IMAGE_SIZE_UNKNOWN, 658 fitsErr); 659 psFree(output); 660 return NULL; 661 } 662 663 firstPixel[0] = region.x0 + 1; 664 firstPixel[1] = region.y0 + 1; 665 firstPixel[2] = z + 1; 666 667 if (region.x1 > 0) 668 { 669 lastPixel[0] = region.x1; 670 } else 671 { 672 lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0 673 } 674 if (region.y1 > 0) 675 { 676 lastPixel[1] = region.y1; 677 } else 678 { 679 lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0 680 } 681 lastPixel[2] = z + 1; 682 683 increment[0] = 1; 684 increment[1] = 1; 685 increment[2] = 1; 686 687 switch (bitPix) 688 { 689 case BYTE_IMG: 690 datatype = PS_TYPE_U8; 691 fitsDatatype = TBYTE; 692 break; 693 case SBYTE_IMG: 694 datatype = PS_TYPE_S8; 695 fitsDatatype = TSBYTE; 696 break; 697 case USHORT_IMG: 698 datatype = PS_TYPE_U16; 699 fitsDatatype = TUSHORT; 700 break; 701 case SHORT_IMG: 702 datatype = PS_TYPE_S16; 703 fitsDatatype = TSHORT; 704 break; 705 case ULONG_IMG: 706 datatype = PS_TYPE_U32; 707 fitsDatatype = TUINT; 708 break; 709 case LONG_IMG: 710 datatype = PS_TYPE_S32; 711 fitsDatatype = TINT; 712 break; 713 case LONGLONG_IMG: 714 datatype = PS_TYPE_S64; 715 fitsDatatype = TLONGLONG; 716 break; 717 case FLOAT_IMG: 718 datatype = PS_TYPE_F32; 719 fitsDatatype = TFLOAT; 720 break; 721 case DOUBLE_IMG: 722 datatype = PS_TYPE_F64; 723 fitsDatatype = TDOUBLE; 724 break; 725 default: 726 psError(PS_ERR_IO, true, 727 PS_ERRORTEXT_psFits_FITS_TYPE_UNSUPPORTED, 728 bitPix); 729 psFree(output); 730 return NULL; 731 } 732 733 output = psImageRecycle(output, 734 lastPixel[0]-firstPixel[0]+1, 735 lastPixel[1]-firstPixel[1]+1, 736 datatype); 737 738 // n.b., this assumes contiguous image buffer 739 if (fits_read_subset(fits->p_fd, fitsDatatype, firstPixel, lastPixel, increment, 740 NULL, output->data.V[0], &anynull, &status) != 0) 741 { 742 psFree(output); 743 (void)fits_get_errstatus(status, fitsErr); 744 psError(PS_ERR_IO, true, 745 PS_ERRORTEXT_psFits_READ_FAILED, 746 fitsErr); 747 return NULL; 748 } 749 750 return output; 751 752 } 753 542 754 bool psFitsWriteImage(psFits* fits, 543 755 const psMetadata* header, … … 594 806 } 595 807 596 long firstPixel = (numZPlanes-1)*numRows*numCols; // start write in last z-plane597 598 808 if (input->parent == NULL) { // if no parent, assume that the image data is contiguous 599 809 fits_write_img(fits->p_fd, 600 810 dataType, // datatype 601 firstPixel, // writing to the first z-plane811 1, // writing to the first z-plane 602 812 numCols*numRows, // number of elements to write, i.e., the whole image 603 813 input->data.V[0], // the data 604 814 &status); 605 815 } else { // image data may not be contiguous; write one row at a time 816 int firstPixel = 1; 606 817 for (int row = 0; row < numRows; row++) { 607 818 fits_write_img(fits->p_fd, -
trunk/psLib/src/fits/psFits.h
r2806 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $10 * @date $Date: 200 4-12-23 19:13:53$9 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 37 37 38 38 /** FITS file object. 39 * 39 * 40 40 * This object should be considered opaque to the user; no item in this 41 41 * struct should be accessed directly. … … 51 51 /** Opens a FITS file and allocates the associated psFits object. 52 52 * 53 * @return psFits* new psFits object for the FITS files specified or 53 * @return psFits* new psFits object for the FITS files specified or 54 54 * NULL if the open of the FITS file failed 55 55 */ 56 56 psFits* psFitsAlloc( 57 const char* name, ///< the FITS file name 58 bool readwrite ///< if TRUE, the file is open for read/write. 57 const char* name ///< the FITS file name 59 58 ); 60 59 … … 89 88 /** Get the current extension name. 90 89 * 91 * @return int Current HDU name of the psFits file or NULL if an 90 * @return int Current HDU name of the psFits file or NULL if an 92 91 * error occurred. 93 92 */ … … 96 95 ); 97 96 97 /** Set the current extension's name 98 * 99 * @return bool TRUE if the extension was successfully set, otherwise FALSE. 100 */ 101 bool psFitsSetExtName( 102 psFits* fits, ///< the psFits object 103 const char* name ///< the extension name 104 ); 105 98 106 /** Get the total number of HDUs in the FITS file. 99 107 * 100 * @return int The total number of HDUs in the FITS file or < 0 if an 108 * @return int The total number of HDUs in the FITS file or < 0 if an 101 109 * error occurred. 102 110 */ … … 107 115 /** Get the extension type of the current HDU. 108 116 * 109 * @return psFitsType The type of the current HDU. If PS_FITS_TYPE_UNKNOWN, 117 * @return psFitsType The type of the current HDU. If PS_FITS_TYPE_UNKNOWN, 110 118 * the type could not be determined. 111 119 */ … … 151 159 * @return psImage* the read image or NULL if there was an error. 152 160 */ 153 psImage* psFitsReadImage Section(161 psImage* psFitsReadImage( 154 162 psImage* out, ///< a psImage to recycle. 155 163 psFits* fits, ///< the psFits object … … 182 190 * PS_FITS_TYPE_BINARY_TABLE or PS_FITS_TYPE_ASCII_TABLE. 183 191 * 184 * @return psArray* Array of data items for the specified column or NULL 192 * @return psArray* Array of data items for the specified column or NULL 185 193 * if an error occurred. 186 194 */ … … 207 215 * @return psArray* Array of psMetadata items, which contains the output 208 216 * data items of each row. 209 * 217 * 210 218 * @see psFitsReadTableRow 211 219 */ … … 218 226 * 219 227 * @return bool TRUE if the write was successful, otherwise FALSE 220 * 228 * 221 229 * @see psFitsReadTableRow 222 230 */ -
trunk/psLib/src/image/psImageIO.c
r2911 r2962 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-01- 05 21:16:14$9 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-12 22:17:01 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include "psError.h" 20 20 #include "psMemory.h" 21 #include "psLogMsg.h" 21 22 22 23 #include "psImageErrors.h" … … 46 47 psS32 datatype = 0; 47 48 49 psLogMsg(__func__,PS_LOG_WARN, "psImageReadSection is deprecated. Consider using psFitsReadImage instead."); 50 48 51 if (filename == NULL) { 49 52 psError(PS_ERR_BAD_PARAMETER_NULL, true, … … 240 243 double bzero = 0.0; 241 244 psBool createNewHDU = false; 245 246 psLogMsg(__func__,PS_LOG_WARN, "psImageWriteSection is deprecated. Consider using psFitsWriteImage instead."); 242 247 243 248 /* need a valid image to write */ -
trunk/psLib/src/pslib.h
r2330 r2962 9 9 * @author Eric Van Alst, MHPCC 10 10 * 11 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $12 * @date $Date: 200 4-11-10 23:39:05$11 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2005-01-12 22:17:01 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 172 172 /// @defgroup FileUtils File Utilities 173 173 /// @{ 174 #include "psFits.h" 174 175 175 176 /// @defgroup LookupTable Lookup Table -
trunk/psLib/test/dataIO/Makefile
r2306 r2962 3 3 ## Makefile: test/fileUtils 4 4 ## 5 ## $Revision: 1. 1$ $Name: not supported by cvs2svn $6 ## $Date: 200 4-11-09 00:49:37$5 ## $Revision: 1.2 $ $Name: not supported by cvs2svn $ 6 ## $Date: 2005-01-12 22:17:02 $ 7 7 ## 8 8 ## Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 LDFLAGS := -L../../lib -lpslib -lpstest $(LDFLAGS) 20 20 21 TARGET = tst_psLookupTable_01 21 TARGET = tst_psLookupTable_01 \ 22 tst_psFits 22 23 23 24 OBJS = $(addprefix builddir/,$(addsuffix .o,$(TARGET))) -
trunk/psLib/test/fileUtils/Makefile
r2306 r2962 3 3 ## Makefile: test/fileUtils 4 4 ## 5 ## $Revision: 1. 1$ $Name: not supported by cvs2svn $6 ## $Date: 200 4-11-09 00:49:37$5 ## $Revision: 1.2 $ $Name: not supported by cvs2svn $ 6 ## $Date: 2005-01-12 22:17:02 $ 7 7 ## 8 8 ## Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 LDFLAGS := -L../../lib -lpslib -lpstest $(LDFLAGS) 20 20 21 TARGET = tst_psLookupTable_01 21 TARGET = tst_psLookupTable_01 \ 22 tst_psFits 22 23 23 24 OBJS = $(addprefix builddir/,$(addsuffix .o,$(TARGET)))
Note:
See TracChangeset
for help on using the changeset viewer.
