%  CONTROLLER TUNING 

%  FILENAME: CSTR_TUN.M 
%  DATE: November 1994
%  VERSION: 02
%  COPYRIGHT 1993, 1994 M.Gretzinger & T.Marlin
%            McMaster University   

% This m-file is called by CSTR.M. It sets up a menu to allow the user to 
%       modify the controller tuning constants for the CSTR.


selection4 = 1;

if baseloaded ~= 1
    disp('')
    disp('No data has not been loaded. Press ENTER to continue.')
    pause
    selection4 = 0;
end

while selection4
   clc
   disp('*************************************************************')
   disp('*               CONTROLLER TUNING                           *')
   disp('*                                                           *')
   disp('*************************************************************')
   disp('')
   disp('SELECT THE APPROPRIATE MENU ITEM')
   disp('')
   disp('MODIFY...')
   disp('                                     PRESENT VALUES')
   fprintf('1) Gain, Kc                          %4.2f  (m^3/min)/K\n',kc1)
   fprintf('2) Integral Time, T_I                %4.2f   min\n',ti1)
   fprintf('3) Initial Temp Set Point,Tsp        %4.2f K\n',sp1init)
   fprintf('4) Temp Set Point after step         %4.2f K\n',sp1new)
   disp('5) Return to main menu')
   disp('')
        
   m4 = input('Please enter the desired selection:   ');
        
   if isempty(m4), break, end
        
   m4 = round(m4);
   if (m4<1) | (m4>5)
       disp('')
       disp('Not a valid selection, press ENTER to continue')
       pause;
   end    

   if m4 == 1
       kc1hold = input('Enter new value for Gain, Kc:  ')
       if isempty(kc1hold)
           kc1 = kc1; 
       else    
           kc1=kc1hold;
       end
   
   elseif m4 == 2
       ti1hold = input('Enter new value for Integral Time, T_I:  ');
       if isempty(ti1hold) 
            ti1 = ti1; 
       else
            if ti1hold <= 0.0 ;
               disp(' integral time must be positive, hit ENTER')
               pause
            else
               ti1 = ti1hold;
            end
       end
   
   elseif m4 == 3
       sp1inith = input('Enter Initial Temperature Set Point, Tsp:  ')
       if isempty(sp1inith) 
             sp1init = sp1init; 
       else      
             sp1init = sp1inith;
       end
   
   elseif m4 == 4
       sp1newh = input('Enter Set Point after Step Change:  ')
       if isempty(sp1newh) 
             sp1new = sp1new; 
       else      
             sp1new = sp1newh;
       end
   
   elseif m4 == 5
       break
   end    % if m4
        
end    % while 1 (line )
