% **************************************************************************
% CASCADE-FEEDFORWARD CONTROL SIMULATOR 
% COPYRIGHT (C) 1994, T.E. MARLIN
%
% FILENAME : CFFM1.M
% WRITTEN BY : F.BOUDREAU
% VERSION : 2.0
% LAST UPDATED : NOVEMBER 1994
% DESCRIPTION OF FILE :
%    MENU FOR PROCESS T.F. EDITING. THIS FILE IS USED FOR BOTH THE
%    PRIMARY AND SECONDARY T.F.'s; THE VARIABLE 'loopid' INDICATES
%    WHICH T.F.'s IS BEING EDITED. 1=PRIMARY, 2=SECONDARY.
% ALL FILES IN THIS PACKAGE :
%    CFF     .M  - MAIN MENU AND ENTRY POINT
%    CFFDAT  .M  - EXTERNAL DATA FILE
%    CFFGRAPH.M  - PLOTS SIMULATION RESULTS
%    CFFM1   .M  - MENU FOR PROCESS T.F. EDITING
%    CFFM2   .M  - MENU FOR PID TUNING
%    CFFM3   .M  - MENU FOR DISTURBANCE T.F. EDITING
%    CFFMFF  .M  - FEEDFORWARD CONTROLLER MENU
%    CFFMSIM .M  - SIMULATION OPTIONS MENU
%    CFFNAME .M  - MENU FOR VARIABLES NAMES, INITIAL VALUES, BOUNDS
%    CFFSIM  .M  - EXECUTES SIMULATION
% **************************************************************************

while 1
   clc;   
   fprintf('*************************************************************************\n')
   fprintf('*                                                                       *\n')
   if loopid==1
   fprintf('*                PRIMARY PROCESS TRANSFER FUNCTION EDITING              *\n')
   elseif loopid==2
   fprintf('*               SECONDARY PROCESS TRANSFER FUNCTION EDITING             *\n')
   end
   fprintf('*                                                                       *\n')
   fprintf('*                            Kp%g(T1%g*s+1)exp(-DT%g*s)                    *\n',loopid,loopid,loopid)
   fprintf('*                    Gp%g = ---------------------------                  *\n',loopid)
   fprintf('*                              (T2%g*s+1)(T3%g*s+1)                       *\n',loopid,loopid)
   fprintf('*************************************************************************\n\n')
   fprintf('WHAT PARAMETER WOULD YOU LIKE TO UPDATE ?\n')
   fprintf('                                            Present Values\n')
   fprintf('1) Process Gain (Kp%g)                          %-g\n',loopid,K(loopid))
   fprintf('2) Lead Time Constant (T1%g)                    %-g\n',loopid,TA(loopid))
   fprintf('3) Dead Time (DT%g)                             %-g\n',loopid,D(loopid))   
   fprintf('4) Lag Time Constant (T2%g)                     %-g\n',loopid,T1(loopid))
   fprintf('5) Lag Time Constant (T3%g)                     %-g\n',loopid,T2(loopid))
   fprintf('6) Quit to main menu\n')
      
   m1 = input('PLEASE ENTER A SELECTION : ');
   if isempty(m1) == 1      % RETURN TO MAIN MENU IF <CR> ONLY IS PRESSED
      break
   end
   m1 = round(m1);
   if (m1<1 | m1>6)           % VALIDATES SELECTION
      disp('')
      disp('NOT A VALID SELECTION')
      disp('')
      disp('PRESS ENTER TO CONTINUE')
      pause;
   end 
   if m1 == 1
      temp = input(sprintf('Kp%g : ',loopid));
      if isempty(temp) ~= 1
         K(loopid)=temp;
      end
   elseif m1 == 2
      temp = input(sprintf('T1%g : ',loopid));
      if isempty(temp) ~= 1
         TA(loopid) = temp;
      end
   elseif m1 == 3
      temp = input(sprintf('D%g : ',loopid));
      if isempty(temp) ~= 1
         if temp >= 0
            D(loopid) = temp;
         else
            disp('dead time must be non-negative, please reenter')
            pause (2)
         end
      end
   elseif m1 == 4
      temp = input(sprintf('T2%g : ',loopid));
      if isempty(temp) ~= 1 
         if (temp) < 0.0
           disp(' Caution: you are defining an unstable process!')
           disp(' Reenter a positive value if you want a stable process')
           pause (4)
           T1(loopid) = temp;
         else
           T1(loopid) = temp;
         end
       end

   elseif m1 == 5
      temp = input(sprintf('T3%g : ',loopid));
      if isempty(temp) ~= 1
         if (temp) < 0.0
           disp(' Caution: you are defining an unstable process!')
           disp(' Reenter a positive value if you want a stable process')
           pause (4)
           T2(loopid) = temp;
         else
           T2(loopid) = temp;
         end
      end

   elseif m1 == 6
      break
   end % if
end % while
