Overview
Comment:Replaced deprecated is_struct and struct_contains with isstruct and isfield.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: e919e8d1a22e6ec9ecb69c524206a8c633df05abd38fc53123f51ed8fff120b3
User & Date: geraint@users.sourceforge.net on 2004-08-18 23:19:04
Other Links: branch diff | manifest | tags
Context
2004-08-18
23:21:40
Removed labels on one vector bond to demonstrate port aliasing. check-in: 1a8abdb3d9 user: geraint@users.sourceforge.net tags: origin/master, trunk
23:19:04
Replaced deprecated is_struct and struct_contains with isstruct and isfield. check-in: e919e8d1a2 user: geraint@users.sourceforge.net tags: origin/master, trunk
23:05:56
Fixed port aliasing. check-in: 59259429ab user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/ibg2abg.m from [7ebb891e47] to [268bf69a52].

81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  ## "comp" contains components, subsystems and external SS
  ## "port" contains internal SS:[...]

  ####################################################
  ## count number of vector bonds on each component ##
  ####################################################

  if (struct_contains(objects, "comp"))
    for [comp, comp_name] = objects.comp
      n = size(struct_elements(comp))(1) - 1;
      eval(sprintf("objects.comp.%s.n_bonds = %i;",
		   comp_name, n));
    endfor
  endif
  
  if (struct_contains(objects, "port"))
    for [port, port_name] = objects.port
      n = size(struct_elements(port))(1) - 1;
      eval(sprintf("objects.port.%s.n_bonds = %i;",
		   port_name, n));
    endfor
  endif








|







|







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  ## "comp" contains components, subsystems and external SS
  ## "port" contains internal SS:[...]

  ####################################################
  ## count number of vector bonds on each component ##
  ####################################################

  if (isfield(objects, "comp"))
    for [comp, comp_name] = objects.comp
      n = size(struct_elements(comp))(1) - 1;
      eval(sprintf("objects.comp.%s.n_bonds = %i;",
		   comp_name, n));
    endfor
  endif
  
  if (isfield(objects, "port"))
    for [port, port_name] = objects.port
      n = size(struct_elements(port))(1) - 1;
      eval(sprintf("objects.port.%s.n_bonds = %i;",
		   port_name, n));
    endfor
  endif

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  ##       bond%i
  ##         label

  ########################################################
  ## ensure labels exist on all ports of each component ##
  ########################################################

  if (struct_contains(objects, "comp"))
    for [comp, comp_name] = objects.comp
      if (strcmp(comp.type, "0") | strcmp(comp.type, "1"))

	## convert type
	if (strcmp(comp.type, "0"))
	  comp.type = "zero";
	elseif (strcmp(comp.type, "1"))







|







118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  ##       bond%i
  ##         label

  ########################################################
  ## ensure labels exist on all ports of each component ##
  ########################################################

  if (isfield(objects, "comp"))
    for [comp, comp_name] = objects.comp
      if (strcmp(comp.type, "0") | strcmp(comp.type, "1"))

	## convert type
	if (strcmp(comp.type, "0"))
	  comp.type = "zero";
	elseif (strcmp(comp.type, "1"))
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
    endfor
  endif

  ####################
  ## expand aliases ##
  ####################

  if (struct_contains(objects, "comp"))
    for [comp, comp_name] = objects.comp
      if ((! strcmp(comp.type, "zero")) & (! strcmp(comp.type, "one")))
	alias = eval(sprintf("%s_alias", comp.type));
	if (is_struct(alias))
	  for [bond, bond_name] = comp;
	    if (isstruct(bond))
	      if (struct_contains(alias, bond.label))
		old_name = bond.label;
		new_name = eval(sprintf("alias.%s", old_name));
		bond.label = new_name;
		mtt_info(sprintf("Aliasing [%s] on %s (%s) to [%s]",
				 old_name, comp_name, comp.type, new_name),
			 infofile);
	      endif







|



|


