def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)

    all_designs = []
    if os.path.isdir(job_dir):
        for d in os.listdir(job_dir):
            if d.endswith('.csv'):
                d = os.path.join(job_dir, d)
                os.remove(d)
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir, dir + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        for design in all_designs:
            lock = Lock()
            if need_design:
                if design == need_design:
                    pass
                else:
                    continue

            def scan_sigal(job_dir, design):
                print_always('scanning %s' % design)
                design_path = os.path.join(job_dir, design)  # e60_ecp3/g64
                srr_file = ''
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    if (not re.search("Target", dir)
                        ) and os.path.isdir(dir_scan) and not srr_file:
                        srr_file = get_unique_file([dir_scan, ".srr"])
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file:
                    #    srr_file = get_unique_file([dir_scan, ".srr"])
                    if re.search("Target", dir) and os.path.isdir(dir_scan):
                        pass
                    else:
                        continue
                    recover = RecoverPath(dir_scan)
                    used_dir = ''
                    for f_d in os.listdir(dir_scan):
                        f_d_full = os.path.join(dir_scan, f_d)
                        if os.path.isdir(f_d_full):
                            if used_dir:
                                print 'Worning: There are two implementation in the design'
                            used_dir = f_d_full
                    #srr_file = get_unique_file([used_dir, ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path, dir, srr_file)
                        scan_time.scan_srr(srr_file)
                    mrp_file = get_unique_file([used_dir, ".mrp"])
                    if not_exists(mrp_file, "map report file"):

                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file = ""
                    target_fmax_for_time = '_'
                    #------------------------------------------------#
                    if 1:
                        useful_dir = used_dir
                        base_name = os.path.basename(useful_dir)
                        scan_time.reset_par_time_data()
                        target_fmax_for_match = target_fmax_re.search(dir)
                        if target_fmax_for_match:
                            target_fmax_for_time = target_fmax_for_match.group(
                                1)
                        twr_p = os.path.join(useful_dir,
                                             '*' + base_name + ".twr")
                        twr_file = get_unique_file(twr_p)
                        if not twr_file:
                            twr_file = get_unique_file([useful_dir, ".twr"])
                        time_file = os.path.join(useful_dir, time_file)
                        par_file = get_unique_file([useful_dir, ".par"])
                        if twr_file:
                            scan_twr.scan_report(twr_file)
                            scan_time.scan_report(time_file)
                            scan_time.scan_par(par_file)
                            #########################
                            #time_title = ['design']+scan_time.get_title2()
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items() +
                                                 mrp_data.items() +
                                                 par_data.items() +
                                                 real_cpu_total.items())
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))

                            #########################
                            #data = [design] + scan_mrp.get_data() + \
                            #      scan_twr.get_data() + data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                            ['_']*len(data_list)
                            else:
                                data_list = scan_mrp.get_data() + \
                                  scan_twr.get_data() + data_list
                            data = [design] + data_list
                            append_file(report_file, ",".join(data))
                            data = [design]
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            append_file(
                                report_file_twr,
                                ",".join([design] + scan_twr.get_data()))
                            #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                            scan_time.reset_par_time_data()
                            #lock.release()
                        if not twr_file:
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                  real_cpu_total.items() )
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))
                            #data = [design] + scan_mrp.get_data()+ data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data = [design] + ['_'] * len(
                                    scan_mrp.get_data()) + ['_'
                                                            ] * len(data_list)
                            else:
                                data = [design
                                        ] + scan_mrp.get_data() + data_list
                            append_file(report_file, ",".join(data))
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design + ',' + key + ',' + clock_dict[key]
                        append_file(report_file_clock, line)
                    lock.release()
                    recover.run()

            Process(target=scan_sigal, args=(job_dir, design)).start()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    file_hand_pass = file('pass_case.log', 'w')
    #----------read fail case first:
    try:
        file_hand_fail = file('fail_case.log', 'r')
        fail_case_lines = file_hand_fail.readlines()
        file_hand_fail.close()
        fail_case_lines2 = [
            f_c.split(':')[0].strip() for f_c in fail_case_lines
        ]
    except:
        fail_case_lines2 = []
    file_hand_fail = file('fail_case.log', 'w')
    for key in design_fmax.keys():
        v = design_fmax[key]

        if re.search(r'\d', v):
            file_hand_pass.write(key + '\n')
        else:
            if key in fail_case_lines2:
                fail_k = fail_case_lines[fail_case_lines2.index(key)]
                file_hand_fail.write(fail_k.strip() + '\n')
            else:
                file_hand_fail.write(key + '\n')
    file_hand_pass.close()
    file_hand_fail.close()

    #----------------update run_stand-------------------#
    if 1:
        pass_log = glob.glob('pass_case.log')
        if pass_log:
            pass_log = pass_log[0]
        else:
            pass_log = '__'
        if os.path.isfile(pass_log):
            file_hand = file(pass_log, 'r')
            lines = file_hand.readlines()
            file_hand.close()
            stand_name = glob.glob('*' + '_run_stand.bat')
            if stand_name:
                stand_name = stand_name[0]
            #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
            else:
                stand_name = ''
            run_standard = file(stand_name, 'r')
            run_standard_lines = run_standard.readlines()
            run_standard_lines = list(set(run_standard_lines))
            run_standard.close()
            #--------------
            try:
                again_name = glob.glob('*' + 'run_again.bat')
                if again_name:
                    again_name = again_name[0]
                #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
                else:
                    again_name = ''
                try:
                    again = file(again_name, 'r')
                    again_lines = again.readlines()
                    again_lines = list(set(again_lines))
                    again.close()
                    replaced_job_dir = os.path.basename(os.getcwd())
                    again_lines = [
                        re.sub(r'--job-dir=\S+',
                               '--job-dir=' + replaced_job_dir, ag)
                        for ag in again_lines
                    ]
                    new_again = []
                    #again_lines = [re.sub(r'--job-dir=\S+',replaced_job_dir,ag) for ag in again_lines]
                    #for ag in again_lines:
                    for ag in again_lines:
                        file_f = re.findall('--file=(\S+)', ag)
                        if file_f:
                            new_f = os.path.basename(file_f[-1])
                            ag = re.sub(r'--file=(\S+)', '--file=' + new_f, ag)
                        new_again.append(ag)

                    run_standard_lines1 = run_standard_lines + new_again
                    run_standard_lines1 = list(set(run_standard_lines1))
                except:
                    run_standard_lines1 = list(set(run_standard_lines))
                    #pass

                #run_standard_lines = run_standard_lines + again_lines
            except:
                pass

            useful_lines = []
            for case in lines:
                case = case.strip()
                if not case:
                    continue
                else:
                    pass
                case_tab = '--design=' + case
                case_tab_re = re.compile(case_tab + r'(\s+|$)')
                for line in run_standard_lines1:
                    line = line.strip()
                    if not line:
                        continue
                    if case_tab_re.search(line):
                        try:
                            fmax = float(design_fmax[case.strip()])
                            fmax = str(int(fmax))
                            line = re.sub(r'--fmax-sweep=[\s\d]+\d', '', line)
                            line2 = line + ' --fmax-sweep=' + fmax + ' ' + fmax + ' ' + '10 \n'
                            useful_lines.append(line2)
                        except:
                            #line2 = line
                            pass

            run_standard = file(stand_name, 'w')
            run_standard.writelines(useful_lines)
            run_standard.close()
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Seed_is_(.+)")
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)

    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir, dir + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_seed']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        for design in all_designs:
            if need_design:
                if design == need_design:
                    pass
                else:
                    continue
            print_always('scanning %s' % design)
            design_path = os.path.join(job_dir, design)  # e60_ecp3/g64
            srr_file = ''
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                if (not re.search("Target", dir)
                    ) and os.path.isdir(dir_scan) and (not srr_file):
                    srr_file = get_unique_file([dir_scan, ".srr"])
                if re.search("Target", dir) and os.path.isdir(dir_scan):
                    pass
                else:
                    continue
                recover = RecoverPath(dir_scan)
                used_dir = ''
                #-------
                #used_dir = dir_scan
                for f_d in os.listdir(dir_scan):
                    f_d_full = os.path.join(dir_scan, f_d)
                    if os.path.isdir(f_d_full):
                        if used_dir:
                            print 'Warning: There are two implementation in the design'
                        used_dir = f_d_full
                #-------------
                if not srr_file:
                    pass
                else:
                    srr_file = os.path.join(design_path, dir, srr_file)
                    scan_time.scan_srr(srr_file)
                mrp_file = get_unique_file([used_dir, ".mrp"])
                if not_exists(mrp_file, "map report file"):

                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                twr_file = time_file = par_file = ""
                target_fmax_for_time = '_'
                #------------------------------------------------#
                if 1:
                    useful_dir = used_dir
                    base_name = os.path.basename(useful_dir)
                    scan_time.reset_par_time_data()
                    target_fmax_for_match = target_fmax_re.search(dir)
                    if target_fmax_for_match:
                        target_fmax_for_time = target_fmax_for_match.group(1)
                    twr_p = os.path.join(useful_dir, '*' + base_name + ".twr")
                    twr_file = get_unique_file(twr_p)
                    if not twr_file:
                        twr_file = get_unique_file([useful_dir, ".twr"])
                    time_file = os.path.join(useful_dir, time_file)
                    par_file = get_unique_file([useful_dir, ".par"])
                    if twr_file:
                        scan_twr.scan_report(twr_file)
                        scan_time.scan_report(time_file)
                        scan_time.scan_par(par_file)
                        #########################
                        #time_title = ['design']+scan_time.get_title2()
                        srr_data = scan_time.get_srr_time_data()
                        mrp_data = scan_time.get_mrp_time_data()
                        par_data = scan_time.get_par_time_data()
                        real_cpu_total = scan_time.get_total_time()
                        all_time_data = dict(srr_data.items() +
                                             mrp_data.items() +
                                             par_data.items() +
                                             real_cpu_total.items())
                        data_list = []
                        for key in scan_time.get_title():
                            value = all_time_data.get(key, 'NA')
                            data_list.append(value)
                        data_list2 = [design] + [target_fmax_for_time
                                                 ] + data_list
                        append_file(report_file_time, ",".join(data_list2))

                        #########################
                        #data = [design] + scan_mrp.get_data() + \
                        #      scan_twr.get_data() + data_list
                        if all_time_data['Complete'] == 'NA' or all_time_data[
                                'Par_Done'] == 'NA':
                            data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                        ['_']*len(data_list)
                        else:
                            data_list = scan_mrp.get_data() + \
                              scan_twr.get_data() + data_list
                        data = [design] + data_list
                        append_file(report_file, ",".join(data))
                        data = [design]
                        append_file(report_file_mrp,
                                    ",".join([design] + scan_mrp.get_data()))
                        append_file(report_file_twr,
                                    ",".join([design] + scan_twr.get_data()))
                        #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                        scan_time.reset_par_time_data()
                    if not twr_file:
                        srr_data = scan_time.get_srr_time_data()
                        mrp_data = scan_time.get_mrp_time_data()
                        par_data = scan_time.get_par_time_data()
                        real_cpu_total = scan_time.get_total_time()
                        all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                              real_cpu_total.items() )
                        data_list = []
                        for key in scan_time.get_title():
                            value = all_time_data.get(key, 'NA')
                            data_list.append(value)
                        data_list2 = [design] + [target_fmax_for_time
                                                 ] + data_list
                        append_file(report_file_time, ",".join(data_list2))
                        #data = [design] + scan_mrp.get_data()+ data_list
                        if all_time_data['Complete'] == 'NA' or all_time_data[
                                'Par_Done'] == 'NA':
                            data = [design] + ['_'] * len(
                                scan_mrp.get_data()) + ['_'] * len(data_list)
                        else:
                            data = [design] + scan_mrp.get_data() + data_list
                        append_file(report_file, ",".join(data))
                        append_file(report_file_mrp,
                                    ",".join([design] + scan_mrp.get_data()))
                        scan_time.reset_par_time_data()
                scan_mrp.scan_clocks(mrp_file)
                clock_dict = scan_mrp.get_parse_line_clocks()
                for key in clock_dict.keys():
                    line = design + ',' + key + ',' + clock_dict[key]
                    append_file(report_file_clock, line)
                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    design = opt.design
    syn = opt.synthesis
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_xilinx.ScanXilinxMrp()
    scan_twr = tool_scan_xilinx.ScanXilinxTwr()
    scan_time = tool_scan_xilinx.ScanXilinxTimeMem()
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)
    print for_pattern

    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    if design:
        print_always('scanning %s' % design)
        if design in all_designs:
            design_path = os.path.join(job_dir, design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(
                        os.path.join(design_path, dir)):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(job_dir, dir + '.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner:  #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))

                    if 1:
                        report_name, subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name + '_mrp' + subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name + '_twr' + subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name + '_time_mem' + subtex
                        if not_exists(report_file_time):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))

                ######################
                    dir_scan = os.path.join(design_path, dir)
                    twr_file = time_file = ""
                    if 'rev_1' in os.listdir(dir_scan):
                        scan_time.set_srr_data()
                        foo = os.path.join(dir_scan, 'rev_1', '*.srr')
                        srr_file = get_unique_file(foo)
                        if srr_file:
                            scan_time.scan_srr(srr_file)
                    for foo in os.listdir(dir_scan):
                        foo = os.path.join(dir_scan, foo)
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                print foo
                                recover = RecoverPath(
                                    os.path.join(design_path, dir, foo))
                                scan_mrp.reset()
                                #scan_time.reset()
                                scan_time.set_map_data()
                                scan_time.set_par_data()

                                scan_twr.reset()
                                print_always("  Scanning %s" % foo)
                                _project_name = "%s_%s" % (dir, design[:7])
                                project_name = _project_name.strip("_")
                                mrp_file = os.path.join(
                                    dir_scan, foo, project_name + "_map.mrp")
                                scan_mrp.scan_report(mrp_file)
                                scan_time.scan_map(mrp_file)
                                par_file = os.path.join(
                                    dir_scan, foo, project_name + ".par")
                                scan_time.scan_par(par_file)
                                twr_file = os.path.join(
                                    dir_scan, foo, project_name + ".twr")

                                scan_twr.scan_report(twr_file)
                                time_file = os.path.join(
                                    dir_scan, foo, "mpar_log.time")
                                #scan_time.scan_report(time_file)
                                data1 = scan_mrp.get_data()
                                append_file(report_file_mrp,
                                            ",".join([design] + data1))
                                data2 = scan_twr.get_data()
                                append_file(report_file_twr,
                                            ",".join([design] + data2))
                                data3 = scan_time.get_data()
                                append_file(report_file_time,
                                            ",".join([design] + data3))
                                data = data1 + data2 + data3
                                append_file(report_file,
                                            ",".join([design] + data))
                                recover.run()

        else:
            print 'The design is not exists in the job_dir'
            return
    else:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always('scanning %s' % design)
            design_path = os.path.join(job_dir, design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(
                        os.path.join(design_path, dir)):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(job_dir, dir + '.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner:  #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name, subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name + '_mrp' + subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name + '_twr' + subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name + '_time_mem' + subtex
                        if not_exists(report_file_time):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))

                ######################
                    dir_scan = os.path.join(design_path, dir)
                    twr_file = time_file = ""
                    if 'rev_1' in os.listdir(dir_scan):
                        scan_time.set_srr_data()
                        foo = os.path.join(dir_scan, 'rev_1', '*.srr')
                        srr_file = get_unique_file(foo)
                        if srr_file:
                            scan_time.scan_srr(srr_file)

                    for foo in os.listdir(dir_scan):
                        if os.path.isdir(os.path.join(design_path, dir, foo)):
                            if re.search("Target", foo):
                                recover = RecoverPath(
                                    os.path.join(design_path, dir, foo))
                                scan_mrp.reset()
                                #scan_time.reset()
                                scan_time.set_map_data()
                                scan_time.set_par_data()
                                scan_twr.reset()
                                print_always("  Scanning %s" % foo)
                                _project_name = "%s_%s" % (dir, design[:7])
                                project_name = _project_name.strip("_")
                                mrp_file = os.path.join(
                                    dir_scan, foo, project_name + "_map.mrp")
                                scan_mrp.scan_report(mrp_file)
                                scan_time.scan_map(mrp_file)
                                par_file = os.path.join(
                                    dir_scan, foo, project_name + ".par")
                                scan_time.scan_par(par_file)
                                twr_file = os.path.join(
                                    dir_scan, foo, project_name + ".twr")
                                scan_twr.scan_report(twr_file)
                                #time_file = os.path.join(dir_scan,foo,"mpar_log.time")
                                #scan_time.scan_report(time_file)
                                data1 = scan_mrp.get_data()
                                append_file(report_file_mrp,
                                            ",".join([design] + data1))
                                data2 = scan_twr.get_data()
                                append_file(report_file_twr,
                                            ",".join([design] + data2))
                                data3 = scan_time.get_data()
                                append_file(report_file_time,
                                            ",".join([design] + data3))
                                data = data1 + data2 + data3
                                append_file(report_file,
                                            ",".join([design] + data))
                                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    #----------------update run_stand-------------------#
    pass_log = glob.glob('*' + syn + '_pass_case.log')
    if pass_log:
        pass_log = pass_log[0]
    else:
        pass_log = '__'
    if os.path.isfile(pass_log):
        file_hand = file(pass_log, 'r')
        lines = file_hand.readlines()
        file_hand.close()
        stand_name = glob.glob('*' + syn + '_run_standard.bat')
        if stand_name:
            stand_name = stand_name[0]
        #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
        else:
            stand_name = ''
        run_standard = file(stand_name, 'r')
        run_standard_lines = run_standard.readlines()
        run_standard.close()
        useful_lines = []
        for case in lines:
            case = case.strip()
            if not case:
                continue
            else:
                pass
            case_tab = '--design=' + case
            case_tab_re = re.compile(case_tab + r'(\s+|$)')
            for line in run_standard_lines:
                line = line.strip()
                if not line:
                    continue
                if case_tab_re.search(line):
                    try:
                        fmax = float(design_fmax[case.strip()])
                        fmax = str(int(fmax))
                        #line = case_tab_re.sub('',line)
                        line = re.sub(r'--fmax-sweep=[\s\d]+\d', '', line)
                        line2 = line + ' --fmax-sweep=' + fmax + ' ' + fmax + ' ' + '10 \n'
                    except:
                        line2 = line

                    useful_lines.append(line2)
        run_standard = file(stand_name, 'w')
        run_standard.writelines(useful_lines)
        run_standard.close()
        '''        
Ejemplo n.º 4
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)

    all_designs = []
    if os.path.isdir(job_dir):
        for d in os.listdir(job_dir):
            if d.endswith('.csv'):
                d = os.path.join(job_dir, d)
                os.remove(d)
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir, dir + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        #for design in all_designs:
        for root1, dirs1, files1 in os.walk(job_dir):
            root1 = os.path.abspath(root1)
            find_mrp = 0
            for f in files1:
                if f.endswith('.mrp'):
                    find_mrp = 1
                    break
            if find_mrp == 1:
                pass
            else:
                continue
            design_path = os.path.join(root1)  # e60_ecp3/g64
            srr_file = ''
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                if (not re.search("Target", dir)
                    ) and os.path.isdir(dir_scan) and not srr_file:
                    srr_file = get_unique_file([dir_scan, ".srr"])
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz

                #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file
                recover = RecoverPath(design_path)

                mrp_file = get_unique_file([design_path, ".mrp"])
                if not_exists(mrp_file, "map report file"):

                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                append_file(report_file_mrp,
                            ",".join([design_path] + scan_mrp.get_data()))
                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    file_hand_pass = file('pass_case.log', 'w')
    #----------read fail case first:
    try:
        file_hand_fail = file('fail_case.log', 'r')
        fail_case_lines = file_hand_fail.readlines()
        file_hand_fail.close()
        fail_case_lines2 = [
            f_c.split(':')[0].strip() for f_c in fail_case_lines
        ]
    except:
        fail_case_lines2 = []
    file_hand_fail = file('fail_case.log', 'w')
    for key in design_fmax.keys():
        v = design_fmax[key]

        if re.search(r'\d', v):
            file_hand_pass.write(key + '\n')
        else:
            if key in fail_case_lines2:
                fail_k = fail_case_lines[fail_case_lines2.index(key)]
                file_hand_fail.write(fail_k.strip() + '\n')
            else:
                file_hand_fail.write(key + '\n')
    file_hand_pass.close()
    file_hand_fail.close()
Ejemplo n.º 5
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    design = opt.design
    scan_mrp = tool_scan_xilinx.ScanXilinxMrp()
    scan_twr = tool_scan_xilinx.ScanXilinxTwr()
    scan_time = tool_scan_xilinx.ScanXilinxTimeMem()
    scan_timing_rpt = tool_scan_xilinx.ScanXilinxTimingRpt()
    scan_placed_rpt = tool_scan_xilinx.ScanXilinxPlacedRpt()
    tag = opt.special_structure
    report_name = opt.report_name  #this is useless now
    if report_name == 'report.csv':
        report_file = os.path.basename(job_dir) + '.csv'
    report_path = opt.report_path
    if not report_path:
        report_path = job_dir
    report_file = os.path.join(report_path, report_file)
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    if not design:
        for dir in os.listdir(job_dir):  # get all the design path
            dir2 = os.path.join(job_dir, dir)
            if os.path.isdir(dir2):
                all_designs.append(dir)
            else:
                pass
    else:
        all_designs.append(design)
    report_file_list = []
    if 1:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always('scanning %s' % design)
            design_path = os.path.join(job_dir, design, tag)
            for dir in os.listdir(design_path):
                if dir.endswith('.runs') and os.path.isdir(
                        os.path.join(design_path, dir)):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file_list.append(report_file)

                    ######################
                    dir_scan = os.path.join(design_path, dir)
                    twr_file = time_file = ""
                    if 'rev_1' in os.listdir(dir_scan):
                        scan_time.set_srr_data()
                        foo = os.path.join(dir_scan, 'rev_1', '*.srr')
                        srr_file = get_unique_file(foo)
                        if srr_file:
                            scan_time.scan_srr(srr_file)

                    for foo in os.listdir(dir_scan):
                        if os.path.isdir(os.path.join(design_path, dir, foo)):
                            if re.search("Target", foo):  # this is ISE
                                recover = RecoverPath(
                                    os.path.join(design_path, dir, foo))
                                scan_mrp.reset()
                                #scan_time.reset()
                                scan_time.set_map_data()
                                scan_time.set_par_data()
                                scan_twr.reset()
                                print_always("  Scanning %s" % foo)
                                _project_name = "%s_%s" % (dir, design[:7])
                                project_name = _project_name.strip("_")
                                mrp_file = os.path.join(
                                    dir_scan, foo, project_name + "_map.mrp")
                                if os.path.isfile(mrp_file):
                                    if not_exists(report_file):
                                        title = ["Design"]
                                        for item in scanner:  #mrp twr time
                                            title += item.get_title()
                                        append_file(report_file,
                                                    ",".join(title))
                                    if 1:
                                        report_name, subtex = os.path.splitext(
                                            report_file)
                                        report_file_mrp = report_name + '_mrp' + subtex
                                        if not_exists(report_file_mrp):
                                            title = ["Design"]
                                            #for item in scanner: #mrp twr time
                                            title += (scanner[0]).get_title()
                                            append_file(
                                                report_file_mrp,
                                                ",".join(title))
                                        report_file_twr = report_name + '_twr' + subtex
                                        if not_exists(report_file_twr):
                                            title = ["Design"]
                                            #for item in scanner: #mrp twr time
                                            title += (scanner[1]).get_title()
                                            append_file(
                                                report_file_twr,
                                                ",".join(title))
                                        report_file_time = report_name + '_time_mem' + subtex
                                        if not_exists(report_file_time):
                                            title = ["Design"]
                                            #for item in scanner: #mrp twr time
                                            title += (scanner[2]).get_title()
                                            append_file(
                                                report_file_time,
                                                ",".join(title))

                                    scan_mrp.scan_report(mrp_file)
                                    scan_time.scan_map(mrp_file)
                                    par_file = os.path.join(
                                        dir_scan, foo, project_name + ".par")
                                    scan_time.scan_par(par_file)
                                    twr_file = os.path.join(
                                        dir_scan, foo, project_name + ".twr")
                                    scan_twr.scan_report(twr_file)
                                    #time_file = os.path.join(dir_scan,foo,"mpar_log.time")
                                    #scan_time.scan_report(time_file)
                                    data1 = scan_mrp.get_data()
                                    append_file(report_file_mrp,
                                                ",".join([design] + data1))
                                    data2 = scan_twr.get_data()
                                    append_file(report_file_twr,
                                                ",".join([design] + data2))
                                    data3 = scan_time.get_data()
                                    append_file(report_file_time,
                                                ",".join([design] + data3))
                                    data = data1 + data2 + data3
                                    append_file(report_file,
                                                ",".join([design] + data))

                                #for vivado
                                if not os.path.isfile(twr_file):
                                    if 1:
                                        title = ["Design"]
                                        for item in [
                                                scan_timing_rpt,
                                                scan_placed_rpt
                                        ]:  #mrp twr time
                                            title += item.get_title()
                                        if not_exists(report_file):
                                            append_file(
                                                report_file, ",".join(title))
                                        if 0:
                                            report_name, subtex = os.path.splitext(
                                                report_file)
                                            report_file_mrp = report_name + '_mrp' + subtex
                                            if not_exists(report_file_mrp):
                                                title = ["Design"]
                                                #for item in scanner: #mrp twr time
                                                title += (
                                                    scanner[0]).get_title()
                                                append_file(
                                                    report_file_mrp,
                                                    ",".join(title))
                                            report_file_twr = report_name + '_twr' + subtex
                                            if not_exists(report_file_twr):
                                                title = ["Design"]
                                                #for item in scanner: #mrp twr time
                                                title += (
                                                    scanner[1]).get_title()
                                                append_file(
                                                    report_file_twr,
                                                    ",".join(title))
                                            report_file_time = report_name + '_time_mem' + subtex
                                            if not_exists(report_file_time):
                                                title = ["Design"]
                                                #for item in scanner: #mrp twr time
                                                title += (
                                                    scanner[2]).get_title()
                                                append_file(
                                                    report_file_time,
                                                    ",".join(title))
                                    timing_rpt = os.path.join(
                                        dir_scan, foo,
                                        '*timing_summary_routed.rpt')
                                    timing_rpt = get_unique_file(timing_rpt)
                                    total_data = [design]
                                    if timing_rpt:
                                        scan_timing_rpt.scan_report(timing_rpt)
                                        total_data += scan_timing_rpt.get_data(
                                        )
                                    else:
                                        total_data += ['NA'] * len(
                                            scan_timing_rpt.get_title())

                                    placed_rpt = os.path.join(
                                        dir_scan, foo,
                                        '*utilization_placed.rpt')
                                    placed_rpt = glob.glob(placed_rpt)
                                    used_rpt = ''
                                    for rpt in placed_rpt:
                                        if rpt.find('clock_utilization') != -1:
                                            continue
                                        else:
                                            used_rpt = rpt
                                            break
                                    if used_rpt:
                                        scan_placed_rpt.scan_report(used_rpt)
                                        total_data += scan_placed_rpt.get_data(
                                        )
                                    else:
                                        total_data += ['NA'] * len(
                                            scan_placed_rpt.get_title())

                                    append_file(report_file,
                                                ",".join(total_data))
                                    for_bqs_data = '<scan_case>\n'
                                    for id1, t in enumerate(title):

                                        for_bqs_data = for_bqs_data + "\t<%s>" % t + total_data[
                                            id1] + "</%s>\n" % t
                                    for_bqs_data = for_bqs_data + "</scan_case>"
                                    print '#BQS_RETRN_DATA_BEGIN#'
                                    print for_bqs_data
                                    print '#BQS_RETRN_DATA_END#'
                                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    #----------------update run_stand-------------------#
    if 0:
        pass_log = glob.glob('*' + syn + '_pass_case.log')
        if pass_log:
            pass_log = pass_log[0]
        else:
            pass_log = '__'
        if os.path.isfile(pass_log):
            file_hand = file(pass_log, 'r')
            lines = file_hand.readlines()
            file_hand.close()
            stand_name = glob.glob('*' + syn + '_run_standard.bat')
            if stand_name:
                stand_name = stand_name[0]
            #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
            else:
                stand_name = ''
            run_standard = file(stand_name, 'r')
            run_standard_lines = run_standard.readlines()
            run_standard.close()
            useful_lines = []
            for case in lines:
                case = case.strip()
                if not case:
                    continue
                else:
                    pass
                case_tab = '--design=' + case
                case_tab_re = re.compile(case_tab + r'(\s+|$)')
                for line in run_standard_lines:
                    line = line.strip()
                    if not line:
                        continue
                    if case_tab_re.search(line):
                        try:
                            fmax = float(design_fmax[case.strip()])
                            fmax = str(int(fmax))
                            #line = case_tab_re.sub('',line)
                            line = re.sub(r'--fmax-sweep=[\s\d]+\d', '', line)
                            line2 = line + ' --fmax-sweep=' + fmax + ' ' + fmax + ' ' + '10 \n'
                        except:
                            line2 = line

                        useful_lines.append(line2)
            run_standard = file(stand_name, 'w')
            run_standard.writelines(useful_lines)
            run_standard.close()
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    if family:
        for_pattern = '_'+family
    if syn:
        for_pattern = for_pattern + '_'+syn
    dir_pattern = re.compile(for_pattern)
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    if design:
        print_always( 'scanning %s'%design)
        if design in all_designs:
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,dir+'.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        if not_exists(report_file_clock):
                            append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan)
                    if not_exists('rev_1', "srr file directory"):
                        continue
                    srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                    if srr_file:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    _project_name = "%s_%s" % (dir, design[:7])
                    project_name = _project_name.strip("_")
                    mrp_file = project_name + ".mrp"
                    if not_exists(mrp_file, "map report file"):
                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file= ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([foo, ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                                scan_twr.scan_report(twr_file)
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) + ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+ ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    
        else:
            print 'The design is not exists in the job_dir'
            return
    
    else:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,dir+'.csv')
                    if report_file in report_file_list:
                        pass
                    else:
                        report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan)
                    if not_exists('rev_1', "srr file directory"):
                        
                        continue
                    srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    _project_name = "%s_%s" % (dir, design[:7])
                    project_name = _project_name.strip("_")
                    mrp_file = project_name + ".mrp"
                    if not_exists(mrp_file, "map report file"):
                        
                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file= ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_time.reset_par_time_data()
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([foo, ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                                scan_twr.scan_report(twr_file)
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                #data = [design] + scan_mrp.get_data() + \
                                #      scan_twr.get_data() + data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                                ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                                scan_time.reset_par_time_data()
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                      real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                #data = [design] + scan_mrp.get_data()+ data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                                scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    recover.run()
            
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted,note)
    #----------------update run_stand-------------------#
    pass_log = glob.glob('*'+syn+'_pass_case.log')
    if pass_log:
        pass_log = pass_log[0]
    else:
        pass_log = '__'
    if os.path.isfile(pass_log):
        file_hand = file(pass_log,'r')
        lines = file_hand.readlines()
        file_hand.close()
        stand_name = glob.glob('*'+syn+'_run_standard.bat')
        if stand_name:
            stand_name = stand_name[0]
        #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
        else:
            stand_name = ''
        run_standard = file(stand_name,'r')
        run_standard_lines = run_standard.readlines()
        run_standard.close()
        useful_lines = []
        for case in lines:
            case = case.strip()
            if not case:
                 continue
            else:
                 pass
            case_tab = '--design='+case
            case_tab_re = re.compile(case_tab+r'(\s+|$)')
            for line in run_standard_lines:
                line = line.strip()
                if not line:
                    continue
                if case_tab_re.search(line):
                    try:
                        fmax = float( design_fmax[case.strip()] )
                        fmax = str( int( fmax ))
                    #line = case_tab_re.sub('',line)
                        line = re.sub(r'--fmax-sweep=[\s\d]+\d','',line)
                        line2 = line + ' --fmax-sweep='+fmax+' '+fmax+' '+'10 \n'
                    except:
                        line2 = line
                    useful_lines.append(line2)
        run_standard = file(stand_name,'w')
        run_standard.writelines(useful_lines)
        run_standard.close()
Ejemplo n.º 7
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    
    if 1:
        root_dir = os.getcwd()
        for design in all_designs:
            if need_design:
                if design ==  need_design:
                    pass
                else:
                    continue
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            if 1:
                if 1:
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,'aa'+'.csv')
                    if report_file in report_file_list:
                        pass
                    else:
                        report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    #dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(design_path)
                    srr_file = get_unique_file([os.path.join(design_path,'impl'), ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    twr_file = time_file = par_file= mrp_file = ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Seed_is_(.+)")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_time.reset_par_time_data()
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                mrp_file = get_unique_file([foo, ".mrp"])
                                scan_mrp.scan_report(mrp_file)
                                scan_time.scan_mrp(mrp_file)
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([os.path.join(foo,'PrjName.dir'), ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                               
                                if design.startswith('hu'):
                                    scan_twr.scan_report(twr_file,'clk_246mhz_c') ### add by yu
                                
                                elif design =='fir1c':
                                        scan_twr.scan_report(twr_file,'fir_clk_c')
                                elif design.startswith('fir'):
                                        scan_twr.scan_report(twr_file,'fir_clk')
                                elif design.startswith('config'):
                                        scan_twr.scan_report(twr_file,'clk_c')
                                else:
                                    scan_twr.scan_report(twr_file,'i_clk')
                                
                                
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                #data = [design] + scan_mrp.get_data() + \
                                #      scan_twr.get_data() + data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                                ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                                scan_time.reset_par_time_data()
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                      real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                #data = [design] + scan_mrp.get_data()+ data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                                scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f,add_average=1)
            report_sort.write_note(file_sorted,note)
def scan_report():
    opt = option()
    scanner = (tool_scan_altera.ScanAlteraFit(), tool_scan_altera.ScanAlteraFmax())
    job_dir = opt.job_dir
    if not os.path.isdir(job_dir):
        print 'Error, can not get directory:%s'%job_dir
        return -1
    design = opt.design
    tag = opt.special_structure
    report_name = opt.report_name #this is useless now
    if report_name == 'report.csv':
        report_file = os.path.basename(job_dir)+'.csv'
    report_path = opt.report_path
    if not report_path:
        report_path = job_dir
    report_file = os.path.join(report_path,report_file)
    scan_fit = tool_scan_altera.ScanAlteraFit()
    scan_fmax =  tool_scan_altera.ScanAlteraFmax()
    scan_time_mem = tool_scan_altera.ScanTimeMem()
    all_designs = []
    if not design:
        if os.path.isdir(job_dir):
            pass
        else:
            print 'The job_dir:%s is not a directory'%job_dir
            return
        for dir in os.listdir(job_dir):  # get all the design path
            dir2 =  os.path.join(job_dir,dir)
            if os.path.isdir(dir2):
                all_designs.append(dir)
            else:
                pass
    else:
        all_designs.append(design)
    report_file_list = []
    if 1:
        root_dir = os.getcwd()
        title = ["Design"]
        for item in (scan_fit,scan_fmax,scan_time_mem): #mrp twr time
            title += item.get_title()
        append_file(report_file, ",".join(title))
        global_title = title
        for design in all_designs:
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path): #at here dir should be as "_cyclone4_syn"
                if dir == tag:
                    #####################
                    scanner = (scan_fit, scan_fmax,scan_time_mem)
                    
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        append_file(report_file, ",".join(global_title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_fit = report_name+'_fit'+subtex
                        if not_exists(report_file_fit):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_fit, ",".join(title))
                        report_file_sta = report_name+'_sta'+subtex
                        if not_exists(report_file_sta):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_sta, ",".join(title))
                        report_file_time_mem = report_name+'_time_mem'+subtex
                        if not_exists(report_file_time_mem):
                            title = ["Design"]
                            title += (scanner[2]).get_title()
                            append_file(report_file_time_mem, ",".join(title))  
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan) 
                    fit_file = sta_file = map_file = srr_file =  ""
                    
                    if 'rev_1' in os.listdir('.'): # this part used to scan srr if run synthesis with synpro
                        scan_time_mem.reset()
                        foo = os.path.join(dir_scan,'rev_1')
                        srr_file = get_unique_file(foo+'/'+'*.srr')
                        if srr_file:
                            scan_time_mem.scan_srr(srr_file)
                    
                    for foo in os.listdir("."):
                        data = []
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_fit.reset()
                                scan_fmax.reset()
                                scan_time_mem.set_fit_data()
                                scan_time_mem.set_map_data()
                                print_always("  Scanning %s" % foo)
                                fit_file = get_unique_file(foo+'/'+"*.fit.rpt")
                                sta_file = get_unique_file(foo+'/'+"*.sta.rpt")
                                map_file = get_unique_file(foo+'/'+'*.map.rpt')
                                if fit_file:
                                    scan_fit.scan_report(fit_file)
                                    #raw_input(1)
                                    scan_time_mem.scan_fit(fit_file)
                                    #raw_input(2)
                                    data1=[design]+scan_fit.get_data()
                                    append_file(report_file_fit, ",".join(data1))
                                    data = data + data1
                                else:
                                    data1=[design]+['NA']*len(scan_fit.get_title() )
                                    data = data + data1
                                    print 'AA'
                                if sta_file:
                                    scan_fmax.scan_report(sta_file)
                                    #raw_input(3)
                                    data2=[design]+scan_fmax.get_data()
                                    append_file(report_file_sta, ",".join(data2))
                                    data = data + data2[1:]
                                else:
                                    data1=['NA']*len(scan_fmax.get_title() )
                                    data = data + data1
                                if map_file:
                                    scan_time_mem.scan_map(map_file)
                                    #raw_input(4)
                                    scan_t_m = scan_time_mem.get_data()
                                    append_file(report_file_time_mem, ",".join([design]+scan_t_m))
                                    data  = data + scan_t_m
                                else:
                                    data1=['NA']*len(scan_time_mem.get_title() )
                                    data = data + data1
                                append_file(report_file, ",".join(data))
                                for_bqs_data = '<scan_case>\n'
                                for id1, t in enumerate( global_title):
                                    for_bqs_data = for_bqs_data + "\t<%s>"%t+data[id1]+"</%s>\n"%t
                                for_bqs_data = for_bqs_data +"</scan_case>"
                                print '#BQS_RETRN_DATA_BEGIN#'
                                print for_bqs_data
                                print '#BQS_RETRN_DATA_END#'
                    recover.run()
        os.chdir(root_dir) 
    #report_file_list = []    
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted,note)
    #----------------update run_stand-------------------#
    if 0:
        pass_log = glob.glob('*'+syn+'_pass_case.log')
        if pass_log:
            pass_log = pass_log[0]
        else:
            pass_log = '__'
        if os.path.isfile(pass_log):
            file_hand = file(pass_log,'r')
            lines = file_hand.readlines()
            file_hand.close()
            stand_name = glob.glob('*'+syn+'_run_standard.bat')
            if stand_name:
                stand_name = stand_name[0]
            #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
            else:
                stand_name = ''
            run_standard = file(stand_name,'r')
            run_standard_lines = run_standard.readlines()
            run_standard.close()
            useful_lines = []
            for case in lines:
                case = case.strip()
                if not case:
                     continue
                else:
                     pass
                case_tab = '--design='+case
                case_tab_re = re.compile(case_tab+r'(\s+|$)')
                for line in run_standard_lines:
                    line = line.strip()
                    if not line:
                        continue
                    if case_tab_re.search(line):
                        try:
                            fmax = float( design_fmax[case.strip()] )
                            fmax = str( int( fmax ))
                        #line = case_tab_re.sub('',line)
                            line = re.sub(r'--fmax-sweep=[\s\d]+\d','',line)
                            line2 = line + ' --fmax-sweep='+fmax+' '+fmax+' '+'10 \n'
                        except:
                            line2 = line
                        
                        useful_lines.append(line2)
            run_standard = file(stand_name,'w')
            run_standard.writelines(useful_lines)
            run_standard.close()