File indexing completed on 2024-12-29 03:35:52

0001 import sys
0002 import ltspice
0003 import os
0004 
0005 if __name__ == "__main__":
0006     if len(sys.argv) < 2:
0007         raise Exception("Pass the filename as second argument!")
0008     filenameWithPath = sys.argv[1]
0009 
0010     (path, filename) = os.path.split(filenameWithPath)
0011 
0012     namespace = filename.split(".")[0]
0013 
0014     l = ltspice.Ltspice(filenameWithPath)
0015     l.parse()
0016 
0017     isComplex = False
0018     if "complex" in l.flags:
0019         isComplex = True
0020 
0021     data_str = ""
0022     size = len(l.x_raw)
0023     for r in range(size):
0024         line = ""
0025         for index, v in enumerate(l.variables):
0026             if v == "time":
0027                 s = l.get_time()
0028             elif v == "frequency":
0029                 s = l.get_frequency()
0030             else:
0031                 s = l.get_data(v)
0032             line += f'{s[r].real:{1}.{15}e}'
0033             if isComplex:
0034                 line += ","
0035                 line += f'{s[r].imag:{1}.{15}e}'
0036 
0037             if index < len(l.variables) - 1:
0038                 line += ","
0039         data_str += f"{line}\n"
0040 
0041     #data_str = f"QVector<QStringList> refData = {{{data_str}}};"
0042     #filename_string = f'const QString filename = "{filename}";\n'
0043 
0044 
0045     #data_str = f"namespace {namespace} {{\n\n{filename_string}\n{data_str}\n}}"
0046 
0047 
0048 
0049     with open(filenameWithPath + ".refdata", "w") as f:
0050         f.write(data_str)
0051