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/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,
Note: See TracChangeset for help on using the changeset viewer.