Index: mttroot/mtt/bin/trans/m/cbg2ese.m ================================================================== --- mttroot/mtt/bin/trans/m/cbg2ese.m +++ mttroot/mtt/bin/trans/m/cbg2ese.m @@ -1,19 +1,25 @@ -function structure = cbg2ese(system_name, system_type, full_name, infofile) +function structure = cbg2ese(system_name, system_type, full_name, ... + repetition,... + structure, infofile) % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %%%%% Model Transformation Tools %%%%% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Matlab function cbg2ese.m % Acausal bond graph to causal bond graph: mfile format +% Structure matrix [states,nonstates,inputs,outputs,zero_outputs] % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% Version control history % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %% $Id$ % %% $Log$ +% %% Revision 1.5 1996/08/24 15:02:23 peter +% %% Writes `END;' to keep reduce happy. +% %% % %% Revision 1.4 1996/08/19 09:03:41 peter % %% Handles repeating components. % %% % %% Revision 1.3 1996/08/18 20:08:02 peter % %% Included additional structure: structure(5) = zero_outputs. @@ -24,10 +30,11 @@ % %% Revision 1.1 1996/08/08 15:53:23 peter % %% Initial revision % %% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +system_name, system_type, full_name, pc = '%'; if nargin<3 eqnfile = 'stdout'; end; @@ -42,20 +49,20 @@ else full_name = [full_name, '_', system_name]; end; full_name_type = [full_name, '_', system_type]; -ese_name = [system_name, '_ese.r']; cbg_name = [full_name_type, '_cbg']; abg_name = [system_type, '_abg']; cmp_name = [system_type, '_cmp']; % Return if cbg file doesn't exist if exist(cbg_name)~=2 return end; % Setup file +ese_name = sprintf('%s_%1.0f_ese.r', full_name, repetition); filenum = fopen(ese_name, 'w'); % Evaluate the system function to get the bonds eval(['[junk,components]=', abg_name, ';']); eval(['bonds=', cbg_name, ';']); @@ -65,15 +72,11 @@ error('Incorrect bonds matrix: must have 2 columns'); end; % Find number of components [n_components,columns] = size(components); - - %Structure matrix [states,nonstates,inputs,outputs,zero_outputs] - structure = zeros(1,5); - - + n_components = n_components 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 @@ -84,12 +87,15 @@ comp_type = 'zero'; end; if strcmp(comp_type,'1') comp_type = 'one'; end; - - ports = length(bond_list); + + comp_type = comp_type + ports = length(bond_list) + repetitions = repetitions + if repetitions>1 port_pairs = ports/2; if round(port_pairs)~=port_pairs; mtt_info(['Repeated component ', comp_name, ... ' has an odd number of ports - ignoring repetitions']); @@ -102,10 +108,11 @@ even_bonds = bond_list(2:2:ports); next_bond = max(max(abs(components)))+1; end; for k = 1:repetitions + if repetitions>1 if k==1 bond_list(1:2:ports-1) = odd_bonds; else bond_list(1:2:ports-1) = bond_list(2:2:ports); @@ -119,22 +126,52 @@ bond_list(2:2:ports) = new_bonds; end; end; % Invoke the appropriate equation-generating procedure + name_r = sprintf('%s_%1.0f', full_name, repetition); eqn_name = [comp_type, '_eqn'] if exist(eqn_name)~=2 % Try a compound component - cbg2ese(comp_name, comp_type, full_name, infofile); + disp('---PUSH---'); + structure = cbg2ese(comp_name, comp_type, full_name, k, ... + structure, infofile); + % Link up the bonds + name_k = sprintf('%s_%1.0f', full_name, k); + name_comp_name = sprintf('%s_%s_%1.0f', full_name, comp_name, k); + for port_number=1:length(bond_list) + + % Effort + if comp_bonds(port_number,1)==1 % Source + fprintf(filenum, '%s_MTT_inport_%1.0f := %s;\n', ... + name_comp_name, port_number, varname(name_r, ... + bond_list(port_number),1)); + else % sensor + fprintf(filenum, '%s := %s_MTT_outport_%1.0f;\n', ... + varname(name_r, ... + bond_list(port_number),1), name_comp_name, port_number); + end; + % flow + if comp_bonds(port_number,2)==-1 % Source + fprintf(filenum, '%s_MTT_inport_%1.0f := %s;\n', ... + name_comp_name, port_number, varname(name_r, ... + bond_list(port_number),-1)); + else % sensor + fprintf(filenum, '%s := %s_MTT_outport_%1.0f;\n', ... + varname(name_r, ... + bond_list(port_number),-1), name_comp_name, port_number); + end; + end; + + disp('---POP---'); else % its a simple component eval(['structure = ', ... eqn_name, ... - '(bond_list,comp_bonds,direction,cr,args,structure,filenum);' ]); + '(name_r,bond_list,comp_bonds,direction,cr,args,structure,filenum);' ]); end; end; end; - fprintf(filenum, 'END;'); fclose(filenum);