source: trunk/symbol_table/pablo/demo_strms.py @ 2185

Last change on this file since 2185 was 2185, checked in by ksherdy, 7 years ago

Fixed template glue.

File size: 5.0 KB
Line 
1from bitutil import *
2import marker_strms
3import div2_group_strms
4import logbase2_group_strms
5import div2_logbase2_group_strms
6import bit_byte_group_strms
7import sys
8
9class Basis_bits():
10        bit_0 = 0
11        bit_1 = 0
12        bit_2 = 0
13        bit_3 = 0
14        bit_4 = 0
15        bit_5 = 0
16        bit_6 = 0
17        bit_7 = 0
18
19def Demo_div2(u8data, basis_bits):
20
21    lgth = len(u8data)
22
23    markers = marker_strms.Markers()
24    marker_strms.Classify_markers(basis_bits, markers)
25    marker_strms.Generate_markers(markers)
26
27    groups = div2_group_strms.Groups()
28    div2_group_strms.Gen_lgth_groups(markers, groups)
29
30    print_aligned_streams([('Input Data', u8data),
31        ('markers.spans', bitstream2string(markers.spans, lgth)),
32        ('markers.starts', bitstream2string(markers.starts, lgth)),
33        ('markers.follows', bitstream2string(markers.follows, lgth)),
34        ('groups.starts', bitstream2string(groups.starts, lgth)),
35        ('groups.follows', bitstream2string(groups.follows, lgth)),
36        ('groups.follows_2', bitstream2string(groups.follows_2, lgth)),
37        ('groups.follows_4', bitstream2string(groups.follows_4, lgth)),
38        ('groups.follows_6', bitstream2string(groups.follows_6, lgth)),
39        ('groups.follows_8', bitstream2string(groups.follows_8, lgth)),
40        ('groups.follows_10', bitstream2string(groups.follows_10, lgth)),
41        ('groups.follows_12', bitstream2string(groups.follows_12, lgth)),
42        ('groups.follows_14', bitstream2string(groups.follows_14, lgth)),
43        ('groups.follows_16', bitstream2string(groups.follows_16, lgth)),
44        ('groups.follows_0', bitstream2string(groups.follows_0, lgth))])
45
46def Demo_logbase2(u8data, basis_bits):
47
48    lgth = len(u8data)
49
50    markers = marker_strms.Markers()
51    marker_strms.Classify_markers(basis_bits, markers)
52    marker_strms.Generate_markers(markers)
53
54    groups = logbase2_group_strms.Groups()
55    logbase2_group_strms.Gen_lgth_groups(markers, groups)
56
57    print_aligned_streams([('Input Data', u8data),
58        ('markers.spans', bitstream2string(markers.spans, lgth)),
59        ('markers.starts', bitstream2string(markers.starts, lgth)),
60        ('markers.follows', bitstream2string(markers.follows, lgth)),
61        ('groups.starts', bitstream2string(groups.starts, lgth)),
62        ('groups.follows', bitstream2string(groups.follows, lgth)),
63        ('groups.follows_1', bitstream2string(groups.follows_1, lgth)),
64        ('groups.follows_2', bitstream2string(groups.follows_2, lgth)),
65        ('groups.follows_4', bitstream2string(groups.follows_4, lgth)),
66        ('groups.follows_8', bitstream2string(groups.follows_8, lgth)),
67        ('groups.follows_16', bitstream2string(groups.follows_16, lgth)),
68        ('groups.follows_0', bitstream2string(groups.follows_0, lgth))])
69
70def Demo_div2_logbase2(u8data, basis_bits):
71
72    lgth = len(u8data)
73
74    markers = marker_strms.Markers()
75    marker_strms.Classify_markers(basis_bits, markers)
76    marker_strms.Generate_markers(markers)
77
78    groups = div2_logbase2_group_strms.Groups()
79    div2_logbase2_group_strms.Gen_lgth_groups(markers, groups)
80
81    print_aligned_streams([('Input Data', u8data),
82        ('markers.spans', bitstream2string(markers.spans, lgth)),
83        ('markers.starts', bitstream2string(markers.starts, lgth)),
84        ('markers.follows', bitstream2string(markers.follows, lgth)),
85        ('groups.starts', bitstream2string(groups.starts, lgth)),
86        ('groups.follows', bitstream2string(groups.follows, lgth)),
87        ('groups.follows_2', bitstream2string(groups.follows_2, lgth)),
88        ('groups.follows_4', bitstream2string(groups.follows_4, lgth)),
89        ('groups.follows_6', bitstream2string(groups.follows_6, lgth)),
90        ('groups.follows_8', bitstream2string(groups.follows_8, lgth)),
91        ('groups.follows_16', bitstream2string(groups.follows_16, lgth)),
92        ('groups.follows_0', bitstream2string(groups.follows_0, lgth))])
93
94def Demo_bit_byte(u8data, basis_bits):
95
96    lgth = len(u8data)
97
98    markers = marker_strms.Markers()
99    marker_strms.Classify_markers(basis_bits, markers)
100    marker_strms.Generate_markers(markers)
101
102    groups = bit_byte_group_strms.Groups()
103    bit_byte_group_strms.Gen_lgth_groups(markers, groups)
104
105    print_aligned_streams([('Input Data', u8data),
106        ('markers.spans', bitstream2string(markers.spans, lgth)),
107        ('markers.starts', bitstream2string(markers.starts, lgth)),
108        ('markers.follows', bitstream2string(markers.follows, lgth)),
109        ('groups.starts', bitstream2string(groups.starts, lgth)),
110        ('groups.follows', bitstream2string(groups.follows, lgth)),
111        ('groups.follows_7', bitstream2string(groups.follows_7, lgth)),
112        ('groups.follows_0', bitstream2string(groups.follows_0, lgth))])
113
114if __name__ == "__main__":
115
116    if len(sys.argv) < 2:
117        sys.stderr.write("Usage: python " + filename + " <filename>\n")
118        sys.exit(2)
119
120    u8data = readfile(sys.argv[1])
121
122    basis_bits = Basis_bits()
123    (b, EOF_mask) = transpose_streams(u8data)
124
125    basis_bits.bit_0 = b[0]
126    basis_bits.bit_1 = b[1]
127    basis_bits.bit_2 = b[2]
128    basis_bits.bit_3 = b[3]
129    basis_bits.bit_4 = b[4]
130    basis_bits.bit_5 = b[5]
131    basis_bits.bit_6 = b[6]
132    basis_bits.bit_7 = b[7]
133
134    # Demo_div2(u8data, basis_bits)
135    # Demo_logbase2(u8data, basis_bits)
136    Demo_div2_logbase2(u8data, basis_bits)
137    # Demo_bit_byte(u8data, basis_bits)
138
Note: See TracBrowser for help on using the repository browser.