IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 12:45:24 PM (17 years ago)
Author:
eugene
Message:

update from mainline

Location:
branches/eam_branches/20090715
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715

  • branches/eam_branches/20090715/psLib/src/fits/psFitsHeader.c

    r23376 r25022  
    147147    return keyword;
    148148}
    149 
    150149
    151150bool psFitsCheckCompressedImagePHU(const psFits *fits, psMetadata *header)
     
    497496static bool fitsWriteHeader(psFits *fits, // The FITS file handle
    498497                            const psMetadata *output, // Metadata that is to be output into the FITS file
    499                             bool keyStarts // Write out the key starts?
     498                            bool keyStarts, // Write out the key starts?
     499                            bool phuImage   // Are we writing a PHU image?
    500500                           )
    501501{
    502502    int status = 0;                     // Status of cfitsio calls
     503    int extnum = psFitsGetExtNum(fits); // Number of extension
    503504    bool simple = true;                 // If SIMPLE is T, then the file should conform to the FITS standard
    504505    psFitsCompressionType compress = psFitsCompressionGetType(fits); // Compression type
    505     if (psFitsGetExtNum(fits) == 0) {
     506    if (extnum == 0) {
     507
    506508        // We allow the user to write SIMPLE, but it must be boolean
    507509        psMetadataItem *simpleItem = psMetadataLookup(output, "SIMPLE"); // SIMPLE in the header
     
    526528    bool compressing = ((!fits->options || fits->options->conventions.compression) &&
    527529                        compress != PS_FITS_COMPRESS_NONE) ? true : false; // Are we compressing?
    528 
    529530    if (compressing) {
    530531        psMetadataItem *simpleItem = psMetadataLookup(output, "SIMPLE"); // SIMPLE in the header
     
    538539            }
    539540        }
    540         //        int value = simple;             // Temporary holder for boolean
    541         //        fits_update_key(fits->fd, TLOGICAL, "ZSIMPLE", &value,
    542         //                        "Uncompressed file's conformance to FITS standard", &status);
     541        if (simple && phuImage && extnum == 1) {
     542            // ZSIMPLE is required for decompression with funpack, etc.  For funpack to work, ZSIMPLE needs to
     543            // go early in the FITS header (otherwise we get "Extension doesn't start with SIMPLE or XTENSION
     544            // keyword.").  We put it after ZIMAGE by reading ZIMAGE (which sets the insertion pointer) and
     545            // then inserting ZSIMPLE.
     546            char comment[FLEN_CARD];    // Comment for ZIMAGE; unused
     547            int value;                  // Value for ZIMAGE; unused
     548            fits_read_key(fits->fd, TLOGICAL, "ZIMAGE", &value, comment, &status);
     549            fits_insert_key_log(fits->fd, "ZSIMPLE", simple, "Uncompressed file's conforms to FITS", &status);
     550        }
    543551    }
    544552
     
    699707    PS_ASSERT_METADATA_NON_NULL(output, false);
    700708
    701     return fitsWriteHeader(fits, output, true);
     709    return fitsWriteHeader(fits, output, true, false);
     710}
     711
     712bool psFitsWriteHeaderImage(psFits *fits,
     713                            const psMetadata *output,
     714                            bool phuImage
     715                            )
     716{
     717    PS_ASSERT_FITS_NON_NULL(fits, false);
     718    PS_ASSERT_FITS_WRITABLE(fits, false);
     719    PS_ASSERT_METADATA_NON_NULL(output, false);
     720
     721    return fitsWriteHeader(fits, output, true, phuImage);
    702722}
    703723
     
    733753    }
    734754
    735     if (output && !fitsWriteHeader(fits, output, false)) {
     755    if (output && !fitsWriteHeader(fits, output, false, false)) {
    736756        psError(PS_ERR_IO, false, "Unable to write FITS header.\n");
    737757        return false;
Note: See TracChangeset for help on using the changeset viewer.