To visualize your two dimensional data easily I recommend the freeware ‘DS9’.

It reads several file types, but the easiest for you is probably just raw dumps of your 2D arrays.

I will outline how to write those below.

 

First, here is how to get DS9, which can be installed on almost any platform.

 

Go to this URL: (Harvard/Smithsonian Astrophysical Observatory)

 

 

Once DS9 is installed and loaded, you need to open the data file. Assuming it is a raw array,

Follow “Open Other > Open Array” to find the file you want to open. Here is how DS9 looks in Windows

 

                                   

 

 

Once you have identified the file, you must specify several parameters, including the dimension

of the array, the data type, whether there are any header bytes in the record and architecture of

the machine that wrote the file. The data type (pixel size) should match the data type used in

your code. If your code was written in FORTRAN you need to tell DS9 to skip 4 bytes.

Otherwise, keep that parameter at zero.

 

If you wrote the file on a Sun or a Mac, then the architecture will be ‘Big-Endian’,

If you wrote the file on a Windows or Linux machine it will be “Little-Endian’.

 

                                   

 

You can load multiple frames using the frame button. You can select various color maps, adjust

the scaling (such as log or square root scaling of the numbers). You can also display slices

through the 2D data using the analysis tool.  There are various other features. Play with it.

 

                                   

 

You can save the image to a jpg, tif, fits or mpg file. This can be done from the tool bar or from the file

command button. For example, see the image below.

 

                                   

 

You can also save the file as a postscript image file using the print command.

 

                                   

 

 

 

In order to write raw data files that can be read by DS9 you can follow these examples:

 

First in C

 

/********************************************************/

/* Makes an array, then dumps it as an unformatted file */

/********************************************************/

 

#include <stdio.h>

#include <math.h>

 

#define DIM 512

FILE *pfile = NULL;

int i,j;

float numbers[DIM][DIM];

 

int main()

{

  i=0;

  j=0;

 

  /* creating a test array, each element=x*y */

  for(j=0;j<DIM;++j)

     {

       for(i=0;i<DIM;++i)

         numbers[i][j]=(i+1)*(j+1);

     }

 

  /*opening and writing the unformatted array */

  pfile=fopen("data.out","wb");

  fwrite(numbers,sizeof(float),DIM*DIM,pfile);

  fclose(pfile);

 

  return 0;

}

 

 

In FORTRAN:

 

     Program dumpfile

c   Create an array of dimension nXm = 256X256

      real array(256,256)

 

      open(unit = 8, file = ‘filename’, format = ‘unformatted’)

c   create a dummy array for the example

 

      do i = 1,256

      do j = 1,256

         array(i,j) = 1.0

      end

      end

 

c    write out the array

 

      write(8)array

 

      end