Load a text file with target coordinates. Returns
        an array of target locations in Galactic coordinates.
        File description:
        [NAME] [LON] [LAT] [RADIUS] [COORD]
        
        The values of LON and LAT will depend on COORD:
        COORD = [GAL  | CEL | HPX  ],
        LON   = [GLON | RA  | NSIDE]
        LAT   = [GLAT | DEC | PIX  ]

def parse_targets(filename):
        """
        Load a text file with target coordinates. Returns
        an array of target locations in Galactic coordinates.
        File description:
        [NAME] [LON] [LAT] [RADIUS] [COORD]
        
        The values of LON and LAT will depend on COORD:
        COORD = [GAL  | CEL | HPX  ],
        LON   = [GLON | RA  | NSIDE]
        LAT   = [GLAT | DEC | PIX  ]

        """
        base,ext = os.path.splitext(filename)
        if (ext=='.fits'):
            import fitsio
            data = fitsio.read(filename)
        elif (ext=='.txt'):
            from numpy.lib import NumpyVersion
            if NumpyVersion(np.__version__) < '1.14.0':
                data = np.genfromtxt(filename,names=True,dtype=None)
            else:
                data = np.genfromtxt(filename,names=True,dtype=None,encoding=None)
            #data = np.genfromtxt(filename,unpack=True,usecols=list(range(5)),dtype=object,names=True)
        elif (ext=='.yaml'):
            import yaml
            data = [(k,v['kernel']['lon']['value'],v['kernel']['lat']['value'],0.5,'CEL') for k,v in yaml.load(open(filename)).items()]
            data = np.rec.fromrecords(data,names=['name','lon','lat','radius','coord'])
        else:
            msg = "Unrecognized file type: %s"%filename
            raise IOError(msg)

        data = np.atleast_1d(data)
        data.dtype.names = list(map(str.lower,data.dtype.names))

        # Deal with one-line input files
        #if data.ndim == 1: data = np.array([data]).T
        names = data['name']
        out   = data[['lon','lat','radius']].copy()
         
        coord = np.char.lower(data['coord'])
        gal = (coord=='gal')
        cel = (coord=='cel')
        hpx = (coord=='hpx')
         
        if cel.any():
            glon,glat = cel2gal(data['lon'][cel],data['lat'][cel])
            out['lon'][cel] = glon
            out['lat'][cel] = glat
        if hpx.any():
            glon,glat = pix2ang(data['lat'][hpx],data['lon'][hpx])
            out['lon'][hpx] = glon
            out['lat'][hpx] = glat
         
        return names,out.view(np.ndarray)