Write
Writes image data to a FITS file. The second version can write a specific number of bytes from the image data to a specific offset within the FITS file.
Syntax
void Write( data );
void Write( data, bytesToWrite, fPixl );
Parameters
void* data
Pointer to pixel image data.
long bytesToWrite
The number of bytes to write from the image data.
long fPixl
[ optional ] The start pixel within the FITS file image. If left blank, then the next write position will be this->fPixel plus bytesToWrite. If fPixel >= 0, then data will be written there.
Returns
None
Required Headers
CFitsFile.h
Namespace
arc
Throws
std::runtime_error
Remarks
Can be used to write a sub-image of the image data into a FITS file. This is not the same as writing image data into a sub-image of the FITS file. Use the WriteSubImage method for that task.
Example
        // This code demonstrates how to write a 1024x1200
        // pixel FITS file filled with a gradient.

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

        using namespace std;
        using namespace arc;

        int main()
        {
            unsigned short *pBuf = NULL;
            unsigned short val = 0;

            try {
                CFitsFile cFits( "Image.fit", 1024, 1200 );

                //
                // Create new image data
                //
                pBuf = new unsigned short[ 1024 * 1200 ];

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

                //
                // Fill the new buffer with a gradient image
                //
                for ( int r=0; r<1024; r++ )
                {
                    for ( int c=0; c<1200; c++ )
                    {
                        pBuf[ c + r * 1200 ] = val;
                    }

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

                //
                // Write the image data
                //
                cFits.Write( pBuf );

                delete[] pBuf;
            }
            catch ( std::exception &e )
            {
                cerr << "Exception Occurred: " << e.what() << endl;
                if ( pBuf != NULL ) delete[] pBuf;
            }
        }
Example
        // This code demonstrates how to write a 200x300 sub-image
        // from a 1024x1200 pixel image into the FITS file at the
        // start location of ( 0, 0 ).

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

        using namespace std;
        using namespace arc;

        int main()
        {
            unsigned short *pBuf = NULL;
            unsigned short val = 0;

            try {
                CFitsFile cFits( "Image.fit", 1024, 1200 );

                //
                // Create new image data
                //
                pBuf = new unsigned short[ 1024 * 1200 ];

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

                //
                // Fill the new buffer with a gradient image
                //
                for ( int r=0; r<1024; r++ )
                {
                    for ( int c=0; c<1200; c++ )
                    {
                        pBuf[ c + r * 1200 ] = val;
                    }

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

                //
                // Write the image data
                //
                cFits.Write( pBuf, ( 200 * 300 * sizeof( unsigned short ) ), 0 );

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

© Astronomical Research Cameras, Inc.