##^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Lance Simms, Stanford University 2009
#fits_append.py
#
#PURPOSE:
#  An example of how to open a file, write some data, close it, open it
#  back up again and append more data...  This is necessary since some 
#  images are too large to be held in memory.
#
#
import pyfits
from pylab import *
from numpy import *
import os

#Use a Test file
FitsFileName = '/afs/slac/u/ki/lances/python/pyraf/Test.fits'
if os.path.exists(FitsFileName): os.remove(FitsFileName)

#Form the data array
A=zeros((100,100), int16)

#Get a primary HDU for the file to be written
HDU = pyfits.PrimaryHDU(A)
print HDU.header.ascardlist()

#Create an HDU list that contains the new primary HDU
HDUList = pyfits.HDUList([HDU])
HDUList.writeto(FitsFileName)

#Open it back up and append another A
pyfits.append(FitsFileName, A)
pyfits.append(FitsFileName, A)
