Changeset 3369
- Timestamp:
- Mar 2, 2005, 6:02:44 PM (21 years ago)
- Location:
- trunk/Ohana/src/libfits/header
- Files:
-
- 2 edited
-
F_modify.c (modified) (5 diffs)
-
F_scan.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/header/F_modify.c
r2415 r3369 1 1 # include "fits.h" 2 2 3 char *fits_keyword_start (char *line); 3 4 char *fits_keyword_end (char *line); 4 5 void pad_ending (char *line, char value, int Nbyte); … … 98 99 } 99 100 101 /* given a FITS card line, return pointer to the start of the data area */ 102 char *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 100 121 /* given a FITS card line, return pointer to the end of the data area */ 101 122 char *fits_keyword_end (char *line) { … … 105 126 106 127 /* 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++; } 109 134 110 c1 = c2 + 2;111 135 if (c1[0] == 0x27) { /* entry a string, skip over 'fred' */ 112 136 for (done = FALSE, c2 = c1 + 1; !done && (c2 < line + 80); c2++) { … … 116 140 } 117 141 if (c2[0] == 0x27) { 118 c1 = c2 + 1;142 c1 = c2; 119 143 done = TRUE; 120 144 } … … 124 148 } 125 149 } else { 126 while ((*c1 == ' ') && (c1 < line + 80)) c1++;127 150 while ((*c1 != ' ') && (c1 < line + 80)) c1++; 128 151 } -
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.
