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,8 @@ function [port_bonds, status] = abg2cbg(system_name, ... system_type, full_name, ... - port_bonds, port_status, typefile, infofile) + port_bonds, port_bond_direction, port_status, typefile, infofile) % abg2cbg - acausal to causal bg conversion % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% @@ -15,10 +15,14 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.22 1997/08/19 10:21:09 peterg +% %% Only copy port cuaslity info if not already set within the +% %% subsystem. I thought I'd done this already .... +% %% % %% Revision 1.21 1997/08/18 16:25:25 peterg % %% Minor bug fixes % %% % %% Revision 1.20 1997/08/18 12:45:24 peterg % %% Replaced: comp_bonds = bonds(bond_list,:) @@ -143,12 +147,11 @@ 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]=', 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'); @@ -158,10 +161,38 @@ % Find number of components [n_components,columns] = size(components); if n_components==0 % there is nothing to be done return end; + +port_bond_direction + +% Coerce the port (SS:[]) component bonds to have the same direction as +% of the bonds in the encapsulating system +if n_ports>0 + port_bond_index = abs(components(1:n_ports,1)) % relevant bond numbers + for i=1:n_ports + % Is the direction different? + if (sign(components(i,1))~=port_bond_direction(i)) + disp(sprintf("Flip port %i",i)); + % Flip direction at port + components(i,1) = - components(i,1); + % and at the other end + for j=n_ports+1:n_components + for k=1:columns + if (abs(components(j,k))==port_bond_index(i)) + components(j,k) = - components(j,k); + end + end + end; + % Flip the bond causalities (these are arrow-orientated) + bonds(port_bond_index(i),:) = -bonds(port_bond_index(i),:); + end + end +end + + % Set initial status status = -ones(n_components,1); % If not at top level, then copy the port bonds. @@ -173,11 +204,10 @@ if n_port_bonds~=n_ports mtt_info(sprintf('%s: %1.0f port bonds incompatible with %1.0f ports', ... full_name, n_port_bonds, n_ports), infofile); else % Copy the port bonds & status - port_bond_index = abs(components(1:n_ports,1)) % relevant bond numbers for j = 1:n_port_bonds jj = port_bond_index(j); for k = 1:2 if bonds(jj,k)==0 % only copy if not already set bonds(jj,k) = port_bonds(j,k); @@ -187,11 +217,11 @@ end end else n_port_bonds=0; end; -bonds,port_bonds +% bonds,port_bonds % Causality indicator total = 2*n_bonds; done = sum(sum(abs(bonds)))/total*100; @@ -245,12 +275,14 @@ if exist(cause_name)~=2 % Try a compound component % Port status depends on whether the corresponding bonds are % fully causal at this stage. one = ones(n_bonds,1); port_status = (sum(abs(comp_bonds'))'==2*one) - one; + % Direction of bonds on the ports (0 if next to port) + port_bond_direction = -sign(components(i,1:n_bonds))'; [comp_bonds,s] = abg2cbg(name, comp_type, full_name, - comp_bonds, port_status, ... + comp_bonds, port_bond_direction, port_status, ... typefile, infofile); % Create a single status from the status vector s if max(abs(s)) == 0 % Causal status(i) = 0; @@ -328,18 +360,18 @@ % $$$ file_name = [full_name, '_', system_type] file_name = [full_name, '_cbg.m']; disp(['Writing ', file_name]); cbgfilenum = fopen(file_name,'w'); -write_cbg(cbgfilenum,full_name,system_type,bonds,status); +write_cbg(cbgfilenum,full_name,system_type,bonds,status,components); fclose(cbgfilenum); -% Return the port bonds - arrow orientated causality +% 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,:) end; disp('===================================='); disp(['END: ', full_name, ' (', fun_name, ')']); disp('====================================');