IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 8, 2008, 11:40:25 AM (18 years ago)
Author:
Paul Price
Message:

Explicitly writing ZBITPIX (with lower value than what is actually
used for BITPIX) resulted in truncated dynamic range. Being more
careful with what keywords are allowed to be written.

File:
1 edited

Legend:

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

    r17447 r17587  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2008-04-17 23:43:02 $
     9 *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-05-08 21:40:25 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4747// List of FITS header keys not to write (handled by cfitsio); NULL-terminated
    4848static const char *noWriteFitsKeys[] = { "SIMPLE", "XTENSION", "BITPIX", "NAXIS", "EXTNAME", "BSCALE",
    49                                          "BZERO", "TFIELDS", "PCOUNT", "GCOUNT", "ZIMAGE", "ZBITPIX",
    50                                          "ZCMPTYPE", "PSBITPIX", NULL };
     49                                         "BZERO", "TFIELDS", "PCOUNT", "GCOUNT", "PSBITPIX", NULL };
    5150
    5251// List of the start of FITS header keys not to write (handled by cfitsio); NULL-terminated
    53 static const char *noWriteFitsKeyStarts[] = { "NAXIS", "TTYPE", "TFORM", "ZNAXIS", "ZTILE", "ZNAME", "ZVAL",
    54                                               NULL };
     52static const char *noWriteFitsKeyStarts[] = { "NAXIS", "TTYPE", "TFORM", NULL };
     53
     54// List of compressed FITS header keys not to write (handled by cfitsio); NULL-terminated
     55static const char *noWriteCompressedKeys[] = { "ZBITPIX", "ZIMAGE", "ZBITPIX", "ZCMPTYPE", NULL };
     56
     57// List of the start of FITS header keys not to write (handled by cfitsio); NULL-terminated
     58static const char *noWriteCompressedKeyStarts[] = { "ZNAXIS", "ZTILE", "ZNAME", "ZVAL", NULL };
    5559
    5660// List of FITS header keys that may be present if the header is considered "empty"; NULL-terminated
     
    6569
    6670// Translation for compressed image headers           FROM        TO
     71// The "From" and "To" are appropriate for reading.
    6772static keywordTranslation compressTranslation[] = { { "ZSIMPLE",  "SIMPLE" },
    6873                                                    { "ZTENSION", "XTENSION" },
     
    9499}
    95100
     101// Compare a keyword with a list of keyword beginnings; return true if the keyword starts with one of these
     102static bool keywordStartsWith(const char *keyword, // Keyword to check
     103                              const char *list[] // List of keyword beginnings
     104                              )
     105{
     106    bool writeKey = true;   // Write this keyword?
     107    for (int i = 0; list[i] && writeKey; i++) {
     108        if (strncmp(keyword, list[i], strlen(list[i])) == 0) {
     109            return true;
     110        }
     111    }
     112    return false;
     113}
     114
     115
    96116// Translate one keyword to another.
    97117// This is appropriate for reading
     
    125145        }
    126146    }
    127     // It translates to itself, so ignore
    128     return NULL;
     147    // It translates to itself
     148    return keyword;
    129149}
    130150
     
    528548            // image, the NAXISn haven't been changed; or after converting to F32, the BITPIX hasn't been
    529549            // changed) so we'll take care of that for them.
    530             if (keywordInList(name, noWriteFitsKeys)) {
    531                 if (strcmp(name, "SIMPLE") == 0 || compress == PS_FITS_COMPRESS_NONE ||
    532                     (fits->options && !fits->options->conventions.compression)) {
    533                     // No compression happening, so don't write keyword
     550
     551            // Also block out TTYPEn, NAXISn, etc --- keywords that start with a certain sequence.
     552            // We want to do this when writing an image or table, since it guarantees that the NAXISn etc
     553            // that go in are correct.  However, when we're writing a "blank" HDU (header only), we want
     554            // to preserve NAXISn etc for reference, so we don't do this.
     555
     556            // Options for compression
     557            if (compress != PS_FITS_COMPRESS_NONE &&
     558                (!fits->options || fits->options->conventions.compression)) {
     559                // Check to see if the keyword should be translated
     560                name = (char*)keywordUntranslate(name, compressTranslation); // Casting away const for cfitsio
     561
     562                if (keywordInList(name, noWriteCompressedKeys) ||
     563                    (keyStarts && keywordStartsWith(name, noWriteCompressedKeyStarts))) {
    534564                    continue;
    535565                }
    536                 // Check to see if the keyword should be translated rather than written
    537                 name = (char*)keywordUntranslate(name, compressTranslation); // Casting away const for cfitsio
    538                 if (!name) {
    539                     // Not in translation list, so don't write
    540                     continue;
    541                 }
    542             }
    543 
    544             if (keyStarts) {
    545                 // Also block out TTYPEn, NAXISn, etc --- keywords that start with a certain sequence.
    546                 // We want to do this when writing an image or table, since it guarantees that the NAXISn etc
    547                 // that go in are correct.  However, when we're writing a "blank" HDU (header only), we want
    548                 // to preserve NAXISn etc for reference, so we don't do this.
    549                 bool writeKey = true;   // Write this keyword?
    550                 for (int i = 0; noWriteFitsKeyStarts[i] && writeKey; i++) {
    551                     if (strncmp(item->name, noWriteFitsKeyStarts[i], strlen(noWriteFitsKeyStarts[i])) == 0) {
    552                         writeKey = false;
    553                     }
    554                 }
    555                 if (!writeKey) {
    556                     // Don't write it; skip to the next key
    557                     continue;
    558                 }
     566            }
     567
     568            if (keywordInList(name, noWriteFitsKeys) ||
     569                (keyStarts && keywordStartsWith(name, noWriteFitsKeyStarts))) {
     570                continue;
    559571            }
    560572        }
Note: See TracChangeset for help on using the changeset viewer.