function [ZVe,NVe,Q,IN,OU,MT,NV,BRF]=struc000(SOR,OU,P1,P2)
%        [ZVe,NVe,Q,IN,OU,MT,NV,BRF]=struc000(SOR,OU,P1,P2)
%STRUC000 K(3S):Par=[V11 T11 V12 T12 V13 T21 V21 T31];
%               Reg=[VR1 d11 VR2 d12 VR3];
%               pre-filter definition: VFi=1+d12 (limes) and bf1=d12
%                                      (polynomial equalizing)
%         three loops cascade structure including explanations how to define
%         controller and plant;
%         structure and simulation see SIST000.mdl; loop design:
%         inner loop:  PI-type controller, two first-order time-delay elements,
%                      mean value measurement
%         middle loop: pre-filter, PI-type controller controller, gain,
%                      integration with feedback, mean value measurement
%         outer loop:  P-type controller, integrator

%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 Amount Optimum, symbolical plant and control structure
%            definition, application basis for: bod_es. / bod_esg.m / bod_esp.m

% Copyright (c) 2011 Dr. Gert-Helge Geitner; TU Dresden, Fak. ET,
%                    Elektrotechnisches Institut (ETI); Mommsenstr. 13;
%                    D-01062 Dresden, Germany;
%                    Tel./Fax ++49-351-463-32917/33655
%                    e-mail: Gert-Helge.Geitner@tu-dresden.de
% Digital Amount 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

% szx  definition of particular plant transfer functions of the continuous
% snx  part as string (completely defining numerator and denominator and using
%      continuous numbers sz1 till szx or sn1 till snx), as well as:
% Q  = block connection matrix (row number=number of blocks,1.column=block number
%      other columns = signed numbers of respective antecessor blocks
%                      with regard to the block in consideration);
% IN = number of the input block of the total structure;
% OU = numbers of those blocks which have to be considered as an output
% MT = matrix containing info how to z-transform partial plants using outputs
%      "OU" (row numbers = output numbers "OU" in same sequence,
%      1.column = real non-whole-number time delay        - see function trans.m
%      2.column = code for coupling/measurement: 0 = T/A
%                                                1 = T/M or H/A
%                                                2 = H/M  - see function trans.m
% NV = string name vector, defines the sequence of plant gains, plant time
%      constants etc. for transfer of numerical values;
%      names have to be completed via semicolon AND space
%HINT:
% whole-number time delays inside the plant model may be shifted to the interface
% between both parts of the total model (sx plant blocks, dx controller blocks)
% For this reason whole-number time delays may be attached to dx blocks redarding
% structure input.


% ****** beginning ******
 sz1='V11;';			sn1='[T11 1];';
 sz2='V12;';			sn2='[T12 1];';
 sz3='V13;';			sn3='1;';
 sz4='1;';			    sn4='[T21 0];';
 sz5='V21;';			sn5='1;';
 sz6='1;';			    sn6='[T31 0];';
 Q=[1 0  0
    2 1  0
    3 2  0
    4 3 -5
    5 4  0
    6 4  0]; IN=[1]; OU=[2 4 6];
 MT=[0 2
     0 2
     0 1];
 NV=['V11; T11; V12; T12; V13; T21; V21; T31; '];
% ****** 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
%rzx  Definition of particular controller transfer functions of the discontinuous
%rnx  part as string (completely defining numerator and denominator). In doing so
%     continuous numbering has to guarantee that outputs "OU" which were defined
%     for the continuous plant will represent the first blocks of a discontinous
%     structure to be set up, because those represent discontinuous transfer 
%     functions related to vector "IN" above.
% Example: If there are given 5 outputs of the continuous plant then numbering
%          of controller numerator and controller denominator polynomials has
%          to start with number 6, e.g.:  >>>  rz6 till rzy or rn6 till rny  <<<
% Hint:  Regarding optimization all possible interessting continuous plant
%        outputs of the total structure should be included from the beginning, 
%        in order to avoid a future change of numbering. Not necessarily all
%        outputs have to be applied in each case.
% Please note: In case of pre-filters it will be necessary to take account of
%              as well as polynomial equalizing (controller numerator = filter
%              denominator) and stationary filter behaviour (limes) immediately
%              via definition of transfer functions!
% QQ =block connection matrix for discontinuous structure; first "length(OU)"
%     block numbers are allocated to the IN/OU model of the total plant, as
%     mentioned above; hence it follows that the first "length(OU)" blocks 
%     have to dispose of the same input block assignment in matrix QQ!
%     matrix design: like matrix Q (see above)
% BME/BMA=matrices containing numbers of input (BME) or output (BMA) blocks each
%   related to the computation variant and partial structure to be optimized;
%   definition of column design:
%   a, Each column meets a computational variant. The number of elements in a
%      column unequal to zero meets the number of computation loops.
%   b, The content of an element itself meets the number of an input (BME) or
%      output (BMA) block.
%   definition of the row design:
%   a, The computation (optimization) starts with row 1 of any selected column.
%      BME provides the input block number, BMA provides the output block number
%      of the control (partial) structure taken into consideration.
%   b, example 1:
%      BME=[3];  BMA=[1];  One computation (optimization) variant with one loop.
%                          Input block regarding optimization will be no.3,
%                          and block no. 1 is defined to be the output block.
%   c, example 2:
%      BME=[1 1 7   BMA=[2 1 3   Three optimization variants shall be researched.
%           7 1 0        4 2 0   The 2. variant needs 3, the 1. variant needs two
%           0 7 0];      0 3 0]; the 3. variant needs 1 optimization loops.
%                                Action of variant 1: first computation loop with
%                                block 1 as input, block 2 as output, second
%                      computation loop with block 7 as input, block 4 as output.
% BRF=selection of a computation variant from BME/BMA columns
% BM= Matrix of same structure as BME/BMA matrices, but at least with last
%     element at each column equal to zero. Thus matrix BM features one more row
%     always in comparison with matrices BME/BMA. The content of the elements
%     meets the number of unknown to be computed in each case.
% NV= string name vector, defines the sequence of controller gains and controller
%     polynomial coefficients for transfer of numerical values; defines also
%     together with matrix BM the computational sequence for the unknown;
%     names have to be completed via semicolon AND space.
%HINT:
% Possible whole-number time delays inside the plant model may be defined and
% considered here inside discontinous part as "controller block" - as mentioned
% above in paragraph "plant structure definition" - if parameters are known.


%******* beginning ******
 rz4='[VR1 VR1d11];';              rn4='[1 -1];';
 rz5='VR2*[1 d12];';               rn5='[1 -1];';
%filter specification: VFi=1+d12 (limes) and bf1=d12 (polynomial equalizing)
% --> essential use of Jacobian (gradients) because of products of unknown
 rz6='VR3;';                       rn6='1;';
 rz7='(1+d12);';                   rn7='[1 d12];';

QQ=[1  4 0
    2  4 0
    3  4 0
    4 -1 5
    5 -2 7
    6 -3 0
    7  6 0];
BME=[4 7 6]'; BMA=[1 2 3]'; BRF=1; BM=[2 2 1 0]';
NV=['VR1; VR1d11; VR2; d12; VR3; '];
%****** 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
