Logo Search packages:      
Sourcecode: qfits version File versions  Download package

int qfits_header_getitem ( const qfits_header hdr,
int  idx,
char *  key,
char *  val,
char *  com,
char *  lin 
)

Return the i-th key/val/com/line tuple in a header.

Parameters:
hdr Header to consider
idx Index of the requested card
key Output key
val Output value
com Output comment
lin Output initial line
Returns:
int 0 if Ok, -1 if error occurred.
This function is useful to browse a FITS header object card by card. By iterating on the number of cards (available in the 'n' field of the qfits_header struct), you can retrieve the FITS lines and their components one by one. Indexes run from 0 to n-1. You can pass NULL values for key, val, com or lin if you are not interested in a given field.

  int i ;
  char key[FITS_LINESZ+1] ;
  char val[FITS_LINESZ+1] ;
  char com[FITS_LINESZ+1] ;
  char lin[FITS_LINESZ+1] ;

  for (i=0 ; i<hdr->n ; i++) {
      qfits_header_getitem(hdr, i, key, val, com, lin);
    printf("card[%d] key[%s] val[%s] com[%s]\n", i, key, val, com);
  }

This function has primarily been written to interface a qfits_header object to other languages (C++/Python). If you are working within a C program, you should use the other header manipulation routines available in this module.

Definition at line 633 of file qfits_header.c.

References current, current_idx, first, and n.

{
    keytuple    *   k ;
    int             count ;

    if (hdr==NULL) return -1 ;
    if (key==NULL && val==NULL && com==NULL && lin==NULL) return 0 ;
    if (idx<0 || idx>hdr->n) return -1 ;

    /* Get pointer to keytuple */
    if (idx == 0) {
          ((qfits_header *)hdr)->current_idx = 0 ;
          ((qfits_header *)hdr)->current = hdr->first ;
          k = hdr->current ;
      } else if (idx == hdr->current_idx + 1) {
          ((qfits_header *)hdr)->current = ((keytuple*) (hdr->current))->next ;
          ((qfits_header *)hdr)->current_idx++ ;
          k = hdr->current ;
      } else {
          count=0 ;
          k = (keytuple*)hdr->first ;
          while (count<idx) {
            k = k->next ;
            count++ ;
        }
      }

    /* Fill return values */
    if (key!=NULL) strcpy(key, k->key);
    if (val!=NULL) {
        if (k->val!=NULL) strcpy(val, k->val);
        else val[0]=0 ;
    }
    if (com!=NULL) {
        if (k->com!=NULL) strcpy(com, k->com);
        else com[0]=0 ;
    }
    if (lin!=NULL) {
        if (k->lin!=NULL) strcpy(lin, k->lin);
        else lin[0]=0 ;
    }
    return 0 ;
}


Generated by  Doxygen 1.6.0   Back to index