CCfits  2.6
Reading an Image

Image reading calls are made very simple: the FITS object is created with the readDataFlag set to true, and reading is done on construction. The following call

image.read(contents)

calls

PHDU::read(std::valarray<S>& image).

This copies the entire image from the FITS object into the std::valarray object contents, sizing it as necessary. PHDU::read() and ExtHDU::read() [for image extensions] take a range of arguments that support (a) reading the entire image - as in this example; (b) sections of an image starting from a given pixel; (c) rectangular subsets. See the class references for PHDU and ExtHDU for details.

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);
// 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;
}