我有一个代码可以读取三个文件,两个文件保持不变(未更改),第三个需要在每次运行后更改。在名为run1-rbd-new.rbd
的文件下面的代码中。我每次运行后都需要更改这些文件中的第三种。是的,我正在手动更改文件的名称。
我是否可以自动执行每次运行,它会自动更改文件,例如运行* -rbd-new.rbd。
file1 = "original-impact.rbd"
file2 = "run1-rbd-new.rbd"
file_inv = "readback_adder_inverted.rbd"
src1 = open (file1,'r')
src2 = open (file2,'r')
src3= open(file_inv,'r')
num_lines_nonbram = 1891426 # non-bram data from line 102 to 1891426 write 1891427 b/c loops works one line minus and its non-bram data num_lines_bram; write for time being changed it later
num_lines = 2432181 # for Artix-7
num_bits = 77829792 # for Artix-7
bits_perline = 32
del_lines = 101 # number of header lines; must be deleted
num_bit_flip_zeros = 0
num_bit_flip_ones = 0
num_same_bits = 0
Total_bit_flip = 0
Total_bits = 0
Total_lut_bits = 0
Total_non_lut_bits = 0
total_bit_flips = 0
lut_bit_flip_at_0 = 0
non_lut_bit_flip_at_0 = 0
lut_bit_flip_at_1 = 0
non_lut_bit_flip_at_1 = 0
i=0
while i < del_lines:
line1 = src1.readline()
line2 = src2.readline()
line_inv = src3.readline()
i+=1
i=0
j=0
k=0
while i < (num_lines_nonbram-del_lines):
line1 = src1.readline()
line2 = src2.readline()
line_inv = src3.readline()
while k < bits_perline:
if ((line1[k] == "0" and line_inv[k]== "0" and line2[k] == "0" or line1[k] == "1" and line_inv[k]== "1" and line2[k] == "1" )):
num_same_bits += 1
else:
if (line1[k]=="0" and line2[k]=="1"):
num_bit_flip_zeros += 1
if (line1[k]=="1" and line2[k]=="0"):
num_bit_flip_ones += 1
if ((line1[k] == "0" and line_inv[k]== "1" and line2[k] == "1")):
lut_bit_flip_at_0 += 1
if ((line1[k] == "0" and line_inv[k]== "0" and line2[k] == "1")):
non_lut_bit_flip_at_0 += 1
if ((line1[k] == "1" and line_inv[k]== "0" and line2[k] == "0")):
lut_bit_flip_at_1 += 1
if ((line1[k] == "1" and line_inv[k]== "1" and line2[k] == "0")):
non_lut_bit_flip_at_1 += 1
k +=1
k = 0
i+=1
Total_bit_flip = num_bit_flip_zeros + num_bit_flip_ones
Total_lut_bits = lut_bit_flip_at_0+lut_bit_flip_at_1
Total_non_lut_bits = non_lut_bit_flip_at_0+non_lut_bit_flip_at_1
print "-----------------------------------"
print file2
print "Number of bit flips at 0 = %d" %num_bit_flip_zeros + '\n' "Number of bit flips at 1 = %d" %num_bit_flip_ones +'\n' "Total number of bit flips = %d" %Total_bit_flip + '\n'
print "-----------------------------------"
print "Number of lut bits @0 = %d" %lut_bit_flip_at_0 + '\n' + "Number of lut bit @1 = %d" %lut_bit_flip_at_1 + '\n'+ "Number of non-lut bits @0 = %d" %non_lut_bit_flip_at_0 + '\n' + "Number of non-lut bits@1 = %d" %non_lut_bit_flip_at_1
print "-----------------------------------"
print "Verification"
print "Total bits at zero = %d" %num_bit_flip_zeros + "= %d" %(lut_bit_flip_at_0+non_lut_bit_flip_at_0)
print "Total bits at ones = %d" %num_bit_flip_ones +"= %d" %(lut_bit_flip_at_1+non_lut_bit_flip_at_1)
src2.close()
src1.close()