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

qfits_header* qfits_header_read_hdr_string ( const unsigned char *  hdr_str,
int  nb_char 
)

Read a FITS header from a 'hdr' string.

Parameters:
hdr_str String containing the hdr file
nb_char Number of characters in the string
Returns:
Pointer to newly allocated qfits_header or NULL in error case
This function parses a 'hdr' string, and returns an allocated qfits_header object.

Definition at line 196 of file qfits_rw.c.

References qfits_getcomment(), qfits_getkey(), qfits_getvalue(), qfits_header_append(), qfits_header_destroy(), and qfits_header_new().

{
    qfits_header    *   hdr ;
    char                line[81];
    char            *   key,
                    *   val,
                    *   com ;
    int                 ind ;
    int                 i, j ;

    /* Check input */
    if (hdr_str==NULL) return NULL ;

    /* Initialise */
    key = val = com = NULL ; 

    /* Create the header */
    hdr = qfits_header_new() ;
    
    /* Go through the file */
    ind = 0 ;
    while (ind <= nb_char - 80) {
        strncpy(line, (char*)hdr_str + ind, 80) ;
        line[80] = (char)0 ;
        for (i=0 ; i<81 ; i++) {
            if (line[i] == '\n') {
                for (j=i ; j<81 ; j++) line[j] = ' ' ;
                line[80] = (char)0 ;
                break ;
            }
        }
        if (!strcmp(line, "END")) {
            line[3] = ' ';
            line[4] = (char)0 ;
        }
        
        /* Rule out blank lines */
        if (!is_blank_line(line)) {

            /* Get key, value, comment for the current line */
            key = qfits_getkey(line);
            val = qfits_getvalue(line);
            com = qfits_getcomment(line);

            /* If key or value cannot be found, trigger an error */
            if (key==NULL) {
                qfits_header_destroy(hdr);
                return NULL ;
            }
            /* Append card to linked-list */
            qfits_header_append(hdr, key, val, com, NULL);
        }
        ind += 80 ;
    }

    /* The last key should be 'END' */
    if (strlen(key)!=3) {
        qfits_header_destroy(hdr);
        return NULL ;
    } 
    if (key[0]!='E' || key[1]!='N' || key[2]!='D') {
        qfits_header_destroy(hdr);
        return NULL ;
    }
    
    return hdr ;
}


Generated by  Doxygen 1.6.0   Back to index