Index: /trunk/Ohana/src/libfits/header/F_modify.c
===================================================================
--- /trunk/Ohana/src/libfits/header/F_modify.c	(revision 3368)
+++ /trunk/Ohana/src/libfits/header/F_modify.c	(revision 3369)
@@ -1,4 +1,5 @@
 # include "fits.h"
 
+char *fits_keyword_start (char *line);
 char *fits_keyword_end (char *line);
 void pad_ending (char *line, char value, int Nbyte);
@@ -98,4 +99,24 @@
 }
 
+/* given a FITS card line, return pointer to the start of the data area */
+char *fits_keyword_start (char *line) {
+
+  int done;
+  char *c;
+
+  /* find the end of the existing data region */
+  c = line + 8;
+  if (*c != '=') return (c);  /* no data in COMMENT field */
+  
+  c += 2;
+  /* advance pointer over whitespace */
+  while ((*c == ' ') && (c < line + 80)) { c++; }
+  
+  /* skip one quote mark */
+  if ((*c == 0x27) && (c < line + 80)) { c++; }
+
+  return (c);
+}
+
 /* given a FITS card line, return pointer to the end of the data area */
 char *fits_keyword_end (char *line) {
@@ -105,8 +126,11 @@
 
   /* find the end of the existing data region */
-  c2 = line + 8;
-  if (*c2 != '=') return (c2);  /* no data in COMMENT field */
+  c1 = line + 8;
+  if (*c1 != '=') return (c1);  /* no data in COMMENT field */
+  c1 += 2;
+
+  /* advance pointer over whitespace */
+  while ((*c1 == ' ') && (c1 < line + 80)) { c1++; }
   
-  c1 = c2 + 2;
   if (c1[0] == 0x27) { /* entry a string, skip over 'fred' */
     for (done = FALSE, c2 = c1 + 1; !done && (c2 < line + 80); c2++) {
@@ -116,5 +140,5 @@
       }
       if (c2[0] == 0x27) {
-	c1 = c2 + 1;
+	c1 = c2;
 	done = TRUE;
       }
@@ -124,5 +148,4 @@
     }
   } else {
-    while ((*c1 == ' ') && (c1 < line + 80)) c1++;
     while ((*c1 != ' ') && (c1 < line + 80)) c1++;
   }
Index: /trunk/Ohana/src/libfits/header/F_scan.c
===================================================================
--- /trunk/Ohana/src/libfits/header/F_scan.c	(revision 3368)
+++ /trunk/Ohana/src/libfits/header/F_scan.c	(revision 3369)
@@ -1,3 +1,6 @@
 # include "fits.h"
+
+char *fits_keyword_start (char *line);
+char *fits_keyword_end (char *line);
 
 int fits_scan (Header *header, char *field, char *mode, int N,...) {
@@ -14,5 +17,5 @@
 int fits_vscan (Header *header, char *field, char *mode, int N, va_list argp) {
 
-  char *p, *q, tmp[81];
+  char *p, *q, *s, tmp[81];
   int Nchar;
   double value;
@@ -25,5 +28,5 @@
   if (!strcmp (mode, "%S")) {
     strncpy (va_arg (argp, char *), p + 8, FT_HISTORY_LENGTH);
-    goto gotvalue;
+    return (TRUE);
   }
 
@@ -40,54 +43,50 @@
     fits_stripwhite (tmp);
     strcpy (va_arg (argp, char *), tmp);
-    goto gotvalue;
+    return (TRUE);
   }
 
   /* extract data into char array (exclude containing ' chars) */
   if (!strcmp (mode, "%s")) {
-    q = fits_keyword_end (p);
-    q -= 1;
-    p += 10;
+    s = fits_keyword_start (p); /* points at first char (not ') */
+    q = fits_keyword_end (p); /* points at following space or ' */
 
-    /* exclude containing ' chars, if they exist */
-    /* we are not requiring a string entry to have the quotes */
-    if (*p == 0x27) p++;
-    if (*q == 0x27) q--;
-
-    Nchar = MAX (0, (q - p + 1));
+    Nchar = MAX (0, (q - s));
     bzero (tmp, 81);
-    memcpy (tmp, p, Nchar);
+    memcpy (tmp, s, Nchar);
     fits_stripwhite (tmp);
     strcpy (va_arg (argp, char *), tmp);
-    goto gotvalue;
+    return (TRUE);
   }
   
   /* boolean data, requires int target */
   if (!strcmp (mode, "%t")) {
-    if (p[29]  == 'T') 
+    s = fits_keyword_start (p);
+    if (*s == 'T') {
       *va_arg (argp, int *) = TRUE;
-    if (p[29]  == 'F') 
+      return (TRUE);
+    }
+    if (*s == 'F') {
       *va_arg (argp, int *) = FALSE;   
-    goto gotvalue;
+      return (TRUE);
+    }
   }
 
   /* remaining options are numerical data */
   /* need to interpret 1.0d5 as 1.0e5 */
-  if (p[10] == 0x27) p++;  /** skip over initial ' (SOME BAD sources write floats with '') **/
-  value = strtod (p + 10, &q);
+  s = fits_keyword_start (p); /* points at first char (not ') */
+  q = fits_keyword_end (p); /* points at following space or ' */
+  value = strtod (s, &q);
   if ((*q == 'd') || (*q == 'D')) 
     value *= pow (10.0, atof (q + 1));
 
-  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; goto gotvalue; }
-  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; goto gotvalue; }
-  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; goto gotvalue; }
-  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; goto gotvalue; }
-  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; goto gotvalue; }
-  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; goto gotvalue; }
+  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; return (TRUE); }
+  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; return (TRUE); }
+  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; return (TRUE); }
+  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; return (TRUE); }
+  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; return (TRUE); }
+  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; return (TRUE); }
 
   /* no valid mode found */
   return (FALSE);
-
- gotvalue:
-  return (TRUE);
 }
 
