IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3369


Ignore:
Timestamp:
Mar 2, 2005, 6:02:44 PM (21 years ago)
Author:
eugene
Message:

cleaned handling of single quotes

Location:
trunk/Ohana/src/libfits/header
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/header/F_modify.c

    r2415 r3369  
    11# include "fits.h"
    22
     3char *fits_keyword_start (char *line);
    34char *fits_keyword_end (char *line);
    45void pad_ending (char *line, char value, int Nbyte);
     
    9899}
    99100
     101/* given a FITS card line, return pointer to the start of the data area */
     102char *fits_keyword_start (char *line) {
     103
     104  int done;
     105  char *c;
     106
     107  /* find the end of the existing data region */
     108  c = line + 8;
     109  if (*c != '=') return (c);  /* no data in COMMENT field */
     110 
     111  c += 2;
     112  /* advance pointer over whitespace */
     113  while ((*c == ' ') && (c < line + 80)) { c++; }
     114 
     115  /* skip one quote mark */
     116  if ((*c == 0x27) && (c < line + 80)) { c++; }
     117
     118  return (c);
     119}
     120
    100121/* given a FITS card line, return pointer to the end of the data area */
    101122char *fits_keyword_end (char *line) {
     
    105126
    106127  /* find the end of the existing data region */
    107   c2 = line + 8;
    108   if (*c2 != '=') return (c2);  /* no data in COMMENT field */
     128  c1 = line + 8;
     129  if (*c1 != '=') return (c1);  /* no data in COMMENT field */
     130  c1 += 2;
     131
     132  /* advance pointer over whitespace */
     133  while ((*c1 == ' ') && (c1 < line + 80)) { c1++; }
    109134 
    110   c1 = c2 + 2;
    111135  if (c1[0] == 0x27) { /* entry a string, skip over 'fred' */
    112136    for (done = FALSE, c2 = c1 + 1; !done && (c2 < line + 80); c2++) {
     
    116140      }
    117141      if (c2[0] == 0x27) {
    118         c1 = c2 + 1;
     142        c1 = c2;
    119143        done = TRUE;
    120144      }
     
    124148    }
    125149  } else {
    126     while ((*c1 == ' ') && (c1 < line + 80)) c1++;
    127150    while ((*c1 != ' ') && (c1 < line + 80)) c1++;
    128151  }
  • trunk/Ohana/src/libfits/header/F_scan.c

    r2766 r3369  
    11# include "fits.h"
     2
     3char *fits_keyword_start (char *line);
     4char *fits_keyword_end (char *line);
    25
    36int fits_scan (Header *header, char *field, char *mode, int N,...) {
     
    1417int fits_vscan (Header *header, char *field, char *mode, int N, va_list argp) {
    1518
    16   char *p, *q, tmp[81];
     19  char *p, *q, *s, tmp[81];
    1720  int Nchar;
    1821  double value;
     
    2528  if (!strcmp (mode, "%S")) {
    2629    strncpy (va_arg (argp, char *), p + 8, FT_HISTORY_LENGTH);
    27     goto gotvalue;
     30    return (TRUE);
    2831  }
    2932
     
    4043    fits_stripwhite (tmp);
    4144    strcpy (va_arg (argp, char *), tmp);
    42     goto gotvalue;
     45    return (TRUE);
    4346  }
    4447
    4548  /* extract data into char array (exclude containing ' chars) */
    4649  if (!strcmp (mode, "%s")) {
    47     q = fits_keyword_end (p);
    48     q -= 1;
    49     p += 10;
     50    s = fits_keyword_start (p); /* points at first char (not ') */
     51    q = fits_keyword_end (p); /* points at following space or ' */
    5052
    51     /* exclude containing ' chars, if they exist */
    52     /* we are not requiring a string entry to have the quotes */
    53     if (*p == 0x27) p++;
    54     if (*q == 0x27) q--;
    55 
    56     Nchar = MAX (0, (q - p + 1));
     53    Nchar = MAX (0, (q - s));
    5754    bzero (tmp, 81);
    58     memcpy (tmp, p, Nchar);
     55    memcpy (tmp, s, Nchar);
    5956    fits_stripwhite (tmp);
    6057    strcpy (va_arg (argp, char *), tmp);
    61     goto gotvalue;
     58    return (TRUE);
    6259  }
    6360 
    6461  /* boolean data, requires int target */
    6562  if (!strcmp (mode, "%t")) {
    66     if (p[29]  == 'T')
     63    s = fits_keyword_start (p);
     64    if (*s == 'T') {
    6765      *va_arg (argp, int *) = TRUE;
    68     if (p[29]  == 'F')
     66      return (TRUE);
     67    }
     68    if (*s == 'F') {
    6969      *va_arg (argp, int *) = FALSE;   
    70     goto gotvalue;
     70      return (TRUE);
     71    }
    7172  }
    7273
    7374  /* remaining options are numerical data */
    7475  /* need to interpret 1.0d5 as 1.0e5 */
    75   if (p[10] == 0x27) p++;  /** skip over initial ' (SOME BAD sources write floats with '') **/
    76   value = strtod (p + 10, &q);
     76  s = fits_keyword_start (p); /* points at first char (not ') */
     77  q = fits_keyword_end (p); /* points at following space or ' */
     78  value = strtod (s, &q);
    7779  if ((*q == 'd') || (*q == 'D'))
    7880    value *= pow (10.0, atof (q + 1));
    7981
    80   if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; goto gotvalue; }
    81   if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; goto gotvalue; }
    82   if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; goto gotvalue; }
    83   if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; goto gotvalue; }
    84   if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; goto gotvalue; }
    85   if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; goto gotvalue; }
     82  if (!strcmp (mode, "%d"))  { *va_arg (argp, int *)       = value; return (TRUE); }
     83  if (!strcmp (mode, "%u"))  { *va_arg (argp, unsigned *)  = value; return (TRUE); }
     84  if (!strcmp (mode, "%ld")) { *va_arg (argp, long *)      = value; return (TRUE); }
     85  if (!strcmp (mode, "%hd")) { *va_arg (argp, short *)     = value; return (TRUE); }
     86  if (!strcmp (mode, "%f"))  { *va_arg (argp, float *)     = value; return (TRUE); }
     87  if (!strcmp (mode, "%lf")) { *va_arg (argp, double *)    = value; return (TRUE); }
    8688
    8789  /* no valid mode found */
    8890  return (FALSE);
    89 
    90  gotvalue:
    91   return (TRUE);
    9291}
    9392
Note: See TracChangeset for help on using the changeset viewer.