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

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

Moved pablo src to pablo dir.

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