Index: /branches/eam_rel9_b1/psLib/src/fits/psFitsHeader.c
===================================================================
--- /branches/eam_rel9_b1/psLib/src/fits/psFitsHeader.c	(revision 6880)
+++ /branches/eam_rel9_b1/psLib/src/fits/psFitsHeader.c	(revision 6881)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-11-14 22:18:30 $
+ *  @version $Revision: 1.1.6.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-18 03:40:44 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -110,8 +110,22 @@
                                         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
+                    char *lastSpace = NULL; // The last space in the string
+                    while (strlen(keyValueFixed) > 1 && (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 +133,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;
