pro t_aper,image,fitsfile,apr,skyrad,badpix,PRINT=print,SILENT=silent, $
        NEWTABLE = newtable, SETSKYVAL = setskyval,EXACT = Exact
 On_error,2                         ;Return to caller

 if N_params() LT 2 then begin
    print,'Syntax - T_APER, image, fitsfile, [ apr, skyrad, badpix'
    print,'              /EXACT, SETSKY = ,PRINT = , NEWTABLE = ,/SILENT ]'
  return
 endif

 newfile = keyword_set(NEWTABLE)
 if not keyword_set(NEWTABLE) then newtable = fitsfile

 dummy = readfits( fitsfile, hprimary, /SILENT )
 tab = readfits( fitsfile, h, /exten)

 ftinfo,h,ft_str
 ttype = strtrim(ft_str.ttype,2)
 xc = ftget( ft_str, tab, 'X' ) - 1.      ;Subtract to conv from FORTRAN to IDL
 yc = ftget( ft_str, tab, 'Y' ) - 1.

 phpadu = sxpar( hprimary, 'PHPADU', Count = n )  ;Try to get photons per ADU
 if n EQ 0 then begin
        phpadu = sxpar( hprimary, 'GAIN', Count  = n)
        if n EQ 0 then phpadu = sxpar( hprimary, 'CCDGAIN', Count = n)
        if n EQ 0 then phpadu = sxpar( hprimary, 'ATODGAIN', Count = n)
        if n EQ 0 then begin
        read,'Enter photons per ADU (CCD Gain):  ',phpadu
        message,'Storing photon/ADU value of ' + strtrim(phpadu,2) + $
               ' in header',/INF
       sxaddpar,hprimary,'PHPADU',phpadu,'Photons Per ADU',before = 'HISTORY'
       endif
 endif

 message,'Using photon/ADU value of ' + strtrim(phpadu,2),/INF

 aper, image, xc, yc, mags, errap, sky, skyerr, phpadu, apr, skyrad,$
     badpix, PRINT = print, SILENT=silent, SETSKYVAL = setskyval, EXACT = exact

 ans=''
 if NOT keyword_set(SILENT) and (NOT newfile) then read, $
    'T_APER: Update table with current results [Y]? ',ans

 if strupcase(ans) NE 'N' then begin   
    sxaddpar,h,'EXTNAME','IDL DAOPHOT: APER',' Last DAOPHOT step'
    sxaddpar,h,'SKYIN',skyrad[0],' Inner Sky Radius','TTYPE1' 
    sxaddpar,h,'SKYOUT',skyrad[1],' Outer Sky Radius','TTYPE1'
    sxaddpar,h,'BADPIX1',badpix[0],' Bad Pixel Value: LOW','TTYPE1'
    sxaddpar,h,'BADPIX2',badpix[1],' Bad Pixel Value: HIGH','TTYPE1'

    gsky = where(ttype EQ 'SKY', N_sky)
    if N_sky EQ 0 then ftaddcol,h,tab,'SKY',8,'F8.3'
    ftput,h,tab,'SKY',0,sky
    
    gskyerr = where(ttype EQ 'ERR_SKY', N_skyerr)
    if N_skyerr EQ 0 then ftaddcol,h,tab,'ERR_SKY',8,'F8.3'
    ftput,h,tab,'ERR_SKY',0,skyerr
    nstars = N_elements(xc)
    name = 'MAG'       &  e_name = 'ERR_AP'
    units = ' MAG'
    f_format = 'F7.3'  &  e_format ='F6.3'

    for i = 1,N_elements(apr) do begin    
       ii = strtrim(i,2)
      apsize = 'APR' + ii
      sxaddpar,h,apsize,apr[i-1],' Aperture ' + ii + ' Size','TTYPE1'
      field = 'AP' + ii + '_' + name                
      efield = e_name + ii 
      gap = where(ttype EQ field, Nap)
     
      if Nap EQ 0 then begin            ;Create new columns?
           ftaddcol,h,tab,field,8,f_format,units
           ftaddcol,h,tab,efield,8,e_format,units
      endif
      ftput,h,tab,field,0,fltarr(nstars) + mags[i-1,*]
      ftput,h,tab,efield,0,fltarr(nstars) + errap[i-1,*]
    endfor     

    sxaddhist,'T_APER: '+ systime(),h
 endif

 writefits, newtable, 0, hprimary
 writefits, newtable, tab,h,/append

 return
 end