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

qfits_header* qfits_header_readext ( const char *  filename,
int  xtnum 
)

Read an extension header from a FITS file.

Parameters:
filename Name of the FITS file to read
xtnum Extension number to read, starting from 0.
Returns:
Newly allocated qfits_header structure.
Strictly similar to qfits_header_read() but reads headers from extensions instead. If the requested xtension is 0, this function returns the main header.

Returns NULL in case of error.

Definition at line 280 of file qfits_rw.c.

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

Referenced by qfits_header_read(), and qfitsloader_init().

{
    qfits_header*   hdr ;
    int             n_ext ;
    char            line[81];
    char        *   where ;
    char        *   start ;
    char        *   key,
                *   val,
                *   com ;
    int             seg_start ;
    int             seg_size ;
    size_t          size ;

    /* Check input */
    if (filename==NULL || xtnum<0)
        return NULL ;

    /* Check that there are enough extensions */
    if (xtnum>0) {
        n_ext = qfits_query_n_ext(filename);
        if (xtnum>n_ext) {
            return NULL ;
        }
    }

    /* Get offset to the extension header */
    if (qfits_get_hdrinfo(filename, xtnum, &seg_start, &seg_size)!=0) {
        return NULL ;
    }

    /* Memory-map the input file */
    start = qfits_falloc((char *)filename, seg_start, &size) ;
    if (start==NULL) return NULL ;

    hdr   = qfits_header_new() ;
    where = start ;
    while (1) {
        memcpy(line, where, 80);
        line[80] = (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);
                hdr = NULL ;
                break ;
            }
            /* Append card to linked-list */
            qfits_header_append(hdr, key, val, com, line);
            /* Check for END keyword */
            if (strlen(key)==3)
                if (key[0]=='E' &&
                    key[1]=='N' &&
                    key[2]=='D')
                    break ;
        }
        where += 80 ;
        /* If reaching the end of file, trigger an error */
        if ((int)(where-start)>=(int)(seg_size+80)) {
            qfits_header_destroy(hdr);
            hdr = NULL ;
            break ;
        }
    }
    qfits_fdealloc(start, seg_start, size) ;
    return hdr ;
}


Generated by  Doxygen 1.6.0   Back to index