This example reads and prints out all the data in the ASCII and the binary tables that were previously created by WRITEASCII and WRITEBINTABLE. Note that the exact same FITSIO routines are used to read both types of tables.
subroutine readtable C read and print data values from an ASCII or binary table integer status,unit,readwrite,blocksize,hdutype,ntable integer felem,nelems,nullj,diameter,nfound,irow,colnum real nulle,density character filename*40,nullstr*1,name*8,ttype(3)*10 logical anynull 1 status=0 C Get an unused Logical Unit Number to use to open the FITS file 2 call ftgiou(unit,status) C open the FITS file previously created by WRITEIMAGE filename='ATESTFILEZ.FITS' readwrite=0 3 call ftopen(unit,filename,readwrite,blocksize,status) C loop twice, first reading the ASCII table, then the binary table 4 do ntable=1,2 C move to the next extension 5 call ftmrhd(unit,1,hdutype,status) print *,' ' if (hdutype .eq. 1)then print *,'Extension ',ntable,' is an ASCII table.' else if (hdutype .eq. 2)then print *,'Extension ',ntable,' is a binary table.' end if C read the TTYPEn keywords, which give the names of the columns 6 call ftgkns(unit,'TTYPE',1,3,ttype,nfound,status) write(*,2000)ttype 2000 format(8x,3a10) C read the data, one row at a time, and print them out felem=1 nelems=1 nullstr=' ' nullj=0 nulle=0. do irow=1,6 colnum=1 7 call ftgcvs(unit,colnum,irow,felem,nelems,nullstr,name, & anynull,status) colnum=2 8 call ftgcvj(unit,colnum,irow,felem,nelems,nullj,diameter, & anynull,status) colnum=3 9 call ftgcve(unit,colnum,irow,felem,nelems,nulle,density, & anynull,status) write(*,2001)irow,name,diameter,density 2001 format(i4,a10,i10,f10.2) end do end do C close the file and free the unit number 10 call ftclos(unit, status) call ftfiou(unit, status) C check for any error, and if so print out error messages 11 if (status .gt. 0)call printerror(status) end