from astropy.io import fits
import sys

#filename='4XMM_DR12cat_slim_v1.0_UDS.fits.catalog'
filename='4XMM_slim_DR14cat_v1.0_Coma.fits'
fout=filename.replace(".fits", ".names.reg")

hdul = fits.open(filename)
#hdul.info()

tbdata = hdul[1].data
hdul.close()


with open("./{}".format(fout), 'w') as writer:
    for rec in tbdata:
        print("fk5;circle({}, {}, 0.008)".format(rec['sc_ra'],rec['sc_dec']))
        writer.write("fk5;circle({}, {}, {}) # text={{{}}}\n".format(rec['sc_ra'],rec['sc_dec'],rec['sc_poserr']/3600,rec['IAUNAME']))

