Changeset 12549
- Timestamp:
- Mar 22, 2007, 11:40:47 AM (19 years ago)
- Location:
- trunk/psLib/src/fits
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFits.c
r12431 r12549 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.6 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-03- 14 00:39:50$9 * @version $Revision: 1.63 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-03-22 21:40:47 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 29 29 #include "psTrace.h" 30 30 #include "psVector.h" 31 #include "psAbort.h" 31 32 32 33 #define MAX_STRING_LENGTH 256 // maximum length string for FITS routines 34 static char *defaultExtword = "EXTNAME"; 33 35 34 36 static bool isHDUEmpty(const psFits* fits) … … 171 173 fits->fd = fptr; 172 174 fits->writable = (iomode == READWRITE); 175 fits->extword = NULL; 173 176 psMemSetDeallocator(fits,(psFreeFunc)fitsFree); 174 177 … … 182 185 } 183 186 184 187 bool psFitsSetExtnameWord (psFits *fits, const char *extword) 188 { 189 PS_ASSERT_PTR_NON_NULL(fits, false); 190 PS_ASSERT_PTR_NON_NULL(extword, false); 191 192 psFree (fits->extword); 193 fits->extword = psStringCopy (extword); 194 return true; 195 } 196 197 // move to the first HDU where extword == extname. this is equivalent to fits_movnam_hdu() for 198 // a user-defined word in place of EXTNAME 199 bool p_psFitsMoveExtName_UserKey(const psFits *fits, 200 const char *extname, 201 const char *extword) 202 { 203 PS_ASSERT_PTR_NON_NULL(fits, false); 204 PS_ASSERT_PTR_NON_NULL(extname, false); 205 PS_ASSERT_PTR_NON_NULL(extword, false); 206 207 int status = 0; 208 int hdutype = 0; 209 char name[MAX_STRING_LENGTH]; 210 211 // NOTE: fits_* return 0 for success 212 for (int i = 1; true; i++) { 213 // are we able to read the next HDU? 214 if (fits_movabs_hdu(fits->fd, i, &hdutype, &status)) { 215 char fitsErr[MAX_STRING_LENGTH]; 216 fits_get_errstatus(status, fitsErr); 217 psError(PS_ERR_LOCATION_INVALID, true, 218 _("Could not find HDU with %s = '%s'. CFITSIO Error: %s"), 219 extword, extname, fitsErr); 220 return false; 221 } 222 // is there a keyword called 'extword'? 223 if (fits_read_key_str(fits->fd, (char *)extword, name, NULL, &status)) { 224 continue; 225 } 226 // do we have the right hdu (names match)? 227 if (!strcmp (name, extname)) { 228 return true; 229 } 230 } 231 psAbort("we should not reach here"); 232 } 233 234 // XXX I will need to define a low-level function p_psFitsMoveExtName_UserKey () which 235 // uses fits_movabs_hdu() to replicate the functionality of fits_movnam_hdu using an 236 // alternate name for EXTNAME 185 237 bool psFitsMoveExtName(const psFits* fits, 186 238 const char* extname) … … 200 252 } 201 253 254 if (fits->extword != NULL) { 255 bool result = p_psFitsMoveExtName_UserKey(fits, extname, fits->extword); 256 return (result); 257 } 202 258 203 259 if (fits_movnam_hdu(fits->fd, ANY_HDU, (char*)extname, 0, &status) != 0) { … … 291 347 char name[MAX_STRING_LENGTH]; 292 348 293 if (fits_read_key_str(fits->fd, "EXTNAME", name, NULL, &status) != 0) {294 status = 0; 295 if (fits_read_key_str(fits->fd, "HDUNAME", name, NULL, &status) != 0) {296 int num = psFitsGetExtNum(fits);297 snprintf(name, MAX_STRING_LENGTH, "EXT-%3d",num);298 } 349 char *extword = (fits->extword == NULL) ? defaultExtword : fits->extword; 350 351 if (fits_read_key_str(fits->fd, extword, name, NULL, &status) != 0) { 352 psError(PS_ERR_BAD_PARAMETER_NULL, true, 353 _("Header keyword %s is not found"), extword); 354 return NULL; 299 355 } 300 356 return psStringCopy(name); … … 317 373 int status = 0; 318 374 319 if (fits_update_key_str(fits->fd, "EXTNAME", (char*)name, NULL, &status) != 0) { 375 char *extword = (fits->extword == NULL) ? defaultExtword : fits->extword; 376 377 if (fits_update_key_str(fits->fd, extword, (char*)name, NULL, &status) != 0) { 320 378 char fitsErr[MAX_STRING_LENGTH]; 321 379 (void)fits_get_errstatus(status, fitsErr); -
trunk/psLib/src/fits/psFits.h
r11248 r12549 4 4 * @author Robert DeSonia, MHPCC 5 5 * 6 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-0 1-23 22:47:23$6 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-03-22 21:40:47 $ 8 8 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 9 9 */ … … 43 43 typedef struct 44 44 { 45 fitsfile* fd; ///< the CFITSIO fits files handle. 46 bool writable; ///< Is the file writable? 45 fitsfile* fd; ///< the CFITSIO fits files handle. 46 bool writable; ///< Is the file writable? 47 char *extword; ///< user-specified word to name extensions (NULL implies EXTNAME) 47 48 } 48 49 psFits; … … 84 85 ); 85 86 87 // move to the first HDU where extword == extname. this is equivalent to fits_movnam_hdu() for 88 // a user-defined word in place of EXTNAME 89 bool p_psFitsMoveExtName_UserKey(const psFits *fits, 90 const char *extname, 91 const char *extword); 86 92 87 93 /** Moves the FITS HDU to the specified extension name. -
trunk/psLib/src/fits/psFitsTable.c
r12431 r12549 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 6$ $Name: not supported by cvs2svn $10 * @date $Date: 2007-03- 14 00:39:50$9 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2007-03-22 21:40:47 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 585 585 (char**)columnTypes->data, // format of the columns 586 586 NULL, // physical unit of columns 587 (char*)extname, // extension name; casting away const because cfitsio is horrible587 NULL, // skip extension name: we set the by hand below 588 588 &status); 589 589 } else { … … 605 605 (char**)columnTypes->data, // format of the columns 606 606 NULL, // physical unit of columns 607 (char*)extname, // extension name; casting away const because cfitsio is horrible607 NULL, // skip extension name: we set this by hand below 608 608 0, &status); 609 609 } … … 629 629 } 630 630 631 // write the header, if any. 632 if (extname && strlen(extname) > 0) { 633 if (!psFitsSetExtName(fits, extname)) { 634 psError(PS_ERR_IO, false, "Unable to write FITS header extension name.\n"); 635 psFree(colSpecsIter); 636 psFree(colSpecs); 637 return false; 638 } 639 } 631 640 632 641 // cfitsio requires that we write the data by columns --- urgh!
Note:
See TracChangeset
for help on using the changeset viewer.
