def iraf_phot(f,x,y,zmag=26.5,apin=10,skyin=15,skywidth=10):
    """Compute the magnitude of the star at location x/y"""
    import pyfits
    import re
    infits=pyfits.open(f,'update')
    f=re.sub(r'.fits$','',f)
    
    ### Get my python routines
    from pyraf import iraf
    from pyraf.irafpar import IrafParList

    ### keep all the parameters locally cached.
    iraf.set(uparm="./")
    iraf.set(imtype="fits")


    ### Load the required IRAF packages
    iraf.digiphot()
    iraf.apphot()
    iraf.daophot()
    
    ### temp file name hash.
    tfile={}
    
    iraf.datapars.datamax=60000
    iraf.datapars.datamin=-1000
    iraf.datapars.airmass='AIRMASS'
    iraf.datapars.filter='FILTER'
    iraf.datapars.obstime='TIME-OBS'
    iraf.datapars.exposure='EXPTIME'
    iraf.datapars.gain='GAIN'
    iraf.datapars.ccdread='RDNOISE'
    iraf.datapars.fwhmpsf=5.0
    
    iraf.centerpars.calgorithm='centroid'
    iraf.photpars.zmag=zmag
    iraf.photpars.apertures=apin
    iraf.fitskypars.annulus=skyin
    iraf.fitskypars.dannulus=skywidth
    iraf.daophot.verbose=iraf.no
    iraf.daophot.verify=iraf.no
    iraf.daophot.update=iraf.no
    
    iraf.psf.interactive=iraf.no
    iraf.pstselect.interactive=iraf.no
    
    iraf.datapars.saveParList()
    iraf.fitskypars.saveParList()
    iraf.centerpars.saveParList()
    iraf.findpars.saveParList()
    iraf.photpars.saveParList()
    
    tfiles = ['coo','mag']
    

    
    for file in tfiles:
        extname=f
        tfile[file]=extname+"."+file
        if ( os.access(tfile[file],os.F_OK) ):
            os.unlink(tfile[file])
            
    this_image=f
        
    fd = open(tfile['coo'],'w')
    fd.write('%f %f\n' % ( x, y) )
    fd.close()
    
    print "Measuring photometry psf star in "+tfile['coo']
    iraf.daophot.phot(image=this_image,
                      coords=tfile['coo'],
                      output=tfile['mag'])

    import string
    a=iraf.txdump(tfile['mag'],"MAG,XCEN,YCEN",iraf.yes,Stdout=1)
    (mag,x,y)=string.split(a[0])

    inhdu=infits[0].header
    
    inhdu.update("PSFMAG",float(mag),comment="PSF Magnitude")
    inhdu.update("PSF_X",float(x),comment="PSF Magnitude")
    inhdu.update("PSF_Y",float(y),comment="PSF Magnitude")
    inhdu.update("ZMAG",zmag,comment="ZMAG of PSF ")

    ## now measure using a smaller aperture to get aper correction
    iraf.photpars.apertures=apin*3.0
    os.unlink(tfile['mag'])
    iraf.daophot.phot(image=this_image,
                      coords=tfile['coo'],
                      output=tfile['mag'])
    a=iraf.txdump(tfile['mag'],"MAG,XCEN,YCEN",iraf.yes,Stdout=1)
    (magout,x,y)=string.split(a[0])
    inhdu.update("APCOR",float(magout)-float(mag),comment="AP_OUT - AP_IN")
    inhdu.update("AP_IN",apin*3.0,comment="Small aperature")
    inhdu.update("AP_OUT",apin,comment="Large aperture")

    
    #    ### append this psf to the output images....
    
    infits.close()
    
    ### remove the temp file we used for this computation.
    #for tf in tfile.keys():
    #    if os.access(tfile[tf],os.F_OK):
    #        os.unlink(tfile[tf])
    return 0