Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

QUCS->Python data converter

40 views
Skip to first unread message

wzab

unread,
Jan 20, 2009, 9:27:50 AM1/20/09
to
Archive-name: qucs.py
Submitted-by: wz...@ise.pw.edu.pl
Version: 1.0

This archive contains sources of the converter allowing to read the
QUCS generated data into the Python program.
The data read from a QUCS file are placed into a qucs_data object.
This object contains two dictionaries:
* deps - for dependent variables
* indeps - for independent variables

Entry for each independent variable contains just a vector with values
of that variable
Entry for each dependent variable is an object of the qucs_dep_var
class, with the followinf fields:
* val - multi-dimensional array with values of that variable
* ind_vars - the vector with the names of the independent variables
corresponding to indices of the "val" array

The archive contains also source of the demo QUCS project (test1.sch
and test1.dpl). If you run the simulation, you should get the test1.dat
file. Then you can read it in the following way (below is the sample
interactive ipython session):

$ipython -pylab
In [1]: import qucs
In [2]: r=qucs.qucs_data("test1.dat")
In [3]: r.deps["Pr1.v"].ind_vars
Out[3]: ['acfrequency', 'Cctr', 'A1']
In [4]: plot(log(abs(r.deps["Pr1.v"].val[:,2,:])))


#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.6.3).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `#!/bin/sh' line above, then type `sh FILE'.
#
lock_dir=_sh29560
# Made on 2009-01-20 15:24 CET by <wzab@wzlaphp>.
# Source directory was `/tmp/qucs_python'.
#
# Existing files will *not* be overwritten, unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2655 -rw-r--r-- qucs.py
# 526 -rw-r--r-- test1.dpl
# 1105 -rw-r--r-- test1.sch
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir ;;
esac
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and'
${echo} 'installing GNU `touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir}
then : ; else ${echo} 'lock directory '${lock_dir}' exists'
exit 1
fi
if mkdir ${lock_dir}
then ${echo} 'x - created lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to create lock directory `'${lock_dir}\''.'
exit 1
fi
# ============= qucs.py ==============
if test -f 'qucs.py' && test "$first_param" != -c; then
${echo} 'x -SKIPPING qucs.py (file already exists)'
else
${echo} 'x - extracting qucs.py (text)'
sed 's/^X//' << 'SHAR_EOF' > 'qucs.py' &&
#!/usr/bin/python
# QUCS->Python+pylab converter ver.1.0
# Public domain code, writter by Wojciech M. Zabolotny
# ( wzab<at>ise.pw.edu.pl ) 20.01.2009
import sys
import pylab
class qucs_dep_var:
X def __init__(this,vals,ind_vars):
X this.val=vals
X this.ind_vars=ind_vars
X
class qucs_data:
X def __init__(this,fname=""):
X this.indeps={}
X this.deps={}
X if fname != "":
X f=open(fname,"rb")
X l=f.readline().strip()
X # In the first line check whether we have a qucs data
X if l != "<Qucs Dataset 0.0.14>":
X raise("This is not a qucs data file!")
X # Now we should start reading dependent vars, and independent vars
X # The next line should be either dependend variable or independent variable
X while True:
X l=f.readline().strip()
X if l=="":
X break
X if l[0:6]=="<indep":
X #This is declaration of the independent variable
X this.create_indep(l[6:-1],f)
X elif l[0:4]=="<dep":
X #This is declaration of the dependent variable
X this.create_dep(l[4:-1],f)
X f.close()
X
X def conv_dta(this,line):
X nline=line.replace("j","")
X if len(line)!=len(nline):
X nline=nline+"j"
X return complex(nline)
X def create_dep(this,ldef,infile):
X #Create the dependent variable with the name defined in the first field
X vnames=ldef.split()
X #Calculate the dimensions
X dims=[]
X vsize=1
X for iname in vnames[1:]:
X vs=len(this.indeps[iname])
X dims.append(vs)
X vsize*=vs
X #Reserve the data buffer
X dta = pylab.zeros(vsize,complex)
X #Read the data
X for i in xrange(0,vsize):
X l=infile.readline().strip()
X dta[i]=this.conv_dta(l)
X #Now make sure, that the last line is "<indep>"
X l=infile.readline().strip()
X if l != "</dep>":
X raise("Wrong syntax in line: "+l)
X #Reshape the data buffer into the multi-dimensional array
X dta=pylab.reshape(dta,dims,'FORTRAN')
X this.deps[vnames[0]]=qucs_dep_var(dta,vnames[1:])
X
X def create_indep(this,ldef, infile):
X #Create the independent variable with the name defined in the first field
X #In the first line we should find the variable name and its length
X [vname, vsize]=ldef.split()
X vsize=int(vsize)
X #Create the empty data
X dta = pylab.zeros(vsize,complex)
X #Read the data
X for i in xrange(0,vsize):
X l=infile.readline().strip()
X dta[i]=this.conv_dta(l)
X #Now make sure, that the last line is "<indep>"
X l=infile.readline().strip()
X if l != "</indep>":
X raise("Wrong syntax in line: "+l)
X this.indeps[vname]=dta
X
X
SHAR_EOF
(set 20 09 01 20 15 09 08 'qucs.py'; eval "$shar_touch") &&
chmod 0644 'qucs.py'
if test $? -ne 0
then ${echo} 'restore of qucs.py failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'qucs.py: MD5 check failed'
) << SHAR_EOF
797e0ab6f66c89b2385a3c423af03b24 qucs.py
SHAR_EOF
else
test `LC_ALL=C wc -c < 'qucs.py'` -ne 2655 && \
${echo} 'restoration warning: size of qucs.py is not 2655'
fi
fi
# ============= test1.dpl ==============
if test -f 'test1.dpl' && test "$first_param" != -c; then
${echo} 'x -SKIPPING test1.dpl (file already exists)'
else
${echo} 'x - extracting test1.dpl (text)'
sed 's/^X//' << 'SHAR_EOF' > 'test1.dpl' &&
<Qucs Schematic 0.0.14>
<Properties>
X <View=0,-26,800,740,1,0,0>
X <Grid=10,10,0>
X <DataSet=test1.dat>
X <DataDisplay=test1.sch>
X <OpenDisplay=1>
X <showFrame=0>
X <FrameText0=Tytu\x0142>
X <FrameText1=Stworzona przez:>
X <FrameText2=Data:>
X <FrameText3=Rewizja:>
</Properties>
<Symbol>
</Symbol>
<Components>
</Components>
<Wires>
</Wires>
<Diagrams>
X <Rect 90 504 626 450 3 #c0c0c0 1 11 1 10 1 1e+07 1 0.003 1 1 1 -1 0.2 1 315 0 225 "" "" "">
X <"Pr1.v" #ff0000 0 3 0 0 0>
X </Rect>
</Diagrams>
<Paintings>
</Paintings>
SHAR_EOF
(set 20 09 01 20 15 06 27 'test1.dpl'; eval "$shar_touch") &&
chmod 0644 'test1.dpl'
if test $? -ne 0
then ${echo} 'restore of test1.dpl failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'test1.dpl: MD5 check failed'
) << SHAR_EOF
593dfa79e6272709dbf43e65c4b1f9bf test1.dpl
SHAR_EOF
else
test `LC_ALL=C wc -c < 'test1.dpl'` -ne 526 && \
${echo} 'restoration warning: size of test1.dpl is not 526'
fi
fi
# ============= test1.sch ==============
if test -f 'test1.sch' && test "$first_param" != -c; then
${echo} 'x -SKIPPING test1.sch (file already exists)'
else
${echo} 'x - extracting test1.sch (text)'
sed 's/^X//' << 'SHAR_EOF' > 'test1.sch' &&
<Qucs Schematic 0.0.14>
<Properties>
X <View=0,0,1207,800,0.7,0,0>
X <Grid=10,10,1>
X <DataSet=test1.dat>
X <DataDisplay=test1.dpl>
X <OpenDisplay=1>
X <showFrame=0>
X <FrameText0=Tytu\x0142>
X <FrameText1=Stworzona przez:>
X <FrameText2=Data:>
X <FrameText3=Rewizja:>
</Properties>
<Symbol>
</Symbol>
<Components>
X <R R1 1 240 190 -26 15 0 0 "50 Ohm" 1 "26.85" 0 "0.0" 0 "0.0" 0 "26.85" 0 "european" 0>
X <Vac V1 1 150 220 18 -26 0 1 "{A1}" 1 "1 GHz" 0 "0" 0 "0" 0>
X <GND * 1 150 250 0 0 0 0>
X <GND * 1 350 250 0 0 0 0>
X <VProbe Pr1 1 490 130 28 -31 0 0>
X <GND * 1 500 150 0 0 0 0>
X <.SW SW1 1 810 70 0 73 0 0 "AC1" 1 "lin" 1 "Cctr" 1 "0" 1 "100n" 1 "3" 1>
X <.SW SW2 1 1020 70 0 72 0 0 "SW1" 1 "lin" 1 "A1" 1 "1V" 1 "2V" 1 "2" 1>
X <.AC AC1 1 620 70 0 44 0 0 "log" 1 "10" 1 "10 MHz" 1 "10" 1 "no" 0>
X <C C1 1 350 220 17 -26 0 1 "{Cctr}" 1 "" 0 "neutral" 0>
</Components>
<Wires>
X <150 190 210 190 "" 0 0 0 "">
X <270 190 350 190 "" 0 0 0 "">
X <470 150 470 190 "" 0 0 0 "">
X <470 150 480 150 "" 0 0 0 "">
X <350 190 470 190 "" 0 0 0 "">
</Wires>
<Diagrams>
</Diagrams>
<Paintings>
</Paintings>
SHAR_EOF
(set 20 09 01 20 15 06 27 'test1.sch'; eval "$shar_touch") &&
chmod 0644 'test1.sch'
if test $? -ne 0
then ${echo} 'restore of test1.sch failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'test1.sch: MD5 check failed'
) << SHAR_EOF
e7d11a9d459a7f37234de3b56909e2da test1.sch
SHAR_EOF
else
test `LC_ALL=C wc -c < 'test1.sch'` -ne 1105 && \
${echo} 'restoration warning: size of test1.sch is not 1105'
fi
fi
if rm -fr ${lock_dir}
then ${echo} 'x - removed lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to remove lock directory `'${lock_dir}\''.'
exit 1
fi
exit 0

0 new messages