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 14<br />
long nelements(1);<br />
// Find the total size of the array.<br />
// this is a little fancier than necessary ( It’s only<br />
// calculating naxes[0]*naxes[1]) but it demonstrates use of the<br />
// C++ standard library accumulate algorithm.<br />
nelements = std::accumulate(&naxes[0],&naxes[naxis],1,std::multiplies<br />
());<br />
// create a new image extension with a 300x300 array containing float data.<br />
std::vector extAx(2,300);<br />
string newName ("NEW-EXTENSION");<br />
ExtHDU* imageExt = pFits->addImage(newName,FLOAT_IMG,extAx);<br />
// create a dummy row with a ramp. Create an array and copy the row to<br />
// row-sized slices. [also demonstrates the use of valarray slices].<br />
// also demonstrate implicit type conversion when writing to the image:<br />
// input array will be of type float.<br />
std::valarray row(vectorLength);<br />
for (long j = 0; j < vectorLength; ++j) row[j] = j;<br />
std::valarray array(nelements);<br />
for (int i = 0; i < numberOfRows; ++i)<br />
{<br />
array[std::slice(vectorLength*static_cast(i),vectorLength,1)] =<br />
row + i;<br />
}<br />
// create some data for the image extension.<br />
long extElements = std::accumulate(extAx.begin(),extAx.end(),1,<br />
std::multiplies());<br />
std::valarray ranData(extElements);<br />
const float PIBY (M_PI/150.);<br />
for ( int jj = 0 ; jj < extElements ; ++jj)<br />
{<br />
float arg = PIBY*jj;<br />
ranData[jj] = std::cos(arg);<br />
}<br />
long<br />
fpixel(1);<br />
// write the image extension data: also demonstrates switching between<br />
// HDUs.<br />
imageExt->write(fpixel,extElements,ranData);<br />
//add two keys to the primary header, one long, one complex.<br />
long exposure(1500);<br />
std::complex omega(std::cos(2*M_PI/3.),std::sin(2*M_PI/3));<br />
pFits->pHDU().addKey("EXPOSURE", exposure,"Total Exposure Time");<br />
pFits->pHDU().addKey("OMEGA",omega," Complex cube root of 1 ");<br />
// The function PHDU& FITS::pHDU() returns a reference to the object<br />
Generated on Tue Dec 6 2011 16:12:51 for <strong>CCfits</strong> by Doxygen