% FILE NAME: DISTURB.M
% DONE BY : RENO CIPOLLA 
% DATE: JAnuary 1995
% VERSION: 2.0
% COPYRIGHT 1995 T. Marlin and R. Cipolla   
% The parameters for the disturbance are entered via this menu
% *************************************************************

while 1
  clc
  disp('*************************************************************')
  disp('*           MODIFY DISTURBANCE PARAMETERS                   *')
  disp('*                                                           *')
  disp('*************************************************************')
  disp('')
  disp('SELECT THE APPROPRIATE MENU ITEM(S)')
  disp('')
  disp('MODIFY...')
  disp('                                       PRESENT VALUES')
  fprintf('1) Disturbance Gain, Kpd                 %4.4f\n',Kpd)
  fprintf('2) Dead time, thetad                     %4.2f\n',thetad(1))
  fprintf('3) Lead time,tauleadd                    %4.2f\n',tauleadd(1))
  fprintf('4) Time Constant taud1                   %4.2f\n',taud1(1))
  fprintf('5) Time Constant taud2                   %4.2f\n',taud2(1))
  fprintf('6) Time Constant taud3                   %4.2f\n',taud3(1))
  fprintf('7) Damping Coefficient                   %4.2f\n',xid)
  disp('8) Set Disturbance Dynamics = Process Dynamics ')
  disp('9) Return To Main Menu')
  disp('')      
  DIS = input('Enter Your Selection:   ');
  
  if isempty(DIS), break, end
      
  DIS = round(DIS);
  if (DIS<1) | (DIS>9)
      disp('')
      disp('Not a valid selection')
      disp('')
      disp('Press ENTER to continue')
      pause;
  end    
  if DIS == 1
      junk = input('Enter value for disturbance gain, Kpd:  ') ;
      if isempty(junk)
          junk=Kpd;
      end
      Kpd=junk;

  elseif DIS == 2
      junk = input('Enter value for the dead time:  ') ;
      if junk < 0
       disp('')
       disp(' You cannot have a negative dead time')
       disp('')
       disp(' Press any key to continue')
       pause
       junk=thetad(1);
      end
      if isempty(junk)
          junk=thetad(1);
      end
      thetad(1)=junk;
%      if thetad(1) ~= theta(1)
%          Dyn='n';
%      else
%          Dyn='y';
%      end
  
  elseif DIS == 3
      junk = input('Enter Lead time (numerator):  ') ;
      if isempty(junk)
          junk=tauleadd(1);
      end
      tauleadd(1)=junk;
%      if tauleadd(1) ~= taulead(1)
%          Dyn='n';
%      else
%          Dyn='y';
%      end
   
  elseif DIS == 4
      junk = input('Enter value for time constant, taud1:  ') ;
      if isempty(junk)
         junk=taud1(1);
      end
      if junk < 0
         junk = taud1(1);
         disp ('time constant must be nonnegative')
         disp (' press enter to continue')
         pause
      end

      taud1(1)=junk;

%      if taud1(1) ~= tau1(1)
%          Dyn='n';
%      else
%          Dyn='y';
%      end
  
  elseif DIS == 5
      junk = input('Enter value for time constant, taud2:  ') ;
      if isempty(junk)
          junk=taud2(1);
      end
      if junk < 0
         junk = taud1(2);
         disp ('time constant must be nonnegative')
         disp (' press enter to continue')
         pause
      end

      taud2(1)=junk;

%      if taud2(1) ~= tau2(1)
%          Dyn='n';
%      else
%          Dyn='y';
%      end
  
  elseif DIS == 6
      junk = input('Enter value for time constant, taud3:  ') ;
      if isempty(junk)
          junk=taud3(1);
      end
      if junk < 0
         junk = taud1(3);
         disp ('time constant must be nonnegative')
         disp (' press enter to continue')
         pause
      end

      taud3(1)=junk;

%      if taud3(1) ~= tau3(1)
%          Dyn='n';
%      else
%          Dyn='y';
%      end
  
  elseif DIS == 7
      junk = input('Enter value for Damping coef.:  ') ;
      if isempty(junk)
          junk=xid;
      end
      if junk < 0
         junk = xid;
         disp ('damping coef. must be nonnegative')
         disp ('press enter to continue')
         pause
      end

      xid=junk;

%      if xid ~= xi
%          Dyn='n';
%      else
%          Dyn='y';
%      end
  
  elseif DIS==8
    Dyn = input('Make the Disturbance dynamics same as the Process ? [y/n] ','s');
    
    if isempty (Dyn)
       Dyn = 'n';
       end

    if Dyn == 'y'
      taud1(1)=tau1(1); taud2(1)=tau2(1); taud3(1)=tau3(1); thetad(1)=theta(1); 
      tauleadd(1)=taulead(1); xid=xi;
   
      disp(' ')
      disp(' ')
      disp(' The Disturbance dynamics have been set equal to the process dynamics.') 
      disp(' The disturbance gain is unchanged, press enter to continue ')
      pause 
    elseif Dyn == 'n'
       disp(' ')
       disp('Specify Disturbance Dynamics in the menu if you wish.')
       disp('')
       disp('Press Enter to continue.... ') 
       pause
    end

  else
      break
  end        % if DIS

end 




