diff --git a/qucs/qucs/python/parse_result.py b/qucs/qucs/python/parse_result.py index 453e337cb7..c7a7989606 100644 --- a/qucs/qucs/python/parse_result.py +++ b/qucs/qucs/python/parse_result.py @@ -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, @@ -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 diff --git a/qucs/qucs/python/parse_result_example.py b/qucs/qucs/python/parse_result_example.py index 6ea365be5c..0cc422d921 100644 --- a/qucs/qucs/python/parse_result_example.py +++ b/qucs/qucs/python/parse_result_example.py @@ -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'] diff --git a/qucs/qucs/python/qucs-py/qucs.py b/qucs/qucs/python/qucs-py/qucs.py index 6aa099b658..ba82086e03 100644 --- a/qucs/qucs/python/qucs-py/qucs.py +++ b/qucs/qucs/python/qucs-py/qucs.py @@ -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 != "": + 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 @@ -51,7 +52,7 @@ 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 "" @@ -59,7 +60,7 @@ def create_dep(this,ldef,infile): if l != "": 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): @@ -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 ""