Index: mttroot/mtt/bin/trans/mtt_header ================================================================== --- mttroot/mtt/bin/trans/mtt_header +++ mttroot/mtt/bin/trans/mtt_header @@ -10,10 +10,20 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.2 2000/11/03 00:55:42 geraint +## typo: missed out 'd' in mttedx +## todo: need to accommodate mttsimpar +## +## Revision 1.1 2000/11/02 04:28:39 geraint +## Initial revision +## +## Revision 1.8 2000/10/17 16:35:03 peterg +## No parameter,state or input conversion in txt files +## ## Revision 1.7 2000/10/17 09:53:20 peterg ## Fixed logic rep ## ## Revision 1.6 2000/10/17 08:37:23 peterg ## Included logic rep @@ -58,11 +68,11 @@ case $rep in cse) states=yes; inputs=yes; parameters=yes; - output='mttedx,mtte' + output='mttdx,mtte' args=$eqnargs ;; csex) states=yes; inputs=yes; @@ -113,11 +123,11 @@ ;; simpar) states=no; inputs=no; parameters=no; - output=mttsimpar + output='mttsimpar_map' ;; sm) states=no; inputs=no; parameters=yes; @@ -168,14 +178,211 @@ start='' parameters=no states=no inputs=no ;; + oct) + modeline="// -*-c++-*- Put Emacs into c++-mode"; + Lc='//'; + oct_header=yes; + ;; *) echo Language $language not supported - sorry; exit 1 esac + +# Argument specific stuff +function get_arg_specific_stuff () +{ + arg_name=${1:-""} + case ${arg_name} in + mtta | mtte) + arg_type="Matrix" + arg_size="(MTTNX,MTTNX)" + ;; + mttb) + arg_type="Matrix" + arg_size="(MTTNX,MTTNU)" + ;; + mttc) + arg_type="Matrix" + arg_size="(MTTNY,MTTNX)" + ;; + mttd) + arg_type="Matrix" + arg_size="(MTTNY,MTTNU)" + ;; + mttax | mttdx | mttedx | mttx | open) + arg_type="ColumnVector" + arg_size="(MTTNX)" + ;; + mttpar) + arg_type="ColumnVector" + arg_size="(MTTNPAR)" + ;; + mttsimpar_map) + arg_type="Octave_map" + arg_size=""; + ;; + mttu) + arg_type="ColumnVector" + arg_size="(MTTNU)" + ;; + mtty) + arg_type="ColumnVector" + arg_size="(MTTNY)" + ;; + mttt) + arg_type="const double" + arg_size="" + ;; + nil) + arg_type="void *" + arg_size="(0x0)" + ;; + *) + echo "Argument ${arg} not supported - sorry"; exit 1 + esac +} + + +function get_field () +{ # parse comma separated string + s=${1:-""} # comma separated string + i=${2:-0} # field number in string + + if [ 0 -eq ${i} ]; then # return number of fields + echo ${s} |\ + awk -F\, '{ print NF }' + else # return ith field + echo ${s} |\ + awk -F\, -v i=${i} '{ print $i }' + fi +} + + +function get_extra_fields () +{ # return list of words in s2 and not in s1 + s1=${1:-""} # comma separated list + s2=${2:-""} # comma separated list + + c1=$(get_field ${s1} 0) # count words in s1 + c2=$(get_field ${s2} 0) # count words in s2 + + ans="" + + i2=0 # s2 word index + while [ ${i2} -lt ${c2} ]; do + flag=0 # appearance of word in s1 and s2? + i2=$((${i2} + 1)) + w2=$(get_field ${s2} ${i2}) # i2 th word in s2 + i1=0 # s1 word index + while [ ${i1} -lt ${c1} ]; do + i1=$((${i1} + 1)) + w1=$(get_field ${s1} ${i1}) # i1 th word in s1 + if [ ${w2} = ${w1} ]; then + flag=1 # w2 occurs in s1 + fi + done + if [ ${flag} -eq 0 ]; then # w2 is not in s1? + if [ -z ${ans} ]; then # string is empty? + ans=${w2} # assign w2 + else + ans=${ans},${w2} # append w2 + fi + fi + done + echo ${ans} +} + + +function write_DLD_header () +{ + cat < +#include +#include + +#include +#include "${system}_def.h" +#include "${system}_sympar.h" + +DEFUN_DLD (${system}_${rep}, args, , +"Octave ${rep} representation of system ${system} +Generated by MTT on $(date)") +{ + + octave_value_list retval; + +EOF +} + + +function map_DLD_inputs () +{ + s=${1:-""} # comma separated input list + if [ -z ${s} ];then return; fi + c=$(get_field ${s} 0) # count of inputs + i=0 + printf " if (${c} != args.length ()) usage (\"expected ${c} argument(s): ${s}\");\n\n" + while [ ${i} -lt ${c} ]; do + j=${i} + i=$((${i} + 1)) + w=$(get_field ${s} ${i}) # argument name + get_arg_specific_stuff ${w} + case ${arg_type} in + "const double") + printf " ${arg_type}\t${w}\t= args(${j}).double_value ();\n" + ;; + ColumnVector | Matrix | *) + printf " ${arg_type}\t${w}\t= args(${j}).vector_value ();\n" + ;; + esac + done + printf "\n" +} + + +function declare_DLD_outputs () +{ + s=${1:-""} # comma separated output list + c=$(get_field ${s} 0) # count of outputs + i=0 + while [ ${i} -lt ${c} ]; do + i=$((${i} + 1)) + w=$(get_field ${s} ${i}) # argument name + get_arg_specific_stuff ${w} + printf " ${arg_type}\t${w}\t${arg_size};\n" + done + cat <