function [ZVe,NVe,Q,IN,OU,MT,NV,BRF]=struc031(SOR,OU,P1,P2)
%        [ZVe,NVe,Q,IN,OU,MT,NV,BRF]=struc031(SOR,OU,P1,P2)
%STRUC031 S(dt/fo/ba-u/PI): Par=[VS TM TSu];
%                           Reg=[VR d1];
%                           P1=m;
%                           P2=[T1 T2]
%         single control loop featuring dead times in forward and backward path,
%         undelayed input; loop design:
%         forward path: PI-type controller, time delay: m < T, whole-number
%                       dead time(T1), two first-order time-delay elements, 
%                       mean value measurement
%         backward path: whole-number dead time (T2)
%             >>> use of possible parameter transfer to strucxxx.m <<<
%		         P1=m      real time delay (forwards)
%                P2(1)=T1  whole-number time delay (forwards)
%                P2(2)=T2  whole-number time delay (backwards)
%	      Application: computation of an average controller design in case of
%			           use of bus systems - undelayed input signals
%	      structure and simulation see SIST031.mdl for average control parameters

%AUXILIARY FILE for symbolical definition - no stand-alone calling !!!
%	  SOR:   switch - to shift between plant or control structure
%	  OU:    vector using continuous output numbers for discretized plant state
%            description
%     P1,P2: posibility of any parameter transfer via bod_es.m

% KEY WORDS: Digital Magnitude Optimum, symbolical plant and control structure
%            definition, application basis for: bod_es. / bod_esg.m / bod_esp.m

% Copyright (c) 2011-2023 Dr. Gert-Helge Geitner, TU Dresden,
%                     https://wwwpub.zih.tu-dresden.de/~geitner/ae_1_0e.htm
% Digital Magnitude Optimum reference: Geitner, G.-H.:
%                    Entwurf digitaler Regler für elektrische Antriebe.
%                    VDE-Verlag GmbH Berlin und Offenbach 1996
%                    ISBN 3-8007-1847-2

if SOR==0  %plant structure definition

% ****** beginning ******
  sz1='VS;';			sn1='[TM 1];';
  sz2='1;';			sn2='[TSu 1];';

 Q=[1 0
    2 1]; IN=[1]; OU=[2];
 MT=[P1 2];			% parameter P1 = real time delay
 NV=['VS; TM; TSu; '];
% ****** ending ******

s=0; zae=0; ZVe=[]; NVe=[]; BRF=0;
while s==0 zae=zae+1;  eval(['ZVe=[ZVe sz' num2str(zae) '];'],'s=1;');
                       eval(['NVe=[NVe sn' num2str(zae) '];'],'s=1;'); end

else  %control structure definition

%******* beginning ******
 rz2='[VR VRd1];';                      rn2='[1 -1];';
 rz3='[';
    for i=1:P2(1) rz3=[rz3,'0 ']; end   %P2(1) = whole-number time delay
    rz3=[rz3,'1];'];                    rn3='1;';
 rz4='[';
    for i=1:P2(2) rz4=[rz4,'0 ']; end   %P2(2) = whole-number time delay
    rz4=[rz4,'1];'];                    rn4='1;';

QQ=[1  3
    2 -4
    3  2
    4  1];
BME=[2]'; BMA=[1]'; BRF=1; BM=[2 0]';
NV=['VR; VRd1; '];
%****** ending ******


s=0; zae=length(OU); ZVe=[]; NVe=[];
while s==0 zae=zae+1;  eval(['ZVe=[ZVe rz' num2str(zae) '];'],'s=1;');
                       eval(['NVe=[NVe rn' num2str(zae) '];'],'s=1;'); end
Q=QQ;IN=BME;OU=BMA;MT=BM;
end
