Index: trunk/psLib/src/fits/psFitsHeader.c
===================================================================
--- trunk/psLib/src/fits/psFitsHeader.c	(revision 6767)
+++ trunk/psLib/src/fits/psFitsHeader.c	(revision 6883)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-04 19:52:42 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-18 18:58:41 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -132,23 +132,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';
-                    success = psMetadataAdd(out,
-                                            PS_LIST_TAIL,
-                                            keyName,
-                                            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);
+            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
+                    }
+                    break;
                 }
-                break;
             case 'L':
                 tempBool = (keyValue[0] == 'T') ? 1 : 0;
