Overview
Comment:Now uses named ports.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: f84d84397e2e908bdb8cb73a81ad0ed5f0b2bfbb8f159921c97279cd99e21954
User & Date: gawthrop@users.sourceforge.net on 1997-08-02 19:37:53
Other Links: branch diff | manifest | tags
Context
1997-08-04
12:49:17
Modified to use named (as opposed to numbered) ports.
Generates a list of component ports in the .rbg file.
As octave handles string vectors properly, the .cmp file format is not
really necessary - but I've let it be for the moment.
check-in: a524632e5a user: gawthrop@users.sourceforge.net tags: origin/master, trunk
1997-08-02
19:37:53
Now uses named ports. check-in: f84d84397e user: gawthrop@users.sourceforge.net tags: origin/master, trunk
19:35:47
Initial revision check-in: 6bbd7487ff user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/rbg2abg.m from [deb6ad7165] to [7cea7c30eb].

1
2
3
4
5
6
7



8
9
10
11
12
13
14
function [bonds,components] = rbg2abg(rbonds,rstrokes,rcomponents,rports,infofile)

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$



% %% Revision 1.10  1997/03/17  13:45:42  peterg
% %% Added more error info.
% %%
% %% Revision 1.9  1996/12/31  11:25:57  peterg
% %% Clearer error messages for incorrect ports.
% %%
% %% Revision 1.8  1996/12/04 21:52:39  peterg
|






>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function [bonds,components] = rbg2abg(name,rbonds,rstrokes,rcomponents,port_coord,port_name,infofile)

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %% Revision 1.11  1997/04/29 09:12:37  peterg
% %% Added error message if port label near to >1 bond.
% %%
% %% Revision 1.10  1997/03/17  13:45:42  peterg
% %% Added more error info.
% %%
% %% Revision 1.9  1996/12/31  11:25:57  peterg
% %% Clearer error messages for incorrect ports.
% %%
% %% Revision 1.8  1996/12/04 21:52:39  peterg
40
41
42
43
44
45
46



47
48
49
50
51
52
53


if nargin<5
  infofile='stdout';
else
  fnum = fopen(infofile, 'w');
end;




% Xfig scaling factor
scale = 1200.0/2.54546;

% Rotation matrix
rot = [0 -1; 1 0];








>
>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59


if nargin<5
  infofile='stdout';
else
  fnum = fopen(infofile, 'w');
end;

%Default to no components
components = [0];

% Xfig scaling factor
scale = 1200.0/2.54546;

% Rotation matrix
rot = [0 -1; 1 0];

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
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
  error('Incorrect rbonds matrix: must have 6 columns');
end;

% Find number of components
[n_components,columns] = size(rcomponents);

% Find number of ports
[n_ports,columns] = size(rports);

% Determine coordinates of the arrow end of the bond and the other end
other_end_1 = rbonds(:,1:2);
arrow_end   = rbonds(:,3:4);
other_end_2 = rbonds(:,5:6);

distance_1   = length2d(other_end_1 - arrow_end);
distance_2   = length2d(other_end_2 - arrow_end);
which_end    = (distance_1>distance_2)*[1 1];
one          = ones(size(which_end));
other_end    = which_end.*other_end_1 + (one-which_end).*other_end_2;
arrow_vector = ( which_end.*other_end_2 + (one-which_end).*other_end_1 ) - ...
    arrow_end;
 
% Locate the bond end nearest to each port
% col 1 of port_near_bond contains a signed bond number (+ for arrow end)
% col 2  of port_near_bond contains the corresponding port number
for i = 1:n_ports
   [i rports(i,1:2)/scale rports(i,3)]
   near_bond = adjbond(rports(i,1:2),arrow_end,other_end)
   [rows,cols]=size(near_bond);
   if rows>1
     error(sprintf ...
	 ("A port is near to more than one bond at coordinates %g,%g\n", ...
	 rports(i,1)/scale,  rports(i,2)/scale));
   end;

  signed_bond = near_bond(1)*sign(1.5-near_bond(2));
  port_near_bond(i,:) = [signed_bond, rports(i,3)];
end;

