def load_abgfiles(dir=None):
    """Load the targets from a file"""
    import ephem,string
    if dir is None:
        import tkFileDialog
	try: 
            dir=tkFileDialog.askdirectory()
        except:
            return
    if dir is None:
        return None
    from glob import glob
    files=glob(dir+"/*.abg")
    import os
    for f in files:
        (name,ext)=os.path.splitext(os.path.basename(f))
	NAME=name.strip().upper()
	kbos[name]=f
	#print name
        aei=file(dir+"/"+name+".aei")
        lines=aei.readlines()
        aei.close()
        objInfoDict[name]="%6s %6s %6s\n" % ( string.center("a",6),
				            string.center("e",6),
	 				    string.center("i",6) ) 
        try:
          (a,e,i,N,w,T) = lines[4].split()
        except:
          print lines[4]
          (a,e,i,N,w,T) = (0,0,0,0,0,0)
        objInfoDict[name]+="%6.2f %6.3f %6.2f\n" % (float(a),float(e),float(i))
        s=lines[5][0:2]
        (a,e,i,N,w,T) = lines[5][2:-1].split()
        objInfoDict[name]+=" %6.3f %6.3f %6.3f\n" % (float(a),float(e),float(i))
        abg = file(dir+"/"+name+".abg")
        lines = abg.readlines()
        abg.close()
	for line in lines:
	    if not line[0:5] == "# Bar":
	        continue
            objInfoDict[name]+=line[2:-1]+"\n"
            break
        res=file(dir+"/"+name+".res")
        lines=res.readlines()
        res.close()
        line=lines.pop()
        values=line.split()
        s = "[nobs: "+values[0]+" dt: "+values[1]+"]\n"
        objInfoDict[name]+=s
        mpc = file(dir+"/../mpc/"+name+".mpc")
        lines=mpc.readlines()
        mpc.close()
	last_date=0
	for line in lines:
	    if len(line)==0:
		continue
	    if line[0]=="#":
		continue
            this_year=int(line[15:19])
            this_month=int(line[20:22])
            this_day = int(line[23:25])
	    this_date =  this_year+this_month/12.0 +this_day/365.25
	    if last_date < this_date:
		last_date=this_date
		year=this_year
		day = this_day
		month=this_month	
        mag={}
        for line in lines:
            try:
                mags=line[65:69].strip()
		if len(mags)==0:
		    continue
                filter=line[70]
	        if filter not in mag:
                    mag[filter]=[]
                mag[filter].append(float(mags)) 
	    except:
	        continue
        mags=''
        for filter in mag:
	    magv=0
 	    for m in mag[filter]:
	        magv = magv+m/len(mag[filter]) 
            mags = mags+ "%4.1f-%s " % ( magv , filter)
        if len(mags)==0:
	    mags= "N/A"
        objInfoDict[name]+="MAG: "+mags+"\n"
        objInfoDict[name]+="Last obs: %s %s %s \n" % (year,month, day)

    doplot(kbos)