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

char* qfits_getcomment ( const char *  line  ) 

Find the comment 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 comment. Returns NULL in case of error, or if no comment can be found. The returned pointer is statically allocated in this function, so do not modify or try to free it.

Definition at line 408 of file qfits_card.c.

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

{
    static char comment[81];
    int    i ;
    int    from, to ;
    int    inq ;

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

    /* Special cases: END, HISTORY, COMMENT and blank have no comment */
    if (!strncmp(line, "END ", 4)) return NULL ;
    if (!strncmp(line, "HISTORY ", 8)) return NULL ;
    if (!strncmp(line, "COMMENT ", 8)) return NULL ;
    if (!strncmp(line, "        ", 8)) return NULL ;

    memset(comment, 0, 81);
    /* Get past the keyword */
    i=0 ;
    while (line[i]!='=' && i<80) i++ ;
    if (i>=80) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getcomment: no equal sign on line\n");
#endif
        return NULL ;
    }
    i++ ;
    
    /* Get past the value until the slash */
    inq = 0 ;
    while (i<80) {
        if (line[i]=='\'')
            inq = !inq ;
        if (line[i]=='/')
            if (!inq)
                break ;
        i++ ;
    }
    if (i>=80) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getcomment: no slash found on line\n");
#endif
        return NULL ;
    }
    i++ ;
    /* Get past the first blanks */
    while (line[i]==' ') i++ ;
    from=i ;

    /* Now backtrack from the end of the line to the first non-blank char */
    to=79 ;
    while (line[to]==' ') to-- ;

    if (to<from) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getcomment: from>to?\n");
#endif
        return NULL ;
    }
    /* Copy relevant characters into output buffer */
    strncpy(comment, line+from, to-from+1);
    /* Null-terminate the string */
    comment[to-from+1] = (char)0;
    return comment ;
}


Generated by  Doxygen 1.6.0   Back to index