Public domain sources of the data converter from qucs (http://qucs.sf.net)
to Octave (http://www.octave.org).
Details in the comments on the begining of the file.
Wojciech M. Zabolotny
wzab<at>ise.pw.edu.pl
#!/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=_sh28148
# Made on 2009-01-16 13:03 CET by <wzab@wzlaphp>.
# Source directory was `/tmp/qucs_conv'.
#
# Existing files will *not* be overwritten, unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 3620 -rw-r--r-- qucs_conv.m
#
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_conv.m ==============
if test -f 'qucs_conv.m' && test "$first_param" != -c; then
${echo} 'x -SKIPPING qucs_conv.m (file already exists)'
else
${echo} 'x - extracting qucs_conv.m (text)'
sed 's/^X//' << 'SHAR_EOF' > 'qucs_conv.m' &&
% qucs_conv - the function for conversion of QUCS (http://qucs.sf.net)
% produced datafiles into the Octave (http://www.gnu.org/software/octave/)
% data structure.
% ver. 1.0 16.01.2009, written by Wojciech M. Zabolotny (wzab<at>ise.pw.edu.pl)
% This is a public domain code
%
% The converted data are stored into a structure containing two fields:
% "indeps" - nested structure with independent variables as vectors
% "deps" - nested structure, containing dependend variables as
% yet another nested structure with two fields:
% "indvars" - the cell array of names of independent variables
% associated with this dependent variable
% "dta" - the multi-dimensional array containing the values
% of the particular dependent variable
% The names of the fields in the "deps" and "indeps" structures are
% obtained from the variable names in QUCS simulation, with one
% significant change - dots (".") have been replaced with underscores
% ("_") to form valid Octave field name
function res=qucs_conv(fname)
X global rdat
X rdat=struct();
X f=fopen(fname,"r");
X l=fgetl(f);
X if strcmp(l,"<Qucs Dataset 0.0.14>")==0
X error("This is not a QUCS file")
X end
X while 1
X l=fgetl(f);
X if l==-1
X break
X elseif strcmp(l(1:4),"<dep")==1
X read_dep(l(2:end-1),f);
X elseif strcmp(l(1:6),"<indep")==1
X read_indep(l(2:end-1),f);
X end
X end
X res=rdat;
end
X
function dep=read_dep(line,file)
X global rdat
X %disp(line)
X % We extract the name of the variable
X [nv,line]=strtok(line); % remove the leading "<dep"
X [nv,line]=strtok(line);
X % Replace dots with underscores
X nv=strrep(nv,".","_") ;
X vsize=1;
X vdims=[];
X vindeps=cell();
X % Now we find all the independent variables
X while 1
X [iv,line]=strtok(line);
X if strcmp(iv,"")==1
X break
X end
X iv=strrep(iv,".","_");
X %Calculate the size
X vdim=length(getfield(rdat.indeps,iv));
X %vdims(end+1)=vdim;
X vdims(end+1)=vdim;
X vindeps(end+1)=iv;
X vsize*=vdim;
X end
X %printf("%s\n",["vdims=" num2str(vdims) " vsize=" num2str(vsize)])
X % alocate the storage
X dta=zeros(1,vsize);
X for i=1:vsize
X line=fgetl(file);
X %disp(line)
X dta(1,i) = dta_conv(line);
X end
X line=fgetl(file);
X if strcmp(line,"</dep>")==0
X error(["Wrong syntax after dep? Was:" line])
X end
X dta=reshape(dta,vdims);
X %keyboard()
X vstruct=struct();
X vstruct.indvars=vindeps;
X vstruct.dta=dta;
X rdat=setfield(rdat,"deps",nv,vstruct);
X res=1;
X %keyboard()
end
X
function indep=read_indep(line,file)
X global rdat
X %disp(line)
X % We extract the name of the variable
X [nv,line]=strtok(line); %remove the leading "<indep"
X [nv,line]=strtok(line);
X % Replace dots with underscores
X nv=strrep(nv,".","_");
X % We extract the size of the variable from the rest of the line
X vsize=str2num(line);
X %printf("%s\n",["vsize=" num2str(vsize)])
X % alocate the storage
X dta=zeros(vsize,1);
X for i=1:vsize
X line=fgetl(file);
X dta(i,1) = dta_conv(line);
X end
X line=fgetl(file);
X if strcmp(line,"</indep>")==0
X error(["Wrong syntax after indep? Was: " line])
X end
X rdat=setfield(rdat,"indeps",nv,dta);
X indep=1;
end
X
function v=dta_conv(line)
X nline=strrep(line,"j","");
X if length(line) != length(nline)
X nline = [ nline "j" ];
X end
X v = str2num(nline);
end
SHAR_EOF
(set 20 09 01 16 12 59 50 'qucs_conv.m'; eval "$shar_touch") &&
chmod 0644 'qucs_conv.m'
if test $? -ne 0
then ${echo} 'restore of qucs_conv.m failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'qucs_conv.m: MD5 check failed'
) << SHAR_EOF
89696972e7e9d19e16b039f526753e96 qucs_conv.m
SHAR_EOF
else
test `LC_ALL=C wc -c < 'qucs_conv.m'` -ne 3620 && \
${echo} 'restoration warning: size of qucs_conv.m is not 3620'
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
% qucs_conv - the function for conversion of QUCS (http://qucs.sf.net)
% produced datafiles into the Octave (http://www.gnu.org/software/octave/)
% data structure.
% ver. 1.0.1 16.01.2009, written by Wojciech M. Zabolotny (wzab<at>ise.pw.edu.pl)
% This is a public domain code
%
% The converted data are stored into a structure containing two fields:
% "indeps" - nested structure with independent variables as vectors
% "deps" - nested structure, containing dependend variables as
% yet another nested structure with two fields:
% "indvars" - the cell array of names of independent variables
% associated with this dependent variable
% "dta" - the multi-dimensional array containing the values
% of the particular dependent variable
% The names of the fields in the "deps" and "indeps" structures are
% obtained from the variable names in QUCS simulation, with one
% significant change - dots (".") have been replaced with underscores
% ("_") to form valid Octave field name
%
% ver. 1.0.1 - corrected conversion of dependent variables with single
% independent variable
function res=qucs_conv(fname)
global rdat
rdat=struct();
f=fopen(fname,"r");
l=fgetl(f);
if strcmp(l,"<Qucs Dataset 0.0.14>")==0
error("This is not a QUCS file")
end
while 1
l=fgetl(f);
if l==-1
break
elseif strcmp(l(1:4),"<dep")==1
read_dep(l(2:end-1),f);
elseif strcmp(l(1:6),"<indep")==1
read_indep(l(2:end-1),f);
end
end
res=rdat;
end
function dep=read_dep(line,file)
global rdat
%disp(line)
% We extract the name of the variable
[nv,line]=strtok(line); % remove the leading "<dep"
[nv,line]=strtok(line);
% Replace dots with underscores
nv=strrep(nv,".","_") ;
vsize=1;
vdims=[];
vindeps=cell();
% Now we find all the independent variables
while 1
[iv,line]=strtok(line);
if strcmp(iv,"")==1
break
end
iv=strrep(iv,".","_");
%Calculate the size
vdim=length(getfield(rdat.indeps,iv));
%vdims(end+1)=vdim;
vdims(end+1)=vdim;
vindeps(end+1)=iv;
vsize*=vdim;
end
%printf("%s\n",["vdims=" num2str(vdims) " vsize=" num2str(vsize)])
% alocate the storage
dta=zeros(1,vsize);
for i=1:vsize
line=fgetl(file);
%disp(line)
dta(1,i) = dta_conv(line);
end
line=fgetl(file);
if strcmp(line,"</dep>")==0
error(["Wrong syntax after dep? Was:" line])
end
if length(vdims)>1
dta=reshape(dta,vdims);
end
%keyboard()
vstruct=struct();
vstruct.indvars=vindeps;
vstruct.dta=dta;
rdat=setfield(rdat,"deps",nv,vstruct);
res=1;
%keyboard()
end
function indep=read_indep(line,file)
global rdat
%disp(line)
% We extract the name of the variable
[nv,line]=strtok(line); %remove the leading "<indep"
[nv,line]=strtok(line);
% Replace dots with underscores
nv=strrep(nv,".","_");
% We extract the size of the variable from the rest of the line
vsize=str2num(line);
%printf("%s\n",["vsize=" num2str(vsize)])
% alocate the storage
dta=zeros(vsize,1);
for i=1:vsize
line=fgetl(file);
dta(i,1) = dta_conv(line);
end
line=fgetl(file);
if strcmp(line,"</indep>")==0
error(["Wrong syntax after indep? Was: " line])
end
rdat=setfield(rdat,"indeps",nv,dta);
indep=1;
end
function v=dta_conv(line)
nline=strrep(line,"j","");
if length(line) != length(nline)
nline = [ nline "j" ];
end
v = str2num(nline);
end