IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15174


Ignore:
Timestamp:
Oct 3, 2007, 10:16:49 AM (19 years ago)
Author:
Paul Price
Message:

An 'empty' PHU may have up to and including 8 keywords.

File:
1 edited

Legend:

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

    r15168 r15174  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.34.4.5 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-10-03 03:01:45 $
     9 *  @version $Revision: 1.34.4.6 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-10-03 20:16:49 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    7272    PS_ASSERT_FITS_NON_NULL(fits, false);
    7373
    74     if (!fits->compression) {
     74    if (!fits->compConvention) {
    7575        // User has turned off compression conventions; doesn't want any nasty surprises
    7676        return false;
     
    9090    int status = 0;                     // CFITSIO status
    9191    fits_get_hdrspace(fits->fd, &numKeys, 0, &status);
    92     if (numKeys >= NUM_EMPTY_KEYS) {
     92    if (numKeys > NUM_EMPTY_KEYS) {
    9393        return false;
    9494    }
     
    140140
    141141    return false;
     142}
     143
     144char *p_psFitsHeaderParseString(char *string)
     145{
     146    if (!string || strlen(string) == 0) {
     147        return string;
     148    }
     149
     150    char *fixed = string;       // Fixed version of the string
     151    // remove the single-quotes at front/end
     152    if (fixed[0] == '\'' && fixed[strlen(string)-1] == '\'') {
     153        string[strlen(string)-1] = '\0'; // Remove the trailing quote
     154        fixed += 1; // Advance past the leading quote
     155    }
     156    // Remove trailing spaces, which are not significant, according to the FITS standard
     157    // http://archive.stsci.edu/fits/fits_standard/node31.html
     158    char *lastSpace = NULL; // The last space in the string
     159    while (strlen(fixed) > 1 && (lastSpace = strrchr(fixed, ' ')) && lastSpace[1] == '\0') {
     160        // This is a trailing space, not a leading space.
     161        lastSpace[0] = '\0'; // Truncate the string here
     162    }
     163
     164    return fixed;
    142165}
    143166
     
    217240            break;
    218241        case 'C': {
    219                 char *keyValueFixed = keyValue; // Fixed version of the string
    220                 // remove the single-quotes at front/end
    221                 if (keyValueFixed[0] == '\'' && keyValueFixed[strlen(keyValue)-1] == '\'') {
    222                     keyValue[strlen(keyValue)-1] = '\0'; // Remove the trailing quote
    223                     keyValueFixed += 1; // Advance past the leading quote
    224                 }
    225                 // Remove trailing spaces, which are not significant, according to the FITS standard
    226                 // http://archive.stsci.edu/fits/fits_standard/node31.html
    227                 char *lastSpace = NULL; // The last space in the string
    228                 while (strlen(keyValueFixed) > 1 && (lastSpace = strrchr(keyValueFixed, ' ')) &&
    229                         lastSpace[1] == '\0') {
    230                     // This is a trailing space, not a leading space.
    231                     lastSpace[0] = '\0'; // Truncate the string here
    232                 }
    233 
    234                 // Need to trap NAN, INF and -INF written by psFitsWriteHeader.
    235                 // cfitsio won't write these, so we write them as strings, and then have to trap them on read.
    236                 if (strcasecmp(keyValueFixed, "NAN") == 0) {
    237                     success = psMetadataAddF32(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, NAN);
    238                 } else if (strcasecmp(keyValueFixed, "INF") == 0) {
    239                     success = psMetadataAddF32(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, INFINITY);
    240                 } else if (strcasecmp(keyValueFixed, "-INF") == 0) {
    241                     success = psMetadataAddF32(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, -INFINITY);
    242                 } else {
    243                     success = psMetadataAddStr(header, PS_LIST_TAIL, keyName, dupFlag, keyComment,
    244                                                keyValueFixed);
    245                 }
    246                 break;
     242            char *keyValueFixed = p_psFitsHeaderParseString(keyValue); // Fixed version of the string
     243
     244            // Need to trap NAN, INF and -INF written by psFitsWriteHeader.
     245            // cfitsio won't write these, so we write them as strings, and then have to trap them on read.
     246            if (strcasecmp(keyValueFixed, "NAN") == 0) {
     247                success = psMetadataAddF32(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, NAN);
     248            } else if (strcasecmp(keyValueFixed, "INF") == 0) {
     249                success = psMetadataAddF32(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, INFINITY);
     250            } else if (strcasecmp(keyValueFixed, "-INF") == 0) {
     251                success = psMetadataAddF32(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, -INFINITY);
     252            } else if (!fits->compConvention ||
     253                       (strcmp(keyName, "EXTNAME") != 0 || strcmp(keyValueFixed, "COMPRESSED_IMAGE") != 0)) {
     254                // Ignore EXTNAME=COMPRESSED_IMAGE if compression convention is to be respected
     255                success = psMetadataAddStr(header, PS_LIST_TAIL, keyName, dupFlag, keyComment,
     256                                           keyValueFixed);
    247257            }
     258            break;
     259        }
    248260        case 'L': {
    249                 bool temp = (keyValue[0] == 'T') ? 1 : 0;
    250                 success = psMetadataAddBool(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, temp);
    251                 break;
    252             }
     261            bool temp = (keyValue[0] == 'T') ? 1 : 0;
     262            success = psMetadataAddBool(header, PS_LIST_TAIL, keyName, dupFlag, keyComment, temp);
     263            break;
     264        }
    253265        default:
    254266            psError(PS_ERR_IO, true, _("Specified FITS metadata type, %c, is not supported."), keyType);
Note: See TracChangeset for help on using the changeset viewer.