Overview
Comment:Added hard error reporting
Added error when two unlabled bonds point in.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: fc8f983688d98cc1281facd55acdbfa6bbcc57a0eaca25dcb856aaa22a13d275
User & Date: gawthrop@users.sourceforge.net on 1998-07-02 15:12:05
Other Links: branch diff | manifest | tags
Context
1998-07-02
17:16:06
Commented out redundent code -- obsolete due to new default mechanism check-in: 69243f733c user: gawthrop@users.sourceforge.net tags: origin/master, trunk
15:12:05
Added hard error reporting
Added error when two unlabled bonds point in.
check-in: fc8f983688 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
14:50:11
Initial revision check-in: d7a8ba12d4 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/m/rbg2abg.m from [c3724ad5a6] to [117b8cf421].

1
2
3
4
5
6
7



8
9
10
11
12
13
14
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.31  1998/07/02 14:30:50  peterg
% %% Corrected various bugs - including resettting n_ports to correct value
% %%
% %% Revision 1.30  1998/07/02 13:40:50  peterg
% %% Added extra ports names (due to defaults) to relevant lists:
% %% 	port_name
% %% 	port_bond
% %%
% %% Revision 1.29  1998/07/02 13:28:31  peterg
% %% Added defaults in new form BEFORE alias expansion
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240
241
242

243
244
245
246
247
248

249
250
251
252
253




254


255
256
257

258
259
260
261
262
263
264
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

253
254
255
256
257
258
259
260
261
262

263
264
265
266

267
268
269
270
271
272
273
274







-
+









-
+













+














+





-
+





+
+
+
+
-
+
+


-
+







  %Get component type
  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,
    mtt_error(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,
    mtt_error(sprintf("Component %s (%s) is at both ends of a bond", comp_name,
    comp_type),fnum);
  end;
    

  % which end of bond at component?
  bond_end = index(:,2); 
  direction = -sign(bond_end-1.5*one);
  signed_bond_list = bond_list.*direction;
  components = add_bond(components,signed_bond_list',i);
  
  # Unalias all the ports on this component - if not a junction
  unlabelled_ports = 0;  
  in_bonds = 0;
  out_bonds = 0;
  if ((comp_type!="0")&&(comp_type!="1")) # Don't do junctions
    for j=1:n_comp_bonds
      signed_bond = signed_bond_list(j);
      port_name_index = getindex(port_bond,signed_bond);
      port_direction = sign(signed_bond);
      
      if port_name_index==0	# There is no port on this bond - so try
				# to default
	unlabelled_ports++;
	if(unlabelled_ports==1)
	  if port_direction>0
	    in_bonds++;
	    port_name_i = "in";
	  else
	    out_bonds++;
	    port_name_i = "out";
	  end;
	elseif (unlabelled_ports==2)
	  if port_direction>0
	    if (++in_bonds>1)
	      mtt_info(["More than one unlabelled in port on component " \
	      mtt_error(["More than one unlabelled INport on component " \
			comp_name " (" comp_type ")"],fnum);
	    else
	      port_name_i = "in";
	    end
	  else
	    if (++out_bonds>1)
	      mtt_error(["More than one unlabelled OUTport on component " \
			comp_name " (" comp_type ")"],fnum);
	    else
	    port_name_i = "out";
	      port_name_i = "out";
	    end
	  end;
	else
	  mtt_info(["More than two unlabelled ports on component " \
	  mtt_error(["More than two unlabelled ports on component " \
		    comp_name " (" comp_type ")"],fnum);
        end
	mtt_info(["Defaulting port name [" port_name_i "]\t on component " \
		  comp_name " (" comp_type ")" ],fnum);
	port_name = [port_name; ["[" port_name_i "]"]];	# add to list
	[port_name_index,junk] = size(port_name); # the corresponding
				# index
354
355
356
357
358
359
360
361

362
363
364

365
366
367
368
369
370
371
364
365
366
367
368
369
370

371
372
373

374
375
376
377
378
379
380
381







-
+


-
+







    % bond
    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,n_other_subports] = split_port(other_port_name, ',');
      if n_other_subports~=n_subports
	mtt_info(['Vector ports ', port_name_i, ' and ', other_port_name, 'are not compatible'],fnum);
	mtt_error(['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);
      mtt_error(['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);
446
447
448
449
450
451
452
453

454
455
456
457
458
459
460
456
457
458
459
460
461
462

463
464
465
466
467
468
469
470







-
+







  % 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);
    mtt_error(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
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
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







-
+











-
+







-
+







    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);
    portnames=""; 
    for kk=1:k 
      portnames=sprintf("%s %s",portnames, unsorted_port_list(kk,:));
    end;
    mtt_info(portnames,fnum);
    mtt_error(portnames,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);
    % mtt_error(['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);
      % mtt_error(['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]'];
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
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







-
+









-
+





-
+



-
+







  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); 
      mtt_error(['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); 
	mtt_error(['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); 
	mtt_error(['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); 
	mtt_error(['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 ]