Index: mttroot/mtt/bin/trans/m/cbg2ese.m ================================================================== --- mttroot/mtt/bin/trans/m/cbg2ese.m +++ mttroot/mtt/bin/trans/m/cbg2ese.m @@ -1,9 +1,15 @@ function structure = cbg2ese(system_name, system_type, system_cr, ... system_args, full_name, full_name_repetition, ... repetition,... structure, structure_file, infofile) +% Set up globals to count the component inputs and outputs. This relies on +% the named SS (the ports) being in the correct order. Using globals here +% avoids changing the common argument list for all _eqn files for something +% which is only used for named SS components. +global local_u_index +global local_y_index % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % @@ -14,10 +20,13 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.13 1997/05/19 16:45:56 peterg +% %% Fixed ISW bug -- deleted spurious ISW_eqn.m file +% %% % %% Revision 1.12 1997/04/15 09:17:26 peterg % %% Added the structure file - contains details of states etc. % %% % %% Revision 1.11 1996/12/07 18:20:11 peterg % %% Replaces null argument by a default and tells user. @@ -117,10 +126,15 @@ n_components = n_components % Set up the first dummy bond number - needed for repetative components next_bond = max(max(abs(components)))+1; + % Set up the counters for the labelled SS. These are, by definition, + % encountered first and so the counters will not be messed up by subsystems. + local_u_index = 0; + local_y_index = 0; + for i = 1:n_components comp = nozeros(components(i,:)); bond_list = abs(comp); direction = sign(comp)'*[1 1]; % Convert from arrow orientated to component orientated causality @@ -197,30 +211,35 @@ '\n\t%s Equations linking up subsystem %s (%s)\n\n', ... pc, comp_name, comp_type); name_comp_name = sprintf('%s_%s_%d', ... full_name_repetition, comp_name, k); + u_index = 0; y_index = 0; % Count the inputs and outputs for port_number=1:length(bond_list) % Effort if comp_bonds(port_number,1)==1 % Source + u_index = u_index + 1; fprintf(ese_file, '%s_MTTu%d := %s;\n', ... - name_comp_name, port_number, varname(name_r, ... + name_comp_name, u_index, varname(name_r, ... bond_list(port_number),1)); - else % sensor - fprintf(ese_file, '%s := %s_MTTy%d;\n', ... + else % Sensor + y_index = y_index + 1; + fprintf(ese_file, '%s := %s_MTTy%d;\n', ... varname(name_r, ... - bond_list(port_number),1), name_comp_name, port_number); + bond_list(port_number),1), name_comp_name, y_index); end; - % flow + % Flow if comp_bonds(port_number,2)==-1 % Source + u_index = u_index + 1; fprintf(ese_file, '%s_MTTu%d := %s;\n', ... - name_comp_name, port_number, varname(name_r, ... + name_comp_name, u_index, varname(name_r, ... bond_list(port_number),-1)); - else % sensor - fprintf(ese_file, '%s := %s_MTTy%d;\n', ... + else % Sensor + y_index = y_index + 1; + fprintf(ese_file, '%s := %s_MTTy%d;\n', ... varname(name_r, ... - bond_list(port_number),-1), name_comp_name, port_number); + bond_list(port_number),-1), name_comp_name, y_index); end; end; disp('---POP---'); else % its a simple component Index: mttroot/mtt/lib/comp/simple/SS_eqn.m ================================================================== --- mttroot/mtt/lib/comp/simple/SS_eqn.m +++ mttroot/mtt/lib/comp/simple/SS_eqn.m @@ -1,7 +1,15 @@ function structure = SS_eqn(name,bond_number,bonds,direction,cr,args, ... structure,filenum); + +% Set up globals to count the component inputs and outputs. This relies on +% the named SS (the ports) being in the correct order. Using globals here +% avoids changing the common argument list for all _eqn files for something +% which is only used for named SS components. +global local_u_index +global local_y_index + % SS_eqn - equations for SS component % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -17,10 +25,13 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.11 1997/05/09 08:21:07 peterg +% %% Explicit computation of port number -- avoids str2num +% %% % %% Revision 1.10 1997/03/22 17:13:03 peterg % %% Fixed bug for port nos. > 1 digit! % %% % %% Revision 1.9 1997/03/22 15:50:59 peterg % %% Changed %1.0f to %d format. @@ -79,43 +90,50 @@ inputs = structure(3); outputs = structure(4); zero_outputs = structure(5); -if strcmp(effort_attribute, 'MTT_port') % Its a numbered port - % Convert string to number - % port_number = abs(flow_attribute)-abs('0'); - %port_number = str2num(flow_attribute); - - %Compute port number - str_port_number = flow_attribute; - N_string = length(str_port_number); - port_number=0; - for i=1:N_string - port_number = 10*port_number + abs(str_port_number(i))-abs('0'); - end; +if strcmp(effort_attribute, 'MTT_port') % Its a named port + +% Note: we don't have numbered ports now, so the correct indices are deduced +% by incrementing the two globals: local_u_index and local_y_index +% $$$ % Convert string to number +% $$$ % port_number = abs(flow_attribute)-abs('0'); +% $$$ % port_number = str2num(flow_attribute); + +% $$$ %Compute port number +% $$$ str_port_number = flow_attribute; +% $$$ N_string = length(str_port_number); +% $$$ port_number=0; +% $$$ for i=1:N_string +% $$$ port_number = 10*port_number + abs(str_port_number(i))-abs('0'); +% $$$ end; % Effort if bonds(1,1)==-1 % Source + local_u_index = local_u_index + 1; fprintf(filenum, '%s := %s_MTTu%d;\n', ... - varname(name, bond_number,1), name, port_number); + varname(name, bond_number,1), name, local_u_index); else % Sensor + local_y_index = local_y_index + 1; fprintf(filenum, '%s_MTTy%d := %s;\n', ... - name, port_number, varname(name, bond_number,1)); + name, local_y_index, varname(name, bond_number,1)); end; % Flow if bonds(1,2)==1 % Source + local_u_index = local_u_index + 1; fprintf(filenum, '%s := %s_MTTu%d;\n', ... - varname(name, bond_number,-1), name, port_number); + varname(name, bond_number,-1), name, local_u_index); else % Sensor + local_y_index = local_y_index + 1; fprintf(filenum, '%s_MTTy%d := %s;\n', ... - name, port_number, varname(name, bond_number,-1)); + name, local_y_index, varname(name, bond_number,-1)); end; return end; - +% Now do SS which are not ports. % Effort if strcmp(effort_attribute, 'external') if bonds(1,1)==-1 % Source inputs = inputs+1; fprintf(filenum, '%s := MTTu(%d,1);\n', ...