aboutsummaryrefslogtreecommitdiffstats
path: root/sources/apps/QUAC-TRNG/scripts/convert_ent.py
blob: b2c66eab2d9f8f6cf6e76b203a7c74062fdfec79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import argparse
from numpy import array

parser = argparse.ArgumentParser(description = "Run this script to preprocess entropy files")
parser.add_argument('indir', help="Path to entropy files")
args = parser.parse_args()

files = []
for fname in os.listdir(args.indir):
  files.append(fname)

for file in files:
  print("Processing:", file)
  # Add this placement
  fpath = os.path.normpath(args.indir + '/' + file)
  infile = open(fpath,'r')
  wfile = file.split('.')[0] + '_floats.bin'
  wfpath = os.path.normpath(args.indir + '/' + wfile)
  output_file = open(wfpath, 'wb')

  lines  = infile.readlines()

  # First row reserved for metadata
  for lidx in range(1,len(lines)):
    line     = lines[lidx].strip()
    split    = line.split()
    elements = [float(i) for i in split[1:]]    
    a = array(elements,'float32')
    a.tofile(output_file)

  output_file.close()