Nic30 / pyDigitalWaveTools

Python library for operations with VCD and other digital wave files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example for "passthrough" - load a .vcd file, and export the same data as .vcd?

sdbbs opened this issue · comments

commented

Sorry for the many edits, came to press "post" way too quickly.

I was wondering, if it was possible to use this library to convert .vcd files. I guess the library does not really support resampling, but I was wondering if it was possible to load a .vcd file into an internal data model, and then export that internal data model as a .vcd file.

This is as far as I got so far:

import io

import json
import sys
from pyDigitalWaveTools.vcd.parser import VcdParser

import datetime
from pyDigitalWaveTools.vcd.common import VCD_SIG_TYPE
from pyDigitalWaveTools.vcd.value_format import VcdBitsFormatter
from pyDigitalWaveTools.vcd.writer import VcdWriter

import quantiphy # since we have to convert timescales from input to output

if len(sys.argv) > 1:
  fname = sys.argv[1]
else:
  print('Give me a vcd file to parse')
  sys.exit(-1)

with open(fname) as vcd_file:
  vcd = VcdParser()
  vcd.parse(vcd_file)

print("Timescale is '{}' for {}".format(vcd.timescale, fname)) # vcd.timescale is string
in_ts_phy = quantiphy.Quantity(vcd.timescale)
print("'phy' version of timescale is '{}', value {}, units '{}'".format(in_ts_phy, in_ts_phy.real, in_ts_phy.units))
print(vcd.scope.name) # 'root'

vcdo = VcdWriter()
d = datetime.datetime.strptime("2018-04-12 18:04:03.652880", "%Y-%m-%d %H:%M:%S.%f")
vcdo.date(d)
timescale_ps = int( in_ts_phy.scale(scale=(1e12, 'ps')).real )
print("Timescale in ps is: {}".format(timescale_ps)) # 1000 (ps for 1 ns), ok
vcdo.timescale( timescale_ps )

... but beyond this, I cannot see how do I transfer the data model held in vcd to the output vcdo.

Is this kind of "passthrough" possible with the current pyDigitalWaveTools?

commented

Thanks for that - that is fantastic! I can closing this issue, then ... thanks again!