Changeset 14984
- Timestamp:
- Sep 21, 2007, 5:06:16 PM (19 years ago)
- Location:
- branches/pap_branch_070920/psLib/src/fits
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_070920/psLib/src/fits/psFits.c
r14878 r14984 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.71 $ $Name: not supported by cvs2svn $10 * @date $Date: 2007-09- 18 03:01:17$9 * @version $Revision: 1.71.2.1 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-09-22 03:06:16 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 65 65 return false; 66 66 } 67 fits->fd = NULL;67 fits->fd = NULL; 68 68 } 69 69 return true; … … 74 74 if (!fits) return; 75 75 if (fits->fd) { 76 fitsClose(fits);76 fitsClose(fits); 77 77 } 78 78 psFree (fits->extword); … … 182 182 } 183 183 184 psErrorCode p_psFitsError(const char* filename, 185 unsigned int lineno, 186 const char* func, 187 int status, 188 bool new, 189 const char *errorMsg, 190 ... 191 ) 192 { 193 if (status == 0) { 194 return PS_ERR_NONE; 195 } 196 197 va_list ap; // Variable arguments 198 va_start(ap, errorMsg); 199 psString msg = NULL; // Message to pass to psError 200 psStringAppendV(&msg, errorMsg, ap); 201 va_end(ap); 202 203 char cfitsioMsg[MAX_STRING_LENGTH]; // Error message from cfitsio 204 (void)fits_get_errstatus(status, cfitsioMsg); 205 206 psStringAppend(&msg, "[CFITSIO error: %s]", cfitsioMsg); 207 208 psErrorCode code = p_psError(filename, lineno, func, PS_ERR_IO, new, msg); // Error code 209 psFree(msg); 210 return code; 211 } 212 184 213 static void psFitsOptionsFree(psFitsOptions *opt) 185 214 { … … 227 256 // a user-defined word in place of EXTNAME 228 257 bool p_psFitsMoveExtName_UserKey(const psFits *fits, 229 const char *extname,230 const char *extword)258 const char *extname, 259 const char *extword) 231 260 { 232 261 PS_ASSERT_PTR_NON_NULL(fits, false); … … 242 271 // NOTE: fits_* return 0 for success 243 272 for (int i = 1; true; i++) { 244 // are we able to read the next HDU?245 246 int status = 0;247 if (fits_movabs_hdu(fits->fd, i, &hdutype, &status)) {248 char fitsErr[MAX_STRING_LENGTH];249 fits_get_errstatus(status, fitsErr);250 psError(PS_ERR_LOCATION_INVALID, true,251 _("Could not find HDU with %s = '%s'. CFITSIO Error: %s"),252 extword, extname, fitsErr);253 return false;254 }255 // is there a keyword called 'extword'? (read as string regardless of type)256 status = 0;257 if (fits_read_keyword(fits->fd, (char *)extword, name, NULL, &status)) {258 continue;259 }260 // if this was read as a string, we will have leading and trailing single-quotes261 // try both for comparison262 263 // do we have the right hdu (names match)?264 if (!strcmp (name, extname) || !strcmp (name, extstring)) {265 return true;266 }273 // are we able to read the next HDU? 274 275 int status = 0; 276 if (fits_movabs_hdu(fits->fd, i, &hdutype, &status)) { 277 char fitsErr[MAX_STRING_LENGTH]; 278 fits_get_errstatus(status, fitsErr); 279 psError(PS_ERR_LOCATION_INVALID, true, 280 _("Could not find HDU with %s = '%s'. CFITSIO Error: %s"), 281 extword, extname, fitsErr); 282 return false; 283 } 284 // is there a keyword called 'extword'? (read as string regardless of type) 285 status = 0; 286 if (fits_read_keyword(fits->fd, (char *)extword, name, NULL, &status)) { 287 continue; 288 } 289 // if this was read as a string, we will have leading and trailing single-quotes 290 // try both for comparison 291 292 // do we have the right hdu (names match)? 293 if (!strcmp (name, extname) || !strcmp (name, extstring)) { 294 return true; 295 } 267 296 } 268 297 psAbort("we should not reach here"); … … 290 319 291 320 if (fits->extword != NULL) { 292 bool result = p_psFitsMoveExtName_UserKey(fits, extname, fits->extword);293 return (result);321 bool result = p_psFitsMoveExtName_UserKey(fits, extname, fits->extword); 322 return (result); 294 323 } 295 324 … … 389 418 psError(PS_ERR_BAD_PARAMETER_NULL, true, 390 419 _("Header keyword %s is not found"), extword); 391 return NULL;420 return NULL; 392 421 } 393 422 return psStringCopy(name); -
branches/pap_branch_070920/psLib/src/fits/psFits.h
r14877 r14984 4 4 * @author Robert DeSonia, MHPCC 5 5 * 6 * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $7 * @date $Date: 2007-09- 18 02:56:36 $6 * @version $Revision: 1.31.2.1 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-09-22 03:06:16 $ 8 8 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 9 9 */ … … 21 21 #include "psMetadata.h" 22 22 #include "psImage.h" 23 24 #include "psErrorCodes.h" 23 25 24 26 /** FITS HDU type. … … 51 53 typedef struct 52 54 { 53 fitsfile* fd; ///< the CFITSIO fits files handle.54 bool writable; ///< Is the file writable?55 char *extword; ///< user-specified word to name extensions (NULL implies EXTNAME)55 fitsfile* fd; ///< the CFITSIO fits files handle. 56 bool writable; ///< Is the file writable? 57 char *extword; ///< user-specified word to name extensions (NULL implies EXTNAME) 56 58 } 57 59 psFits; … … 84 86 ); 85 87 86 /** Creates a new FITS options struct 88 89 /// Generate an error including the cfitsio error string 90 #ifdef DOXYGEN 91 psErrorCode psFitsError( 92 int status, ///< cfitsio status value 93 bool new, ///< new error? 94 const char *errorMsg, ///< printf-style format of header line 95 ... ///< any parameters required in format 96 ); 97 #else // ifdef DOXYGEN 98 psErrorCode p_psFitsError( 99 const char* filename, ///< file name 100 unsigned int lineno, ///< line number in file 101 const char* func, ///< function name 102 int status, ///< cfitsio status value 103 bool new, ///< new error? 104 const char *errorMsg, ///< printf-style format of header line 105 ... ///< any parameters required in format 106 ) PS_ATTR_FORMAT(printf, 6, 7); 107 #ifndef SWIG 108 #define psFitsError(status,new,...) \ 109 p_psFitsError(__FILE__,__LINE__,__func__,status,new,__VA_ARGS__) 110 #endif // ifndef SWIG 111 #endif // ifdef DOXYGEN 112 113 114 /** Creates a new FITS options struct 87 115 * 88 116 * @return psFitsOptions or NULL on failure … … 146 174 // a user-defined word in place of EXTNAME 147 175 bool p_psFitsMoveExtName_UserKey(const psFits *fits, 148 const char *extname,149 const char *extword);176 const char *extname, 177 const char *extword); 150 178 151 179 /** Moves the FITS HDU to the specified extension name.
Note:
See TracChangeset
for help on using the changeset viewer.
