def trim(hdu):
    """TRIM a CFHT MEGAPRIME frame  using the DATASEC keyword"""
    datasec = re.findall(r'(\d+)',
                         hdu.header.get('DATASEC'))
    l=int(datasec[0])-1
    r=int(datasec[1])
    b=int(datasec[2])-1
    t=int(datasec[3])
    if opt.verbose:
        print "Trimming [%d:%d,%d:%d]" % ( l,r,b,t)
    hdu.data = hdu.data[b:t,l:r]    
    hdu.header.update('DATASEC',"[%d:%d,%d:%d]" % (1,r-l+1,1,t-b+1), comment="Image was trimmed")
    hdu.header.update('ODATASEC',"[%d:%d,%d:%d]" % (l+1,r,b+1,t), comment="previous DATASEC")
    return