Differences From Artifact [ea5247f84f]:

To Artifact [fbe5a968f6]:


19
20
21
22
23
24
25



26
27
28
29
30
31
32
  ## Structure matrix [states,nonstates,inputs,outputs,zero_outputs]
  
  ## ###############################################################
  ## ## Version control history
  ## ###############################################################
  ## ## $Id$
  ## ## $Log$



  ## ## Revision 1.53  2005/03/21 11:09:47  gawthrop
  ## ## Now handles bicausal SS component -
  ## ##   ie source-source or sensor-sensor
  ## ##
  ## ## Revision 1.52  2004/09/12 22:27:27  geraint
  ## ## Appended 't' to fopen mode string to open in text mode.
  ## ##







>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  ## Structure matrix [states,nonstates,inputs,outputs,zero_outputs]
  
  ## ###############################################################
  ## ## Version control history
  ## ###############################################################
  ## ## $Id$
  ## ## $Log$
  ## ## Revision 1.54  2009/11/02 16:54:03  geraint
  ## ## Replaced deprecated functions from Octave 2.1 for Octave 3.0: is_struct -> isstruct, struct_contains -> isfield, struct_elements -> fieldnames, is_complex -> iscomplex, setstr -> char
  ## ##
  ## ## Revision 1.53  2005/03/21 11:09:47  gawthrop
  ## ## Now handles bicausal SS component -
  ## ##   ie source-source or sensor-sensor
  ## ##
  ## ## Revision 1.52  2004/09/12 22:27:27  geraint
  ## ## Appended 't' to fopen mode string to open in text mode.
  ## ##
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
    full_name = system_name;
    full_name_repetition = system_name;
    system_type = system_name;
  else
    full_name = [full_name, sub_delim, system_name];

    if (repetition>1)
      full_name_repetition = [full_name_repetition, \
			      sub_delim, system_name, sub_delim, \
			      num2str(repetition)];
    else
      full_name_repetition = [full_name_repetition, \
			      sub_delim, system_name];
    endif
    
  end;
  
  
  







|
|


|







229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
    full_name = system_name;
    full_name_repetition = system_name;
    system_type = system_name;
  else
    full_name = [full_name, sub_delim, system_name];

    if (repetition>1)
      full_name_repetition = [full_name_repetition, ...
			      sub_delim, system_name, sub_delim, ...
			      num2str(repetition)];
    else
      full_name_repetition = [full_name_repetition, ...
			      sub_delim, system_name];
    endif
    
  end;
  
  
  
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
  
  ## Set up the counters for the labelled SS. These are, by definition,
  ## encountered first and so the counters will not be messed up by subsystems.
  local_u_index = 0;
  local_y_index = 0;
  
  if (length(system_args)==0)
    mtt_info(sprintf("No arguments given so no argument aliasing done for system %s(%s)",\
		     system_name,system_type), infofilenum);
    AliasingArguments=0;
  else
    AliasingArguments=1;
  endif;
  
  if (length(system_cr)==0)
    mtt_info(sprintf("No cr given so no cr aliasing done for system %s(%s)",\
		     system_name,system_type), infofilenum);
    AliasingCRs=0;
  else
    AliasingCRs=1;  endif;
  
  
  fields=["ports";"subsystems"]; # Do for both ports and subsystems -







|







|







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
  
  ## Set up the counters for the labelled SS. These are, by definition,
  ## encountered first and so the counters will not be messed up by subsystems.
  local_u_index = 0;
  local_y_index = 0;
  
  if (length(system_args)==0)
    mtt_info(sprintf("No arguments given so no argument aliasing done for system %s(%s)", ...
		     system_name,system_type), infofilenum);
    AliasingArguments=0;
  else
    AliasingArguments=1;
  endif;
  
  if (length(system_cr)==0)
    mtt_info(sprintf("No cr given so no cr aliasing done for system %s(%s)", ...
		     system_name,system_type), infofilenum);
    AliasingCRs=0;
  else
    AliasingCRs=1;  endif;
  
  
  fields=["ports";"subsystems"]; # Do for both ports and subsystems -
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
    	direction = sign(comp)'*[1 1];
				# Convert from arrow orientated to component orientated causality
    	comp_bonds = CBG.bonds(bond_list,:).*direction;
	
    	## disp(["---- ", field, " ---"]);    
    	
	if AliasingArguments	# Alias the args list if appropriate
    	  message = sprintf("\tfor component  %s (%s) within %s",\
			    comp_name,subsystem.type,full_name);    
    	  if isfield(CBG,"alias")
	    subsystem.arg = alias_args(subsystem.arg,CBG.alias,";",message,infofilenum,full_name);
    	  endif;
	endif;
	
	if AliasingCRs	# Alias the CR list if appropriate
    	  message = sprintf("\tfor component  %s (%s) within %s",\
			    comp_name,subsystem.type,full_name);    
    	  if isfield(CBG,"alias")
	    subsystem.cr = alias_args(subsystem.cr,CBG.alias,";",message,infofilenum,full_name);
    	  endif;
	endif;

	## Substitute positional ($1 etc) arguments







