Overview
Comment:Now counts the local input and outputs by order of appearence rather
than by port number - it therfore handles ports with bicausality correctely.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 27b5d4d5a5e07c39bebda82c9b8ca26055554613b4ed47889bdac7db1ae503ac
User & Date: gawthrop@users.sourceforge.net on 1997-08-26 07:51:30
Other Links: branch diff | manifest | tags
Context
1997-08-26
08:20:18
Initial revision check-in: 50fd2b16fd user: gawthrop@users.sourceforge.net tags: origin/master, trunk
07:51:30
Now counts the local input and outputs by order of appearence rather
than by port number - it therfore handles ports with bicausality correctely.
check-in: 27b5d4d5a5 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
1997-08-25
07:51:47
Version 2.5. check-in: 39d0b3986f user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/cbg2ese.m from [26cd575170] to [026a8be4a2].

1
2
3
4






5
6
7
8
9
10
11
12
13
14
15
16
17
18



19
20
21
22
23
24
25
function structure = cbg2ese(system_name, system_type, system_cr, ...
    system_args, full_name, full_name_repetition, ...
    repetition,...
    structure, structure_file, 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.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.
% %%
% %% Revision 1.10  1996/12/07 17:37:07  peterg




>
>
>
>
>
>














>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% 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.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.
% %%
% %% Revision 1.10  1996/12/07 17:37:07  peterg
115
116
117
118
119
120
121





122
123
124
125
126
127
128
  % Find number of components
  [n_components,columns] = size(components);
  n_components = n_components
  
  % Set up the first dummy bond number - needed for repetative components
  next_bond = max(max(abs(components)))+1;






  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
    comp_bonds = bonds(bond_list,:).*direction;
    







>
>
>
>
>







124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  % Find number of components
  [n_components,columns] = size(components);
  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
    comp_bonds = bonds(bond_list,:).*direction;
    
195
196
197
198
199
200
201

202
203
204

205
206
207
208

209
210
211
212
213
214

215
216
217
218

219
220
221
222
223
224
225
226
227
228
	% Link up the bonds
	fprintf(ese_file, ...
	    '\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);
	

	for port_number=1:length(bond_list)
	  % Effort
	  if comp_bonds(port_number,1)==1 % Source

	     fprintf(ese_file, '%s_MTTu%d := %s;\n', ...
		 name_comp_name, port_number, varname(name_r, ...
		 bond_list(port_number),1));
	   else % sensor

	     	 fprintf(ese_file, '%s := %s_MTTy%d;\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(ese_file, '%s_MTTu%d := %s;\n', ...
		 name_comp_name, port_number, varname(name_r, ...
		 bond_list(port_number),-1));
	   else % sensor

	     	 fprintf(ese_file, '%s := %s_MTTy%d;\n', ...
		 varname(name_r, ...
		 bond_list(port_number),-1), name_comp_name, port_number);
	   end;	
	 end;
	
	disp('---POP---');
      else % its a simple component
	fprintf(ese_file, '\n\t%s Equations for component %s (%s), repetition %d\n\n', ...
	    pc, comp_name, comp_type,k);







>



>

|

|
>
|

|

|

>

|

|
>
|

|







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
	% Link up the bonds
	fprintf(ese_file, ...
	    '\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, u_index, varname(name_r, ...
		 bond_list(port_number),1));
	   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, y_index);
	  end;
	  % 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, u_index, varname(name_r, ...
		 bond_list(port_number),-1));
	   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, y_index);
	   end;	
	 end;
	
	disp('---POP---');
      else % its a simple component
	fprintf(ese_file, '\n\t%s Equations for component %s (%s), repetition %d\n\n', ...
	    pc, comp_name, comp_type,k);

Modified mttroot/mtt/lib/comp/simple/SS_eqn.m from [b0e9681c1e] to [312d13fc4c].

1
2








3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21



22
23
24
25
26
27
28
function structure =  SS_eqn(name,bond_number,bonds,direction,cr,args, ...
    structure,filenum);








% SS_eqn - equations for SS component
% 
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%     %%%%% Model Transformation Tools %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Matlab function  SS_eqn
% structure =  SS_eqn(name,bond_number,bonds,direction,cr,args, ...
%    structure,filenum);


% Copyright (c) P.J. Gawthrop, 1996.

			
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$



% %% 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.
% %%
% %% Revision 1.8  1996/12/10 16:52:29  peterg


>
>
>
>
>
>
>
>



















>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 %%%%%
%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Matlab function  SS_eqn
% structure =  SS_eqn(name,bond_number,bonds,direction,cr,args, ...
%    structure,filenum);


% Copyright (c) P.J. Gawthrop, 1996.

			
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% 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.
% %%
% %% Revision 1.8  1996/12/10 16:52:29  peterg
77
78
79
80
81
82
83
84



85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100
101

102
103
104
105
106

107
108
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
end;


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;

  % Effort 
  if bonds(1,1)==-1 % Source

    fprintf(filenum, '%s := %s_MTTu%d;\n', ...
        varname(name, bond_number,1), name, port_number);
  else % Sensor

    fprintf(filenum, '%s_MTTy%d := %s;\n', ...
        name, port_number, varname(name, bond_number,1));
  end;
  % Flow 
  if bonds(1,2)==1 % Source

    fprintf(filenum, '%s := %s_MTTu%d;\n', ...
        varname(name, bond_number,-1), name, port_number);
  else % Sensor

    fprintf(filenum, '%s_MTTy%d := %s;\n', ...
        name, port_number, varname(name, bond_number,-1));
  end;  
  return
end;


% Effort
if strcmp(effort_attribute, 'external')
  if bonds(1,1)==-1 % Source
    inputs = inputs+1;
    fprintf(filenum, '%s := MTTu(%d,1);\n', ...
        varname(name, bond_number,1),inputs);
  else % Sensor







|
>
>
>
|
|
|

|
|
|
|
|
|
|



>

|

>

|



>

|

>

|




|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
end;


inputs = structure(3);
outputs = structure(4);
zero_outputs = structure(5);

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, local_u_index);
  else % Sensor
    local_y_index = local_y_index + 1;
    fprintf(filenum, '%s_MTTy%d := %s;\n', ...
        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, local_u_index);
  else % Sensor
    local_y_index = local_y_index + 1;
    fprintf(filenum, '%s_MTTy%d := %s;\n', ...
        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', ...
        varname(name, bond_number,1),inputs);
  else % Sensor


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]