|







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
    endfor
  endif

  ####################
  ## expand aliases ##
  ####################

  if (isfield(objects, "comp"))
    for [comp, comp_name] = objects.comp
      if ((! strcmp(comp.type, "zero")) & (! strcmp(comp.type, "one")))
	alias = eval(sprintf("%s_alias", comp.type));
	if (isstruct(alias))
	  for [bond, bond_name] = comp;
	    if (isstruct(bond))
	      if (isfield(alias, bond.label))
		old_name = bond.label;
		new_name = eval(sprintf("alias.%s", old_name));
		bond.label = new_name;
		mtt_info(sprintf("Aliasing [%s] on %s (%s) to [%s]",
				 old_name, comp_name, comp.type, new_name),
			 infofile);
	      endif
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
  ##       bond%i
  ##         label

  ##########################################
  ## create sub-bonds according to labels ##
  ##########################################

  if (struct_contains(objects, "comp"))
    for [comp, comp_name] = objects.comp
      for [bond, bond_name] = comp
	if (index(bond_name, "bond") == 1)
	  [sub_bonds, n_sub_bonds] = split_port(bond.label);
	  for i = 1:n_sub_bonds
	    eval(sprintf("bond.subbond%i.label = '%s';",
			 i, deblank(sub_bonds(i,:))))
	  endfor
	endif
	eval(sprintf("comp.%s = bond;", bond_name));
      endfor
      eval(sprintf("objects.comp.%s = comp;", comp_name));
    endfor
  endif

  if (struct_contains(objects, "port"))
    for [port, port_name] = objects.port
      for [bond, bond_name] = port
	if (index(bond_name, "bond") == 1)
	  [sub_bonds, n_sub_bonds] = split_port(bond.label);
	  for i = 1:n_sub_bonds
	    eval(sprintf("bond.subbond%i.label = '%s';",
			 i, deblank(sub_bonds(i,:))));







|















|







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
  ##       bond%i
  ##         label

  ##########################################
  ## create sub-bonds according to labels ##
  ##########################################

  if (isfield(objects, "comp"))
    for [comp, comp_name] = objects.comp
      for [bond, bond_name] = comp
	if (index(bond_name, "bond") == 1)
	  [sub_bonds, n_sub_bonds] = split_port(bond.label);
	  for i = 1:n_sub_bonds
	    eval(sprintf("bond.subbond%i.label = '%s';",
			 i, deblank(sub_bonds(i,:))))
	  endfor
	endif
	eval(sprintf("comp.%s = bond;", bond_name));
      endfor
      eval(sprintf("objects.comp.%s = comp;", comp_name));
    endfor
  endif

  if (isfield(objects, "port"))
    for [port, port_name] = objects.port
      for [bond, bond_name] = port
	if (index(bond_name, "bond") == 1)
	  [sub_bonds, n_sub_bonds] = split_port(bond.label);
	  for i = 1:n_sub_bonds
	    eval(sprintf("bond.subbond%i.label = '%s';",
			 i, deblank(sub_bonds(i,:))));
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
  disp("-- finished writing bonds matrix --")  

  #################################
  ## map component data to cmp.m ##
  #################################

  ## count number of components
  if (struct_contains(objects, "comp"))
    n_comps = size(struct_elements(objects.comp), 1)
  else
    n_comps = 0;
  endif

  ## count number of internal ports
  if (struct_contains(objects, "port"))
    n_ports = size(struct_elements(objects.port), 1)
  else
    n_ports = 0;
  endif

  ## read data from _cmp.m
  for cmp = 1:(n_comps + n_ports)







|






|







