Changeset 3369 for trunk/Ohana/src/libfits/header/F_scan.c
- Timestamp:
- Mar 2, 2005, 6:02:44 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libfits/header/F_scan.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/header/F_scan.c
r2766 r3369 1 1 # include "fits.h" 2 3 char *fits_keyword_start (char *line); 4 char *fits_keyword_end (char *line); 2 5 3 6 int fits_scan (Header *header, char *field, char *mode, int N,...) { … … 14 17 int fits_vscan (Header *header, char *field, char *mode, int N, va_list argp) { 15 18 16 char *p, *q, tmp[81];19 char *p, *q, *s, tmp[81]; 17 20 int Nchar; 18 21 double value; … … 25 28 if (!strcmp (mode, "%S")) { 26 29 strncpy (va_arg (argp, char *), p + 8, FT_HISTORY_LENGTH); 27 goto gotvalue;30 return (TRUE); 28 31 } 29 32 … … 40 43 fits_stripwhite (tmp); 41 44 strcpy (va_arg (argp, char *), tmp); 42 goto gotvalue;45 return (TRUE); 43 46 } 44 47 45 48 /* extract data into char array (exclude containing ' chars) */ 46 49 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 ' */ 50 52 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)); 57 54 bzero (tmp, 81); 58 memcpy (tmp, p, Nchar);55 memcpy (tmp, s, Nchar); 59 56 fits_stripwhite (tmp); 60 57 strcpy (va_arg (argp, char *), tmp); 61 goto gotvalue;58 return (TRUE); 62 59 } 63 60 64 61 /* boolean data, requires int target */ 65 62 if (!strcmp (mode, "%t")) { 66 if (p[29] == 'T') 63 s = fits_keyword_start (p); 64 if (*s == 'T') { 67 65 *va_arg (argp, int *) = TRUE; 68 if (p[29] == 'F') 66 return (TRUE); 67 } 68 if (*s == 'F') { 69 69 *va_arg (argp, int *) = FALSE; 70 goto gotvalue; 70 return (TRUE); 71 } 71 72 } 72 73 73 74 /* remaining options are numerical data */ 74 75 /* 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); 77 79 if ((*q == 'd') || (*q == 'D')) 78 80 value *= pow (10.0, atof (q + 1)); 79 81 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); } 86 88 87 89 /* no valid mode found */ 88 90 return (FALSE); 89 90 gotvalue:91 return (TRUE);92 91 } 93 92
Note:
See TracChangeset
for help on using the changeset viewer.
