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

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

Modified symbol table for integration with current ICXML structure.

File size: 5.0 KB
RevLine 
[2174]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
[2291]23    marker = marker_strms.Markers()
24    marker_strms.Classify_marker(basis_bits, marker)
25    marker_strms.Generate_marker(marker)
[2174]26
27    groups = div2_group_strms.Groups()
[2291]28    div2_group_strms.Gen_lgth_groups(marker, groups)
[2174]29
30    print_aligned_streams([('Input Data', u8data),
[2291]31        ('marker.spans', bitstream2string(marker.spans, lgth)),
32        ('marker.starts', bitstream2string(marker.starts, lgth)),
33        ('marker.follows', bitstream2string(marker.follows, lgth)),
[2174]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
[2291]50    marker = marker_strms.Markers()
51    marker_strms.Classify_marker(basis_bits, marker)
52    marker_strms.Generate_marker(marker)
[2174]53
54    groups = logbase2_group_strms.Groups()
[2291]55    logbase2_group_strms.Gen_lgth_groups(marker, groups)
[2174]56
57    print_aligned_streams([('Input Data', u8data),
[2291]58        ('marker.spans', bitstream2string(marker.spans, lgth)),
59        ('marker.starts', bitstream2string(marker.starts, lgth)),
60        ('marker.follows', bitstream2string(marker.follows, lgth)),
[2174]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
[2291]74    marker = marker_strms.Markers()
75    marker_strms.Classify_marker(basis_bits, marker)
76    marker_strms.Generate_marker(marker)
[2174]77
78    groups = div2_logbase2_group_strms.Groups()
[2291]79    div2_logbase2_group_strms.Gen_lgth_groups(marker, groups)
[2174]80
81    print_aligned_streams([('Input Data', u8data),
[2291]82        ('marker.spans', bitstream2string(marker.spans, lgth)),
83        ('marker.starts', bitstream2string(marker.starts, lgth)),
84        ('marker.follows', bitstream2string(marker.follows, lgth)),
[2174]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
[2291]98    marker = marker_strms.Markers()
99    marker_strms.Classify_marker(basis_bits, marker)
100    marker_strms.Generate_marker(marker)
[2174]101
102    groups = bit_byte_group_strms.Groups()
[2291]103    bit_byte_group_strms.Gen_lgth_groups(marker, groups)
[2174]104
105    print_aligned_streams([('Input Data', u8data),
[2291]106        ('marker.spans', bitstream2string(marker.spans, lgth)),
107        ('marker.starts', bitstream2string(marker.starts, lgth)),
108        ('marker.follows', bitstream2string(marker.follows, lgth)),
[2174]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)
[2185]136    Demo_div2_logbase2(u8data, basis_bits)
137    # Demo_bit_byte(u8data, basis_bits)
[2174]138
Note: See TracBrowser for help on using the repository browser.