Changeset 27838 for branches/tap_branches/Ohana/src/libfits/header/F_scan.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/Ohana
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/Ohana merged eligible /branches/eam_branches/Ohana.20100407 27635-27772 /branches/pap_delete/Ohana 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/Ohana/src/libfits/header/F_scan.c
r21059 r27838 2 2 # include <gfitsio.h> 3 3 4 // this only scans the regular and non-boolean fields 4 5 int gfits_scan (Header *header, char *field, char *mode, int N,...) { 5 6 … … 13 14 } 14 15 16 // alternate version for the special types (boolean, comments, COMMENT) 17 int gfits_scan_alt (Header *header, char *field, char *mode, int N,...) { 18 19 int status; 20 va_list argp; 21 22 va_start (argp, N); 23 status = gfits_vscan_alt (header, field, mode, N, argp); 24 va_end (argp); 25 return (status); 26 } 27 28 // this only scans the regular and non-boolean fields 15 29 int gfits_vscan (Header *header, char *field, char *mode, int N, va_list argp) { 16 30 17 31 char *p, *q, *s, tmp[81]; 18 32 int Nchar, status; 19 double value; 33 long long value; 34 double fvalue; 20 35 21 36 /* find the correct line with field */ … … 26 41 } 27 42 43 /* all others require '=' in column 8 */ 44 if (p[8] != '=') return (FALSE); 45 46 /* extract data into char array (exclude containing ' chars) */ 47 if (!strcmp (mode, "%s")) { 48 s = gfits_keyword_start (p); /* points at first char (not ') */ 49 q = gfits_keyword_end (p); /* points at following space or ' */ 50 51 Nchar = MAX (0, (q - s)); 52 bzero (tmp, 81); 53 memcpy (tmp, s, Nchar); 54 stripwhite (tmp); 55 strcpy (va_arg (argp, char *), tmp); 56 return (TRUE); 57 } 58 59 /* remaining options are numerical data */ 60 /* need to interpret 1.0d5 as 1.0e5 */ 61 s = gfits_keyword_start (p); /* points at first char (not ') */ 62 q = gfits_keyword_end (p); /* points at following space or ' */ 63 64 if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) { 65 fvalue = strtod (s, &q); 66 if ((*q == 'd') || (*q == 'D')) 67 fvalue *= pow (10.0, atof (q + 1)); 68 69 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = fvalue; return (TRUE); } 70 if (!strcmp (mode, "%lf")) { *va_arg (argp, double *) = fvalue; return (TRUE); } 71 } 72 73 value = strtoll (s, &q, 0); 74 if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1)); 75 76 if (!strcmp (mode, "%d")) { *va_arg (argp, int *) = value; return (TRUE); } 77 if (!strcmp (mode, "%ld")) { *va_arg (argp, long *) = value; return (TRUE); } 78 if (!strcmp (mode, "%lld")) { *va_arg (argp, long long *) = value; return (TRUE); } 79 if (!strcmp (mode, "%Ld")) { *va_arg (argp, long long *) = value; return (TRUE); } 80 if (!strcmp (mode, "%u")) { *va_arg (argp, unsigned *) = value; return (TRUE); } 81 if (!strcmp (mode, "%lu")) { *va_arg (argp, unsigned long *) = value; return (TRUE); } 82 if (!strcmp (mode, "%llu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); } 83 if (!strcmp (mode, "%Lu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); } 84 if (!strcmp (mode, "%hd")) { *va_arg (argp, short *) = value; return (TRUE); } 85 86 /* no valid mode found */ 87 return (FALSE); 88 } 89 90 // alternate version for the special types (boolean, comments, COMMENT) 91 int gfits_vscan_alt (Header *header, char *field, char *mode, int N, va_list argp) { 92 93 char *p, *q, *s, tmp[81]; 94 int Nchar, status; 95 96 /* find the correct line with field */ 97 p = gfits_header_field (header, field, N); 98 if (p == NULL) { 99 status = gfits_vscan_hierarch (header, field, mode, N, argp); 100 return (status); 101 } 102 28 103 /* non-data entry (COMMENT, HISTORY) */ 29 104 if (!strcmp (mode, "%S")) { … … 47 122 } 48 123 49 /* extract data into char array (exclude containing ' chars) */50 if (!strcmp (mode, "%s")) {51 s = gfits_keyword_start (p); /* points at first char (not ') */52 q = gfits_keyword_end (p); /* points at following space or ' */53 54 Nchar = MAX (0, (q - s));55 bzero (tmp, 81);56 memcpy (tmp, s, Nchar);57 stripwhite (tmp);58 strcpy (va_arg (argp, char *), tmp);59 return (TRUE);60 }61 62 124 /* boolean data, requires int target */ 63 125 if (!strcmp (mode, "%t")) { … … 73 135 } 74 136 75 /* remaining options are numerical data */76 /* need to interpret 1.0d5 as 1.0e5 */77 s = gfits_keyword_start (p); /* points at first char (not ') */78 q = gfits_keyword_end (p); /* points at following space or ' */79 value = strtod (s, &q);80 if ((*q == 'd') || (*q == 'D'))81 value *= pow (10.0, atof (q + 1));82 83 if (!strcmp (mode, "%d")) { *va_arg (argp, int *) = value; return (TRUE); }84 if (!strcmp (mode, "%u")) { *va_arg (argp, unsigned *) = value; return (TRUE); }85 if (!strcmp (mode, "%ld")) { *va_arg (argp, long *) = value; return (TRUE); }86 if (!strcmp (mode, "%hd")) { *va_arg (argp, short *) = value; return (TRUE); }87 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = value; return (TRUE); }88 if (!strcmp (mode, "%lf")) { *va_arg (argp, double *) = value; return (TRUE); }89 90 137 /* no valid mode found */ 91 138 return (FALSE); … … 97 144 char *p, *q, *s, tmp[81]; 98 145 int Nchar, Nfield; 99 double value; 146 long long value; 147 double fvalue; 100 148 101 149 /* find the correct line with field */ … … 156 204 s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */ 157 205 q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */ 158 value = strtod (s, &q); 159 if ((*q == 'd') || (*q == 'D')) 160 value *= pow (10.0, atof (q + 1)); 161 162 if (!strcmp (mode, "%d")) { *va_arg (argp, int *) = value; return (TRUE); } 163 if (!strcmp (mode, "%u")) { *va_arg (argp, unsigned *) = value; return (TRUE); } 164 if (!strcmp (mode, "%ld")) { *va_arg (argp, long *) = value; return (TRUE); } 165 if (!strcmp (mode, "%hd")) { *va_arg (argp, short *) = value; return (TRUE); } 166 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = value; return (TRUE); } 167 if (!strcmp (mode, "%lf")) { *va_arg (argp, double *) = value; return (TRUE); } 206 207 if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) { 208 fvalue = strtod (s, &q); 209 if ((*q == 'd') || (*q == 'D')) 210 fvalue *= pow (10.0, atof (q + 1)); 211 212 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = fvalue; return (TRUE); } 213 if (!strcmp (mode, "%lf")) { *va_arg (argp, double *) = fvalue; return (TRUE); } 214 } 215 216 value = strtoll (s, &q, 0); 217 if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1)); 218 219 if (!strcmp (mode, "%d")) { *va_arg (argp, int *) = value; return (TRUE); } 220 if (!strcmp (mode, "%ld")) { *va_arg (argp, long *) = value; return (TRUE); } 221 if (!strcmp (mode, "%lld")) { *va_arg (argp, long long *) = value; return (TRUE); } 222 if (!strcmp (mode, "%Ld")) { *va_arg (argp, long long *) = value; return (TRUE); } 223 if (!strcmp (mode, "%u")) { *va_arg (argp, unsigned *) = value; return (TRUE); } 224 if (!strcmp (mode, "%lu")) { *va_arg (argp, unsigned long *) = value; return (TRUE); } 225 if (!strcmp (mode, "%llu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); } 226 if (!strcmp (mode, "%Lu")) { *va_arg (argp, unsigned long long *) = value; return (TRUE); } 227 if (!strcmp (mode, "%hd")) { *va_arg (argp, short *) = value; return (TRUE); } 168 228 169 229 /* no valid mode found */
Note:
See TracChangeset
for help on using the changeset viewer.
