aboutsummaryrefslogtreecommitdiff
path: root/ee/__init__.py
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-08-02 22:28:17 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-08-02 22:28:17 +0200
commit2384a4e12cb029cbd6c8595fa9f3c5a666a391da (patch)
treef85afbc25f437c578c9fc7e49409b615794c930c /ee/__init__.py
parentfb3fe7200c129bb23777ebb2a09bf86f7644bffd (diff)
downloadee-python-2384a4e12cb029cbd6c8595fa9f3c5a666a391da.tar.gz
ee-python-2384a4e12cb029cbd6c8595fa9f3c5a666a391da.tar.bz2
ee-python-2384a4e12cb029cbd6c8595fa9f3c5a666a391da.tar.xz
ee-python-2384a4e12cb029cbd6c8595fa9f3c5a666a391da.zip
o Importing formatting tools.
Diffstat (limited to 'ee/__init__.py')
-rw-r--r--ee/__init__.py120
1 files changed, 0 insertions, 120 deletions
diff --git a/ee/__init__.py b/ee/__init__.py
deleted file mode 100644
index 08a283c..0000000
--- a/ee/__init__.py
+++ /dev/null
@@ -1,120 +0,0 @@
-import sympy
-import numpy as np
-
-__all__ = [
- 'read_ltspice_raw'
-]
-
-class LtSpiceRaw(object):
- def __init__(self, variables, values):
- self.variables = variables
- self.values = values
-
- def get_values(self, variable):
- return self.values[variable.idx]
-
- def get_variable(self, idx=None, expression=None):
- if idx is not None:
- return self.variables[idx]
- if expression is not None:
- v = [v for v in self.variables if v.expression == expression]
- if len(v) != 1:
- raise Exception('Unknown variable: ' + str(variable))
- return v[0]
- raise Exception('idx or expression must be given')
-
-class LtSpiceVariable(object):
- def __init__(self, idx, expression, kind):
- self.idx = idx
- self.expression = expression
- self.kind = kind
-
-class LtSpiceReader(object):
-
- def __init__(self, f):
- self.f = f
- self.mode = 'header'
- self.headers = {}
- self.variables = []
- self.values = []
-
- def read_header(self, line):
- sep = line.find(':')
- key = line[0:sep]
- value = line[sep + 1:].strip()
-
-# print("key='{}', value='{}'".format(key, str(value)))
-
- if key == 'Binary':
- self.set_binary_mode()
- elif key == 'Variables':
- self.no_variables = int(self.headers['No. Variables'])
- self.mode = 'variables'
- else:
- self.headers[key] = value
-
- def read_variable(self, line):
- parts = line.split('\t')
- idx = int(parts[1])
- expression = parts[2]
- kind = parts[3]
- self.variables.append(LtSpiceVariable(idx, expression, kind))
-
- if len(self.variables) == self.no_variables:
- self.mode = 'header'
-
- def set_binary_mode(self):
- self.mode = 'binary'
-
- def read_binary(self):
- pos = self.f.tell()
- no_points = int(self.headers['No. Points'])
- no_variables = int(self.headers['No. Variables'])
-# print("variables={}, no_points={}, pos={}".format(no_variables, no_points, pos))
- self.values = vs = np.zeros((no_variables, no_points))
- for p in range(no_points):
- vs[0][p] = np.fromfile(self.f, count=1, dtype='float64')
- pointdata = np.fromfile(self.f, count=no_variables - 1, dtype='float32')
-# print("value={:0=0.15e}".format(vs[0][p]))
- for v in range(1, no_variables):
-# print("p={}, v={}".format(p, v))
-# print(" value={:0=0.15e}".format(pointdata[v - 1]))
- vs[v][p] = pointdata[v - 1]
-
- def read(self):
- while True:
- line = self.f.readline();
-
- if len(line) == 0:
- break
-
- self.f.read(1) # The data is utf16 encoded so read the extra null byte
-
- # if this wasn't the last line .readline() includes the newline
- if line[-1] == '\n' or line[-1] == 0x0a:
- line = line[:-1]
-
- print("len(line)={}, line={}".format(len(line), str(line)))
- line = line.decode(encoding="utf-16")
-
- if self.mode == 'header':
- self.read_header(line)
- elif self.mode == 'variables':
- self.read_variable(line)
-
- # The binary data can't be read with readline()
- if self.mode == 'binary':
-# self.f.read()
- self.read_binary()
- break
-
- if len(self.variables) == 0:
- raise Exception("Something didn't quite work when parsing file, no variables found")
-
- return LtSpiceRaw(self.variables, self.values)
-
-def read_ltspice_raw(filename):
-
- with open(filename, mode="rb") as f:
- r = LtSpiceReader(f)
- return r.read()