IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12549


Ignore:
Timestamp:
Mar 22, 2007, 11:40:47 AM (19 years ago)
Author:
magnier
Message:

adding user-definable fits->extword to psFits

Location:
trunk/psLib/src/fits
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFits.c

    r12431 r12549  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.62 $ $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 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2929#include "psTrace.h"
    3030#include "psVector.h"
     31#include "psAbort.h"
    3132
    3233#define MAX_STRING_LENGTH 256  // maximum length string for FITS routines
     34static char *defaultExtword = "EXTNAME";
    3335
    3436static bool isHDUEmpty(const psFits* fits)
     
    171173    fits->fd = fptr;
    172174    fits->writable = (iomode == READWRITE);
     175    fits->extword = NULL;
    173176    psMemSetDeallocator(fits,(psFreeFunc)fitsFree);
    174177
     
    182185}
    183186
    184 
     187bool 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
     199bool 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
    185237bool psFitsMoveExtName(const psFits* fits,
    186238                       const char* extname)
     
    200252    }
    201253
     254    if (fits->extword != NULL) {
     255        bool result = p_psFitsMoveExtName_UserKey(fits, extname, fits->extword);
     256        return (result);
     257    }
    202258
    203259    if (fits_movnam_hdu(fits->fd, ANY_HDU, (char*)extname, 0, &status) != 0) {
     
    291347    char name[MAX_STRING_LENGTH];
    292348
    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;
    299355    }
    300356    return psStringCopy(name);
     
    317373    int status = 0;
    318374
    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) {
    320378        char fitsErr[MAX_STRING_LENGTH];
    321379        (void)fits_get_errstatus(status, fitsErr);
  • trunk/psLib/src/fits/psFits.h

    r11248 r12549  
    44 * @author Robert DeSonia, MHPCC
    55 *
    6  * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-23 22:47:23 $
     6 * @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-03-22 21:40:47 $
    88 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    99 */
     
    4343typedef struct
    4444{
    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)
    4748}
    4849psFits;
     
    8485);
    8586
     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
     89bool p_psFitsMoveExtName_UserKey(const psFits *fits,
     90                                 const char *extname,
     91                                 const char *extword);
    8692
    8793/** Moves the FITS HDU to the specified extension name.
  • trunk/psLib/src/fits/psFitsTable.c

    r12431 r12549  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.26 $ $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 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    585585                        (char**)columnTypes->data, // format of the columns
    586586                        NULL, // physical unit of columns
    587                         (char*)extname, // extension name; casting away const because cfitsio is horrible
     587                        NULL, // skip extension name: we set the by hand below
    588588                        &status);
    589589    } else {
     
    605605                         (char**)columnTypes->data, // format of the columns
    606606                         NULL, // physical unit of columns
    607                          (char*)extname, // extension name; casting away const because cfitsio is horrible
     607                         NULL, // skip extension name: we set this by hand below
    608608                         0, &status);
    609609    }
     
    629629    }
    630630
     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    }
    631640
    632641    // cfitsio requires that we write the data by columns --- urgh!
Note: See TracChangeset for help on using the changeset viewer.