我正在制作一个需要从输入文件中读取77位二进制字符串的Verilog程序。输入文件将被格式化为一串77 1&0;以及0'后面跟着' \ n'。
我的程序希望逐行读取并将整个字符串存储到看起来像这样的注册表中:
fscanf(data_input_file, "???????", DATA_REG)
我正在使用
from matplotlib.widgets import Lasso
from matplotlib.colors import colorConverter
from matplotlib.collections import RegularPolyCollection
from matplotlib import path
import matplotlib.pyplot as plt
from numpy import nonzero
from numpy.random import rand
class Datum(object):
colorin = colorConverter.to_rgba('red')
colorout = colorConverter.to_rgba('blue')
def __init__(self, x, y, include=False):
self.x = x
self.y = y
if include:
self.color = self.colorin
else:
self.color = self.colorout
class LassoManager(object):
def __init__(self, ax, data):
self.axes = ax
self.canvas = ax.figure.canvas
self.data = data
self.Nxy = len(data)
facecolors = [d.color for d in data]
self.xys = [(d.x, d.y) for d in data]
self.ind = []
fig = ax.figure
self.collection = RegularPolyCollection(
fig.dpi, 6, sizes=(100,),
facecolors=facecolors,
offsets=self.xys,
transOffset=ax.transData)
ax.add_collection(self.collection)
self.cid = self.canvas.mpl_connect('button_press_event', self.onpress)
def callback(self, verts):
facecolors = self.collection.get_facecolors()
p = path.Path(verts)
ind = p.contains_points(self.xys)
self.ind = nonzero([p.contains_point(xy) for xy in self.xys])[0]
for i in range(len(self.xys)):
if ind[i]:
facecolors[i] = colorConverter.to_rgba('red')
# print ind
else:
facecolors[i] = colorConverter.to_rgba('blue')
self.canvas.draw_idle()
self.canvas.widgetlock.release(self.lasso)
del self.lasso
def onpress(self, event):
if self.canvas.widgetlock.locked():
return
if event.inaxes is None:
return
self.lasso = Lasso(event.inaxes,
(event.xdata, event.ydata),
self.callback)
# acquire a lock on the widget drawing
self.canvas.widgetlock(self.lasso)
data = np.random.rand(5, 5)
fig, ax = plt.subplots()
# No, no need for collection
ax.imshow(data, aspect='auto', origin='lower',picker=True)
data = [Datum(*xy) for xy in rand(10, 2)]
lman = LassoManager(ax, data)
plt.show()
但我不确定在引文中加入什么。我希望字符串按字面解释;也就是说,如果数字是... 0000001110 ...我希望DATA_REG包含0000001110,而不是1110或14。
感谢您的帮助!
答案 0 :(得分:0)
你有两个选择。如果要读取的行总数不是那么大,则可以将整个文件读入内存
reg [76:0] memory[0:MAX_LINES];
integer index;
initial $readmemb("filename",memory);
always @index DATA_REG = memory[index];// or just use memory[index] directly
或者你可以做
status = $fsanf(data_input_file, "%b", DATA_REG);
答案 1 :(得分:0)
您可以指定您正在阅读的数据的宽度,如下所示:
status = $fsanf(data_input_file, "%**77**b", DATA_REG);
您需要确保输入文件中的数据具有相同的宽度。