IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 30, 2008, 10:01:42 AM (18 years ago)
Author:
eugene
Message:

add ability to read HIERARCH keywords if basic keyword is not found

File:
1 edited

Legend:

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

    r10073 r21059  
    11# include <ohana.h>
    22# include <gfitsio.h>
    3 
    4 char *gfits_keyword_start (char *line);
    5 char *gfits_keyword_end (char *line);
    6 void pad_ending (char *line, char value, int Nbyte);
    73
    84int gfits_modify (Header *header, char *field, char *mode, int N,...) {
     
    5147    strncpy (comment, qe, p + 80 - qe);
    5248  }
    53   pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
     49  gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
    5450
    5551  /* write the numeric modes */
     
    9692    strncpy (data, qs, MAX (MIN (qe - qs, 71), 0));
    9793    strncpy (comment, va_arg (argp, char *), 80);
    98     pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
     94    gfits_pad_ending (comment, ' ', 82);  /* comment must contain spaces to the end */
    9995    snprintf (string, 81, "%-8s= %s / %-s", field, data, comment);
    10096    /* this will keep the original line, but truncate the comment */
     
    156152  } else {
    157153    while ((*c1 != ' ') && (c1 < line + 80)) c1++;
     154  }
     155  return (c1);
     156}
     157
     158/* given a pointer to the FITS HIERARCH card field name, return pointer to the start of the data area */
     159char *gfits_hierarch_keyword_start (char *line, char *field) {
     160
     161  char *c;
     162
     163  /* find the end of the existing data region */
     164  c = line + strlen(field) + 1;
     165  if (*c != '=') return (c);  /* non-data fields are not allowed */
     166 
     167  c += 2;
     168  /* advance pointer over WHITESPACE */
     169  while ((*c == ' ') && (c < line + 71)) { c++; }
     170 
     171  /* skip one quote mark */
     172  if ((*c == 0x27) && (c < line + 71)) { c++; }
     173
     174  return (c);
     175}
     176
     177/* given a pointer to the FITS HIERARCH card field name, return pointer to the end of the data area */
     178char *gfits_hierarch_keyword_end (char *line, char *field) {
     179
     180  int done;
     181  char *c1, *c2;
     182
     183  /* find the end of the existing data region */
     184  c1 = line + strlen(field) + 1;
     185  if (*c1 != '=') return (NULL);  /* non-data fields are not allowed */
     186  c1 += 2;
     187
     188  /* advance pointer over WHITESPACE */
     189  while ((*c1 == ' ') && (c1 < line + 71)) { c1++; }
     190 
     191  if (c1[0] == 0x27) { /* entry a string, skip over 'fred' */
     192    for (done = FALSE, c2 = c1 + 1; !done && (c2 < line + 71); c2++) {
     193      if ((c2[0] == 0x27) && (c2[1] == 0x27)) {
     194        c2 += 2;
     195        continue;
     196      }
     197      if (c2[0] == 0x27) {
     198        c1 = c2;
     199        done = TRUE;
     200      }
     201    }
     202    if (!done) { /* error in line: mismatched ' chars, return fixed position */
     203      c1 = line + 30;
     204    }
     205  } else {
     206    while ((*c1 != ' ') && (c1 < line + 71)) c1++;
    158207  }
    159208  return (c1);
     
    171220
    172221/* fill 'line' with Nbyte space from first NULL to last byte with value */
    173 void pad_ending (char *line, char value, int Nbyte) {
     222void gfits_pad_ending (char *line, char value, int Nbyte) {
    174223 
    175224  char *p;
Note: See TracChangeset for help on using the changeset viewer.