Differences From Artifact [1ee5212ade]:

To Artifact [03870c28de]:


1
2
3
4
5
6
7



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

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



% %% Revision 1.22  1997/09/18 19:49:37  peterg
% %% Added test for uniquness of bonds on a component -- if non-unique
% %% implies same component at both ends of a bond.
% %%
% %% Revision 1.21  1997/09/16  15:14:14  peterg
% %% Added warning if a component has no bonds.
% %%







>
>
>







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.23  1997/12/04 14:24:22  peterg
% %% Removed error message about through-pointing arrows
% %%
% %% Revision 1.22  1997/09/18 19:49:37  peterg
% %% Added test for uniquness of bonds on a component -- if non-unique
% %% implies same component at both ends of a bond.
% %%
% %% Revision 1.21  1997/09/16  15:14:14  peterg
% %% Added warning if a component has no bonds.
% %%
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
% %%
% %% Revision 1.1  1996/08/04 18:30:14  peter
% %% Initial revision
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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

%Default to no components
components = [0];







|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
% %%
% %% Revision 1.1  1996/08/04 18:30:14  peter
% %% Initial revision
% %%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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

%Default to no components
components = [0];
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
  eval(['[comp_type, comp_name] = ', name, '_cmp(i)']);

  % There are n_comp_bonds bonds on this component with corresponding index
  [index,n_comp_bonds] = getindex(comp_near_bond,i);

  if index(1,1)==0
    mtt_info(sprintf("Component %s (%s) has no bonds", comp_name,
    comp_type),infofile);
  end;
  
  % Create the signed list of bonds on this component
  one = ones(n_comp_bonds,1);
  bond_list = index(:,1); %  bond at component
  
  % Check that all bonds are unique -- error if not
  if unique(bond_list)==0
    mtt_info(sprintf("Component %s (%s) is at both ends of a bond", comp_name,
    comp_type),infofile);
  end;
    
  bond_end = index(:,2);  % which end of bond at component?
  direction = -sign(bond_end-1.5*one);
  signed_bond_list = bond_list.*direction;
  components = add_bond(components,signed_bond_list',i);
end;







|









|







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
  eval(['[comp_type, comp_name] = ', name, '_cmp(i)']);

  % There are n_comp_bonds bonds on this component with corresponding index
  [index,n_comp_bonds] = getindex(comp_near_bond,i);

  if index(1,1)==0
    mtt_info(sprintf("Component %s (%s) has no bonds", comp_name,
    comp_type),fnum);
  end;
  
  % Create the signed list of bonds on this component
  one = ones(n_comp_bonds,1);
  bond_list = index(:,1); %  bond at component
  
  % Check that all bonds are unique -- error if not
  if unique(bond_list)==0
    mtt_info(sprintf("Component %s (%s) is at both ends of a bond", comp_name,
    comp_type),fnum);
  end;
    
  bond_end = index(:,2);  % which end of bond at component?
  direction = -sign(bond_end-1.5*one);
  signed_bond_list = bond_list.*direction;
  components = add_bond(components,signed_bond_list',i);
end;
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
    signed_bond_index = port_bond(i);
    [other_bond_index,n_other] = getindex(port_bond,-signed_bond_index);
    if n_other == 1
      other_port_name = port_name(other_bond_index,:);
      other_subport = split(other_port_name, ',');
      [n_other_subports,junk] = size(other_subport);
      if n_other_subports~=n_subports
	mtt_info(['Vector ports ', port_name_i, ' and ', other_port_name, 'are not compatible'],infofile);
      end
    else 
      mtt_info(['Vector port ', port_name_i, ' has no matching port'], infofile);
    end;
    
    if other_bond_index>i %then its not been done yet
      mtt_info(['Vector port: ', port_name_i],infofile);
      mtt_info(['matching: ', other_port_name],infofile);
      % Remove sign info.
      bond_index = abs(signed_bond_index);
      sig = sign(signed_bond_index);
      
      % Put the first element of each port list in the expanded list
      exp_port_name = [exp_port_name; subport(1,:)];
      exp_port_name = [exp_port_name; other_subport(1,:)];







|


|



|
|







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    signed_bond_index = port_bond(i);
    [other_bond_index,n_other] = getindex(port_bond,-signed_bond_index);
    if n_other == 1
      other_port_name = port_name(other_bond_index,:);
      other_subport = split(other_port_name, ',');
      [n_other_subports,junk] = size(other_subport);
      if n_other_subports~=n_subports
	mtt_info(['Vector ports ', port_name_i, ' and ', other_port_name, 'are not compatible'],fnum);
      end
    else 
      mtt_info(['Vector port ', port_name_i, ' has no matching port'], fnum);
    end;
    
    if other_bond_index>i %then its not been done yet
      mtt_info(['Vector port: ', port_name_i],fnum);
      mtt_info(['matching: ', other_port_name],fnum);
      % Remove sign info.
      bond_index = abs(signed_bond_index);
      sig = sign(signed_bond_index);
      
      % Put the first element of each port list in the expanded list
      exp_port_name = [exp_port_name; subport(1,:)];
      exp_port_name = [exp_port_name; other_subport(1,:)];
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
  % Check that number of bonds on the component is the same as the number of
  % ports
  [n_comp_ports,m_comp_ports] = size(port_list);
  if (n_comp_ports~=n_comp_bonds) & ...
	~(strcmp(comp_type,'zero')|strcmp(comp_type,'one'))
    message=sprintf('Component %s (%s) has %1.0f impinging bonds but has %1.0f ports', ...
	comp_name,comp_type,n_comp_bonds,n_comp_ports);
    mtt_info(message, infofile);
  end;
  
  unsorted_port_list="";
  if n_ports>0 % then there are some named ports
    % so find those associated with the bonds on this component.
    k=0; 
    for j = 1:n_comp_bonds







|







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  % Check that number of bonds on the component is the same as the number of
  % ports
  [n_comp_ports,m_comp_ports] = size(port_list);
  if (n_comp_ports~=n_comp_bonds) & ...
	~(strcmp(comp_type,'zero')|strcmp(comp_type,'one'))
    message=sprintf('Component %s (%s) has %1.0f impinging bonds but has %1.0f ports', ...
	comp_name,comp_type,n_comp_bonds,n_comp_ports);
    mtt_info(message, fnum);
  end;
  
  unsorted_port_list="";
  if n_ports>0 % then there are some named ports
    % so find those associated with the bonds on this component.
    k=0; 
    for j = 1:n_comp_bonds
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433

434

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
  else 
    k=0;
  end;
    
  %Either all ports or no ports should be labelled - write error
  %message if this is not so
  if (k~=0)&(k~=n_comp_bonds)
    mtt_info(['Component ', comp_name, ' (', comp_type, ') has wrong number of labels'], infofile); 
    mtt_info(sprintf("\tit has %1.0f labels but should have 0 or %1.0f",k,n_comp_bonds), infofile); 
  end;
  
  %Compute the number of labeled ports
  [n_unsorted_ports,m_unsorted_ports] = size(unsorted_port_list);
  if m_unsorted_ports==0
    n_unsorted_ports = 0;
  end;
  n_unsorted_ports,n_comp_bonds
  % One port defaults:
  if (n_comp_bonds==1)&(n_unsorted_ports==0)
    %if (direction(1)<0) & ~strcmp(comp_type,'SS') % Wrong way for default
    % mtt_info(['One-port ', comp_name, ' (', comp_type, ') has the sign pointing the wrong way '], infofile);
    %end;
    unsorted_port_list = port_list;
  end;
  
  %Two port defaults
  if (n_comp_bonds==2)&(n_unsorted_ports==0)
    if direction(1)==direction(2) % Wrong way for default
      % mtt_info(['Two-port ', comp_name, ' (', comp_type, ') does not have through-pointing arrows'], infofile);
    end;
    if direction(1)==1 %in
      % mtt_info([comp_name, ' in'],infofile);
      unsorted_port_list = ['in';'out'];
    else %reverse the order
      % mtt_info([comp_name, ' out'],infofile);
      unsorted_port_list = ['out';'in'];
    end;
  end;
  
  % Recompute the number of unsorted ports
  [n_unsorted_ports,m_unsorted_ports] = size(unsorted_port_list);
  if m_unsorted_ports==0
    n_unsorted_ports = 0;
  end;
  
  % Junctions or no lables(order of ports unimportant)
  if strcmp(comp_type,'zero')|strcmp(comp_type,'one')
    for j = 1:n_comp_bonds
      components(i,j) = signed_bond_list(j);
    end
  else %Order of ports is important
    unsorted_port_list, port_list
    if n_unsorted_ports==0
      mtt_info(['Component ', comp_name, ' (', comp_type, ') has no labeled ports'], infofile); 
    end;
    %Write out the signed bond list in the correct order

    for j = 1:n_comp_bonds

      name_k = unsorted_port_list(j,:);
      k = name_in_list(name_k, port_list);
      % Check that it only appears once in port list
      if length(k)>1
	mtt_info(['Component ', comp_name, ' (', comp_type, ') has ports with the same name:  ', name_k], infofile); 
      end;
      
      %Check that it only appears one in the label list
      kk = name_in_list(name_k,unsorted_port_list);
      if length(kk)>1
	mtt_info(['Component ', comp_name, ' (', comp_type, ') has multiple port labels:  ', name_k], infofile); 
      end;
      
      if k==0
	mtt_info(['Component ', comp_name, ' (', comp_type, ') has an unrecognised port: ', name_k], infofile); 
      else
	components(i,k) = signed_bond_list(j);     
      end;
    end;
  end;
end;








|
|











|







|


|


|


















|


>
|
>
|



|





|



|







381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
  else 
    k=0;
  end;
    
  %Either all ports or no ports should be labelled - write error
  %message if this is not so
  if (k~=0)&(k~=n_comp_bonds)
    mtt_info(['Component ', comp_name, ' (', comp_type, ') has wrong number of labels'], fnum); 
    mtt_info(sprintf("\tit has %1.0f labels but should have 0 or %1.0f",k,n_comp_bonds), fnum); 
  end;
  
  %Compute the number of labeled ports
  [n_unsorted_ports,m_unsorted_ports] = size(unsorted_port_list);
  if m_unsorted_ports==0
    n_unsorted_ports = 0;
  end;
  n_unsorted_ports,n_comp_bonds
  % One port defaults:
  if (n_comp_bonds==1)&(n_unsorted_ports==0)
    %if (direction(1)<0) & ~strcmp(comp_type,'SS') % Wrong way for default
    % mtt_info(['One-port ', comp_name, ' (', comp_type, ') has the sign pointing the wrong way '], fnum);
    %end;
    unsorted_port_list = port_list;
  end;
  
  %Two port defaults
  if (n_comp_bonds==2)&(n_unsorted_ports==0)
    if direction(1)==direction(2) % Wrong way for default
      % mtt_info(['Two-port ', comp_name, ' (', comp_type, ') does not have through-pointing arrows'], fnum);
    end;
    if direction(1)==1 %in
      % mtt_info([comp_name, ' in'],fnum);
      unsorted_port_list = ['in';'out'];
    else %reverse the order
      % mtt_info([comp_name, ' out'],fnum);
      unsorted_port_list = ['out';'in'];
    end;
  end;
  
  % Recompute the number of unsorted ports
  [n_unsorted_ports,m_unsorted_ports] = size(unsorted_port_list);
  if m_unsorted_ports==0
    n_unsorted_ports = 0;
  end;
  
  % Junctions or no lables(order of ports unimportant)
  if strcmp(comp_type,'zero')|strcmp(comp_type,'one')
    for j = 1:n_comp_bonds
      components(i,j) = signed_bond_list(j);
    end
  else %Order of ports is important
    unsorted_port_list, port_list
    if n_unsorted_ports==0
      mtt_info(['Component ', comp_name, ' (', comp_type, ') has no labeled ports'], fnum); 
    end;
    %Write out the signed bond list in the correct order
unsorted_port_list
for j = 1:n_comp_bonds
      j
      name_k = unsorted_port_list(j,:)
      k = name_in_list(name_k, port_list);
      % Check that it only appears once in port list
      if length(k)>1
	mtt_info(['Component ', comp_name, ' (', comp_type, ') has ports with the same name:  ', name_k], fnum); 
      end;
      
      %Check that it only appears one in the label list
      kk = name_in_list(name_k,unsorted_port_list);
      if length(kk)>1
	mtt_info(['Component ', comp_name, ' (', comp_type, ') has multiple port labels:  ', name_k], fnum); 
      end;
      
      if k==0
	mtt_info(['Component ', comp_name, ' (', comp_type, ') has an unrecognised port: ', name_k], fnum); 
      else
	components(i,k) = signed_bond_list(j);     
      end;
    end;
  end;
end;


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