function [ParMa,VarMa]=zust_aut2(TM,TF,TL,VT,VTel)
%ZUST_AUT2 state control structure 1; 3 coefficients; parameter variation;
%          [ParMa(,VarMa)] =zust_aut2(TM,TF,TL(,VT,VTel))
% calculation of the coefficients of a discontinuous state control structure,
% example by Brandenburg: at 35(1987)7, pp. 275/83; using BOD;  T=sampling time;
% *** quod vide: variation of sampling time and first order time delay model of
%                the closed current control loop - T, Tel ***
% (,VT,VTel):  optionally external vectorial definition of >>>parameter ranges<<<
%              regarding these two time constants; when indicated single elements
%              and >>>n o n - l i n e a r<<< definition possible!
% ParMa:       parameter matrix containing calculated feed back coefficientes
%              1. row: Kd;    2. row: Km;    3. row: Kn;
% (,VarMa):    matrix of variables containing associated time constants
%              1. row: T;     2. row: Tel    - for diagrams
% Hint: In case of menu driven input of a parameter range set minimum==maximum
%       to >>>a v o i d<<< parameter variation if indicated.

% KEY WORDS: Discontinuous Amplitude Optimum, BOD; state control structure;
%		     parameter variation; sampling time, remaing time constant

%  ***** preconditions: existence of functions zust_au2.m, zust_aug2.m ****

%  Copyright (c) 1997-2009. All Rights Reserved.
%                     Dr. Gert-Helge Geitner; TU Dresden, Fak. ET,
%                     Elektrotechnisches Institut (ETI); Mommsenstr. 13;
%                     D-01062 Dresden, Germany;
%                     http://eeiwzg.et.tu-dresden.de/ae2_files/ae_1.htm
%  Reference regarding Discontinuous Amplitude Optimum: Geitner, G.-H.:
%                     Entwurf digitaler Regler fuer elektrische Antriebe.
%                     publisher: VDE-Verlag GmbH Berlin und Offenbach 1995
%                     ISBN 3-8007-1847-2

if nargin~=3&nargin~=5 error('Incorrect number of input arguments!'); end
if length(TM)~=1|length(TF)~=1|length(TL)~=1
   error('Incorrect dimension regarding first three input values!'); end
if nargin==5  %loop counter calculations
   SZT=length(VT); SZE=length(VTel);
else
   VT  =input('Sampling time / ms [minimum maximum]=');
  VTel=input('Remaining time const. current control loop / ms [minimum maximum]=');
   if length(VT)~=2|length(VTel)~=2 error('Number of values incorrect!'); end
   if VT(1)>VT(2)|VTel(1)>VTel(2) error('min/max interchanged!'); end
   if VT(1)<0|VT(2)<0|VTel(1)<0|VTel(2)<0
				error('Illegal negative values detected!'); end
   if VT(1)==VT(2) SZT=1; VT=VT*[1 0]';
   else
      ans=input('Step size of T: standard 50% (any) / input(0) ? =');
      if isempty(ans)|ans~=0 swT=50; 
      else swT=input('Input step size of T in % =');
	        if isempty(swT)|swT<=0|swT>100 error('Incorrect value!'); end
      end
      SZT=ceil(100/swT)+1;       %loop counter
      dT=(VT(2)-VT(1))*swT/100;  %range of definition
      for i=1:SZT-1 VT(i+1)=VT(1)+i*dT; end
   end
   if VTel(1)==VTel(2) SZE=1; VTel=VTel*[1 0]'; 
   else
      ans=input('Step size of Tel: standard 50% (any) / input(0) ? =');
      if isempty(ans)|ans~=0 swE=50;
      else  swE=input('Input step size of Tel in % =');
	         if isempty(swE)|swE<=0|swE>100 error('Incorrect value!'); end
      end
      SZE=ceil(100/swE)+1;            %loop counter
      dTE=(VTel(2)-VTel(1))*swE/100;  %range of definition
      for i=1:SZE-1 VTel(i+1)=VTel(1)+i*dTE; end
   end
end
disp('Number of parameter combinations to be computed ='); disp(SZE*SZT);
ans=input('Start (any) / function abort (0) ? =');
if isempty(ans)|ans~=0 else error('Function aborted!'); end
i=0;
for j=1:SZE
    for k=1:SZT
        i=i+1; disp(['Calculation number: ' num2str(i)])
	     erg=zust_au2(VT(k),VTel(j),TM,TF,TL);
	     ParMa(1,i)=erg(1); ParMa(2,i)=erg(2); ParMa(3,i)=erg(3);
	     VarMa(1,i)=VT(k);  VarMa(2,i)=VTel(j);
    end
end
