%  ***********  GENERAL SINGLE LEVEL CONTROL  **************
%  **  CAN BE USED FOR EXAMPLES 18.2 TO 18.4  *************
%  **  AND FIGURES 18-6A-6C                   *************
%  COPYRIGHT McMASTER UNIVERSITY
%  WRITTEN BY T. MARLIN
%  FILENEME: PIPARA.M
%  LAST UPDATED: DECEMBER 1994
%  VERSION 2.0
%  DESCRIPTION
%  this is the sub-menu called from LEVEL.M 
%  used to  input data for the controller
%  ********************************************************

%  ********************************************************
%  submenu for process
%  ********************************************************

while 1
  clc
  disp('*************************************************************')
  disp('*     SIMULATION OF NON-SELF-REGULATING LEVEL SYSTEM        *')
  disp('*         INPUT THE CONTROLLER PARAMETERS HERE              *')
  disp('*      (for linear PI, set Break=0 and KcL= gain)           *')
  disp('*         (for P-only controller, set Ti=0)                 *')
  disp('*************************************************************')
  disp('')
  disp('SELECT THE APPROPRIATE MENU ITEM(s)')
  disp('')
  disp('                                   PRESENT VALUES')
  fprintf('1) Small controller gain                 %4.3f\n',kcs)
  fprintf('2) Large controller gain (or linear)     %4.3f\n',kcl)
  fprintf('3) Integral time                         %4.3f\n',ti)
  fprintf('4) Break (where gain changes)            %4.3f\n',brk)
  disp('5) Return to Main Menu')
  disp('')
        
  userin = input('Enter the desired selection:   ');
  
  if isempty(userin), break, end   % go back to main menu if ENTER is pressed
      
  userin = round(userin);
  if (userin<1) | (userin>5)
      disp('')
      disp('Not a valid selection')
      disp('')
      disp('Press ENTER to continue')
      pause;
  end    

% ********************************************************  
  if userin == 1
      junk = input('Enter value for small gain: ') ;
      if isempty(junk) 
          junk=kcs;
      end
      kcs = junk ;
% ********************************************************
  elseif userin == 2
      junk = input('Enter value for large gain: ') ;
      if isempty(junk) 
          junk = kcl;
      end
      kcl = junk ;

% *********************************************************
  elseif userin == 3
      junk = input('Enter value for integral time:  ') ;
      if isempty(junk) 
          junk=ti;
      elseif junk < 0.
          junk=ti;
          disp('value must be non-negative, please reenter')
          pause (2)
      end
      ti = junk; 
  
% **********************************************************
  elseif userin == 4
      junk = input('Enter value for BREAK:  ') ;
      if isempty (junk) 
          junk = brk;
      elseif junk < 0.
          junk = brk;
          disp('value must be non-negative, please reenter')
          pause (2)
      end
      brk = junk; 
% **********************************************************  
  else
       break
  end 
  
end 
