// This code demonstrates how to create an XL Buffer,
// fill it with data, and write it to disk in the
// form of a FITS file.
#include <iostream>
#include "CXLBuffer.h"
#include "CFitsFile.h"
using namespace std;
using namespace arc;
int main()
{
long lRows = 10500;
long lCols = 10500;
long lPixelCount = lXLRows * lXLCols;
long lNumOfBuffs = lPixelCount / ( lRows * lCols );
long l = 0;
unsigned short *pBuffer = NULL;
try
{
CXLBuffer<unsigned short> cXLBuff;
//
// Create a buffer for writing to the XL buffer
//
pBuffer = new unsigned short[ lRows * lCols ];
for ( l=0; l<lNumOfBuffs; l++ )
{
//
// Fill the buffer
//
#ifdef WIN32
FillMemory( pBuffer,
sizeof( unsigned short ) * lRows * lCols,
l );
#else
memset( pBuffer,
l,
sizeof( unsigned short ) * lRows * lCols );
#endif
//
// Add the buffer to the XL buffer
//
cout << "Adding " << ( lRows * lCols * sizeof( unsigned short ) )
<< " bytes to sub-buffer " << l << " ... ";
cXLBuff.Append( pBuffer, lRows * lCols );
cout << "success" << endl;
}
delete [] pBuffer;
//
// Handle "extra" pixels
//
long lExtraPixels = lPixelCount % ( lRows * lCols );
pBuffer = new unsigned short[ lExtraPixels ];
cout << "Adding " << ( lExtraPixels * sizeof( unsigned short ) )
<< " bytes to sub-buffer " << l << " ... ";
cXLBuff.Append( pBuffer, lExtraPixels );
cout << "success" << endl;
delete [] pBuffer;
//
// Create a FITS file to save the XL buffer too
//
CFitsFile cFits( sFilename.c_str(),
lXLRows,
lXLCols,
CFitsFile::BPP16 );
//
// Read the XL buffer sub-buffers and write to FITS
//
unsigned short* pSubBuffer = NULL;
long lSubBufBytes = 0;
while ( ( pSubBuffer = cXLBuff.GetNextSubBuffer( &lSubBufBytes ) ) != NULL )
{
cout << "Read " << lSubBufBytes << " bytes -> pix[ 0 ]: " << pSubBuffer[ 0 ] << endl;
cFits.Write( pSubBuffer, lSubBufBytes );
}
//
// Free the XL buffer
//
cXLBuff.Free();
}
catch ( bad_alloc &memAllocException )
{
cout << endl << "MemoryAllocationException: "
<< memAllocException.what() << endl;
}
catch( exception e )
{
cout << endl << e.what() << endl;
}
}
© Astronomical Research Cameras, Inc.