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

int qfits_pixdump ( qfitsdumper qd  ) 

Dump a pixel buffer to an output FITS file in append mode.

Parameters:
qd qfitsdumper control object.
Returns:
int 0 if Ok, -1 otherwise.
This function takes in input a qfitsdumper control object. This object must be allocated beforehand and contain valid references to the data to save, and how to save it.

The minimum fields to fill are:

  • filename: Name of the FITS file to dump to.
  • npix: Number of pixels in the buffer to be dumped.
  • ptype: Type of the passed buffer (PTYPE_FLOAT, PTYPE_INT, PTYPE_DOUBLE)
  • out_ptype: Requested FITS BITPIX for the output.

One of the following fields must point to the corresponding pixel buffer:

  • ibuf for an int pixel buffer (ptype=PTYPE_INT)
  • fbuf for a float pixel buffer (ptype=PTYPE_FLOAT)
  • dbuf for a double pixel buffer (ptype=PTYPE_DOUBLE)

This is a fairly low-level function, in the sense that it does not check that the output file already contains a proper header or even that the file it is appending to is indeed a FITS file. It will convert the pixel buffer to the requested BITPIX type and append the data to the file, without padding with zeros. See qfits_zeropad() about padding.

If the given output file name is "STDOUT" (all caps), the dump will be performed to stdout.

Definition at line 567 of file qfits_image.c.

References qfitsdumper::dbuf, qfitsdumper::fbuf, qfitsdumper::filename, qfitsdumper::ibuf, qfitsdumper::npix, qfitsdumper::out_ptype, and qfitsdumper::ptype.

{
    FILE    *   f_out ;
    byte    *   buf_out ;
    int         buf_free ;
    int         buf_sz ;

    /* Check inputs */
    if (qd==NULL) return -1 ;
    if (qd->filename==NULL) return -1 ;
    switch (qd->ptype) {
        case PTYPE_FLOAT:
        if (qd->fbuf==NULL) return -1 ;
        break ;

        case PTYPE_DOUBLE:
        if (qd->dbuf==NULL) return -1 ;
        break ;

        case PTYPE_INT:
        if (qd->ibuf==NULL) return -1 ;
        break ;

        default:
        return -1 ;
    }
    if (qd->npix <= 0) {
        qfits_error("Negative or NULL number of pixels specified");
        return -1 ;
    }

    /*
     * Special cases: input buffer is identical to requested format.
     * This is only possible on big-endian machines, since FITS is
     * big-endian only.
     */
    buf_out = NULL ;
    buf_free = 1 ;
#ifdef WORDS_BIGENDIAN
    if (qd->ptype==PTYPE_FLOAT && qd->out_ptype==-32) {
        buf_out = (byte*)qd->fbuf ;
        buf_free=0 ;
    } else if (qd->ptype==PTYPE_DOUBLE && qd->out_ptype==-64) {
        buf_out = (byte*)qd->dbuf ;
        buf_free=0 ;
    } else if (qd->ptype==PTYPE_INT && qd->out_ptype==32) {
        buf_out = (byte*)qd->ibuf ;
        buf_free=0 ;
    }
#endif
    buf_sz = qd->npix * BYTESPERPIXEL(qd->out_ptype);

    /* General case */
    if (buf_out==NULL) {
        switch (qd->ptype) {
            /* Convert buffer */
            case PTYPE_FLOAT:
            buf_out = qfits_pixdump_float(  qd->fbuf,
                                            qd->npix,
                                            qd->out_ptype);
            break ;

            /* Convert buffer */
            case PTYPE_INT:
            buf_out = qfits_pixdump_int(    qd->ibuf,
                                            qd->npix,
                                            qd->out_ptype);
            break ;

            /* Convert buffer */
            case PTYPE_DOUBLE:
            buf_out = qfits_pixdump_double( qd->dbuf,
                                             qd->npix,
                                             qd->out_ptype);
            break ;
        }
    }
    if (buf_out==NULL) {
        qfits_error("cannot dump pixel buffer");
        return -1 ;
    }

    /* Dump buffer */
    if (!strncmp(qd->filename, "STDOUT", 6)) {
        f_out = stdout ;
    } else {
        f_out = fopen(qd->filename, "a");
    }
    if (f_out==NULL) {
        qfits_free(buf_out);
        return -1 ;
    }
    fwrite(buf_out, buf_sz, 1, f_out);
    if (buf_free) {
        qfits_free(buf_out);
    }
    if (f_out!=stdout) {
        fclose(f_out);
    }
    return 0 ;
}


Generated by  Doxygen 1.6.0   Back to index