Changeset 28580 for trunk/psLib/src/fits/psFitsTable.c
- Timestamp:
- Jul 1, 2010, 3:10:20 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsTable.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsTable.c
r28511 r28580 69 69 } 70 70 71 72 // Check the FITS file in preparation for reading a table 73 static bool readTableCheck(const psFits *fits // FITS file 74 ) 71 // Check if the FITS file is an empty table 72 static bool emptyTableCheck(const psFits *fits // FITS file 73 ) 75 74 { 76 75 PS_ASSERT_FITS_NON_NULL(fits, false); … … 81 80 } 82 81 83 // check that we are positioned on a table HDU84 82 int status = 0; // CFITSIO status 85 83 int hdutype; // Type of HDU 86 84 fits_get_hdu_type(fits->fd, &hdutype, &status); 87 if (psFitsError(status, true, "Could not determine the HDU type.")) { 85 if (status) { 86 psFitsError(status, true, "Could not determine the HDU type."); 88 87 return false; 89 88 } … … 99 98 return false; 100 99 } 101 } else if (hdutype != ASCII_TBL && hdutype != BINARY_TBL) { 102 psError(PS_ERR_BAD_FITS, true, _("Current FITS HDU is not a table.")); 100 return true; 101 } 102 103 return false; 104 } 105 106 // Check the FITS file in preparation for reading a table 107 static bool readTableCheck(const psFits *fits // FITS file 108 ) 109 { 110 PS_ASSERT_FITS_NON_NULL(fits, false); 111 112 if (psFitsGetExtNum(fits) == 0 && !psFitsMoveExtNum(fits, 1, false)) { 113 psError(PS_ERR_IO, false, "Unable to move to first extension to read table."); 114 return false; 115 } 116 117 // check that we are positioned on a table HDU 118 int status = 0; // CFITSIO status 119 int hdutype; // Type of HDU 120 fits_get_hdu_type(fits->fd, &hdutype, &status); 121 if (status) { 122 psFitsError(status, true, "Could not determine the HDU type."); 123 return false; 124 } 125 if (hdutype != ASCII_TBL && hdutype != BINARY_TBL) { 103 126 return false; 104 127 } … … 114 137 115 138 if (!readTableCheck(fits)) { 139 if (emptyTableCheck(fits)) { 140 return psMetadataAlloc(); 141 } 142 psError(PS_ERR_BAD_FITS, true, "Extension is not a table"); 116 143 return NULL; 117 144 } … … 123 150 fits_get_num_rows(fits->fd, &numRows, &status); 124 151 fits_get_num_cols(fits->fd, &numCols, &status); 125 if (status != 0) {152 if (status) { 126 153 psFitsError(status, true, "Failed to determine the size of the current HDU table."); 127 154 return NULL; … … 236 263 237 264 if (!readTableCheck(fits)) { 265 if (emptyTableCheck(fits)) { 266 return psArrayAlloc(0); 267 } 268 psError(PS_ERR_BAD_FITS, true, "Extension is not a table"); 238 269 return NULL; 239 270 } … … 283 314 284 315 if (!readTableCheck(fits)) { 316 psError(PS_ERR_BAD_FITS, true, "Extension is not a table"); 285 317 return NULL; 286 318 } … … 327 359 328 360 if (!readTableCheck(fits)) { 361 if (emptyTableCheck(fits)) { 362 return psArrayAlloc(0); 363 } 364 psError(PS_ERR_BAD_FITS, true, "Extension is not a table"); 329 365 return NULL; 330 366 } … … 736 772 737 773 if (!readTableCheck(fits)) { 774 psError(PS_ERR_BAD_FITS, true, "Extension is not a table"); 738 775 return NULL; 739 776 } … … 785 822 786 823 if (!readTableCheck(fits)) { 824 if (emptyTableCheck(fits)) { 825 return psMetadataAlloc(); 826 } 827 psError(PS_ERR_BAD_FITS, true, "Extension is not a table"); 787 828 return NULL; 788 829 } … … 794 835 fits_get_num_rows(fits->fd, &numRows, &status); 795 836 fits_get_num_cols(fits->fd, &numCols, &status); 796 if (psFitsError(status, true, "Failed to determine the size of the current HDU table.")) { 837 if (status) { 838 psFitsError(status, true, "Failed to determine the size of the current HDU table."); 797 839 return NULL; 798 840 } … … 800 842 int hdutype; // Type of HDU: need to distinguish ASCII and binary tables 801 843 fits_get_hdu_type(fits->fd, &hdutype, &status); 802 if (psFitsError(status, true, "Could not determine the HDU type.")) { 844 if (status) { 845 psFitsError(status, true, "Could not determine the HDU type."); 803 846 return false; 804 847 } … … 818 861 long repeat; // Number of repeats 819 862 fits_get_eqcoltype(fits->fd, col, &cfitsioType, &repeat, NULL, &status); 820 if (psFitsError(status, true, "Could not determine the column data for %s", name)) { 863 if (status) { 864 psFitsError(status, true, "Could not determine the column data for %s", name); 821 865 psFree(table); 822 866 return false; … … 837 881 } 838 882 fits_read_col_str(fits->fd, col, 1, 1, numRows, "", (char**)array->data, NULL, &status); 839 if (psFitsError(status, true, "Failed to read column %s", name)) { 883 if (status) { 884 psFitsError(status, true, "Failed to read column %s", name); 840 885 psFree(array); 841 886 psFree(table); … … 854 899 fits_read_col(fits->fd, cfitsioType, col, 1, 1, numRows, NULL, 855 900 vector->data.U8, NULL, &status); 856 if (psFitsError(status, true, "Failed to read column %s", name)) { 901 if (status) { 902 psFitsError(status, true, "Failed to read column %s", name); 857 903 psFree(vector); 858 904 psFree(table); … … 965 1011 psFree(names); 966 1012 psFree(types); 967 if (psFitsError(status, true, "Unable to create FITS table with %d columns and %ld rows", 968 numCols, numRows)) { 1013 if (status) { 1014 psFitsError(status, true, "Unable to create FITS table with %d columns and %ld rows", 1015 numCols, numRows); 969 1016 psFree(columns); 970 1017 return false; … … 1018 1065 } 1019 1066 // Check error status from writing column 1020 if (psFitsError(status, true, "Unable to write column %ld of FITS table", col)) { 1067 if (status) { 1068 psFitsError(status, true, "Unable to write column %ld of FITS table", col); 1021 1069 psFree(columns); 1022 1070 return false; … … 1029 1077 // hurt. 1030 1078 ffrdef(fits->fd, &status); 1031 if (psFitsError(status, true, "Could not re-scan HDU.")) { 1079 if (status) { 1080 psFitsError(status, true, "Could not re-scan HDU."); 1032 1081 return false; 1033 1082 }
Note:
See TracChangeset
for help on using the changeset viewer.