406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
  disp("-- finished writing bonds matrix --")  

  #################################
  ## map component data to cmp.m ##
  #################################

  ## count number of components
  if (isfield(objects, "comp"))
    n_comps = size(struct_elements(objects.comp), 1)
  else
    n_comps = 0;
  endif

  ## count number of internal ports
  if (isfield(objects, "port"))
    n_ports = size(struct_elements(objects.port), 1)
  else
    n_ports = 0;
  endif

  ## read data from _cmp.m
  for cmp = 1:(n_comps + n_ports)
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
  ##           index
  ##       index

  ##########################
  ## write n_vector_bonds ##
  ##########################

  if (struct_contains(objects, "comp"))
    for [comp, comp_name] = objects.comp
      n_vector_bonds(comp.index,1) = comp.n_bonds;
    endfor
  endif

  disp("-- finished writing n_vector_bonds --")
  n_vector_bonds

  ###########################################
  ## Write connections matrix (components) ##
  ###########################################
  
  if (struct_contains(objects, "comp"))
    n_comps = size(struct_elements(objects.comp))(1);
  else
    n_comps = 0;
  endif

  components = zeros(n_comps+n_ports, max(n_vector_bonds));

  if (struct_contains(objects, "comp"))
    for [comp, comp_name] = objects.comp
      ## get portlist for component      
      if exist([comp.type, '_cause']) == 0
 	eval(sprintf("ABG = %s_abg;", comp.type));
 	if struct_contains(ABG, "portlist")
 	  port_list = ABG.portlist;
 	else
 	  error(sprintf("Component %s has no ports", comp.type));
 	endif
      else
	## must be a simple component:
	## lib/comp/simple/comp_ports.m assigns port numbers







|












|







|




|







459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
  ##           index
  ##       index

  ##########################
  ## write n_vector_bonds ##
  ##########################

  if (isfield(objects, "comp"))
    for [comp, comp_name] = objects.comp
      n_vector_bonds(comp.index,1) = comp.n_bonds;
    endfor
  endif

  disp("-- finished writing n_vector_bonds --")
  n_vector_bonds

  ###########################################
  ## Write connections matrix (components) ##
  ###########################################
  
  if (isfield(objects, "comp"))
    n_comps = size(struct_elements(objects.comp))(1);
  else
    n_comps = 0;
  endif

  components = zeros(n_comps+n_ports, max(n_vector_bonds));

  if (isfield(objects, "comp"))
    for [comp, comp_name] = objects.comp
      ## get portlist for component      
      if exist([comp.type, '_cause']) == 0
 	eval(sprintf("ABG = %s_abg;", comp.type));
 	if isfield(ABG, "portlist")
 	  port_list = ABG.portlist;
 	else
 	  error(sprintf("Component %s has no ports", comp.type));
 	endif
      else
	## must be a simple component:
	## lib/comp/simple/comp_ports.m assigns port numbers
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
	endfor

      endif
    endfor
  endif
  disp("-- finished getting port_list --")
  port_list

#   if (struct_contains(objects, "comp"))
#     for [comp, comp_name] = objects.comp
#       counter = 0;
#       for [bond, bond_name] = comp
#  	if (index(bond_name, "bond") == 1)
# # 	  if (strcmp(bond.other_end_type, "SS"))
#  	    for [sub_bond, sub_bond_name] = bond
#  	      if (index(sub_bond_name, "subbond") == 1)
#  		components(comp.index, ++counter) = sub_bond.index
#  	      endif
#  	    endfor
# # 	  endif
#  	endif
#       endfor
# #       for [bond, bond_name] = comp
# #   	if (index(bond_name, "bond") == 1)
# #  	  if (!strcmp(bond.other_end_type, "SS"))
# #  	    for [sub_bond, sub_bond_name] = bond
# #  	      if (index(sub_bond_name, "subbond") == 1)
# #  		components(comp.index, ++counter) = sub_bond.index
# #  	      endif
# #  	    endfor
# #  	  endif
# #   	endif
# #       endfor
#     endfor
#   endif
  
   if (struct_contains(objects, "port"))
     for [port, port_name] = objects.port
       counter = 0;
       for [bond, bond_name] = port
 	if (index(bond_name, "bond") == 1)
 	  for [sub_bond, sub_bond_name] = bond
 	    if (index(sub_bond_name, "subbond") == 1)
 	      components(port.index, ++counter) = sub_bond.index;







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|







566
567
568
569
570
571
572
573




























574
575
576
577
578
579
580
581
	endfor

      endif
    endfor
  endif
  disp("-- finished getting port_list --")
  port_list
  




























   if (isfield(objects, "port"))
     for [port, port_name] = objects.port
       counter = 0;
       for [bond, bond_name] = port
 	if (index(bond_name, "bond") == 1)
 	  for [sub_bond, sub_bond_name] = bond
 	    if (index(sub_bond_name, "subbond") == 1)
 	      components(port.index, ++counter) = sub_bond.index;


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