ReWrite3D
Re-writes an existing image in a FITS data cube. The image data MUST match in size to the exising images within the data cube. The image size is NOT checked for by this method.
Syntax
void ReWrite3D( data, imageNumber );
Parameters
void* data
Pointer to image data that will be used to overwrite the specified image within a FITS data cube.
int imageNumber
The index into the data cube of the image to overwrite. Zero based index.
Returns
None
Required Headers
CFitsFile.h
Namespace
arc
Throws
std::runtime_error
Remarks
None
Example
        // This code demonstrates how to rewrite the 7th
        // image in a data cube with a new image.

        #include <iostream>
        #include "CFitsFile.h"

        using namespace std;
        using namespace arc;

        int main()
        {
            long naxes[ CFitsFile::NAXES_SIZE ] = { 0, 0, 0 };
            unsigned short *pBuf = NULL;
            unsigned short val = 0;

            try {
                CFitsFile cFits( "Image.fit" );

                cFits.GetParameters( naxes );

                //
                // Make sure there are at least 7 images
                // in the data cube.
                //
                if ( naxes[ CFitsFile::NAXES_NOF ] < 7 )
                {
                    cerr << "Error: Too few frames in data cube!" << endl;
                    exit( 1 );
                }

                //
                // Create new image data
                //
                pBuf = new unsigned short[ naxes[ CFitsFile::NAXES_ROW ] *
                                           naxes[ CFitsFile::NAXES_COL ] ];

                if ( pBuf == NULL )
                {
                    cerr << "Error: NULL image buffer!" << endl;
                    exit( 1 );
                }

                //
                // Fill the new buffer with a gradient image
                //
                for ( int r=0; r<naxes[ CFitsFile::NAXES_ROW ]; r++ )
                {
                    for ( int c=0; c<naxes[ CFitsFile::NAXES_COL ]; c++ )
                    {
                        pBuf[ c + r * naxes[ CFitsFile::NAXES_COL ] ] = val;
                    }

                    if ( val >= 65535 ) val = 0;
                    else val++;
                }

                //
                // Replace the 7th image ( zero based ) with
                // the new gradient image.
                //
                cFits.ReWrite3D( pBuf, 6 );

                delete[] pBuf;
            }
            catch ( std::exception &e )
            {
                cerr << "Exception Occurred: " << e.what() << endl;
                if ( pBuf != NULL ) delete[] pBuf;
            }
        }

© Astronomical Research Cameras, Inc.