Index: mttroot/mtt/bin/trans/m/rbg2ibg.m ================================================================== --- mttroot/mtt/bin/trans/m/rbg2ibg.m +++ mttroot/mtt/bin/trans/m/rbg2ibg.m @@ -73,12 +73,12 @@ endif ## The (signed) bond corresponding to the ith port label port_bond(i) = near_bond(1) * sign(1.5 - near_bond(2)); endfor - port_bond + ## Now have (signed) bond (port_bond(i)) corresponding to the ith port ## Create inverse mapping for i = 1:n_bonds eval(sprintf('bond_port_head%i = "[]"', i)) eval(sprintf('bond_port_tail%i = "[]"', i)) @@ -97,13 +97,12 @@ ## col 1 of comp_near_bond contains component nearest to the arrow end ## col 2 of comp_near_bond contains component nearest other end for i = 1:n_bonds comp_near_bond(i,:) = adjcomp(arrow_end(i,:), other_end(i,:), \ rcomponents); - [hc_type, hc_name] = eval([name, '_cmp(comp_near_bond(i,1))']); - [tc_type, tc_name] = eval([name, '_cmp(comp_near_bond(i,2))']); endfor + comp_near_bond ## Deduce causality from the strokes (if any) causality = zeros(n_bonds,2); if (n_strokes > 0) ## Find location of centre and ends of stroke @@ -144,19 +143,41 @@ flow_side = stroke_direction * arrow_vector(j,:)' > 0; causality(j,1+flow_side) = 2 * which_end - 1; endif endfor endif + causality - ## Return data + ## Write data for i = 1:n_bonds + [hc_type, hc_name] = eval([name, '_cmp(comp_near_bond(i,1))']); + [tc_type, tc_name] = eval([name, '_cmp(comp_near_bond(i,2))']); + ## components eval(sprintf("bonds.bond%i.head.component\t= '%s:%s'", i, hc_type, \ hc_name)); eval(sprintf("bonds.bond%i.tail.component\t= '%s:%s'", i, tc_type, \ tc_name)); + ## ports eval(sprintf("bonds.bond%i.head.ports\t= bond_port_head%i", i, i)); eval(sprintf("bonds.bond%i.tail.ports\t= bond_port_tail%i", i, i)); + ## causality + if (causality(i,1) == 1) + effort_causality = "head" + elseif (causality(i,1) == -1) + effort_causality = "tail" + else + effort_causality = "none" + endif + + if (causality(i,2) == 1) + flow_causality = "tail" + elseif (causality(i,2) == -1) + flow_causality = "head" + else + flow_causality = "none" + endif + + eval(sprintf("bonds.bond%i.causality.effort\t= '%s'", i, effort_causality)); + eval(sprintf("bonds.bond%i.causality.flow\t= '%s'", i, flow_causality)); endfor - - - + endfunction Index: mttroot/mtt/bin/trans/m/write_ibg.m ================================================================== --- mttroot/mtt/bin/trans/m/write_ibg.m +++ mttroot/mtt/bin/trans/m/write_ibg.m @@ -11,14 +11,17 @@ format_ce = " %s.bonds.b%i.causality.effort\t= \"%s\";\n"; format_cf = " %s.bonds.b%i.causality.flow\t= \"%s\";\n"; fprintf(fid, "## -*-octave-*-\n\n"); fprintf(fid, "function [%s] = %s_ibg\n\n", system_name, system_name); - fprintf(fid, "## Intermediate bond graph representation of %s\n", \ + fprintf(fid, " ## Intermediate bond graph representation of %s\n", \ system_name); - fprintf(fid, "## Generated by MTT on %s\n", ctime(time)); + fprintf(fid, " ## Generated by MTT on %s\n", ctime(time)); + fprintf(fid, " ## head refers to the harpoon end of a bond\n"); + fprintf(fid, " ## tail refers to the other end of a bond\n"); + fprintf(fid, " ## causality.? is the end at which ? is imposed\n\n"); for i=1:nbonds fprintf(fid, "\n ## bond %i\n", i); fprintf(fid, format_hc, system_name, i, \ eval(sprintf("bonds.bond%i.head.component", i))); @@ -26,13 +29,15 @@ eval(sprintf("bonds.bond%i.tail.component", i))); fprintf(fid, format_hp, system_name, i, \ eval(sprintf("bonds.bond%i.head.ports", i))); fprintf(fid, format_tp, system_name, i, \ eval(sprintf("bonds.bond%i.tail.ports", i))); - fprintf(fid, format_ce, system_name, i, "FIXME"); - fprintf(fid, format_cf, system_name, i, "FIXME"); + fprintf(fid, format_ce, system_name, i, \ + eval(sprintf("bonds.bond%i.causality.effort", i))); + fprintf(fid, format_cf, system_name, i, \ + eval(sprintf("bonds.bond%i.causality.flow", i))); endfor; fprintf(fid, "\nendfunction\n"); fclose(fid); endfunction;