IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14985


Ignore:
Timestamp:
Sep 21, 2007, 5:08:05 PM (19 years ago)
Author:
Paul Price
Message:

Adding psFitsEmptyPHU which determines whether the current HDU is an empty PHU. This is expected to be of use for decompressing images where the original consisted of a single image, but now has an empty PHU followed by a table with the compressed image.

Location:
branches/pap_branch_070920/psLib/src/fits
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_070920/psLib/src/fits/psFitsHeader.c

    r14460 r14985  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-08-10 02:23:42 $
     9 *  @version $Revision: 1.34.4.1 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-09-22 03:08:05 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1919#include <unistd.h>
    2020
     21#include "psAssert.h"
    2122#include "psFits.h"
    2223#include "string.h"
     
    3233
    3334#define MAX_STRING_LENGTH 256  // maximum length string for FITS routines
     35#define NUM_EMPTY_KEYS 8                // Number of keywords before header is considered practically empty
    3436
    3537// list of FITS header keys to ignore; NULL-terminated
    36 static char* ignoreFitsKeys[] = {"", NULL};
     38static const char* ignoreFitsKeys[] = {"", NULL};
    3739
    3840// List of FITS header keys that may be duplicated; NULL-terminated
    39 static char *duplicateFitsKeys[] = {"COMMENT", "HIERARCH", "HISTORY", NULL};
     41static const char *duplicateFitsKeys[] = {"COMMENT", "HIERARCH", "HISTORY", NULL};
    4042
    4143// List of FITS header keys not to write (handled by cfitsio); NULL-terminated
    42 static char *noWriteFitsKeys[] = {"SIMPLE", "XTENSION", "BITPIX", "NAXIS", "EXTNAME", "BSCALE", "BZERO",
    43                                   "TFIELDS", NULL};
     44static const char *noWriteFitsKeys[] = {"SIMPLE", "XTENSION", "BITPIX", "NAXIS", "EXTNAME", "BSCALE", "BZERO",
     45                                        "TFIELDS", NULL};
     46
    4447// List of the start of FITS header keys not to write (handled by cfitsio); NULL-terminated
    45 static char *noWriteFitsKeyStarts[] = {"NAXIS", "TTYPE", "TFORM", NULL};
    46 
    47 // List of FITS header keys to be written with fits_write_comment
     48static const char *noWriteFitsKeyStarts[] = {"NAXIS", "TTYPE", "TFORM", NULL};
     49
     50// List of FITS header keys that may be present if the header is considered "empty"; NULL-terminated
     51static const char *emptyKeys[] = { "SIMPLE", "BITPIX", "NAXIS", "EXTEND", "COMMENT", "CHECKSUM", "DATASUM",
     52                                   NULL };
     53
     54// Compare a keyword with a list of keywords; return true if it's in the list
     55static bool keywordInList(const char *keyword, // Keyword to check
     56                          const char **list // List of keywords
     57    )
     58{
     59    for (const char **check = list; *check; *check++) {
     60        if (strcmp(keyword, *check) == 0) {
     61            return true;
     62        }
     63    }
     64    return false;
     65}
     66
     67
     68bool psFitsEmptyPHU(const psFits *fits, const psMetadata *header)
     69{
     70    PS_ASSERT_PTR_NON_NULL(fits, false);
     71    PS_ASSERT_METADATA_NON_NULL(header, false);
     72
     73    int hduNum = 0;                     // Which HDU we're at
     74    fits_get_hdu_num(fits->fd, &hduNum);  /* Get the current output HDU position */
     75
     76    if (hduNum != 1) {
     77        // It's not the PHU, so it can't be an empty PHU!
     78        return false;
     79    }
     80
     81    if (header->list->n == 0) {
     82        // There's nothing in the list
     83        return true;
     84    }
     85
     86    // Check if it's got any keywords of potential interest
     87    psMetadataIterator *iter = psMetadataIteratorAlloc(header, PS_LIST_HEAD, NULL); // Iterator
     88    psMetadataItem *item;               // Item from iteration
     89    while ((item = psMetadataGetAndIncrement(iter))) {
     90        if (!keywordInList(item->name, emptyKeys)) {
     91            psFree(iter);
     92            return false;
     93        }
     94    }
     95
     96    return true;
     97}
     98
    4899
    49100psMetadata* psFitsReadHeader(psMetadata* out,
     
    74125
    75126        // Check to see if the keyword should be ignored
    76         bool ignoreKey = false;         // Ignore this keyword?
    77         for (int i = 0; ignoreFitsKeys[i] && !ignoreKey; i++) {
    78             if (strcmp(keyName, ignoreFitsKeys[i]) == 0) {
    79                 ignoreKey = true;
    80             }
    81         }
    82         if (ignoreKey) {
     127        if (keywordInList(keyName, ignoreFitsKeys)) {
    83128            // We're done here; skip to the next key
    84129            continue;
    85130        }
    86131
    87 #if 0
    88         // This doesn't seem to be necessary
    89         if (strncmp(keyName, "HIERARCH ", 9) == 0) {
    90             char temp[MAX_STRING_LENGTH];
    91             strcpy(temp, &keyName[9]);
    92             strcpy(keyName, temp);
    93         }
    94 #endif
    95 
    96132        // Check to see if the keyword should be duplicated
    97133        int dupFlag = 0;                // Duplicate flag
    98         for (int i = 0; duplicateFitsKeys[i] && !dupFlag; i++) {
    99             if (strcmp(keyName, duplicateFitsKeys[i]) == 0) {
    100                 dupFlag = PS_META_DUPLICATE_OK;
    101             }
     134        if (keywordInList(keyName, duplicateFitsKeys)) {
     135            dupFlag = PS_META_DUPLICATE_OK;
    102136        }
    103137
     
    279313            // image, the NAXISn haven't been changed; or after converting to F32, the BITPIX hasn't been
    280314            // changed) so we'll take care of that for them.
    281             bool writeKey = true;           // Should we write this keyword?
    282             for (int i = 0; noWriteFitsKeys[i] && writeKey; i++) {
    283                 if (strcmp(item->name, noWriteFitsKeys[i]) == 0) {
    284                     writeKey = false;
    285                 }
    286             }
    287             if (!writeKey) {
     315            if (keywordInList(item->name, noWriteFitsKeys)) {
    288316                // Don't write it; skip to the next key
    289317                continue;
     
    294322                // that go in are correct.  However, when we're writing a "blank" HDU (header only), we want
    295323                // to preserve NAXISn etc for reference, so we don't do this.
     324                bool writeKey = true;   // Write this keyword?
    296325                for (int i = 0; noWriteFitsKeyStarts[i] && writeKey; i++) {
    297326                    if (strncmp(item->name, noWriteFitsKeyStarts[i], strlen(noWriteFitsKeyStarts[i])) == 0) {
  • branches/pap_branch_070920/psLib/src/fits/psFitsHeader.h

    r11248 r14985  
    44 * @author Robert DeSonia, MHPCC
    55 *
    6  * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    7  * @date $Date: 2007-01-23 22:47:23 $
     6 * @version $Revision: 1.10.14.1 $ $Name: not supported by cvs2svn $
     7 * @date $Date: 2007-09-22 03:08:05 $
    88 *
    99 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1818#include "psFits.h"
    1919#include "psMetadata.h"
     20
     21/// Determines whether the current HDU is an empty PHU
     22bool psFitsEmptyPHU(const psFits *fits, ///< FITS file pointer
     23                    const psMetadata *header ///< Header
     24    );
     25
    2026
    2127/** Reads the header of the current HDU.
Note: See TracChangeset for help on using the changeset viewer.