def searchTriples(expnums,ccd,plant=False):
    """Given a list of exposure numbers, find all the KBOs in that set of exposures"""
    import MOPfits,os 
    import MOPdbaccess
    
    if len(expnums)!=3:
        raise TaskError, "got %d exposures"%(len(expnums))


    ### Some program Constants
    proc_these_files=[]
    if not plant:
        proc_these_files.append("# Files to be planted and searched\n")
        proc_these_files.append("#            image fwhm plant\n")
        
    import string
    import os.path
    filenames=[]
    import pyfits
    for expnum in expnums:
        ### Get the processed images from AD
        if int(ccd)<18:
            cutout="[-*,-*]"
        else:
            cutout="[*,*]"
        filename=MOPfits.adGet(str(expnum)+opt.raw,extno=int(ccd),cutout=cutout)

        if not os.access(filename,os.R_OK):
            sys.stderr.write("Ad Get Failed\n")
            raise TaskError, 'adGet Failed'
	    
	if opt.none:
	    continue

        filename=os.path.splitext(filename)
        filenames.append(filename[0])

    	try: 
            mysql=MOPdbaccess.connect('bucket','cfhls','MYSQL')
            bucket=mysql.cursor()
	except:
            raise TaskError, "mysql failed"
        bucket.execute("SELECT obs_iq_refccd FROM exposure WHERE expnum=%s" , (expnum, ) )
        row=bucket.fetchone()
	mysql.close()
        fwhm=row[0]
        if not fwhm > 0:
            fwhm=1.0

        if not plant:
            #proc_these_files.append("%s %f %s \n" % ( filename[0], fwhm/0.183, 'no'))
	    pstr='NO'
        else:
	    pstr='YES'
            ### since we're planting we need a psf.  JMPMAKEPSF will
            ### update the proc-these-files listing

        ### run the make psf script .. always.  This creates proc-these-files
        ### which is needed by the find.pl script.
        command='jmpmakepsf.csh ./ %s %s' % ( filename[0], pstr )
        if opt.verbose:
            sys.stderr.write( command )
        try:
            os.system(command)
        except:
            raise TaskError, "jmpmakepsf noexec"
        if os.access(filename[0]+'.jmpmakepsf.FAILED',os.R_OK) or not os.access(filename[0]+".psf.fits", os.R_OK) :
#	    if plant:
#                raise TaskError, "jmpmakepsf failed"
#	do without plant
            if 1==1 :
	        plant=False
		pstr='NO'
	        ### we're not planting so, lets keep going
		### but check that there is a line in proc_these_files
	        add_line=True
		if not os.access('proc-these-files',os.R_OK):
		    f=open('proc-these-files','w')
		    for l in proc_these_files:
		        f.write(l)
		    f.close()
	    	f=open('proc-these-files','r')
		ptf_lines=f.readlines()
		f.close()
		for ptf_line in ptf_lines:
		    if ptf_line[0]=='#':
		        continue
	            ptf_a=ptf_line.split()
		    import re
		    if re.search('%s' % (filename[0]),ptf_a[0]):
		        ### there's already a line for this one
			add_line=False
		        break
                if add_line:
		    f=open('proc-these-files','a')
		    f.write("%s %f %s \n" % ( filename[0], fwhm/0.183, 'no'))
		    f.close()

    if opt.none:
        return(-1)
    prefix=''
    if plant:
        command="plant.csh ./ -rmin %s -rmax %s -ang %s -width %s " % ( opt.rmin, opt.rmax, opt.angle, opt.width)
        try: 
            os.system(command)
        except:
            raise TaskError, 'plant exec. failed'
        if not os.access('plant.OK',os.R_OK):
            raise TaskError, 'plant failed'
        prefix='fk'
    #else:
    #    f=open('proc-these-files','w')
    #    for line in proc_these_files:
    #        f.write(line)
    #    f.flush()
    #    f.close()
    	
    if opt.rerun and os.access('find.OK',os.R_OK):
        os.unlink("find.OK")

    command="find.pl -p "+prefix+" -rn %s -rx %s -a %s -aw %s -d ./ " % ( opt.rmin, opt.rmax, opt.angle, opt.width) 
    #command="find.pl -p "+prefix+" -d ./ " 
    if opt.verbose:
        sys.stderr.write( command )

    try:
        os.system(command)
    except:
        raise TaskErorr, "execute find"
    

    if not os.access("find.OK",os.R_OK):
        raise TaskError, "find failed"

    ### check the transformation file
    command = "checktrans -p "+prefix
    
    try:
        os.system(command)
    except:
        raise TaskError, "execute checktrans"
    
    if not os.access("checktrans.OK",os.R_OK):
        raise TaskError, "checktrans failed"

    if os.access("BAD_TRANS"+prefix,os.R_OK):
        raise TaskError,"BAD TRANS"
        
    astrom=prefix+filenames[0]+".cands.comb"
    if opt.plant:
        astrom=prefix+filenames[0]+".comb.found"
        try:
            #make sure we have +10 lines in this file
	    lines=file(astrom).readlines()
	    if len(lines)<10:
	       raise TaskError,"Too few Found"
	except:
	    raise TaskError, "Error reading %s" %(astrom)
	    
    
    if os.access(astrom,os.R_OK):
        return(1)
    else:
        return(0)
Given a list of exposure numbers, find all the KBOs in that set of exposures