% FILENAME: P_MEAS.M
% DATE: NOV 15, 1993 
% VERSION: 2.0
% REVISED : JANUARY 1995
% COPYRIGHT  1994-5 T. MARLIN AND R. CIPLLOA 
%This file allows the user to define control performance parameters that 
%are used in the simulation and optimization algorithms.
% ********************************************************************

while 1
  clc
  disp('*************************************************************')
  disp('*                CONTROL PERFORMANCE PARAMETERS             *')
  disp('*                                                           *')
  disp('*************************************************************')
  disp('')
  disp('SELECT THE APPROPRIATE MENU ITEM(s)')
  disp('')
  disp('MODIFY...')
  disp('                                                   PRESENT VALUES')
  disp('1) Manipulated Variable Bound Paramaters            --------   ') 
  fprintf('2) Magnitude of Penalty for MV violations            %4.2f\n',rho) 
  fprintf('3) Magnitude of Penalty for CV overshoot             %4.2f\n',rho1) 

  if obj == 1
   disp('4) Objective Function to Minimize                    IAE')
  elseif obj == 2
   disp('4) Objective Function to Minimize                    ISE')
  else
   disp('4) Objective Function to Minimize                    ITAE')
  end
  
  fprintf('5) Model Mismatch (percent of nominal)               %4.2f\n',epsl)
  disp('6) Return to Main Menu                                             ' )
        
  perf = input('Enter the desired selection:   ');
  
  if isempty(perf), break, end   % go back to main menu if ENTER is pressed
      
  perf = round(perf);
  if (perf<1) | (perf>6)
      disp('')
      disp('Not a valid selection')
      disp('')
      disp('Press ENTER to continue')
      pause;
  end    
  
  if perf == 1
      pbound

  elseif perf == 2
      junk = input('Enter value for the MV penalty:  ') ;
      if junk < 0
       disp('')
       disp(' Must be nonnegative')
       disp('')
       disp(' Press any key to continue')
       pause
       junk=rho;
      end

      if isempty(junk)
          junk=rho;
      end
      rho=junk;

  elseif perf == 3
      junk = input('Enter value for the CV penalty:  ') ;
      if junk < 0
       disp('')
       disp(' Must be nonnegative')
       disp('')
       disp(' Press any key to continue')
       pause
       junk=rho1;
      end

      if isempty(junk)
          junk=rho1;
      end
      rho1=junk;

  elseif perf == 4
      disp('')
      disp('1) IAE')
      disp('2) ISE')
      disp('3) ITAE')
      disp('')
      junk = input('Choose function to minimize :  ') ;
      
      if isempty(junk)
          junk=obj;
      end

      if (junk < 1 | junk > 3)
          junk = obj;
          disp (' entry outside allowable values, press enter to continue')
          pause
      end

      obj=junk;

  elseif perf == 5
      junk = input('Enter model error as a % (eg. 50 for 50%):  ') ;
      
      if isempty(junk)
          junk=epsl;
      end
      
      if junk < 0
       disp('')
       disp(' Enter a positive number ')
       disp('')
       disp(' Press any key to continue')
       pause
       junk=epsl;
      end

      if junk >= 100
         junk = epsl;
         disp ('error must be < 100 or process gain can change sign')
         disp (' press enter to continue')
         pause
      end

      epsl=junk;
  else
      break
  end 
  
end 
