Index: mttroot/mtt/bin/trans/m/abg2cbg.m ================================================================== --- mttroot/mtt/bin/trans/m/abg2cbg.m +++ mttroot/mtt/bin/trans/m/abg2cbg.m @@ -1,8 +1,10 @@ -function [port_bonds, status] = abg2cbg(system_name, ... - system_type, full_name, ... - port_bonds, port_bond_direction, port_status, typefile, infofile, errorfile) +function [port_bonds, status] = abg2cbg(system_name, system_type, full_name, + port_bonds, + port_bond_direction, + port_status, + typefile, infofile, errorfile) % abg2cbg - acausal to causal bg conversion % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% @@ -15,10 +17,16 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.30 1998/07/27 20:29:49 peterg +% %% Had another go at causality .... +% %% 1. Impose external causality onto all port bonds +% %% 2. Set C_cause.m so that it DOESN'T set causality +% %% -- I_cause is already ok ! +% %% % %% Revision 1.29 1998/07/10 09:01:42 peterg % %% Added error + info file in new form % %% % %% Revision 1.28 1998/07/08 09:23:42 peterg % %% Undid the previous change -- needs more thought. @@ -174,31 +182,36 @@ status = []; return end; % Evaluate the system function to get the bonds and number of ports -eval(['[bonds,components,n_ports]=', fun_name, ';']); +eval(['[bonds,components,n_ports,N_ports]=', fun_name, ';']); % Find number of bonds [n_bonds,columns] = size(bonds); if (columns ~= 2)&(n_bonds>0) error('Incorrect bonds matrix: must have 2 columns'); end; % Find number of components -[n_components,columns] = size(components); +[n_components,m_components] = size(components); if n_components==0 % there is nothing to be done return end; -% port_bond_direction +port_bond_direction % Coerce the port (SS:[]) component bonds to have the same direction as % of the bonds in the encapsulating system -- but not at top level if (n_ports>0)&&(~at_top_level) - port_bond_index = abs(components(1:n_ports,1)); % relevant bond numbers + port_bond_index = abs(components(1:n_ports,1:m_components))# relevant + # bond + # numbers + port_bond_index = nozeros(reshape(\ + port_bond_index',n_ports*m_components,1))'# vectorise + for i=1:n_ports % Is the direction different? if (sign(components(i,1))~=port_bond_direction(i)) mtt_info(sprintf("Flip port %i",i),infofile); % Flip direction at port @@ -226,11 +239,11 @@ if ~at_top_level % Find number of port bonds [n_port_bonds,columns] = size(port_bonds); % Check compatibility - if ok copy port bonds to the internal bonds list. - if n_port_bonds~=n_ports + if n_port_bonds~=N_ports mtt_error(sprintf('%s: %1.0f port bonds incompatible with %1.0f ports', ... full_name, n_port_bonds, n_ports), errorfile); else % Copy the port bonds & status for j = 1:n_port_bonds @@ -238,11 +251,11 @@ for k = 1:2 # if bonds(jj,k)==0 % only copy if not already set bonds(jj,k) = port_bonds(j,k); # end; end; - status(1:n_ports) = port_status; +# status(1:N_ports) = port_status; end end else n_port_bonds=0; end; @@ -261,11 +274,11 @@ % Inner loop propagates causality while done~=old_done % disp(sprintf('Causality is %3.0f%s complete.', done, pc)); old_done = done; done,ci_index - for i = n_port_bonds+1:n_components % Miss out the ports + for i = n_ports+1:n_components % Miss out the ports if status(i) ~= 0 % only do this if causality not yet complete % Get the bonds on this component comp = nozeros(components(i,:)); bond_list = abs(comp); @@ -334,12 +347,12 @@ status(i) = -1; end; end; else % its a simple component -- or explicit causality defined -# disp(['---', name, ' (', cause_name, ') ---']); -# comp_bonds_in = comp_bonds + disp(['---', name, ' (', cause_name, ') ---']); + comp_bonds_in = comp_bonds % Convert from arrow orientated to component orientated causality comp_bonds = comp_bonds.*direction; % Evaluate the built-in causality procedure @@ -346,13 +359,14 @@ eval([ '[comp_bonds,status(i)] = ', cause_name, '(comp_bonds);' ]); % and convert from component orientated to arrow orientated causality comp_bonds = comp_bonds.*direction; -# comp_bonds_out = comp_bonds + comp_bonds_out = comp_bonds end; - + + bonds,bond_list,comp_bonds % Update the full bonds list bonds(bond_list,:) = comp_bonds; end; end; @@ -372,10 +386,11 @@ end; end; % Print final causality +status final_done = (sum(status==zeros(n_components,1))/n_components)*100; if at_top_level mtt_info(sprintf('Final causality of %s is %3.0f%s complete.', ... full_name, final_done, pc), infofile); @@ -412,13 +427,14 @@ write_cbg(cbgfilenum,full_name,system_type,bonds,status,components); fclose(cbgfilenum); % Return the port bonds - arrow orientated causality - and the direction if ~at_top_level % Not at top level - j = abs(components(1:n_ports,1)); %relevant bond numbers - port_bonds = bonds(j,:); + port_bonds = bonds(port_bond_index,:) # Return port bonds + status(1:n_ports) = zeros(1:n_ports); # Port status not relevant end; disp('===================================='); disp(['END: ', full_name, ' (', fun_name, ')']); disp('===================================='); +