Index: mttroot/mtt/bin/mtt ================================================================== --- mttroot/mtt/bin/mtt +++ mttroot/mtt/bin/mtt @@ -1420,10 +1420,11 @@ rm -f *_ode.cc *_odeo.cc rm -f *_logic.m *_logic.cc *_logic.oct rm -f *_state.m *_state.cc *_state.oct rm -f *_ode2odes.* *.dat2 MTT.core rm -f *_modpar.txt *_modpar.r + rm -f *_ICD.txt *_ICD.c *_ICD.cc *_ICD.m rm -fR *_rep MTT_work exit fi # Clean up named system @@ -1455,10 +1456,11 @@ rm -f $1_ode.cc $1_odeo.cc rm -f $1_logic.m $1_logic.cc $1_logic.oct rm -f $1_state.m $1_state.cc $1_state.oct rm -f $1_ode2odes.* $1.dat2 rm -f $1_modpar.txt $1_modpar.r + rm -f $1_ICD.txt $1_ICD.c $1_ICD.cc $1_ICD.m rm -fR $1_rep MTT_work exit fi if [ "$2" = "rep" ]; then @@ -1977,10 +1979,38 @@ modpar_txt2r $1 #SUMMARY alias name aliases for each subsystem (m) $1_alias.m: $1_alias.txt alias_txt2m $1 + +##SUMMARY ICD interface definition for system (c) +##SUMMARY ICD interface definition for system (cc) +##SUMMARY ICD interface definition for system (m) +##SUMMARY ICD interface definition for system (txt) + +$1_ICD.c: $1_ICD.txt + ICD_txt2lang.sh $1 c + +$1_ICD.cc: $1_ICD.txt + ICD_txt2lang.sh $1 cc + +$1_ICD.m: $1_ICD.txt + ICD_txt2lang.sh $1 m + +$1_ICD.txt: $1_icd.txt2 + icd2ICD_txt22txt.sh $1 + +$1_icd.txt2: $1_cbg.m + touch $1_icd.txt2 + +#SUMMARY ICD interface definitions for each subsystem (m) +$1_icd.m: $1_icd.txt + icd_txt2m.sh $1 + +#SUMMARY ICD interface definitions for each subsystem (txt) +$1_icd.txt: $1_lbl.txt + lbl2icd_txt2txt.sh $1 #SUMMARY cr constitutive relationship for each subsystem (txt) $1_cr.txt: $1_abg.m $1_sub.sh abg2cr_m2txt $1 @@ -2284,11 +2314,11 @@ #SUMMARY abg acausal bond graph (m) #Raw bond graph to acausal bond graph: mfile ifneq ($start_at_abg,yes) -$1_abg.m: $1_rbg.m $1_alias.m $1_cmp.m +$1_abg.m: $1_rbg.m $1_alias.m $1_cmp.m $1_icd.m cmp2sub_m2sh $1 (sh $1_sub.sh "mtt $mtt_switches -q -u -l $level+1 " ' abg m null || exit 1') || exit 1 rbg2abg_m $info_switch $1 endif @@ -2312,11 +2342,11 @@ #SUMMARY def definitions - system orders etc. (h) #SUMMARY struc* structure - list of inputs, outputs and states (txt) #SUMMARY struc structure - list of inputs, outputs and states (tex) #SUMMARY struc* structure - list of inputs, outputs and states (view) #Elementary system equations + definitions -${sys}_ese.r: ${sys}_cbg.m +${sys}_ese.r: ${sys}_cbg.m cbg2ese_m2r $partition $info_switch $Subsystem; #ese_tidy $1 $1_def.r: $1_ese.r touch $1_def.r $1_struc.txt: $1_ese.r ADDED mttroot/mtt/bin/trans/ICD_txt2lang.sh Index: mttroot/mtt/bin/trans/ICD_txt2lang.sh ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/ICD_txt2lang.sh @@ -0,0 +1,54 @@ +#! /bin/sh + +sys=$1 +lang=$2 + +ICD=${sys}_ICD.${lang} +txt=${sys}_ICD.txt +struc=${sys}_struc.txt + +case ${lang} in + c) lb='['; rb=']'; offset=0; comment='//';; + cc) lb='('; rb=')'; offset=1; comment='//';; + m) lb='('; rb=')'; offset=0; comment='#';; + *) echo Language ${lang} not yet supported.; exit -1;; +esac + +echo Creating ${ICD} + +cat < ${ICD} +${comment} Interface Control Definition mappings for system ${sys} +${comment} ${ICD}: Generated by MTT `date` + +EOF + +# ICD.txt Format: +# Input|Output ICD_Name PortName Causality: causality Units: units +# $1 $2 $3 $4 $5 $6 $7 + +cat <> ${ICD} + +${comment} Inputs + +EOF +for name in `cat ${txt} | awk '($1 == "Input:") { print $3 }'` +do + num=`grep ${name} ${struc} | awk '($1 == "input") { print $2 }'` + grep ^Input ${txt} |\ + awk '($3 == name) { printf ("\tmttu%c%d%c\t= %s;\n", lb, num-offset, rb, $2) }'\ + lb=${lb} rb=${rb} name=${name} num=${num} offset=${offset} >> ${ICD} +done + +cat <> ${ICD} + +${comment} Outputs + +EOF +for name in `cat ${txt} | awk '($1 == "Output:") { print $3 }'` +do + num=`grep ${name} ${struc} | awk '($1 == "output") { print $2 }'` + grep ^Output ${txt} |\ + awk '($3 == name) { printf ("\t%-30s = mtty%c%d%c;\n", $2, lb, num-offset, rb) }'\ + lb=${lb} rb=${rb} name=${name} num=${num} offset=${offset} >> ${ICD} +done + ADDED mttroot/mtt/bin/trans/icd2ICD_txt22txt.sh Index: mttroot/mtt/bin/trans/icd2ICD_txt22txt.sh ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/icd2ICD_txt22txt.sh @@ -0,0 +1,31 @@ +#! /bin/sh + +sys=$1 +icd=${sys}_*_icd.txt2 +ICD=${sys}_ICD.txt + +echo Creating ${ICD} + +# lbl.txt ICD Format: +# [#|%]ICD PortName EffortName,EffortUnit;FlowName,FlowUnit +# $1 $2 $3 +# Comma / Semi-colon distinction unenforced + +# icd.txt Format +# PortName EffortName,EffortUnit;FlowName,FlowUnit input|output,input|output +# $1 $2 $3 $4 $5 $6 $7 + +cat < ${ICD} +## Interface Control Definition for System ${sys} +## ${ICD}: Generated by MTT `date` + +EOF + +cat ${icd} |\ + sed 's/[\,\;]/\ /g' |\ + awk ' + ($2 != "null" && $6 == "input") { printf ("Input: %-30s %-30s Causality: Effort Units: %s\n", $2, $1, $3) } + ($4 != "null" && $7 == "input") { printf ("Input: %-30s %-30s Causality: Flow Units: %s\n", $4, $1, $5) } + ($2 != "null" && $6 == "output") { printf ("Output: %-30s %-30s Causality: Effort Units: %s\n", $2, $1, $3) } + ($4 != "null" && $7 == "output") { printf ("Output: %-30s %-30s Causality: Flow Units: %s\n", $4, $1, $5) } + ' | sort >> ${ICD} ADDED mttroot/mtt/bin/trans/icd_txt2m.sh Index: mttroot/mtt/bin/trans/icd_txt2m.sh ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/icd_txt2m.sh @@ -0,0 +1,18 @@ +#! /bin/sh + +# Inform user +echo Creating $1_icd.m + +#Create the component ICD file complete with headers. +echo "function icd = $1_icd" > $1_icd.m +echo "%% Component icd file ($1_icd.m)" >> $1_icd.m +echo "%% Generated by MTT at `date`" >> $1_icd.m + +#Write out the variables +awk '{ + if (NF==2) {i++; print "icd."$1 "\t = \""$2"\";"} + + } + END{ + if (i==0) print "icd = 0;" + }' $1_icd.txt >> $1_icd.m ADDED mttroot/mtt/bin/trans/lbl2icd_txt2txt.sh Index: mttroot/mtt/bin/trans/lbl2icd_txt2txt.sh ================================================================== --- /dev/null +++ mttroot/mtt/bin/trans/lbl2icd_txt2txt.sh @@ -0,0 +1,40 @@ +#! /bin/sh + + ###################################### + ##### Model Transformation Tools ##### + ###################################### + +# Bourne shell script: lbl2icd_txt2txt +# Creates the component ICDs in text form + +# Adapted from lbl2alias_txt2txt + +sys=$1 +icd=${sys}_icd.txt +lbl=${sys}_lbl.txt + +# Inform user +echo Creating ${icd} + +#Create the ICD file complete with headers. +echo "# Component ICD file ($1_icd.txt)" > ${icd} +echo "# Generated by MTT at `date`" >> ${icd} + +#Write out the variables + grep '[%|#]ICD' ${lbl} |\ + awk '{ + if (match($3,"/")==0){ + if (match($2,"\\$")==0){ + icd=$2; name =$3 + } + else{ + icd=$3; name =$2 + } + n=split(icd,a,"|"); + for (i=1; i<=n; i++) + print a[i] "\t" name; + } + } + END{ + print "###_END_OF_ICD_###" + }' >> ${icd} Index: mttroot/mtt/bin/trans/m/cbg2ese.m ================================================================== --- mttroot/mtt/bin/trans/m/cbg2ese.m +++ mttroot/mtt/bin/trans/m/cbg2ese.m @@ -21,10 +21,13 @@ ## ############################################################### ## ## Version control history ## ############################################################### ## ## $Id$ ## ## $Log$ + ## ## Revision 1.40 2001/02/05 01:50:29 geraint + ## ## No unit type comparison at ports if either is "none". + ## ## ## ## Revision 1.40 2000/12/16 08:10:55 geraint ## ## No unit type comparison at ports if either is "none". ## ## ## ## Revision 1.39 2000/11/16 12:54:14 peterg ## ## Added checking of unit consistency at ports @@ -194,11 +197,12 @@ end; ## Setup files ese_name = [full_name_repetition, "_ese.r"]; ese_file = fopen(ese_name, "w") # open file (first time) - + icd_file = fopen([full_name_repetition,"_icd.txt2"],"w") + fprintf(ese_file, "\n%s%s Equation file for system %s (file %s)\n", ... pc, pc, full_name_repetition, ese_name); fprintf(ese_file, "%s%s Generated by MTT\n\n", pc, pc); ## Evaluate the system function to get the bonds @@ -285,11 +289,11 @@ comp_name,subsystem.type,full_name); if struct_contains(CBG,"alias") subsystem.cr = alias_args(subsystem.cr,CBG.alias,";",message,infofilenum,full_name); endif; endif; - + ## Substitute positional ($1 etc) arguments subsystem.cr = subs_arg(subsystem.cr,system_cr, ... "lin",full_name,subsystem.type,comp_name,infofilenum); subsystem.arg = subs_arg(subsystem.arg,system_args, ... "1",full_name,subsystem.type,comp_name,infofilenum); @@ -494,15 +498,42 @@ endfor; endfor; endif; endif endfor + + ## component interface definition + if struct_contains(CBG,"icd") + if struct_contains(CBG.icd,comp_name) + if AliasingArguments + subsystem.icd = alias_args(eval(["CBG.icd.",comp_name]),CBG.alias,";",message,infofilenum,full_name); + endif + endif + if (struct_contains(subsystem,"icd")) + subsystem.icd = subs_arg(subsystem.icd,system_args, ... + "null",full_name,subsystem.type,comp_name,infofilenum); + + fprintf(icd_file,"%s_%s\t%s\t",full_name_repetition,comp_name,subsystem.icd); + if (comp_bonds(1) == 1) + fprintf(icd_file,"output,"); + elseif (comp_bonds(1) == -1) + fprintf(icd_file,"input,"); + endif + if (comp_bonds(2) == 1) + fprintf(icd_file,"input\n"); + elseif (comp_bonds(2) == -1) + fprintf(icd_file,"output\n"); + endif + endif + endif # End of component interface definition + endfor # [subsystem,comp_name] = CBG_field endif # struct_contains(CBG,field) endfor # i=1:2 + fclose(icd_file); fclose(ese_file); # Close endfunction Index: mttroot/mtt/bin/trans/m/write_abg.m ================================================================== --- mttroot/mtt/bin/trans/m/write_abg.m +++ mttroot/mtt/bin/trans/m/write_abg.m @@ -3,10 +3,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.8 1999/10/18 22:41:41 peterg +## Corrected vector junction expansion +## ## Revision 1.7 1999/10/18 05:16:51 peterg ## Now vectorises 0 and 1 junctions !! ## ## Revision 1.6 1998/09/02 11:35:20 peterg ## Removed port.index field @@ -78,11 +81,11 @@ fprintf(fid,Sformat,system_name,new_name,"type",comp_type); fprintf(fid,Sformat,system_name,new_name,"cr",cr); fprintf(fid,Sformat,system_name,new_name,"arg",arg); fprintf(fid,Iformat,system_name,new_name,"repetitions",repetitions); fprintf(fid,Iformat,system_name,new_name,"status",-1); - + ##Connections fprintf(fid,Cformat,system_name,new_name); ## Each vector junction has n*m bonds ## n - dimension of vector ## m - number of bonds @@ -129,10 +132,11 @@ fprintf(fid,PIformat,system_name,name_i,"status",-1); fprintf(fid,PCformat,system_name,name_i); fprintf(fid,"%i ", c(i_port)); fprintf(fid,"];\n"); + endfor; endif; endfor; [N,M]=size(PortList); @@ -170,9 +174,18 @@ if is_struct(alias) for [val,key] = alias fprintf(fid,"%s.alias.%s = \"%s\";\n", system_name,key,val); endfor endif + + fprintf(fid,"\n# Interface Definition\n"); + eval(["icd = ",system_name, "_icd;"]); + if is_struct(icd) + for [val,key] = icd + fprintf(fid,"%s.icd.%s = \"%s\";\n",system_name,key,val); + endfor + endif + fclose(fid);