IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 18, 2006, 8:58:41 AM (20 years ago)
Author:
Paul Price
Message:

Remove trailing spaces from string header values.

File:
1 edited

Legend:

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

    r6767 r6883  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-04-04 19:52:42 $
     9 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-04-18 18:58:41 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    132132                                        atof(keyValue));
    133133                break;
    134             case 'C':
    135                 // remove the single-quotes at front/end
    136                 if (keyValue[0] == '\'' && keyValue[strlen(keyValue)-1] == '\'') {
    137                     keyValue[strlen(keyValue)-1] = '\0';
    138                     success = psMetadataAdd(out,
    139                                             PS_LIST_TAIL,
    140                                             keyName,
    141                                             PS_DATA_STRING | PS_META_DUPLICATE_OK,
    142                                             keyComment,
    143                                             keyValue+1);
    144                 } else {
    145                     success = psMetadataAdd(out,
    146                                             PS_LIST_TAIL,
    147                                             keyName,
    148                                             PS_DATA_STRING | PS_META_DUPLICATE_OK,
    149                                             keyComment,
    150                                             keyValue);
     134            case 'C': {
     135                    char *keyValueFixed = keyValue; // Fixed version of the string
     136                    // remove the single-quotes at front/end
     137                    if (keyValueFixed[0] == '\'' && keyValueFixed[strlen(keyValue)-1] == '\'') {
     138                        keyValue[strlen(keyValue)-1] = '\0'; // Remove the trailing quote
     139                        keyValueFixed += 1; // Advance past the leading quote
     140                    }
     141                    // Remove trailing spaces, which are not significant, according to the FITS standard
     142                    // http://archive.stsci.edu/fits/fits_standard/node31.html
     143                    char *lastSpace = NULL; // The last space in the string
     144                    while (strlen(keyValueFixed) > 1 && (lastSpace = strrchr(keyValueFixed, ' ')) &&
     145                            lastSpace[1] == '\0') {
     146                        // This is a trailing space, not a leading space.
     147                        lastSpace[0] = '\0'; // Truncate the string here
     148                    }
     149                    break;
    151150                }
    152                 break;
    153151            case 'L':
    154152                tempBool = (keyValue[0] == 'T') ? 1 : 0;
Note: See TracChangeset for help on using the changeset viewer.