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,infofile) + port_bonds, typefile, infofile) % abg2cbg - acausal to causal bg conversion % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -14,10 +14,13 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.9 1996/08/30 12:55:40 peter +% %% More heirachical stuff added. +% %% % %% Revision 1.8 1996/08/26 10:04:25 peterg % %% Fixed error due to a line wrap. % %% % %%Revision 1.7 1996/08/16 12:58:58 peter % %% Now does preferred causality of I and C. @@ -53,18 +56,33 @@ end; if nargin<5 infofile = 'stdout'; end; + +% Create a file to contain shell commands which map subsystem types +% onto components +if strcmp(full_name, '') % Then at top level + fprintf(typefile, '# Commands to map types onto subsystems\n'); + fprintf(typefile, '# File %s_type.sh\n', system_name); + fprintf(typefile, '# Generated by MTT on %s\n\n', date); +end; + +full_name +length(full_name) % Create the (full) system name -if length(full_name)==0 +if strcmp(full_name, '') full_name = system_name; system_type = system_name; else full_name = [full_name, '_', system_name]; end; + +% Add to file to contain shell commands which map subsystem types +% onto components +fprintf(typefile, '$1%s$2%s$3\n', system_type, full_name); fun_name = [system_type, '_abg'] % If no such function - then there is nothing to be done. if exist(fun_name)~=2 @@ -96,12 +114,14 @@ % Check compatibility - if ok copy port bonds to the internal bonds list. if n_port_bonds~=n_ports mtt_info(sprintf('%1.0f port bonds incompatible with %1.0f ports', ... n_port_bonds, n_ports), infofile); else % Copy the port bonds - for i = 1:n_ports - bonds(i,:) = port_bonds(i,:); + for i = 1:n_ports % The port SSs come first + j = abs(components(i,1)); % Get the bonds attached to the ports + direction = -sign(components(i,1)); + bonds(j,:) = direction*port_bonds(i,:); end; end; % Set initial status @@ -109,42 +129,60 @@ total = 2*n_bonds; done = sum(sum(abs(bonds)))/total*100; % Outer while loop sets preferred causality -ci_index=1; -while ci_index>0 +ci_index=1; + +while( ci_index>0) old_done = inf; % Inner loop propogates causality while done~=old_done disp(sprintf('Causality is %3.0f%s complete.', done, pc)); old_done = done; for i = 1:n_components if status(i) ~= 0 % only do this if causality not yet complete - comp = nozeros(components(i,:)); - bond_list = abs(comp); - direction = sign(comp)'*[1 1]; - % Convert from arrow orientated to component orientated causality - comp_bonds = bonds(bond_list,:).*direction; - eval([ '[comp_type,name,cr,arg] = ', system_type, '_cmp(i);' ]); - % change name of 0 and 1 components -- matlab doesn't like numbers here - if strcmp(comp_type,'0') - comp_type = 'zero'; - end; - if strcmp(comp_type,'1') - comp_type = 'one'; - end; - - % Component causality procedure name - cause_name = [comp_type, '_cause']; + + % Get the bonds on this component + comp = nozeros(components(i,:)); + bond_list = abs(comp); + direction = sign(comp)'*[1 1]; + + % Convert from arrow orientated to component orientated causality + comp_bonds = bonds(bond_list,:).*direction; + + % Get the component details + eval([ '[comp_type,name,cr,arg] = ', system_type, '_cmp(i);' ]); + + % Change name of 0 and 1 components -- matlab doesn't like numbers here + if strcmp(comp_type,'0') + comp_type = 'zero'; + end; + if strcmp(comp_type,'1') + comp_type = 'one'; + end; + + % Component causality procedure name + cause_name = [comp_type, '_cause']; % Invoke the appropriate causality procedure if exist(cause_name)~=2 % Try a compound component [comp_bonds,s] = abg2cbg(name, comp_type, full_name, comp_bonds, ... - infofile); - status(i)=max(abs(s)); + typefile, infofile); + + % Create a single status from the status vector s + if max(abs(s)) == 0 % Causal + status(i) = 0; + else + if max(s) == 1 % At least one component is overcausal + status(i) = 1; + else % no component is overcausal but some are undercausal + status(i) = -1; + end; + end; + else % its a simple component disp(['---', name, ' (', cause_name, ') ---']); % comp_bonds eval([ '[comp_bonds,status(i)] = ', cause_name, '(comp_bonds);' ]); % comp_bonds @@ -159,11 +197,11 @@ done = sum(sum(abs(bonds)))/total*100; % mtt_info(sprintf('Causality is %3.0f%s complete.', done, pc), infofile); end; - % Set causality of C and I which is not set + % Set causality of a C or I which is not already set [ci_index,prefered] = getdynamic(status,system_type); if ci_index>0 bond_index = components(ci_index,1) % its a one port bonds(bond_index,1) = prefered; bonds(bond_index,2) = prefered; @@ -171,11 +209,12 @@ end; % Print final causality final_done = (sum(status==zeros(n_components,1))/n_components)*100;; -mtt_info(sprintf('Final causality is %3.0f%s complete.', final_done, pc), infofile); +mtt_info(sprintf('Final causality of %s is %3.0f%s complete.', ... + full_name, final_done, pc), infofile); % List overcausal bonds [over_causal_bonds,n] = getindex(status,1); if n>0 for i=over_causal_bonds' @@ -193,16 +232,19 @@ mtt_info(sprintf('Component %s (%s) is undercausal', name, comp_type), ... infofile); end; end; -file_name = [full_name, '_', system_type] -write_cbg(file_name,bonds,status); +% $$$ file_name = [full_name, '_', system_type] +file_name = full_name; +write_cbg(file_name,system_type,bonds,status); % Return the port bonds -for i = 1:n_ports - port_bonds(i,:) = bonds(i,:); +for i = 1:n_ports % The port SSs come first + j = abs(components(i,1)); % Get the bonds attached to the ports + direction = -sign(components(i,1)); + port_bonds(i,:) = direction*bonds(j,:); end; disp('----------------------');