import re
import openpyxl as op
from decimal import Decimal

tp = []
with open('IDMA_Throughput.txt', 'rt') as in_file:  
    for line in in_file: 
        if 'Throughput' in line:   # match actual keyword
            # extract both numbers: cycles and throughput
            match = re.findall(r"\d+\.\d+|\d+", line)
            if match and len(match) >= 2:
                tp.append(match)            

print(tp)

wb = op.load_workbook('IDMA_throughput_blocksize_EHP2.xlsx')  
sh = wb['Sheet1']      
r = 2
for j in range(0, len(tp)):   # iterate exactly over throughput entries
    int_mem = sh.cell(row=r, column=2).value
    ext_mem = sh.cell(row=r, column=3).value
    buff_count = sh.cell(row=r, column=4).value
    burst_size = sh.cell(row=r, column=5).value
    
    # write cycles and throughput
    sh.cell(row=r, column=7).value = Decimal(tp[j][0])   # cycles
    sh.cell(row=r, column=8).value = Decimal(tp[j][1])   # throughput

    r = r + 1
    
wb.save('IDMA_throughput_blocksize_EHP2.xlsx')
