Question

I'm trying to write data in FITS format using compression. Here's what I tried:

#include <vector>
#include "fitsio.h"
#define DIM 100
int main(int argc, char *argv[]) {
    fitsfile *fptr;       /* pointer to the FITS file, defined in fitsio.h */
    std::vector<double> data(DIM*DIM);
    for (unsigned int i=0; i<data.size();i++) data[i]=i;
    int s=0, status;
    fits_create_file(&fptr, "!test3.fits", &s); status+=s;
    fits_set_compression_type(fptr, GZIP_2, &s); status+=s;
    std::vector<long> naxes(2); naxes[0]=DIM; naxes[1]=DIM;
    fits_create_img(fptr,  DOUBLE_IMG, naxes.size(), &naxes[0], &s); status+=s;
    fits_write_img(fptr, TDOUBLE, 1, data.size(), &data[0], &s); status+=s;
    fits_close_file(fptr, &status); status+=s;
    return status;
}

It works since return status is zero. But I can't open the file with anything. Moreover the file test3.fits returns

test3.fits: FITS image data, 16-bit, two's complement binary integer

While if I remove the line fits_set_compression_type ... I get

test3.fits: FITS image data, 64-bit, floating point, double precision

that is correct (and I can open the image)

What I do wrong here?

Was it helpful?

Solution 2

It looks like I create a valid fits file it's just imageJ not reading it properly. Downloaded ds9 at it works pretty well.

OTHER TIPS

There are older FITS libraries that cannot deal with the FITS tile compression standard. Software based on recent cfitsio (and CCfits) and nom.tam.fits is generally compliant with that convention.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top