IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 25, 2006, 5:24:49 PM (20 years ago)
Author:
Paul Price
Message:

psFitsWriteHeader checks that the HDU exists, and creates one if necessary. Added p_psFitsWriteHeader, which does not check. This allows psFitsInsertImage to call p_psFitsWriteHeader, since that already creates the HDU. Was getting into trouble by having psFitsInsertImage create a primary HDU for data, then calling psFitsWriteHeader, which created a primary HDU just for the header (dummy values for BITPIX, NAXIS, etc), then the data couldn't be written out. It would be much better if cfitsio treated data-less PHUs better --- if it recognised an HDU as extant once fits_create_img had been called.

File:
1 edited

Legend:

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

    r7226 r7227  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-05-26 02:48:47 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-05-26 03:24:49 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    218218}
    219219
    220 bool psFitsWriteHeader(psMetadata* output,
    221                        psFits* fits)
    222 {
    223 
     220
     221// Do the work of writing out the header.
     222// Doesn't check to see if a new HDU needs to be created
     223bool p_psFitsWriteHeader(psMetadata *output, // Metadata that is to be output into the FITS file
     224                         psFits *fits   // The FITS file handle
     225                        )
     226{
    224227    if (!fits) {
    225228        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL);
     
    230233        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_METADATA_NULL);
    231234        return false;
    232     }
    233 
    234     int status = 0;                     // Status of cfitsio calls
    235 
    236     // Check to see if there are any extant HDUs
    237     int hdus = psFitsGetSize(fits);     // Number of HDUs
    238     if (hdus == 0) {
    239         // Need to create a dummy image HDU for the primary HDU
    240         fits_create_img(fits->fd, 16, 0, NULL, &status);
    241         if (status) {
    242             char fitsErr[MAX_STRING_LENGTH];
    243             (void)fits_get_errstatus(status, fitsErr);
    244             psError(PS_ERR_IO, true, "Unable to create primary header.\n%s\n", fitsErr);
    245             return false;
    246         }
    247235    }
    248236
     
    250238    psListIterator* iter = psListIteratorAlloc(output->list, PS_LIST_HEAD, true); // Iterator
    251239    psMetadataItem* item;               // Item from iteration
     240    int status = 0;                     // Status of cfitsio calls
    252241    while ((item = psListGetAndIncrement(iter))) {
    253242        // Check to see if the item should be ignored
     
    325314}
    326315
     316bool psFitsWriteHeader(psMetadata* output,
     317                       psFits* fits)
     318{
     319    if (!fits) {
     320        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL);
     321        return false;
     322    }
     323
     324    if (!output) {
     325        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_METADATA_NULL);
     326        return false;
     327    }
     328
     329    // Check to see if there are any extant HDUs
     330    int hdus = psFitsGetSize(fits);     // Number of HDUs
     331    if (hdus == 0) {
     332        // Need to create a dummy image HDU for the primary HDU
     333        int status = 0;                 // Status of cfitsio
     334        fits_create_img(fits->fd, 16, 0, NULL, &status);
     335        if (status) {
     336            char fitsErr[MAX_STRING_LENGTH];
     337            (void)fits_get_errstatus(status, fitsErr);
     338            psError(PS_ERR_IO, true, "Unable to create primary header.\n%s\n", fitsErr);
     339            return false;
     340        }
     341    }
     342
     343    return p_psFitsWriteHeader(output, fits);
     344}
     345
    327346bool psFitsHeaderValidate(psMetadata *header)
    328347{
Note: See TracChangeset for help on using the changeset viewer.