Search code examples
c++imagefits

How to get image data from CCfits


I'm trying to read and write FITS images using C++. I'm trying to use CCfits, but I can't figure out how how to get the pixel buffer. I have used the sample code in the documentation to successfully read the image and print out the primary header, but I get an error when I tried to read the binary data array. Here is the code provided in the CCfits example (I've indicated where the error is).

int readImage()
{
    std::auto_ptr<FITS> pInfile(new FITS("atestfil.fit",Read,true));
    PHDU& image = pInfile->pHDU();
    std::valarray<unsigned long>  contents;

    // read all user-specifed, coordinate, and checksum keys in the image
    image.readAllKeys();
    image.read(contents); // !!!ERROR HERE!!!

    // this doesn’t print the data, just header info.
    std::cout << image << std::endl;
    long ax1(image.axis(0));
    long ax2(image.axis(1));

    for (long j = 0; j < ax2; j+=10)
    {
        std::ostream_iterator<short> c(std::cout,"\t");
        std::copy(&contents[j*ax1], &contents[(j+1)*ax1-1], c);
        std::cout << '\n';
    {
    std::cout << std::endl;
    return 0;
}

The error returned from make is:

undefined reference to `void CCfits::PHDU::read<unsigned long>(std::valarray<unsigned long>&)'

And indeed, according to the documentation I downloaded with the source code there is no function with that signature. So I tried all the other signatures that are documented, but I still get basically the same error (just a different signature mentioned).

In fact, I opened up my local copy of PHDU.h and found this line:

 template<typename S>
        void read(std::valarray<S>& image) ;

I am including -lcfitsio -lCCfits, and the code builds fine if I comment out the the line with the read() function.

Does any body know how to use this library?

Does anyone have a working example?


Solution

  • It appears CCfits doesn't really work as advertised. The read() function is documented and even declared in the header file, but there is no implementation.

    Just use cfitsio, it works.