Overview
Comment:*** empty log message ***
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: f715fc4b7399873f0fe93ca2dc02fa4aeba667a7ab5959b2cbf9fb009a3fab83
User & Date: geraint@users.sourceforge.net on 2003-03-11 23:05:51
Other Links: branch diff | manifest | tags
Context
2003-03-13
14:22:34
No negative bond numbers check-in: 1e4f51e7b0 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2003-03-11
23:05:51
*** empty log message *** check-in: f715fc4b73 user: geraint@users.sourceforge.net tags: origin/master, trunk
13:46:03
Added check for non-finite array elements. check-in: 9d2714a327 user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/ibg2abg.m from [1679af71e2] to [e31ee40699].

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
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







-
+







-
-
+
+







-
+







    if (strcmp(tail.type, "0") | (strcmp(tail.type, "1")))
      tail.is_junction = true;
    else
      tail.is_junction = false;
    endif

    ## assign (vector) port names
###    if (! head.is_junction)
    if (! head.is_junction)
      if (strcmp(bond.head.ports, "[]"))
	head.label = "in";
	mtt_info(sprintf("Defaulting port name %s on component %s (%s)",
			 head.label, head.name, head.type), infofile);
      else
	head.label = mtt_strip_name(bond.head.ports);
      endif
###    endif
###    if (! tail.is_junction)
    endif
    if (! tail.is_junction)
      if (strcmp(bond.tail.ports, "[]"))
	tail.label = "out";
	mtt_info(sprintf("Defaulting port name %s on component %s (%s)",
			 tail.label, tail.name, tail.type), infofile);
      else
	tail.label = mtt_strip_name(bond.tail.ports);
      endif
###    endif
    endif

    ## apply aliases
      if (! head.is_junction)
      head.alias = eval(sprintf("%s_alias", head.type));
      if (is_struct(head.alias))
	if (struct_contains(head.alias, head.label))
	  old_name = head.label;
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

142
143
144
145
146
147
148
149
150
151
152
153
154



155
156
157




158

159
160
161



162
163
164




165
166
167
















































168








169
170


171
172
173
174
175
176
177
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162


163
164
165
166


167
168
169
170
171
172
173


174
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
249
250







+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+










+


+


+





+


+


+











-
-
+
+
+

-
-
+
+
+
+

+

-
-
+
+
+

-
-
+
+
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+

