Index: mttroot/mtt/bin/trans/m/mtt_component_eqn.m ================================================================== --- mttroot/mtt/bin/trans/m/mtt_component_eqn.m +++ mttroot/mtt/bin/trans/m/mtt_component_eqn.m @@ -1,6 +1,7 @@ -function [known] = mtt_component_eqn (fullname, port, causality, known) +function [known] = mtt_component_eqn (fullname, port, causality, \ + known, Cbg) ## function [known] = mtt_component_eqn (fullname, port, causality, known) ## ## Recursively finds the equations giving the signal of specified ## causality on the specified port of component named "name" within @@ -34,20 +35,12 @@ eqn="## No equation -- something wrong"; # Default if length(known)<2 # Invalid known = " "; endif - - ## File containing data structure - cbg_file = sprintf("%s_cbg",Name); - - if (exist(cbg_file)==0) - error(sprintf("mtt_component_eqn: subystem \"%s\" does not exist", Name)); - endif - - ## Subsystem data structure - cbg = eval(sprintf("%s;", cbg_file)); + + cbg = mtt_cbg(Name); # Structure for this subsystem if struct_contains (cbg, "ports") ## Combine ports with the other subsystems for [component_structure, component] = cbg.ports eval(sprintf("cbg.subsystems.%s=cbg.ports.%s;",component,component)); @@ -68,11 +61,12 @@ else # Get name and find equation name = deblank(cbg.portlist(port,:)); if DEBUG disp("----> lower-level system") endif - known = mtt_component_eqn (mtt_fullname(Name,name), 1, causality, known); + known = mtt_component_eqn (mtt_fullname(Name,name), 1, \ + causality, known, cbg); return endif endif @@ -176,32 +170,25 @@ endif endfor ## File containing data structure NAME = mtt_subname(Name); - Cbg_file = sprintf("%s_cbg",NAME); - - if (exist(Cbg_file)==0) - error(sprintf("mtt_component_eqn: subsystem %s does not exist", NAME)); - endif - - ## System data structure - Cbg = eval(sprintf("%s;", Cbg_file)); - + CBG = mtt_cbg(NAME); ## And to which component (at higher level) is it connected? [new_Name,new_name] = mtt_subname(Name); - port_bond = eval(sprintf("Cbg.subsystems.%s.connections(%i);", new_name, port_index)); - [in_name, in_port, in_bond] = mtt_other_end (new_name,port_bond,Cbg); + port_bond = eval(sprintf("CBG.subsystems.%s.connections(%i);", new_name, port_index)); + [in_name, in_port, in_bond] = mtt_other_end (new_name,port_bond,CBG); ## Find its equation if DEBUG disp("----> higher level system") endif - known = mtt_component_eqn (mtt_fullname(new_Name,in_name), in_port, causality, known); + known = mtt_component_eqn (mtt_fullname(new_Name,in_name), \ + in_port, causality, known, cbg); LHS = Source_seqn ("external",Name); RHS = varname(NAME, abs(in_bond), i_cause); eqn = sprintf("%s%s%s := %s;", LHS, SD, name, RHS); @@ -224,19 +211,12 @@ else # Compound component new_NAME = Name; new_Name = mtt_fullname(Name,name); new_name = ""; - ## File containing data structure - Cbg_file = sprintf("%s_cbg",new_Name); - - if (exist(Cbg_file)==0) - error(sprintf("mtt_component_eqn: subsystem %s does not exist", new_Name)); - endif - - ## System data structure - Cbg = eval(sprintf("%s;", Cbg_file)); + ## Get relevant data structure + Cbg = mtt_cbg(new_Name); port_name = Cbg.portlist(port,:); LHS = varname(Name, outsig(1,1), outsig(1,2)); RHS = Sensor_seqn ("external",new_Name); eqn = sprintf("%s := %s%s%s;", LHS, RHS, SD, port_name); @@ -244,11 +224,11 @@ if DEBUG disp("----> same-level subsystem") endif [known] = mtt_component_eqn \ - (mtt_fullname(new_Name,new_name), port, causality, known); + (mtt_fullname(new_Name,new_name), port, causality, known, cbg); endif endif comment = \ @@ -277,11 +257,12 @@ disp("----> same-level component") endif [known] = mtt_component_eqn \ - (mtt_fullname(Name,other_name), other_port, other_causality, known); + (mtt_fullname(Name,other_name), other_port, other_causality, \ + known, cbg); endfor endif ## Write this signal ##comment_2 = sprintf("Connected to:%s", in_component_list);