476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
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
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
if (struct_contains(objects, "comp"))
n_comps = size(struct_elements(objects.comp))(1);
else
n_comps = 0;
endif
components = zeros(n_comps, max(n_vector_bonds));
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
port_list = comp_ports(comp.type, comp.n_bonds)
endif
## but do what with it?
counter = 0;
n_ports = size(port_list,1)
if ((n_ports == 1) | ...
(strcmp(comp.type, "zero")) | (strcmp(comp.type, "one")))
## no ordering necessary
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
for [sub_bond, sub_bond_name] = bond
if (index(sub_bond_name, "subbond") == 1)
components(comp.index, ++counter) = sub_bond.index
endif
endfor
endif
endfor
else
## multiple ports, need to order them
for port = 1 : n_ports
component_type = comp.type
the_port_list = port_list
the_port = port
label = port_list(port,:)
if (index (label, "[") == 1)
label = mtt_strip_name(label)
endif
label = deblank(label)
for [bond, bond_name] = comp
if (index(bond_name, "bond") == 1)
for [sub_bond, sub_bond_name] = bond
if (index(sub_bond_name, "subbond") == 1)
sub_bond_label = sub_bond.label
if (index (sub_bond_label, "[") == 1)
sub_bond_label = mtt_strip_name(sub_bond_label)
endif
sub_bond_label = deblank(sub_bond_label)
## unalias sub_bond label
if exist([comp.type, '_alias'])
eval(sprintf("alias = %s_alias", comp.type))
if isstruct(alias)
while_counter = 0;
while isfield(alias, sub_bond_label)
old_sub_bond_label = sub_bond_label;
sub_bond_label = eval(sprintf("alias.%s", sub_bond_label))
if strcmp(old_sub_bond_label, sub_bond_label)
break;
endif
endwhile
endif
endif
if (strcmp(sub_bond_label, label))
components(comp.index, ++counter) = sub_bond.index
endif
endif
endfor
endif
endfor
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, "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
|