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

char* qfits_getkey ( const char *  line  ) 

Find the keyword in a key card (80 chars).

Parameters:
line allocated 80-char line from a FITS header
Returns:
statically allocated char *
Find out the part of a FITS line corresponding to the keyword. Returns NULL in case of error. The returned pointer is statically allocated in this function, so do not modify or try to free it.

Definition at line 205 of file qfits_card.c.

Referenced by qfits_header_read_hdr(), qfits_header_read_hdr_string(), and qfits_header_readext().

{
    static char     key[81];
    int                i ;

    if (line==NULL) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getkey: NULL input line\n");
#endif
        return NULL ;
    }

    /* Special case: blank keyword */
    if (!strncmp(line, "        ", 8)) {
        strcpy(key, "        ");
        return key ;
    }
    /* Sort out special cases: HISTORY, COMMENT, END do not have = in line */
    if (!strncmp(line, "HISTORY ", 8)) {
        strcpy(key, "HISTORY");
        return key ;
    }
    if (!strncmp(line, "COMMENT ", 8)) {
        strcpy(key, "COMMENT");
        return key ;
    }
    if (!strncmp(line, "END ", 4)) {
        strcpy(key, "END");
        return key ;
    }

    memset(key, 0, 81);
    /* General case: look for the first equal sign */
    i=0 ;
    while (line[i]!='=' && i<80) i++ ;
    if (i>=80) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getkey: cannot find equal sign\n");
#endif
        return NULL ;
    }
    i-- ;
    /* Equal sign found, now backtrack on blanks */
    while (line[i]==' ' && i>=0) i-- ;
    if (i<=0) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getkey: error backtracking on blanks\n");
#endif
        return NULL ;
    }
    i++ ;

    /* Copy relevant characters into output buffer */
    strncpy(key, line, i) ;
    /* Null-terminate the string */
    key[i+1] = (char)0;
    return key ;
}


Generated by  Doxygen 1.6.0   Back to index