Skip to content

Commit

Permalink
Merge pull request #971 from oxmon-2500/qucs#936_python
Browse files Browse the repository at this point in the history
#936 bug corrected, tested with python3
  • Loading branch information
guitorri authored Feb 19, 2020
2 parents 536645c + a044392 commit e93a709
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions qucs/qucs/python/parse_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def parse_file(name):
data['variables'] = variables
# reverse the shape variable in order to get the reshape operation (see below)
# correct
shape = shape[::-1]
shape = shape[::-1].astype('int')
shape = shape.squeeze()

# here comes the clever trick :-)
# if a dependent variable depends on N > 1 (independent) variables,
Expand All @@ -75,6 +76,6 @@ def parse_file(name):
temp = data['variables'][key]
if temp == 'dep':
temp_data = data[key]
data[key] = np.reshape(temp_data, shape)
data[key] = np.reshape(temp_data, shape).squeeze()

return data
8 changes: 5 additions & 3 deletions qucs/qucs/python/parse_result_example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

import parse_result as pr
# usage: python3 parse_result_example.py

# sudo apt-get install python3-tk
# sudo yum install python3-tk
matplotlib.use('TkAgg')

# create the dat file to load with:
# qucsator < rc_ac_sweep.net > rc_ac_sweep.dat



data = pr.parse_file('rc_ac_sweep.dat')

x = data['acfrequency']
Expand Down
9 changes: 5 additions & 4 deletions qucs/qucs/python/qucs-py/qucs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def __init__(this,fname=""):
this.indeps={}
this.deps={}
if fname != "":
f=open(fname,"rb")
f=open(fname,"r")
l=f.readline().strip()
# In the first line check whether we have a qucs data
if l != "<Qucs Dataset 0.0.18>":
print(l)
raise("This is not a qucs data file!")
# Now we should start reading dependent vars, and independent vars
# The next line should be either dependend variable or independent variable
Expand Down Expand Up @@ -51,15 +52,15 @@ def create_dep(this,ldef,infile):
#Reserve the data buffer
dta = pylab.zeros(vsize,complex)
#Read the data
for i in xrange(0,vsize):
for i in range(0,vsize):
l=infile.readline().strip()
dta[i]=this.conv_dta(l)
#Now make sure, that the last line is "<indep>"
l=infile.readline().strip()
if l != "</dep>":
raise("Wrong syntax in line: "+l)
#Reshape the data buffer into the multi-dimensional array
dta=pylab.reshape(dta,dims,'FORTRAN')
dta=pylab.reshape(dta,dims, "FORTRAN")
this.deps[vnames[0]]=qucs_dep_var(dta,vnames[1:])

def create_indep(this,ldef, infile):
Expand All @@ -70,7 +71,7 @@ def create_indep(this,ldef, infile):
#Create the empty data
dta = pylab.zeros(vsize,complex)
#Read the data
for i in xrange(0,vsize):
for i in range(0,vsize):
l=infile.readline().strip()
dta[i]=this.conv_dta(l)
#Now make sure, that the last line is "<indep>"
Expand Down

0 comments on commit e93a709

Please sign in to comment.