MCPcopy Create free account
hub / github.com/Qucs/qucs / parse_file

Function parse_file

qucs/python/parse_result.py:5–81  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

3
4
5def parse_file(name):
6
7 file = open(name)
8
9 # the dict this function returns
10 data = {}
11 numpoints = 1
12 ind = 0
13 shape = []
14 variables = {}
15
16 for line in file:
17 #print line
18 if line.startswith('<'):
19 if line.startswith('<indep'):
20 #print line
21 r = re.match(r'\<(\w+) (\S+) (\d+)\>', line)
22 g = r.groups()
23 # there can be several independent variables -> numpoints keeps
24 # the total number of points
25 numpoints = numpoints * int(g[2])
26 name = g[1]
27 # reserve an array for the values
28 data[name] = np.zeros(int(g[2]))
29 ind = 0
30 # save the simulation points in an array
31 shape = np.append(shape, int(g[2]))
32 # save that this variable is independent
33 variables[name] = 'indep'
34
35 if line.startswith('<dep'):
36 #print line
37 r = re.match(r'\<dep (\S+)', line)
38 g = r.groups()
39 name = g[0]
40 # reserve a complex matrix to be on the safe side
41 data[name] = np.zeros(int(numpoints), np.complex128)
42 ind = 0
43 # store that this is a dependent variable
44 variables[name] = 'dep'
45
46 else:
47 jind = line.find('j')
48
49 if(jind == -1):
50 # real number -> just parse it
51 val = float(line)
52 else:
53 # complex number -> break into re/im part
54 val_re = line[0:jind-1]
55 sign = line[jind-1]
56 val_im = sign + line[jind+1:-1]
57 # and convert it into a complex number
58 val = complex(float(val_re), float(val_im))
59
60 # store the extracted datapoint
61 data[name][ind] = val
62 ind = ind + 1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected