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

Python wrapper for running QUCS simulations with modified parameters

146 views
Skip to first unread message

wzab

unread,
May 5, 2009, 4:25:16 PM5/5/09
to
Archive-name: qucs.py
Submitted-by: wz...@ise.pw.edu.pl
Version: 1.0
#!/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=_sh15350
# Made on 2009-05-05 22:20 CEST by <wzab@wzlaphp>.
# Source directory was `/tmp/qucs'.
#
# Existing files will *not* be overwritten, unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2684 -rw-r--r-- qucsator.py
#
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
# ============= qucsator.py ==============
if test -f 'qucsator.py' && test "$first_param" != -c; then
${echo} 'x -SKIPPING qucsator.py (file already exists)'
else
${echo} 'x - extracting qucsator.py (text)'
sed 's/^X//' << 'SHAR_EOF' > 'qucsator.py' &&
"""
The "qucsator" module modifies file paths and parameters
in the netlist generated by QUCS from the schematic
(usually you can find it in /home/user/.qucs/netlist.txt
after the simulation)
X
Sample use of the module:
X q=qucsator(subst_params={'Rc':'0.6'},
X subst_paths=[
X ['path1','path2'],
X ['/home/user/.qucs/my_prj/','./']
X ] )
X for rc in range(0,10):
X q.result_file="results_"+str(rc)+".txt"
X q.subst_params={'Rc':str(rc)}
X q.run()
"""
import re
import os
class qucsator:
X def __init__(self,netlist="netlist.txt",
X sim_netlist="sim_next.txt",
X results="results.txt",
X subst_paths=[], subst_params={}):
X self.subst_paths=subst_paths
X self.subst_params=subst_params
X self.template_netlist=netlist
X self.simul_netlist=sim_netlist
X self.result_file=results
X self.path_finder=re.compile(r'.*File=\"\{(?P<fn>.*)\}\"')
X self.equ_finder=re.compile(r'Eqn:Eqn.*?\s+(?P<pn>.*?)=\"(?P<pv>.*?)\"')
X
X def try_subst_paths(self,l):
X p=self.path_finder.search(l)
X if p: #There is file reference in this line
X #Try to substitute path
X fn=p.group('fn')
X for i in self.subst_paths:
X pl=len(i[0])
X if i[0]==fn[0:pl]:
X fn=i[1]+fn[pl:]
X s=p.span('fn')
X t=l[:s[0]]+fn+l[s[1]:]
X return t
X return l
X def try_subst_params(self,l):
X p=self.equ_finder.search(l)
X if p: #There is parameter definition in this line
X pn=p.group('pn')
X if self.subst_params.has_key(pn):
X s=p.span('pv')
X t=l[:s[0]]+self.subst_params[pn]+l[s[1]:]
X return t
X return l
X
X def run(self):
X fin=open(self.template_netlist,"r")
X fout=open(self.simul_netlist,"w")
X while True:
X l = fin.readline()
X print l
X if not l:
X break
X l=self.try_subst_paths(l)
X l=self.try_subst_params(l)
X fout.write(l)
X fin.close()
X fout.close()
X os.system("qucsator -i "+self.simul_netlist+\
X " -o "+self.result_file)
X
if __name__ == '__main__':
X q=qucsator(subst_params={'Rc':'0.6'},
X subst_paths=[
X ['path1','path2'],
X ['/home/user/.qucs/my_prj/','./']
X ])
X for rc in range(0,10):
X q.result_file="results_"+str(rc)+".txt"
X q.subst_params={'Rc':str(rc)}
X q.run()
X
SHAR_EOF
(set 20 09 05 05 22 18 34 'qucsator.py'; eval "$shar_touch") &&
chmod 0644 'qucsator.py'
if test $? -ne 0
then ${echo} 'restore of qucsator.py failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'qucsator.py: MD5 check failed'
) << SHAR_EOF
4ee4fcd2d83584b525e6af84cf26e743 qucsator.py
SHAR_EOF
else
test `LC_ALL=C wc -c < 'qucsator.py'` -ne 2684 && \
${echo} 'restoration warning: size of qucsator.py is not 2684'
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