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

qfits_header* qfits_header_read_hdr ( const char *  filename  ) 

Read a FITS header from a 'hdr' file.

Parameters:
filename Name of the file to be read
Returns:
Pointer to newly allocated qfits_header or NULL in error case
This function parses a 'hdr' file, and returns an allocated qfits_header object. A hdr file is an ASCII format were the header is written with a carriage return after each line. The command dfits typically displays a hdr file.

Definition at line 113 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 ;
    FILE            *   in ;
    char                line[81];
    char            *   key,
                    *   val,
                    *   com ;
    int                 i, j ;

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

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

    /* Open the file */
    if ((in=fopen(filename, "r"))==NULL) {
        qfits_error("cannot read [%s]", filename) ;
        return NULL ;
    }
    
    /* Create the header */
    hdr = qfits_header_new() ;
    
    /* Go through the file */
    while (fgets(line, 81, in)!=NULL) {
        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);
                fclose(in) ;
                return NULL ;
            }
            /* Append card to linked-list */
            qfits_header_append(hdr, key, val, com, NULL);
        }
    }
    fclose(in) ;

    /* 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