import struct
import numpy as np
import matplotlib.pyplot as plt
import scipy, scipy.misc
import sys

f = open(sys.argv[1], 'rb')

res = []
wf = []

end = 0

j=0

wfsize=int(sys.argv[2])

while True:
  for i in range(wfsize):
    bytes_read = f.read(struct.calcsize("f"))
    if not bytes_read:
      end=1
      break
    fl = struct.unpack("f", bytes_read)[0]
    #print("%f"%fl);
    res.append(fl)
  if end == 1:
    break
  wf.append(res)
  res=[]
  j += 1

#scipy.misc.imsave('o.jpg', wf)

samples=len(wf)

fig = plt.figure(figsize=(wfsize/100,samples/100+2), dpi=100)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(wf, aspect="normal")
plt.savefig("o.png",bbox_inches='tight')

