IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14984


Ignore:
Timestamp:
Sep 21, 2007, 5:06:16 PM (19 years ago)
Author:
Paul Price
Message:

Adding psFitsError to handle cfitsio errors.

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  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    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 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6565            return false;
    6666        }
    67         fits->fd = NULL;
     67        fits->fd = NULL;
    6868    }
    6969    return true;
     
    7474    if (!fits) return;
    7575    if (fits->fd) {
    76         fitsClose(fits);
     76        fitsClose(fits);
    7777    }
    7878    psFree (fits->extword);
     
    182182}
    183183
     184psErrorCode 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
    184213static void psFitsOptionsFree(psFitsOptions *opt)
    185214{
     
    227256// a user-defined word in place of EXTNAME
    228257bool p_psFitsMoveExtName_UserKey(const psFits *fits,
    229                                 const char *extname,
    230                                 const char *extword)
     258                                const char *extname,
     259                                const char *extword)
    231260{
    232261    PS_ASSERT_PTR_NON_NULL(fits,    false);
     
    242271    // NOTE: fits_* return 0 for success
    243272    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-quotes
    261         // try both for comparison
    262        
    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        }
    267296    }
    268297    psAbort("we should not reach here");
     
    290319
    291320    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);
    294323    }
    295324
     
    389418        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    390419                _("Header keyword %s is not found"), extword);
    391         return NULL;
     420        return NULL;
    392421    }
    393422    return psStringCopy(name);
  • branches/pap_branch_070920/psLib/src/fits/psFits.h

    r14877 r14984  
    44 * @author Robert DeSonia, MHPCC
    55 *
    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 $
    88 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    99 */
     
    2121#include "psMetadata.h"
    2222#include "psImage.h"
     23
     24#include "psErrorCodes.h"
    2325
    2426/** FITS HDU type.
     
    5153typedef struct
    5254{
    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)
    5658}
    5759psFits;
     
    8486);
    8587
    86 /** Creates a new FITS options struct
     88
     89/// Generate an error including the cfitsio error string
     90#ifdef DOXYGEN
     91psErrorCode 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
     98psErrorCode 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
    87115 *
    88116 *  @return psFitsOptions or NULL on failure
     
    146174// a user-defined word in place of EXTNAME
    147175bool p_psFitsMoveExtName_UserKey(const psFits *fits,
    148                                 const char *extname,
    149                                 const char *extword);
     176                                const char *extname,
     177                                const char *extword);
    150178
    151179/** Moves the FITS HDU to the specified extension name.
Note: See TracChangeset for help on using the changeset viewer.