Index: /branches/rel10_ifa/psLib/src/fits/psFitsHeader.c
===================================================================
--- /branches/rel10_ifa/psLib/src/fits/psFitsHeader.c	(revision 6596)
+++ /branches/rel10_ifa/psLib/src/fits/psFitsHeader.c	(revision 6597)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-02-08 01:03:34 $
+ *  @version $Revision: 1.2.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-16 01:00:42 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -110,8 +110,21 @@
                                         atof(keyValue));
                 break;
-            case 'C':
-                // remove the single-quotes at front/end
-                if (keyValue[0] == '\'' && keyValue[strlen(keyValue)-1] == '\'') {
-                    keyValue[strlen(keyValue)-1] = '\0';
+            case 'C': {
+                    char *keyValueFixed = keyValue; // Fixed version of the string
+                    // remove the single-quotes at front/end
+                    if (keyValueFixed[0] == '\'' && keyValueFixed[strlen(keyValue)-1] == '\'') {
+                        keyValue[strlen(keyValue)-1] = '\0'; // Remove the trailing quote
+                        keyValueFixed += 1; // Advance past the leading quote
+                    }
+                    // Remove trailing spaces, which are not significant, according to the FITS standard
+                    // http://archive.stsci.edu/fits/fits_standard/node31.html#SECTION00921000000000000000
+                    char *lastSpace = NULL; // The last space in the string
+                    while ((lastSpace = strrchr(keyValueFixed, ' ')) && lastSpace[1] == '\0') {
+                        // This is a trailing space, not a leading space.
+                        lastSpace[0] = '\0'; // Truncate the string here
+                    }
+
+                    psTrace("pslib.fits.readHeader", 8, "%s: %s (%s)\n", keyName, keyValueFixed, keyComment);
+
                     success = psMetadataAdd(out,
                                             PS_LIST_TAIL,
@@ -119,14 +132,7 @@
                                             PS_DATA_STRING | PS_META_DUPLICATE_OK,
                                             keyComment,
-                                            keyValue+1);
-                } else {
-                    success = psMetadataAdd(out,
-                                            PS_LIST_TAIL,
-                                            keyName,
-                                            PS_DATA_STRING | PS_META_DUPLICATE_OK,
-                                            keyComment,
-                                            keyValue);
+                                            keyValueFixed);
+                    break;
                 }
-                break;
             case 'L':
                 tempBool = (keyValue[0] == 'T') ? 1 : 0;
