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

char* qfits_getvalue ( const char *  line  ) 

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

Definition at line 276 of file qfits_card.c.

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

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

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

    /* Special cases */

    /* END has no associated value */
    if (!strncmp(line, "END ", 4)) {
        return NULL ;
    }
    /*
     * HISTORY has for value everything else on the line, stripping
     * blanks before and after. Blank HISTORY is also accepted.
     */
    memset(value, 0, 81);

    if (!strncmp(line, "HISTORY ", 8) || !strncmp(line, "        ", 8)) {
        i=7 ;
        /* Strip blanks from the left side */
        while (line[i]==' ' && i<80) i++ ;
        if (i>=80) return NULL ; /* Blank HISTORY */
        from=i ;

        /* Strip blanks from the right side */
        to=79 ;
        while (line[to]==' ') to-- ;
        /* Copy relevant characters into output buffer */
        strncpy(value, line+from, to-from+1);
        /* Null-terminate the string */
        value[to-from+1] = (char)0;
        return value ;
    } else if (!strncmp(line, "COMMENT ", 8)) {
        /* COMMENT is like HISTORY */
        /* Strip blanks from the left side */
        i=7 ;
        while (line[i]==' ' && i<80) i++ ;
        if (i>=80) return NULL ;
        from=i ;

        /* Strip blanks from the right side */
        to=79 ;
        while (line[to]==' ') to-- ;

        if (to<from) {
#ifdef DEBUG_FITSHEADER
            printf("qfits_getvalue: inconsistent value search in COMMENT\n");
#endif
            return NULL ;
        }
        /* Copy relevant characters into output buffer */
        strncpy(value, line+from, to-from+1);
        /* Null-terminate the string */
        value[to-from+1] = (char)0;
        return value ;
    }
    /* General case - Get past the keyword */
    i=0 ;
    while (line[i]!='=' && i<80) i++ ;
    if (i>80) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getvalue: no equal sign found on line\n");
#endif
        return NULL ;
    }
    i++ ;
    while (line[i]==' ' && i<80) i++ ;
    if (i>80) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getvalue: no value past the equal sign\n");
#endif
        return NULL ;
    }
    from=i;

    /* Now value section: Look for the first slash '/' outside a string */
    inq = 0 ;
    while (i<80) {
        if (line[i]=='\'')
            inq=!inq ;
        if (line[i]=='/')
            if (!inq)
                break ;
        i++;
    }
    i-- ;

    /* Backtrack on blanks */
    while (line[i]==' ' && i>=0) i-- ;
    if (i<0) {
#ifdef DEBUG_FITSHEADER
        printf("qfits_getvalue: error backtracking on blanks\n");
#endif
        return NULL ;
    }
    to=i ;

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


Generated by  Doxygen 1.6.0   Back to index