blob: 64ccfe4069d330afbd39ce4af950570b631d03db (
plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/python
#
# Pack the formulae into a binary dump to be used in the catalog
#
# Copyright (C) 2016 Santosh Sivaraj <santosiv@in.ibm.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
from struct import *
import csv
from common import *
def formula_pack(formula):
# First pack the header
header = pack(">xxIH6x", formula['flag'], formula['group'])
st = header + pack_text(formula['name']) + pack_text(formula['desc']) + pack_text(formula['formula']) + pack_text(formula['unit'])
t = pad16(st) # this also adds the length
return t
def pack_formulae(formulae_csv):
formulae = ""
with open(formulae_csv) as csvfile:
reader = csv.DictReader(csvfile)
formula = {}
count = 0
for row in reader:
count += 1
formula['name'] = row['Formula Name']
formula['desc'] = row['Formula Description']
formula['formula'] = row['Formula']
formula['unit'] = row['Unit']
formula['group'] = int(row['Group'])
if row['Grouped'] == 'y':
formula['flag'] = 0x04
else:
formula['flag'] = 0
formulae += formula_pack(formula)
return pad_page(formulae, PAGE_SIZE), count
if __name__ == "__main__":
formulae = pack_formulae('formulae.csv')
if len(formulae) == 0:
print "Error in generating formulae binary dump"
f = open('formulae.bin', 'w')
f.write(formulae)
f.close()
hexdump(formulae, " ", 16)
|