CCfits - HEASARC - NASA
CCfits - HEASARC - NASA
CCfits - HEASARC - NASA
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
6 Writing Primary Images and Image Extensions 13<br />
extension of type float is also written by calls in between the writes to the primary<br />
header demonstrating switch between HDUs during writes.<br />
Note that in the example below data of type float is written to an image of type unsigned<br />
int, demonstrating both implicit type conversion and the cfitsio extension to unsigned<br />
data.<br />
User keywords can be added to the PHDU after successful construction and these will<br />
both be accessible as container contents in the in-memory FITS object as well as being<br />
written to disk by cfitsio.<br />
Images are represented by the standard library valarray template class which supports<br />
vectorized operations on numeric arrays (e.g. taking the square root of an array) and<br />
slicing techniques.<br />
The code below also illustrates use of C++ standard library algorithms, and the facilities<br />
provided by the std::valarray class.<br />
int writeImage()<br />
{<br />
// Create a FITS primary array containing a 2-D image<br />
// declare axis arrays.<br />
long naxis = 2;<br />
long naxes[2] = { 300, 200 };<br />
// declare auto-pointer to FITS at function scope. Ensures no resources<br />
// leaked if something fails in dynamic allocation.<br />
std::auto_ptr pFits(0);<br />
try<br />
{<br />
// overwrite existing file if the file already exists.<br />
const std::string fileName("!atestfil.fit");<br />
// Create a new FITS object, specifying the data type and axes for the<br />
primary<br />
// image. Simultaneously create the corresponding file.<br />
// this image is unsigned short data, demonstrating the cfitsio<br />
extension<br />
// to the FITS standard.<br />
pFits.reset( new FITS(fileName , USHORT_IMG , naxis , naxes ) );<br />
}<br />
catch (FITS::CantCreate)<br />
{<br />
// ... or not, as the case may be.<br />
return -1;<br />
}<br />
// references for clarity.<br />
long& vectorLength = naxes[0];<br />
long& numberOfRows = naxes[1];<br />
Generated on Tue Dec 6 2011 16:12:51 for <strong>CCfits</strong> by Doxygen