-
+
+







		   infofile);
	endif
      endif
    endif

    ## expand vector bonds
    disp("--- Expanding vector bonds ---");
    if (! (head.is_junction | tail.is_junction))
      ## junctions can't be expanded until all bonds are assigned      
      ## as label might occur on only one bond
    [head.sub_bonds, head.n_sub_bonds] = split_port(head.label)
    [tail.sub_bonds, tail.n_sub_bonds] = split_port(tail.label)
    if (head.n_sub_bonds != tail.n_sub_bonds)
      mtt_error(sprintf("Vector ports %s and %s are not compatible",
			head.label, tail.label), errorfile);
    elseif (head.n_sub_bonds > 1)
      mtt_info(sprintf("Vector port %s matching %s",
		       head.label, tail.label), infofile);
    endif

      [head.sub_bonds, head.n_sub_bonds] = split_port(head.label)
      [tail.sub_bonds, tail.n_sub_bonds] = split_port(tail.label)
      if (head.n_sub_bonds != tail.n_sub_bonds)
	mtt_error(sprintf("Vector ports %s and %s are not compatible",
			  head.label, tail.label), errorfile);
      elseif (head.n_sub_bonds > 1)
	mtt_info(sprintf("Vector port %s matching %s",
			 head.label, tail.label), infofile);
      endif
    endif
    
    ## assign unique number and causality to each sub-bond
    for sub_bond = 1:head.n_sub_bonds
      ++bond_number;

      eval(sprintf("head.bond%i.index = %i", sub_bond, +bond_number));
      eval(sprintf("tail.bond%i.index = %i", sub_bond, -bond_number));

      ## effort causality
      if (strcmp(bond.causality.effort, "head"))
	causality(bond_number, 1) = +1;
	head.causality = +1;
      elseif (strcmp(bond.causality.effort, "tail"))
	causality(bond_number, 1) = -1;
	head.causality = -1;
      else
	causality(bond_number, 1) = 0;
	head.causality = 0;
      endif

      ## flow causality
      if (strcmp(bond.causality.flow, "head"))
	causality(bond_number, 2) = -1;
	tail.causality = -1;
      elseif (strcmp(bond.causality.flow, "tail"))
	causality(bond_number, 2) = +1;
	tail.causality = +1;
      else
	causality(bond_number, 2) = 0;
	tail.causality = 0;
      endif

      eval(sprintf("head.bond%i.port = deblank(head.sub_bonds(%i,:))",
		   sub_bond, sub_bond));
      eval(sprintf("tail.port%i.port = deblank(tail.sub_bonds(%i,:))",
		   sub_bond, sub_bond));

    endfor

    ## copy bond data to component structure (comp_s)
    if (head.is_port)
      eval(sprintf("comp_s.port.%s.vector_bond%i = head", 
		   head.name, i));
      S = sprintf("comp_s.port.%s", head.name);
      eval(sprintf("%s.vec_bond%i = head", S, i));
      eval(sprintf("%s.name = '%s'", S, head.name));
    else
      eval(sprintf("comp_s.comp.%s.vector_bond%i = head",
		   head.name, i));
      S = sprintf("comp_s.comp.%s", head.name);
      eval(sprintf("%s.vec_bond%i = head", S, i));
      eval(sprintf("%s.name = '%s'", S, head.name));
      eval(sprintf("%s.type = '%s'", S, head.type));
    endif

    if (tail.is_port)
      eval(sprintf("comp_s.port.%s.vector_bond%i = tail", 
		   tail.name, i));
      S = sprintf("comp_s.port.%s", tail.name);
      eval(sprintf("%s.vec_bond%i = tail", S, i));
      eval(sprintf("%s.name = '%s'", S, tail.name));
    else
      eval(sprintf("comp_s.comp.%s.vector_bond%i = tail",
		   tail.name, i));
      S = sprintf("comp_s.comp.%s", tail.name);
      eval(sprintf("%s.vec_bond%i = tail", S, i));
      eval(sprintf("%s.name = '%s'", S, tail.name));
      eval(sprintf("%s.type = '%s'", S, tail.type));
    endif
  endfor

  disp("--- Finished extracting bond data ---");

  #############################
  ## Expand vector junctions ##
  #############################
  if (struct_contains(comp_s, "comp"))
    for [comp, comp_name] = comp_s.comp
      if (strcmp(comp.type, "0") | strcmp(comp.type, "1"))
	n_ports = size(struct_elements(comp), 1) - 2;
	## subtracted 2 for name and type
	n_named_ports = 0;
	for [vec_bond, vec_bond_name] = comp
	  if (index(vec_bond_name, "vec_bond") == 1)
	    if (! strcmp(vec_bond.label, "[]"))
	      n_named_ports += 1;
	      port_name = vec_bond.label;
	    endif
	  endif
	endfor
	if (n_named_ports == 0)
	  for [vec_bond, vec_bond_name] = comp
	    if (index(vec_bond_name, "vec_bond") == 1)
	      vec_bond.label = "in";
	    endif
	  endfor
	elseif (n_named_ports == 1)
	  mtt_info(sprintf("Defaulting all ports on junction %s to %s",
			   comp_name, port_name), infofile);
	  for [vec_bond, vec_bond_name] = comp
	    if (index(vec_bond_name, "vec_bond") == 1)
	      vec_bond.label = port_name;
	    endif
	  endfor
	elseif ((n_named_ports != 0) && (n_named_ports != n_ports))
	  mtt_error(sprintf("Junction must have 0,1 or %i port labels", 
			    n_ports), errorfile);	  
	endif
	for [vec_bond, vec_bond_name] = comp
	  if (index(vec_bond_name, "vec_bond") == 1)
	    [sub_bonds, n_sub_bonds] = split_port(vec_bond.label)
	    for sub_bond = 1:n_sub_bonds
	      ++bond_number;
	      
	      S = sprintf("comp_s.comp.%s.%s", comp_name, \
			  vec_bond_name);
	      ## FIXME: multiply bond_number by direction in next line
	      eval(sprintf("%s.bond%i.index = %i",
			   S, sub_bond, bond_number));
  bonds = causality;
	      ## FIXME: do causality
	    endfor
	  endif
	endfor
     endif
    endfor
  endif
  ## FIXME: add sub_bonds to junctions  

  disp("--- Finished extracting bond data ---");
  
  bonds = causality;


  #################################
  ## Map component data to cmp.m ##
  #################################

  ## count number of components
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
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309







-




















-
+
















-
+







  if (struct_contains(comp_s, "port"))
    n_ports = size(struct_elements(comp_s.port), 1);
  else
    n_ports = 0;
  endif

  ## read data from _cmp.m
  ## write n_vector_bonds
  for cmp = 1:(n_comps + n_ports)
    [this_type, this_name] = eval(sprintf("%s_cmp(%i)", name, cmp));
    ## determine if internal port (and fix name) or subsystem
    if (strcmp(this_type, "SS") & (index(this_name, "[") == 1))
      comp_or_port = "port";
      this_name = mtt_strip_name(this_name);
    else
      comp_or_port = "comp";
    endif
    eval(sprintf("comp_s.%s.%s.index = cmp", comp_or_port, this_name));
  endfor

  disp("--- Finished reading _cmp.m ---");

  ##########################
  ## Write n_vector_bonds ##
  ##########################
  for [comp, comp_name] = comp_s.comp
    i = 0;
    for [val, key] = comp
      if (index(key, "vector_bond") == 1)
      if (index(key, "vec_bond") == 1)
	++i;
      endif
    endfor
    n_vector_bonds(comp.index) = i;
  endfor

  ###########################################
  ## Write connections matrix (components) ##
  ###########################################
  
  components = zeros(n_comps, max(n_vector_bonds));
  if (struct_contains(comp_s, "comp"))
    for [comp, comp_name] = comp_s.comp
      counter = 0;
      bond_list = zeros(1, max(n_vector_bonds));
      for [vbond, vbond_name] = comp
	if (index(vbond_name, "vector_bond") == 1)
	if (index(vbond_name, "vec_bond") == 1)
	  for [sbond, sbond_name] = vbond
	    if (index(sbond_name, "bond") == 1)
	      components(comp.index, ++counter) = sbond.index;
	    endif
	  endfor
	endif
      endfor


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