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_H_field.c

    r16995 r21059  
    6060}
    6161
     62// find the given field among the HIERARCH keywords
     63// these have the form: HIERARCH KEYWORD = value
     64// returns a pointer to the start of the field
     65char *gfits_header_hierarch_field (Header *header, char *field, int N) {
     66
     67  char *buf, *ptr;
     68  int i, Nwant, Nfound, Nfield;
     69
     70  Nfield = strlen (field);
     71  if (Nfield >= 71) return NULL;
     72
     73  buf = header[0].buffer;
     74
     75  /* find the Nth entry */
     76  if (N > 0) {
     77    Nfound = 0;
     78    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
     79      // have we found a HIERARCH entry?
     80      if (strncmp ("HIERARCH", buf, 8)) continue;
     81      ptr = buf + 9; // start of following keyword
     82      if (strncmp (field, ptr, Nfield)) continue;
     83      Nfound ++;
     84      if (Nfound == N) return (ptr);
     85    }
     86  }
     87
     88  /* find the Ntotal - Nth entry */
     89  if (N < 0) {
     90    /* count the entries */
     91    Nfound = 0;
     92    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
     93      if (strncmp ("HIERARCH", buf, 8)) continue;
     94      ptr = buf + 9; // start of following keyword
     95      if (strncmp (field, ptr, Nfield)) continue;
     96      Nfound ++;
     97    }
     98
     99    Nwant = Nfound + N + 1;
     100    buf = header[0].buffer;
     101
     102    /* find the Nwant entry */
     103    Nfound = 0;
     104    for (i = 0; i < header[0].size; i+= FT_LINE_LENGTH, buf += FT_LINE_LENGTH) {
     105      if (strncmp ("HIERARCH", buf, 8)) continue;
     106      ptr = buf + 9; // start of following keyword
     107      if (strncmp (field, ptr, Nfield)) continue;
     108      Nfound ++;
     109      if (Nwant == Nfound) return (ptr);
     110    }
     111  }
     112
     113  return ((char *) NULL);
     114
     115/*
     116
     117   find the Nth entry of this keyword.
     118   if N < 0, find the last - N - 1 word (ie, -1 = last)
     119
     120*/
     121}
     122
    62123/*********************** fits header field ****************************/
    63124char *gfits_header_lineno (Header *header, int N) {
Note: See TracChangeset for help on using the changeset viewer.