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

qfits_header* qfits_table_ext_header_default ( const qfits_table t  ) 

Generate a default extension header to store tables.

Returns:
the header object

Definition at line 144 of file qfits_table.c.

References qfits_col::atom_nb, col, nc, nr, qfits_get_datetime_iso8601(), qfits_header_append(), qfits_header_destroy(), qfits_header_new(), qfits_col::scale, qfits_col::scale_present, tab_t, qfits_col::tlabel, qfits_col::tunit, qfits_col::zero, and qfits_col::zero_present.

{
    qfits_header    *   fh ;
    qfits_col       *   curr_col ;
    char                str_val[FITS_LINESZ] ;
    char                str_val2[FITS_LINESZ] ;
    char            *   date ;
    int                 tab_width ;
    int                 col_pos ;
    int                 i ;

    /* Compute the table width   */
    if ((tab_width = qfits_compute_table_width(t)) == -1) {
        qfits_error("cannot get the table width") ;
        return NULL ;
    }

    /* Create fits header */
    if ((fh=qfits_header_new()) == NULL) {
        qfits_error("cannot create new fits header") ;
        return NULL ;
    }

    /* Check the kind of table */
    if (t->tab_t == QFITS_BINTABLE) {
       
        /* Write extension header */
        qfits_header_append(fh, "XTENSION", "BINTABLE", 
                "FITS Binary Table Extension", NULL) ;
        qfits_header_append(fh, "BITPIX", "8", "8-bits character format", NULL);
        qfits_header_append(fh, "NAXIS", "2","Tables are 2-D char. array",NULL);
        sprintf(str_val, "%d", tab_width) ;
        qfits_header_append(fh, "NAXIS1", str_val, "Bytes in row", NULL) ;
        sprintf(str_val, "%d", (int)(t->nr)) ;        
        qfits_header_append(fh, "NAXIS2", str_val, "No. of rows in table",NULL);
        qfits_header_append(fh, "PCOUNT", "0", "Parameter count always 0",NULL);
        qfits_header_append(fh, "GCOUNT", "1", "Group count always 1", NULL);
        sprintf(str_val, "%d", (int)(t->nc)) ;
        qfits_header_append(fh, "TFIELDS", str_val, "No. of col in table",NULL);
        /* Columns descriptors */
        curr_col = t->col ;
        for (i=0 ; i<t->nc ; i++) {
            sprintf(str_val, "TFORM%d", i+1) ;
            sprintf(str_val2, "'%s'", qfits_build_format(curr_col)) ;
            qfits_header_append(fh, str_val, str_val2, "Format of field", NULL);
                    
            sprintf(str_val, "TTYPE%d", i+1) ;
            sprintf(str_val2, "%s", curr_col->tlabel) ;
            qfits_header_append(fh, str_val, str_val2, "Field label", NULL) ;

            sprintf(str_val, "TUNIT%d", i+1) ;
            sprintf(str_val2, "%s", curr_col->tunit) ;
            qfits_header_append(fh, str_val, str_val2, "Physical unit of field",
                    NULL) ;    
            if (curr_col->zero_present) {
                sprintf(str_val, "TZERO%d", i+1) ;
                sprintf(str_val2, "%f", curr_col->zero) ;
                qfits_header_append(fh, str_val, str_val2, 
                        "NULL value is defined", NULL) ;
            }
            if (curr_col->scale_present) {
                sprintf(str_val, "TSCAL%d", i+1) ;
                sprintf(str_val2, "%f", curr_col->scale) ;
                qfits_header_append(fh, str_val, str_val2, "Scaling applied", 
                        NULL);
            }
            curr_col++ ;
        }
        qfits_header_append(fh,"ORIGIN","ESO-QFITS", "Written by QFITS", NULL);

        date = qfits_get_datetime_iso8601() ;
        sprintf(str_val, "'%s'", date) ;
        qfits_header_append(fh, "DATE", str_val, "[UTC] Date of writing", NULL);
        qfits_header_append(fh, "END", NULL, NULL, NULL);
    
    } else if (t->tab_t == QFITS_ASCIITABLE) {
    
        /* Write extension header */
        qfits_header_append(fh, "XTENSION", "TABLE",
                        "FITS ASCII Table Extension", NULL) ;
        qfits_header_append(fh, "BITPIX", "8", "8-bits character format", NULL);
        qfits_header_append(fh, "NAXIS", "2", "ASCII table has 2 axes", NULL) ;
               
        /* Fill the header  */
        sprintf(str_val, "%d", tab_width) ;
        qfits_header_append(fh, "NAXIS1", str_val, "Characters in a row", NULL);
        sprintf(str_val, "%d", (int)(t->nr)) ;        
        qfits_header_append(fh, "NAXIS2", str_val, "No. of rows in table",NULL);
        qfits_header_append(fh, "PCOUNT", "0", "No group parameters", NULL) ;    
        qfits_header_append(fh, "GCOUNT", "1", "Only one group", NULL);
        sprintf(str_val, "%d", (int)(t->nc)) ;
        qfits_header_append(fh, "TFIELDS", str_val, "No. of col in table",NULL);
        qfits_header_append(fh, "ORIGIN","ESO-QFITS","Written by QFITS",NULL);
        date = qfits_get_datetime_iso8601() ;
        sprintf(str_val, "'%s'", date) ;
        qfits_header_append(fh, "DATE", str_val, "[UTC] Date of writing", NULL);

        /* Columns descriptors */
        curr_col = t->col ;
        col_pos = 1 ;
        for (i=0 ; i<t->nc ; i++) {
            sprintf(str_val, "TTYPE%d", i+1) ;
            sprintf(str_val2, "%s", curr_col->tlabel) ;
            qfits_header_append(fh, str_val, str_val2, "Field label", NULL) ;
            
            sprintf(str_val, "TFORM%d", i+1) ;
            sprintf(str_val2, "'%s'", qfits_build_format(curr_col)) ;
            qfits_header_append(fh, str_val, str_val2, "Format of field", NULL);
                    
            sprintf(str_val, "TBCOL%d", i+1) ;
            sprintf(str_val2, "%d", col_pos) ;
            qfits_header_append(fh, str_val, str_val2,"Start column of field",
                    NULL);
            col_pos += curr_col->atom_nb ;
            
            sprintf(str_val, "TUNIT%d", i+1) ;
            sprintf(str_val2, "%s", curr_col->tunit) ;
            qfits_header_append(fh, str_val, str_val2, "Physical unit of field",
                    NULL) ;    
            if (curr_col->zero_present) {
                sprintf(str_val, "TZERO%d", i+1) ;
                sprintf(str_val2, "%f", curr_col->zero) ;
                qfits_header_append(fh, str_val, str_val2, 
                        "NULL value is defined", NULL) ;
            }
            if (curr_col->scale_present) {
                sprintf(str_val, "TSCAL%d", i+1) ;
                sprintf(str_val2, "%f", curr_col->scale) ;
                qfits_header_append(fh, str_val, str_val2, "Scaling applied", 
                        NULL);
            }
            curr_col++ ;
        }
        qfits_header_append(fh, "END", NULL, NULL, NULL);

    } else {
        qfits_error("Table type not known") ;
        qfits_header_destroy(fh) ;
        return NULL ;
    }
    return fh ;
}


Generated by  Doxygen 1.6.0   Back to index