This routine writes a simple FITS ASCII table containing 3 columns and 6 rows. For convenience, the ASCII table extension is appended to the FITS image file created previously by the WRITEIMAGE routine.
subroutine writeascii
C Create an ASCII table containing 3 columns and 6 rows
integer status,unit,readwrite,blocksize,tfields,nrows,rowlen
integer nspace,tbcol(3),diameter(6), colnum,frow,felem
real density(6)
character filename*40,extname*16
character*16 ttype(3),tform(3),tunit(3),name(6)
data ttype/'Name','Diameter','Density'/
data tform/'A8','I6','F4.2'/
data tunit/' ','km','g/cm'/
data name/'Mercury','Venus','Earth','Mars','Jupiter','Saturn'/
data diameter/4880,12112,12742,6800,143000,121000/
data density/5.1,5.3,5.52,3.94,1.33,0.69/
1 status=0
C Name of the FITS file to append the ASCII table to:
filename='ATESTFILEZ.FITS'
C Get an unused Logical Unit Number to use to open the FITS file
2 call ftgiou(unit,status)
C open the FITS file, with write access
3 readwrite=1
call ftopen(unit,filename,readwrite,blocksize,status)
C append a new empty extension onto the end of the primary array
4 call ftcrhd(unit,status)
C define parameters for the ASCII table (see the above data statements)
tfields=3
nrows=6
extname='PLANETS_ASCII'
C calculate the starting position of each column, and the total row length
nspace=1
5 call ftgabc(tfields,tform,nspace,rowlen,tbcol,status)
C write the required header parameters for the ASCII table
6 call ftphtb(unit,rowlen,nrows,tfields,ttype,tbcol,tform,tunit,
& extname,status)
C write names to the first column, diameters to 2nd col., and density to 3rd
frow=1
felem=1
colnum=1
7 call ftpcls(unit,colnum,frow,felem,nrows,name,status)
colnum=2
call ftpclj(unit,colnum,frow,felem,nrows,diameter,status)
colnum=3
call ftpcle(unit,colnum,frow,felem,nrows,density,status)
C close the FITS file and free the unit number
8 call ftclos(unit, status)
call ftfiou(unit, status)
C check for any error, and if so print out error messages
9 if (status .gt. 0)call printerror(status)
end