Changeset 3028 for trunk/psLib/src/fileUtils/psFits.c
- Timestamp:
- Jan 17, 2005, 5:15:04 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fileUtils/psFits.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fileUtils/psFits.c
r3025 r3028 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $10 * @date $Date: 2005-01-1 7 20:58:21$9 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2005-01-18 03:15:03 $ 11 11 * 12 12 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include "psError.h" 20 20 #include "psFileUtilsErrors.h" 21 #include "psImageExtraction.h" 21 22 #include "psMemory.h" 22 23 #include "psString.h" … … 795 796 datatype); 796 797 798 if (output == NULL) 799 { 800 psError(PS_ERR_UNKNOWN, false, 801 "Failed to allocate a properly sized image."); 802 return false; 803 } 804 797 805 // n.b., this assumes contiguous image buffer 798 806 if (fits_read_subset(fits->p_fd, fitsDatatype, firstPixel, lastPixel, increment, … … 814 822 const psMetadata* header, 815 823 const psImage* input, 816 int numZPlanes) 824 int numZPlanes, 825 char* extname) 817 826 { 818 827 … … 853 862 854 863 fits_create_img(fits->p_fd, bitPix, naxis, naxes, &status); 864 865 if (extname != NULL) { 866 fits_update_key_str(fits->p_fd, "EXTNAME", (char*)extname, NULL, &status); 867 } 855 868 856 869 if (bZero != 0) { // set the bscale/bzero … … 896 909 return true; 897 910 911 } 912 913 bool psFitsUpdateImage(psFits* fits, 914 const psImage* input, 915 psRegion region, 916 int z) 917 { 918 int status = 0; 919 920 if (fits == NULL) { 921 psError(PS_ERR_BAD_PARAMETER_NULL, true, 922 PS_ERRORTEXT_psFits_NULL); 923 return false; 924 } 925 926 if (input == NULL) { 927 psError(PS_ERR_BAD_PARAMETER_NULL, true, 928 PS_ERRORTEXT_psFits_IMAGE_NULL); 929 return false; 930 } 931 932 // check to see if we are positioned on an image HDU 933 int hdutype; 934 if ( fits_get_hdu_type(fits->p_fd,&hdutype, &status) != 0) { 935 char fitsErr[MAX_STRING_LENGTH]; 936 (void)fits_get_errstatus(status, fitsErr); 937 psError(PS_ERR_IO, true, 938 PS_ERRORTEXT_psFits_GET_HDU_TYPE_FAILED, 939 fitsErr); 940 return NULL; 941 } 942 if (hdutype != IMAGE_HDU) { 943 psError(PS_ERR_IO, true, 944 PS_ERRORTEXT_psFits_NOT_IMAGE_TYPE); 945 return NULL; 946 } 947 948 int numCols = input->numCols; 949 int numRows = input->numRows; 950 951 // determine the FITS-equivalent parameters 952 int bitPix; 953 double bZero; 954 int dataType; 955 if (! convertPsTypeToFits(input->type.type, &bitPix, &bZero, &dataType) ) { 956 return false; 957 } 958 959 //check to see if the HDU has the same datatype 960 int fileBitpix; 961 int naxis; 962 long nAxes[3]; 963 nAxes[2] = 1; 964 fits_get_img_param(fits->p_fd, 3, &fileBitpix, &naxis, nAxes, &status); 965 966 //check to see if the HDU has the same datatype 967 if (bitPix != fileBitpix) { 968 char* fitsTypeStr; 969 char* imageTypeStr; 970 PS_TYPE_NAME(fitsTypeStr,fileBitpix); 971 PS_TYPE_NAME(imageTypeStr,input->type.type); 972 psError(PS_ERR_IO, true, 973 PS_ERRORTEXT_psFits_IMAGE_UPDATE_TYPE_MISMATCH, 974 fitsTypeStr, imageTypeStr); 975 return false; 976 } 977 978 //check if the HDU has the z-plane requested 979 if (z >= nAxes[2]) { 980 psError(PS_ERR_BAD_PARAMETER_SIZE, true, 981 PS_ERRORTEXT_psFits_FITS_Z_SMALL, 982 nAxes[2],z); 983 return false; 984 } 985 986 // determine the region in the FITS file domain 987 long firstPixel[3]; 988 long lastPixel[3]; 989 990 firstPixel[0] = region.x0 + 1; 991 firstPixel[1] = region.y0 + 1; 992 firstPixel[2] = z + 1; 993 994 if (region.x1 > 0) { 995 lastPixel[0] = region.x1; 996 } else { 997 lastPixel[0] = nAxes[0] + region.x1; // n.b., region.x1 < 0 998 } 999 if (region.y1 > 0) { 1000 lastPixel[1] = region.y1; 1001 } else { 1002 lastPixel[1] = nAxes[1] + region.y1; // n.b., region.y1 < 0 1003 } 1004 lastPixel[2] = z + 1; 1005 1006 if (firstPixel[0] < 1 || firstPixel[0] > nAxes[0] || 1007 firstPixel[1] < 1 || firstPixel[1] > nAxes[1] || 1008 lastPixel[0] < 1 || lastPixel[0] > nAxes[0] || 1009 lastPixel[1] < 1 || lastPixel[1] > nAxes[1]) { 1010 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 1011 "Specified region [%d:%d,%d:%d], is not valid given the %dx%d FITS image.", 1012 region.y0,region.y1-1,region.x0,region.x1-1); 1013 return false; 1014 1015 } 1016 1017 int dx = lastPixel[0] - firstPixel[0]; 1018 int dy = lastPixel[1] - firstPixel[1]; 1019 if (dx > numCols || 1020 dy > numRows) { 1021 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 1022 "The region [%d:%d,%d:%d], is not valid given the input %dx%d image.", 1023 firstPixel[1]-1,lastPixel[1]-1, 1024 firstPixel[0]-1,lastPixel[0]-1, 1025 numCols, numRows); 1026 return false; 1027 } 1028 1029 psImage* subset; 1030 if (dx != numCols || dy != numRows) { 1031 // the input image needs to be subsetted 1032 subset = psImageSubset((psImage*)input,0,0,dx+1,dy+1); 1033 } else { 1034 subset = psMemIncrRefCounter((psImage*)input); 1035 } 1036 1037 fits_write_subset(fits->p_fd, dataType, firstPixel, lastPixel, subset->data.V[0], &status); 1038 1039 if ( status != 0) { 1040 char fitsErr[MAX_STRING_LENGTH]; 1041 (void)fits_get_errstatus(status, fitsErr); 1042 psError(PS_ERR_IO, true, 1043 PS_ERRORTEXT_psFits_WRITE_FAILED, 1044 fits->filename, fitsErr); 1045 return false; 1046 } 1047 1048 return true; 898 1049 } 899 1050
Note:
See TracChangeset
for help on using the changeset viewer.