% Locate the components at the ends of each bond
% col 1 of comp_near_bond contain the component nearest to the arrow end
% col 2 of comp_near_bond contain the component nearest to the other end
for i = 1:n_bonds
  comp_near_bond(i,:) = adjcomp(arrow_end(i,:),other_end(i,:),rcomponents);
end;

% Produce a list of bonds on each component - sorted if explicit port numbers
for i = 1:n_components    


  

















  % There are n bonds on this component with corresponding index
  [index,n] = getindex(comp_near_bond,i);
  
  % Error message in case we need it!
  port_error = sprintf(... 
      'Component at (%1.3f,%1.3f) has inconsistent port numbers', ...
      rcomponents(i,1)/scale, rcomponents(i,2)/scale);

  if index(1,1) ~= 0 % Then its a genuine component 
    
    % Create the signed list of bonds on this component
    one = ones(n,1);
    bond_list = index(:,1); %  bond at component
    bond_end = index(:,2);  % which end of bond at component?
    direction = -sign(bond_end-1.5*one);
    signed_bond_list = bond_list.*direction;

    % Default sort of bonds (ie no change)
    sort_index = [1:n]'; 
    
    if n_ports>0 % then there are some numbered ports 
      % so find those associated with the bonds on this component.
      k=0; port_number=[];
      for j = 1:n
	b = signed_bond_list(j); 
	% Find the port label on component end of bond (if any)
	[port_index,m] = getindex(port_near_bond(:,1),b);
	if m==1
	  k=k+1;
	  port_number(k,1) = port_near_bond(port_index,2);
	  end;
      end;


      % Must have a lable for each port or non at all
      if k==n % Then a full set of port numbers
	[sorted,sort_index]=sort(port_number);
	
	%Check that all the numbers (1..n) are there
	if sum(sorted==[1:n]')~=n % There is something wrong
	  mtt_info(port_error,fnum);
	  mtt_info(sprintf('\t it must have consecutive ports labels from 1:%1.0f\n', n), ...
	      fnum);
	  port_str = sprintf('\t the port labels are: ');
	  for kk=1:k

	    port_str=sprintf('%s %1.0f', port_str, port_number(kk));


	  end;
	  mtt_info(port_str, fnum);
	end;
      else




	if k~=0
	  mtt_info(port_error,fnum);
	  mtt_info(sprintf('\t it must have 0 or %1.0f ports\n', n), fnum);
	  port_str = sprintf('\t the port labels are: ');
	  for kk=1:k
	    port_str=sprintf('%s %1.0f', port_str, port_number(kk));

	  end;
	  mtt_info(port_str, fnum);
	end;
      end;
      
    end;
  end;
    
  % Write out bond list sorted by port number (if any)
  for j = 1:length(sort_index)
    jj = sort_index(j);
    components(i,j) = signed_bond_list(jj);
  end;
end;

% Deduce causality from the strokes (if any).
causality = zeros(n_bonds,2);
if n_strokes>0
  % Find out location of centre and ends of stroke.
  stroke_end_1 = [rstrokes(:,1) rstrokes(:,2)];
  stroke_end_2 = [rstrokes(:,3) rstrokes(:,4)];







|


















<
|




|

>

|











>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

















<
|
|


|



|


|



>
|
|
|
|
<
<
|
<
<
<
|
>
|
>
>
|
<
|
|
>
>
>
>
|
|
<
|
<
<
>
|
<
|
|
<
|
|
|
<
<
<
<
<
<







69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100
101
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
  error('Incorrect rbonds matrix: must have 6 columns');
end;

% Find number of components
[n_components,columns] = size(rcomponents);

% Find number of ports
[n_ports,columns] = size(port_coord);

% Determine coordinates of the arrow end of the bond and the other end
other_end_1 = rbonds(:,1:2);
arrow_end   = rbonds(:,3:4);
other_end_2 = rbonds(:,5:6);

distance_1   = length2d(other_end_1 - arrow_end);
distance_2   = length2d(other_end_2 - arrow_end);
which_end    = (distance_1>distance_2)*[1 1];
one          = ones(size(which_end));
other_end    = which_end.*other_end_1 + (one-which_end).*other_end_2;
arrow_vector = ( which_end.*other_end_2 + (one-which_end).*other_end_1 ) - ...
    arrow_end;
 
% Locate the bond end nearest to each port
% col 1 of port_near_bond contains a signed bond number (+ for arrow end)
% col 2  of port_near_bond contains the corresponding port number
for i = 1:n_ports

   near_bond = adjbond(port_coord(i,1:2),arrow_end,other_end);
   [rows,cols]=size(near_bond);
   if rows>1
     error(sprintf ...
	 ("A port is near to more than one bond at coordinates %g,%g\n", ...
	 port_coord(i,1)/scale,  port_coord(i,2)/scale));
   end;
  %The (signed) bond corrsponding to the ith port label
  signed_bond = near_bond(1)*sign(1.5-near_bond(2));
  signed_bonds(i) = signed_bond;
end;

% Locate the components at the ends of each bond
% col 1 of comp_near_bond contain the component nearest to the arrow end
% col 2 of comp_near_bond contain the component nearest to the other end
for i = 1:n_bonds
  comp_near_bond(i,:) = adjcomp(arrow_end(i,:),other_end(i,:),rcomponents);
end;

% Produce a list of bonds on each component - sorted if explicit port numbers
for i = 1:n_components    
  %Get component type
  eval(['[comp_type, comp_name] = ', name, '_cmp(i)']);

  if comp_type=='0'
    comp_type = 'zero';
  end

  if comp_type=='1'
    comp_type = 'one';
  end

  % and the port list (if its not an elementary component)
    if exist([comp_type, '_cause'])==0
      eval(['[junk1,junk2,junk3,junk4,junk5,port_list]=', comp_type, '_rbg;']);
    else
      port_list=comp_port(comp_type);
    end;

  port_list

  % There are n bonds on this component with corresponding index
  [index,n] = getindex(comp_near_bond,i);
  
  % Error message in case we need it!
  port_error = sprintf(... 
      'Component at (%1.3f,%1.3f) has inconsistent port numbers', ...
      rcomponents(i,1)/scale, rcomponents(i,2)/scale);

  if index(1,1) ~= 0 % Then its a genuine component 
    
    % Create the signed list of bonds on this component
    one = ones(n,1);
    bond_list = index(:,1); %  bond at component
    bond_end = index(:,2);  % which end of bond at component?
    direction = -sign(bond_end-1.5*one);
    signed_bond_list = bond_list.*direction;


    [n_ports,junk] = size(port_list);
    unsorted_port_list="";
    if n_ports>0 % then there are some numbered ports 
      % so find those associated with the bonds on this component.
      k=0; 
      for j = 1:n
	b = signed_bond_list(j); 
	% Find the port label on component end of bond (if any)
	[port_index,m] = getindex(signed_bonds,b);
	if m==1
	  k=k+1;
	  unsorted_port_list(k,:) = port_name(port_index,:);
	  end;
      end;

      [n_unsorted_ports,m_unsorted_ports] = size(unsorted_port_list);
      if m_unsorted_ports<2
        n_unsorted_ports = 0;
      end;



      unsorted_port_list




      % One port defaults:
      if n_ports==1
        if n_unsorted_ports==0
          unsorted_port_list(1,:) = port_list(1,:);
        end; 

      end;
      
      %Write out the signed bond list in the correct order
        for j = 1:n_ports
          name_k = unsorted_port_list(j,:);
          k = name_in_list(name_k, port_list)
          if k==0
            mtt_info(['Component ', comp_name, ' has an unrecognised port: ', name_k], infofile); 

          else


          components(i,j) = signed_bond_list(k);     
          end;

        end;
    end;

  end;
end;








% Deduce causality from the strokes (if any).
causality = zeros(n_bonds,2);
if n_strokes>0
  % Find out location of centre and ends of stroke.
  stroke_end_1 = [rstrokes(:,1) rstrokes(:,2)];
  stroke_end_2 = [rstrokes(:,3) rstrokes(:,4)];
220
221
222
223
224
225
226


      causality(j,1+flow_side) = 2*which_end-1;
    end;
  end;
end;

bonds = causality;
fclose(fnum);









>
>
236
237
238
239
240
241
242
243
244
      causality(j,1+flow_side) = 2*which_end-1;
    end;
  end;
end;

bonds = causality;
fclose(fnum);



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