IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 22, 2006, 12:38:27 PM (20 years ago)
Author:
Paul Price
Message:

Updating essential headers for psFitsInsertImage. psFitsWriteImage
was not working without this update (complaint was: "Could not write
data to file. CFITSIO Error: 1st key not SIMPLE or XTENSION"). I'm
not sure that this is the best fix, but due to the murkiness of
cfitsio, I think it's important to set these explicitly.

File:
1 edited

Legend:

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

    r6936 r7161  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-04-21 20:41:10 $
     9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-05-22 22:38:27 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    358358
    359359    // write the header, if any.
    360     if (extname != NULL) {
     360    if (extname && strlen(extname) > 0) {
    361361        psFitsSetExtName(fits,extname);
    362362    }
    363363
    364     if (header != NULL) {
    365         if (extname != NULL) {
    366             psMetadataAddStr(header,PS_LIST_TAIL,"EXTNAME",
    367                              PS_META_REPLACE,
    368                              "Extenion Name",
    369                              extname);
    370         }
    371 
     364    if (header) {
     365        // Update header with BITPIX, NAXIS[12], BSCALE, BZERO so we don't clobber the basic header
     366        psMetadataAddS32(header, PS_LIST_TAIL, "BITPIX", PS_META_REPLACE, "Bits per pixel", bitPix);
     367        psMetadataAddS32(header, PS_LIST_TAIL, "NAXIS",  PS_META_REPLACE, "Number of dimensions", naxis);
     368        psMetadataAddS32(header, PS_LIST_TAIL, "NAXIS1", PS_META_REPLACE, "Number of columns", numCols);
     369        psMetadataAddS32(header, PS_LIST_TAIL, "NAXIS2", PS_META_REPLACE, "Number of rows", numRows);
     370        psMetadataAddF64(header, PS_LIST_TAIL, "BSCALE", PS_META_REPLACE, "Pixel value scale", 1.0);
     371        psMetadataAddF64(header, PS_LIST_TAIL, "BZERO",  PS_META_REPLACE, "Pixel value offset", bZero);
     372        if (extname && strlen(extname) > 0) {
     373            psMetadataAddStr(header, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "Extenion Name", extname);
     374        }
    372375        psFitsWriteHeader(header, fits);
     376    } else {
     377        // Write the necessary headers manually
     378        fits_write_key_dbl(fits->fd, "BZERO", bZero, 12, "Pixel Value Offset", &status);
     379        fits_write_key_dbl(fits->fd, "BSCALE", 1.0, 12, "Pixel Value Scale", &status);
     380        // Regrettably have to cast away "const" on extname, because CFITSIO is horrible
     381        fits_write_key_str(fits->fd, "EXTNAME", (char *)extname, "Extension name", &status);
    373382    }
    374383
Note: See TracChangeset for help on using the changeset viewer.