IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2010, 11:22:25 AM (16 years ago)
Author:
eugene
Message:

large update merging in changes for Ohana to support large files

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libfits/header/F_scan.c

    r21059 r27435  
    22# include <gfitsio.h>
    33
     4// this only scans the regular and non-boolean fields
    45int gfits_scan (Header *header, char *field, char *mode, int N,...) {
    56
     
    1314}
    1415 
     16// alternate version for the special types (boolean, comments, COMMENT)
     17int 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
    1529int gfits_vscan (Header *header, char *field, char *mode, int N, va_list argp) {
    1630
    1731  char *p, *q, *s, tmp[81];
    1832  int Nchar, status;
    19   double value;
     33  long long value;
     34  double fvalue;
    2035 
    2136  /* find the correct line with field */
     
    2641  }
    2742
     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)
     91int 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
    28103  /* non-data entry (COMMENT, HISTORY) */
    29104  if (!strcmp (mode, "%S")) {
     
    47122  }
    48123
    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  
    62124  /* boolean data, requires int target */
    63125  if (!strcmp (mode, "%t")) {
     
    73135  }
    74136
    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 
    90137  /* no valid mode found */
    91138  return (FALSE);
     
    97144  char *p, *q, *s, tmp[81];
    98145  int Nchar, Nfield;
    99   double value;
     146  long long value;
     147  double fvalue;
    100148 
    101149  /* find the correct line with field */
     
    156204  s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */
    157205  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); }
    168228
    169229  /* no valid mode found */
Note: See TracChangeset for help on using the changeset viewer.