IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7227


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.

Location:
trunk/psLib
Files:
4 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{
  • trunk/psLib/src/fits/psFitsHeader.h

    r7162 r7227  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-05-22 22:39:07 $
     9 *  @version $Revision: 1.5 $ $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
     
    4242
    4343/** Writes the values of the metadata to the current HDU header.
     44 *  Doesn't check if the header has to be created, so not for general public use.
     45 *
     46 * @return bool         if TRUE, the write was successful, otherwise FALSE.
     47 */
     48bool p_psFitsWriteHeader(
     49    psMetadata* output,                 ///< the psMetadata data in which to write
     50    psFits* fits                        ///< the psFits object
     51);
     52
     53/** Writes the values of the metadata to an HDU header.
    4454 *
    4555 *  @return bool        if TRUE, the write was successful, otherwise FALSE.
  • trunk/psLib/src/fits/psFitsImage.c

    r7224 r7227  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-05-26 00:48:20 $
     9 *  @version $Revision: 1.7 $ $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
     
    296296{
    297297
    298     if (fits == NULL) {
    299         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    300                 PS_ERRORTEXT_psFits_NULL);
    301         return false;
    302     }
    303 
    304     if (input == NULL) {
    305         psError(PS_ERR_BAD_PARAMETER_NULL, true,
    306                 PS_ERRORTEXT_psFits_IMAGE_NULL);
    307         return false;
    308     }
    309     int numCols = input->numCols;
    310     int numRows = input->numRows;
    311 
    312     int status = 0;
     298    if (!fits) {
     299        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_NULL);
     300        return false;
     301    }
     302
     303    if (!input) {
     304        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psFits_IMAGE_NULL);
     305        return false;
     306    }
     307
     308    int numCols = input->numCols;       // Number of columns for image
     309    int numRows = input->numRows;       // Number of rows for image
     310    int status = 0;                     // Status from cfitsio
    313311
    314312    // determine the FITS-equivalent parameters
    315     int bitPix;
    316     double bZero;
    317     int dataType;
     313    int bitPix;                         // Bits per pixel
     314    double bZero;                       // Zero offset
     315    int dataType;                       // cfitsio data type
    318316    if (! convertPsTypeToFits(input->type.type, &bitPix, &bZero, &dataType) ) {
    319317        return false;
    320318    }
    321319
    322     int naxis = 3;
    323     long naxes[3];
    324 
     320    int naxis = 3;                      // Number of axes
     321    long naxes[3];                      // Length of each axis
    325322    naxes[0] = numCols;
    326323    naxes[1] = numRows;
     
    331328    }
    332329
    333     int chdu = psFitsGetExtNum(fits);   // Current HDU number
     330    // Create the image HDU
    334331    int hdus = psFitsGetSize(fits);     // Number of HDUs in file
    335     if (! after) {
    336         if (chdu == 0) {
    337             // set status to signal fits_insert_img to insert a new primary HDU
    338             status = PREPEND_PRIMARY;
    339         } else if (hdus > 0) {
    340             // move back one to perform an insert after the previous HDU
    341             psFitsMoveExtNum(fits, -1, true);
    342         }
    343     }
    344 
    345332    if (hdus == 0) {
    346         status = 0;
     333        // We're creating the first image
    347334        fits_create_img(fits->fd, bitPix, naxis, naxes, &status);
    348335    } else {
     336        if (!after) {
     337            int chdu = psFitsGetExtNum(fits);   // Current HDU number
     338            if (chdu == 0) {
     339                // We're creating a replacement primary HDU.
     340                // Set status to signal fits_insert_img to insert a new primary HDU
     341                status = PREPEND_PRIMARY;
     342            } else {
     343                // Move back one to perform an insert after the previous HDU
     344                psFitsMoveExtNum(fits, -1, true);
     345            }
     346        }
     347        // Insert after the current position
    349348        fits_insert_img(fits->fd, bitPix, naxis, naxes, &status);
     349    }
     350
     351    if (header && !p_psFitsWriteHeader(header, fits)) {
     352        psError(PS_ERR_IO, false, "Unable to write FITS header.\n");
     353        return false;
    350354    }
    351355
     
    361365    }
    362366
    363     if (header) {
    364         psFitsWriteHeader(header, fits);
    365     }
    366367    if (input->parent == NULL) { // if no parent, assume that the image data is contiguous
    367368        fits_write_img(fits->fd,
  • trunk/psLib/test/fits/tst_psFits.c

    r6912 r7227  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2006-04-20 01:13:11 $
     8*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2006-05-26 03:24:37 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    119119
    120120        // set the pixels in the image
    121         psBinaryOp(image,image,"=",psScalarAlloc(lcv,PS_TYPE_F32));
    122         if (! psFitsWriteImage(fitsFile,header,image,1,extname) ) {
     121        psImageInit(image, lcv);
     122        if (! psFitsWriteImage(fitsFile,header,image,0,extname) ) {
    123123            psError(PS_ERR_UNKNOWN, false,
    124124                    "Could not write image.");
Note: See TracChangeset for help on using the changeset viewer.