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, 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.10 1996/12/07 17:37:07 peterg
% %% Now handles numbered SS ports appearing at top level.
% %%
% %% Revision 1.9 1996/12/04 21:49:47 peterg
% %% Compares full-name with empty string (instead of testing for zero
% %% length)
% %%
|
|
>
>
>
|
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 = 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.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
% %% Now handles numbered SS ports appearing at top level.
% %%
% %% Revision 1.9 1996/12/04 21:49:47 peterg
% %% Compares full-name with empty string (instead of testing for zero
% %% length)
% %%
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
% %% Initial revision
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
system_name, system_type, full_name,
pc = '%';
if nargin<3
eqnfile = 'stdout';
end;
if nargin<4
infofile = 'stdout';
end;
% Are we at the top level of the heirarchy?
at_top_level = strcmp(full_name, '');
% Create the (full) system name
if at_top_level
full_name = system_name;
full_name_repetition = system_name;
system_type = system_name;
else
full_name = [full_name, '_', system_name];
full_name_repetition = [full_name_repetition, ...
'_', system_name, '_', num2str(repetition)];
end;
% $$$ full_name_type = [full_name, '_', system_type];
% $$$ cbg_name = [full_name_type, '_cbg'];
cbg_name = [full_name, '_cbg'];
% Return if cbg file doesn't exist
if exist(cbg_name)~=2
disp([cbg_name, ' does not exist']);
return
end;
% Setup file
ese_name = [full_name_repetition, '_ese.r'];
filenum = fopen(ese_name, 'w');
fprintf(filenum, '\n%s%s Equation file for system %s (file %s)\n', ...
pc, pc, full_name_repetition, ese_name);
fprintf(filenum, '%s%s Generated by MTT\n\n', pc, pc);
% Evaluate the system function to get the bonds
eval(['[bonds,status,system_type] = ', cbg_name, ';']);
abg_name = [system_type, '_abg'];
cmp_name = [system_type, '_cmp'];
eval(['[junk,components]=', abg_name, ';']);
|
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
|
% %% Initial revision
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
system_name, system_type, full_name,
pc = '%';
% Set up the names corresponding to the structure matrix.
structure_name = [
'state ',
'nonstate ',
'input ',
'output ',
'zero_output '];
% Are we at the top level of the heirarchy?
at_top_level = strcmp(full_name, '');
% Create the (full) system name
if at_top_level
full_name = system_name;
full_name_repetition = system_name;
system_type = system_name;
else
full_name = [full_name, '_', system_name];
full_name_repetition = [full_name_repetition, ...
'_', system_name, '_', num2str(repetition)];
end;
% $$$ full_name_type = [full_name, '_', system_type];
% $$$ cbg_name = [full_name_type, '_cbg'];
cbg_name = [full_name, '_cbg'];
% Return if cbg file doesn't exist
if exist(cbg_name)~=2
disp([cbg_name, ' does not exist']);
return
end;
% Setup files
ese_name = [full_name_repetition, '_ese.r'];
ese_file = fopen(ese_name, 'w');
fprintf(ese_file, '\n%s%s Equation file for system %s (file %s)\n', ...
pc, pc, full_name_repetition, ese_name);
fprintf(ese_file, '%s%s Generated by MTT\n\n', pc, pc);
% Evaluate the system function to get the bonds
eval(['[bonds,status,system_type] = ', cbg_name, ';']);
abg_name = [system_type, '_abg'];
cmp_name = [system_type, '_cmp'];
eval(['[junk,components]=', abg_name, ';']);
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
name_r = full_name_repetition;
eqn_name = [comp_type, '_eqn']
if exist(eqn_name)~=2 % Try a compound component
disp('---PUSH---');
structure = cbg2ese(comp_name, comp_type, cr, args, ...
full_name, full_name_repetition, ...
k, structure, infofile);
% Link up the bonds
fprintf(filenum, ...
'\n\t%s Equations linking up subsystem %s (%s)\n\n', ...
pc, comp_name, comp_type);
name_comp_name = sprintf('%s_%s_%1.0f', ...
full_name_repetition, comp_name, k);
for port_number=1:length(bond_list)
% Effort
if comp_bonds(port_number,1)==1 % Source
fprintf(filenum, '%s_MTTu%1.0f := %s;\n', ...
name_comp_name, port_number, varname(name_r, ...
bond_list(port_number),1));
else % sensor
fprintf(filenum, '%s := %s_MTTy%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_MTTu%1.0f := %s;\n', ...
name_comp_name, port_number, varname(name_r, ...
bond_list(port_number),-1));
else % sensor
fprintf(filenum, '%s := %s_MTTy%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
fprintf(filenum, '\n\t%s Equations for component %s (%s), repetition %1.0f\n\n', ...
pc, comp_name, comp_type,k);
% Take port SS to be ordinary SS at top level
if at_top_level & strcmp(comp_type, 'SS')
effort_attribute = cr;
flow_attribute = args;
if strcmp(effort_attribute, 'MTT_port') % Its a numbered port
effort_attribute = 'external';
flow_attribute = 'external';
cr = effort_attribute;
args = flow_attribute;
end;
end;
eval(['structure = ', ...
eqn_name, ...
'(name_r,bond_list,comp_bonds,direction,cr,args,structure,filenum);' ]);
end;
end;
end;
fclose(filenum);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
183
184
185
186
187
188
189
190
191
192
193
194
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
name_r = full_name_repetition;
eqn_name = [comp_type, '_eqn']
if exist(eqn_name)~=2 % Try a compound component
disp('---PUSH---');
structure = cbg2ese(comp_name, comp_type, cr, args, ...
full_name, full_name_repetition, ...
k, structure, structure_file, infofile);
% 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);
% Take port SS to be ordinary SS at top level
if at_top_level & strcmp(comp_type, 'SS')
effort_attribute = cr;
flow_attribute = args;
if strcmp(effort_attribute, 'MTT_port') % Its a numbered port
effort_attribute = 'external';
flow_attribute = 'external';
cr = effort_attribute;
args = flow_attribute;
end;
end;
% Save the current structure
old_structure = structure;
% Generate the simple component equations
eval(['structure = ', ...
eqn_name, ...
'(name_r,bond_list,comp_bonds, ...
direction,cr,args,structure,ese_file);' ]);
% If structure has changed, write info to structure file.
structure_change = structure-old_structure;
structure_changes = sum(structure_change);
if structure_changes>0
which_indices = getindex(structure_change,1);
which_indices = which_indices(:,2)';
for which_index=which_indices
value = structure(which_index);
fprintf(structure_file, ...
'%s\t%1.0f\t%s\t%s\t%1.0f\n', ...
structure_name(which_index,:), value, ...
comp_name, full_name, repetition);
end;
end;
end;
end;
end;
% Close the files
fclose(ese_file);
|