|







|







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
    	direction = sign(comp)'*[1 1];
				# Convert from arrow orientated to component orientated causality
    	comp_bonds = CBG.bonds(bond_list,:).*direction;
	
    	## disp(["---- ", field, " ---"]);    
    	
	if AliasingArguments	# Alias the args list if appropriate
    	  message = sprintf("\tfor component  %s (%s) within %s", ...
			    comp_name,subsystem.type,full_name);    
    	  if isfield(CBG,"alias")
	    subsystem.arg = alias_args(subsystem.arg,CBG.alias,";",message,infofilenum,full_name);
    	  endif;
	endif;
	
	if AliasingCRs	# Alias the CR list if appropriate
    	  message = sprintf("\tfor component  %s (%s) within %s", ...
			    comp_name,subsystem.type,full_name);    
    	  if isfield(CBG,"alias")
	    subsystem.cr = alias_args(subsystem.cr,CBG.alias,";",message,infofilenum,full_name);
    	  endif;
	endif;

	## Substitute positional ($1 etc) arguments
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
	    ## Link up the bonds for this compound component
	    fprintf(ese_file, ...
		    "\n\t%s Equations linking up subsystem %s (%s)\n\n", ...
		    pc, comp_name, subsystem.type);
	    
	    if (k>1)
	      name_comp_name = sprintf("%s%s%s%s%d", ...
				       full_name_repetition, sub_delim, \
				       comp_name, sub_delim, k);
	    else
	      name_comp_name = sprintf("%s%s%s", ...
				       full_name_repetition, sub_delim, \
				       comp_name);
	    endif
	    
	    
	    printf("\n\t%s Equations linking up subsystem %s (%s)\n\n",\
		   pc, comp_name, subsystem.type);
	    
	    u_index = 0; y_index = 0; ## Count the inputs and outputs
	    for port_number=1:length(bond_list)
	      repetition,port_number
              port_bond_number = bond_list(port_number)
# 	      this_bond_effort_unit = \
# 		  deblank(bond_effort_unit(port_bond_number,:))
# 	      this_bond_flow_unit = \
# 		  deblank(bond_flow_unit(port_bond_number,:));

# 	      ## Extract the unit/domain stuff
#               this_port_name = subABG.portlist(port_number,:);
              
#               eval(sprintf("this_port = subABG.ports.%s;", \
# 			   this_port_name));
# 	      if isfield(this_port,"units")
#                 eval(["effort_unit = \
# 		    subABG.ports.",this_port_name,".units.effort;"]);
#                 eval(["flow_unit = \
# 		    subABG.ports.",this_port_name,".units.flow;"]);
# 	      else
# 		effort_unit = "none";
# 		flow_unit = "none";
# 	      endif

# 	      ## and check consistency
#               ## Efforts
# 	      if strcmp(this_bond_effort_unit,"null") # set
# 		bond_effort_unit = \
# 		    [bond_effort_unit(1:port_bond_number-1,:)
# 		     effort_unit
# 		     bond_effort_unit(port_bond_number+1:n_bonds,:)
# 		     ]
# 	      elseif (!strcmp(this_bond_effort_unit,"none") && !strcmp(effort_unit,"none")) # check
# 		mtt_info(sprintf(unit_info,full_name, effort_unit, \
# 				 this_bond_effort_unit), infofilenum);
# 		if !strcmp(this_bond_effort_unit,effort_unit)
# 		  error_string = sprintf(unit_error, full_name,\
# 					 effort_unit, \
# 					 this_bond_effort_unit);
# 		  mtt_error(error_string);
# 		endif
# 	      endif
# 	      ## Flows
# 	      if strcmp(this_bond_flow_unit,"null") # set
# 		bond_flow_unit = \
# 		    [bond_flow_unit(1:port_bond_number-1,:)
# 		     flow_unit
# 		     bond_flow_unit(port_bond_number+1:n_bonds,:)
# 		     ]
# 	      elseif (!strcmp(this_bond_flow_unit,"none") && !strcmp(flow_unit,"none")) # check
# 		mtt_info(sprintf(unit_info,full_name, flow_unit, \
# 				 this_bond_flow_unit), infofilenum);
# 		if !strcmp(this_bond_flow_unit,flow_unit)
# 		  error_string = sprintf(unit_error, full_name,\
# 					 flow_unit, \
# 					 this_bond_flow_unit);
# 		  mtt_error(error_string);
# 		endif
# 	      endif
	      

	      ## Effort







