Index: mttroot/mtt/bin/trans/m/ibg2abg.m ================================================================== --- mttroot/mtt/bin/trans/m/ibg2abg.m +++ mttroot/mtt/bin/trans/m/ibg2abg.m @@ -16,12 +16,12 @@ ## populate "head" and "tail" structures ## then copy the contents to an overall structure ## track (signed) vector bond number within each component - head.index = +i - tail.index = -i + head.index = +i; + tail.index = -i; ## extract type of component at each end head_type = deblank(split(bond.head.component, ":")(1,:)); tail_type = deblank(split(bond.tail.component, ":")(1,:)); @@ -46,21 +46,24 @@ tail_name = mtt_strip_name(tail_name); else tail_comp_or_port = "comp"; endif - eval(sprintf("comp_s.%s.%s.type = '%s'", + eval(sprintf("comp_s.%s.%s.type = '%s';", head_comp_or_port, head_name, head_type)); - eval(sprintf("comp_s.%s.%s.type = '%s'", + eval(sprintf("comp_s.%s.%s.type = '%s';", tail_comp_or_port, tail_name, tail_type)); - eval(sprintf("comp_s.%s.%s.bond%i = head", + eval(sprintf("comp_s.%s.%s.bond%i = head;", head_comp_or_port, head_name, i)); - eval(sprintf("comp_s.%s.%s.bond%i = tail", + eval(sprintf("comp_s.%s.%s.bond%i = tail;", tail_comp_or_port, tail_name, i)); endfor + disp("--finished extracting data from ibg.m --") + comp_s + ## comp_s ## comp ## %s (name) ## type ## bond%i @@ -76,22 +79,25 @@ #################################################### if (struct_contains(comp_s, "comp")) for [comp, comp_name] = comp_s.comp n = size(struct_elements(comp))(1) - 1; - eval(sprintf("comp_s.comp.%s.n_bonds = %i", + eval(sprintf("comp_s.comp.%s.n_bonds = %i;", comp_name, n)); endfor endif if (struct_contains(comp_s, "port")) for [port, port_name] = comp_s.port n = size(struct_elements(port))(1) - 1; - eval(sprintf("comp_s.port.%s.n_bonds = %i", + eval(sprintf("comp_s.port.%s.n_bonds = %i;", port_name, n)); endfor endif + + disp("-- finished counting number of bonds on components --") + comp_s ## comp_s ## comp ## %s (name) ## type @@ -125,29 +131,29 @@ if (! strcmp(bond.label, "[]")) n_named_ports += 1; port_label = bond.label; endif endif - eval(sprintf("comp.%s = bond", bond_name)); + eval(sprintf("comp.%s = bond;", bond_name)); endfor ## attach labels to unlabelled ports if (n_named_ports == 0) for [bond, bond_name] = comp if (index(bond_name, "bond") == 1) bond.label = "in"; endif - eval(sprintf("comp.%s = bond", bond_name)); + eval(sprintf("comp.%s = bond;", bond_name)); endfor elseif (n_named_ports == 1) mtt_info(sprintf("Defaulting all ports on junction %s to %s", \ comp_name, port_label), infofile); for [bond, bond_name] = comp if (index(bond_name, "bond") == 1) bond.label = port_label; endif - eval(sprintf("comp.%s = bond", bond_name)); + eval(sprintf("comp.%s = bond;", bond_name)); endfor elseif (n_named_ports != bond.n_bonds) mtt_error(sprintf("Junction must have 0,1 or %i port labels", \ n_bonds), errorfile); endif @@ -164,15 +170,15 @@ endif else bond.label = mtt_strip_name(bond.label); endif endif - eval(sprintf("comp.%s = bond", bond_name)); + eval(sprintf("comp.%s = bond;", bond_name)); endfor endif - eval(sprintf("comp_s.comp.%s = comp", comp_name)); + eval(sprintf("comp_s.comp.%s = comp;", comp_name)); endfor endif #################### ## expand aliases ## @@ -190,17 +196,20 @@ bond.label = new_name; mtt_info(sprintf("Aliasing [%s] on %s (%s) to [%s]", old_name, comp_name, comp.type, new_name), infofile); endif - eval(sprintf("comp.%s = bond", bond_name)); + eval(sprintf("comp.%s = bond;", bond_name)); endfor endif - eval(sprintf("comp_s.%s = comp", comp_name)); + eval(sprintf("comp_s.%s = comp;", comp_name)); endif endfor endif + + disp("-- finished expanding aliases --") + comp_s ## comp_s ## comp ## %s (name) ## type @@ -222,44 +231,38 @@ for [comp, comp_name] = comp_s.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'", + eval(sprintf("bond.subbond%i.label = '%s';", i, deblank(sub_bonds(i,:)))) endfor endif - eval(sprintf("comp.%s = bond", bond_name)); + eval(sprintf("comp.%s = bond;", bond_name)); endfor - eval(sprintf("comp_s.comp.%s = comp", comp_name)); + eval(sprintf("comp_s.comp.%s = comp;", comp_name)); endfor endif if (struct_contains(comp_s, "port")) for [port, port_name] = comp_s.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'", + eval(sprintf("bond.subbond%i.label = '%s';", i, deblank(sub_bonds(i,:)))); endfor endif - eval(sprintf("port.%s = bond", bond_name)); + eval(sprintf("port.%s = bond;", bond_name)); endfor - eval(sprintf("comp_s.port.%s = comp", port_name)); + eval(sprintf("comp_s.port.%s = port;", port_name)); endfor endif - ###################################################### - ## check that both ends of each bond are compatible ## - ###################################################### - - for [bond, bond_name] = bonds - ## FIXME: - 1; - endfor + disp("-- finished creating sub-bonds --") + comp_s ## comp_s ## comp ## %s (name) ## type @@ -307,14 +310,14 @@ tail_comp_or_port = "comp"; endif ## create strings to reference each component head_str = sprintf("comp_s.%s.%s.bond%i", - head_comp_or_port, head_name, i); + head_comp_or_port, head_name, i) tail_str = sprintf("comp_s.%s.%s.bond%i", - tail_comp_or_port, tail_name, i); - + tail_comp_or_port, tail_name, i) + head_bond = eval(head_str); tail_bond = eval(tail_str); ## check compatible sizes head.n_subs = size(struct_elements(head_bond))(1) - 2; @@ -328,38 +331,38 @@ endif ## assign bond number for i = 1:head.n_subs ++unique_bond_number; - eval(sprintf("%s.subbond%i.index = +%i", + eval(sprintf("%s.subbond%i.index = +%i;", head_str, i, unique_bond_number)); - eval(sprintf("%s.subbond%i.index = -%i", + eval(sprintf("%s.subbond%i.index = -%i;", tail_str, i, unique_bond_number)); ## write causality for bond if (strcmp(bond.causality.effort, "head")) - eval(sprintf("causality(%i,1) = +1", unique_bond_number)); + eval(sprintf("causality(%i,1) = +1;", unique_bond_number)); elseif (strcmp(bond.causality.effort, "tail")) - eval(sprintf("causality(%i,1) = -1", unique_bond_number)); + eval(sprintf("causality(%i,1) = -1;", unique_bond_number)); else - eval(sprintf("causality(%i,1) = 0", unique_bond_number)); + eval(sprintf("causality(%i,1) = 0;", unique_bond_number)); endif if (strcmp(bond.causality.flow, "head")) - eval(sprintf("causality(%i,2) = -1", unique_bond_number)); + eval(sprintf("causality(%i,2) = -1;", unique_bond_number)); elseif (strcmp(bond.causality.flow, "tail")) - eval(sprintf("causality(%i,2) = +1", unique_bond_number)); + eval(sprintf("causality(%i,2) = +1;", unique_bond_number)); else - eval(sprintf("causality(%i,2) = 0", unique_bond_number)); + eval(sprintf("causality(%i,2) = 0;", unique_bond_number)); endif endfor endfor - - ## causality matrix is called "bonds" - bonds = causality; + disp("-- finished assigning unique numbers to bonds --") + comp_s + ## comp_s ## comp ## %s (name) ## type ## n_bonds @@ -374,10 +377,14 @@ ## bond%i ## label ## subbond%i ## index + ## causality matrix is called "bonds" + bonds = causality + disp("-- finished writing bonds matrix --") + ################################# ## map component data to cmp.m ## ################################# ## count number of components @@ -402,12 +409,15 @@ 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)); + eval(sprintf("comp_s.%s.%s.index = cmp;", comp_or_port, this_name)); endfor + + disp("-- finished getting component indices from cmp.m --") + comp_s ## comp_s ## comp ## %s (name) ## type @@ -434,10 +444,13 @@ if (struct_contains(comp_s, "comp")) for [comp, comp_name] = comp_s.comp n_vector_bonds(comp.index) = comp.n_bonds; endfor endif + + disp("-- finished writing n_vector_bonds --") + n_vector_bonds ########################################### ## Write connections matrix (components) ## ########################################### @@ -469,14 +482,17 @@ 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) = subbond.index; + components(port.index, ++counter) = sub_bond.index; endif endfor endif endfor endfor endif + + disp("-- finished writing components matrix --") + components endfunction