3 from __future__ 
import division
 
    4 from __future__ 
import print_function
 
   10 parser = argparse.ArgumentParser(description=
'Convert vcd2txt output to tikz-timing line.')
 
   11 parser.add_argument(
'filename', metavar=
'FILE', help=
'input txt file')
 
   12 parser.add_argument(
'signame', metavar=
'SIG', help=
'Signal name')
 
   13 parser.add_argument(
'-s', metavar=
'scale', default=1.0, type=float, help=
'Scale all time spans with this factor')
 
   14 parser.add_argument(
'-l', action=
'store_true', help=
'Logic signal (high/low)')
 
   15 parser.add_argument(
'-b', action=
'store_true', help=
'Display binary value')
 
   16 parser.add_argument(
'-x', action=
'store_true', help=
'Display hex value')
 
   17 parser.add_argument(
'-d', action=
'store_true', help=
'Display decimal value')
 
   18 args = parser.parse_args()
 
   31     return "U" if found_x else "L"
 
   34     return "D{%s}" % value
 
   39     while len(value) % 4 != 0:
 
   41     while len(value) != 0:
 
   42         bin_digits = value[0:4]
 
   47                 hex_digit = hex_digit * 2
 
   49                 hex_digit = hex_digit * 2 + 1
 
   56             hex_string += 
"0123456789abcdef"[hex_digit]
 
   59     return "D{%s}" % hex_string
 
   69             val = val*2 + int(digit)
 
   78 for line 
in fileinput.input(args.filename):
 
   79     (node, time, name, value) = line.strip().split(
'\t')
 
   81     if start_time 
is None or start_time > time:
 
   83     if stop_time 
is None or stop_time < time:
 
   85     if name == args.signame:
 
   95             time_val[+time] = value
 
   97 if start_time 
not in time_val:
 
   98     time_val[start_time] = 
"S" 
  102 for t 
in sorted(time_val.keys()):
 
  103     if last_time 
is not None:
 
  104         print(
"%f%s" % ((t - last_time)*args.s, last_value), end=
'')
 
  105     (last_time, last_value) = (t, time_val[t])
 
  106 if last_time < stop_time:
 
  107     print(
"%f%s" % ((stop_time - last_time)*args.s, last_value), end=
'')