|



|




|






|

|





|


|

|









|





|


|
|






|





|


|
|







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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
	    ## Link up the bonds for this compound component
	    fprintf(ese_file, ...
		    "\n\t%s Equations linking up subsystem %s (%s)\n\n", ...
		    pc, comp_name, subsystem.type);
	    
	    if (k>1)
	      name_comp_name = sprintf("%s%s%s%s%d", ...
				       full_name_repetition, sub_delim, ...
				       comp_name, sub_delim, k);
	    else
	      name_comp_name = sprintf("%s%s%s", ...
				       full_name_repetition, sub_delim, ...
				       comp_name);
	    endif
	    
	    
	    printf("\n\t%s Equations linking up subsystem %s (%s)\n\n", ...
		   pc, comp_name, subsystem.type);
	    
	    u_index = 0; y_index = 0; ## Count the inputs and outputs
	    for port_number=1:length(bond_list)
	      repetition,port_number
              port_bond_number = bond_list(port_number)
# 	      this_bond_effort_unit = ...
# 		  deblank(bond_effort_unit(port_bond_number,:))
# 	      this_bond_flow_unit = ...
# 		  deblank(bond_flow_unit(port_bond_number,:));

# 	      ## Extract the unit/domain stuff
#               this_port_name = subABG.portlist(port_number,:);
              
#               eval(sprintf("this_port = subABG.ports.%s;", ...
# 			   this_port_name));
# 	      if isfield(this_port,"units")
#                 eval(["effort_unit = ...
# 		    subABG.ports.",this_port_name,".units.effort;"]);
#                 eval(["flow_unit = ...
# 		    subABG.ports.",this_port_name,".units.flow;"]);
# 	      else
# 		effort_unit = "none";
# 		flow_unit = "none";
# 	      endif

# 	      ## and check consistency
#               ## Efforts
# 	      if strcmp(this_bond_effort_unit,"null") # set
# 		bond_effort_unit = ...
# 		    [bond_effort_unit(1:port_bond_number-1,:)
# 		     effort_unit
# 		     bond_effort_unit(port_bond_number+1:n_bonds,:)
# 		     ]
# 	      elseif (!strcmp(this_bond_effort_unit,"none") && !strcmp(effort_unit,"none")) # check
# 		mtt_info(sprintf(unit_info,full_name, effort_unit, ...
# 				 this_bond_effort_unit), infofilenum);
# 		if !strcmp(this_bond_effort_unit,effort_unit)
# 		  error_string = sprintf(unit_error, full_name, ...
# 					 effort_unit, ...
# 					 this_bond_effort_unit);
# 		  mtt_error(error_string);
# 		endif
# 	      endif
# 	      ## Flows
# 	      if strcmp(this_bond_flow_unit,"null") # set
# 		bond_flow_unit = ...
# 		    [bond_flow_unit(1:port_bond_number-1,:)
# 		     flow_unit
# 		     bond_flow_unit(port_bond_number+1:n_bonds,:)
# 		     ]
# 	      elseif (!strcmp(this_bond_flow_unit,"none") && !strcmp(flow_unit,"none")) # check
# 		mtt_info(sprintf(unit_info,full_name, flow_unit, ...
# 				 this_bond_flow_unit), infofilenum);
# 		if !strcmp(this_bond_flow_unit,flow_unit)
# 		  error_string = sprintf(unit_error, full_name, ...
# 					 flow_unit, ...
# 					 this_bond_flow_unit);
# 		  mtt_error(error_string);
# 		endif
# 	      endif
	      

	      ## Effort
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
		    cause_name = cause2name(-comp_bonds(1,k));
		  else		# Maybe multiport - but unicausal
		    cause_name = cause2name(-comp_bonds(k,1));
		  endif
 		  fprintf(structure_file, ...
 			  "%s\t%i\t%s\t%s%s%s\t%i\t%s\n", ...
 			  structure_name(which_index,:), value-k+1, ...
 			  comp_name, full_name_repetition, sub_delim, comp_name, \
 			  repetition, cause_name); 
 	    	endfor;
 	      endfor;
 	    endif;
	  endif
	endfor
	fflush (structure_file);







|







563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
		    cause_name = cause2name(-comp_bonds(1,k));
		  else		# Maybe multiport - but unicausal
		    cause_name = cause2name(-comp_bonds(k,1));
		  endif
 		  fprintf(structure_file, ...
 			  "%s\t%i\t%s\t%s%s%s\t%i\t%s\n", ...
 			  structure_name(which_index,:), value-k+1, ...
 			  comp_name, full_name_repetition, sub_delim, comp_name, ...
 			  repetition, cause_name); 
 	    	endfor;
 	      endfor;
 	    endif;
	  endif
	endfor
	fflush (structure_file);

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