% ***************************************************************************
% COPYRIGHT BY DAVE JEWELL AND T.E. MARLIN 1995
% FILENAME : dmc_menu.m
% Version 2.0
% LAST UPDATED : January 1995
% DISCRIPTION OF FILE :
% THIS MENU IS INVOKED BY THE PROPER SELECTION IN THE MAIN MENU
% 
% ***************************************************************************

while 1
clc;
disp('*********************************************************************')
disp('*               DESIGN THE DYNAMIC MATRIX CONTROLLER                *')
disp('*                    ****************************                   *')
disp('*              McMASTER UNIVERSITY CHEMICAL ENGINEERING             *')
disp('*              ========================================             *')
disp('*                                                                   *')
disp('*********************************************************************')
disp('')
disp('WHAT DO YOU WANT TO DO ?')
disp('')
disp('                                                         Present Value')
disp('1) Set DMC Controller Models Equal to Process Models ')
disp('2) Edit DMC Controller Transfer Function Models')
fprintf('3) DMC MV Input  Horizon (units of sample periods, 1-max))   %-g\n', MM)
fprintf('4) DMC Weights on Input Changes (MV1)                        %-g\n', Q1)
fprintf('5) DMC Weights on Input Changes (MV2)                        %-g\n', Q2)
fprintf('6) DMC CV Output Horizon (units of sample periods, 1-max)    %-g\n', NN)  
fprintf('7) DMC Weights on Output (CV1 Deviation from S.P.)           %-g\n', W1)
fprintf('8) DMC Weights on Output (CV2 Deviation from S.P.)           %-g\n', W2)
disp('9) Design DMC Controller');
disp('10) Previous menu')

mm = input('PLEASE ENTER A SELECTION : ');    
mm = round(mm);                 % ROUNDS OF SELECTION 
if isempty(mm) ==1
    break
end

    if (mm<1) | (mm>10)          % VALIDATES SELECTION
       disp('')
       disp('NOT A VALID SELECTION')
       disp('PRESS ENTER TO CONTINUE')
       pause;
    end

if mm == 1

    dmc_eq;                           %  SET DMC MODELS EQUAL TO EXACT PLANT MODEL
    disp('')
    disp( ' DMC MODELS HAVE BEEN SET EXACTLY EQUAL TO THE TRUE PLANT MODELS')   
    pause(2);

elseif mm == 2

TFM=input('Which PLANT Transfer Function - (1) Gm11 (2) Gm12 (3) Gm21 (4) Gm22 : ');
TFM=round(TFM);

if isempty(TFM)~=1
    if (TFM<1) | (TFM>4)        % VALIDATES SELECTION
       disp('')
       disp('NOT A VALID SELECTION, MUST BE BETWEEN 1 AND 4')
       disp('PRESS ENTER TO CONTINUE')
       pause;
    else
       clc
       DMC_MOD;                % CALLS MENU FOR CONTROLLER TF EDITTING
    end
end

elseif mm == 3                 % INPUT THE INPUT HORIZON
 
MMhold = input(' Input the DMC Input (MV) Horizon: ');
if isempty(MMhold)~=1
     MMhold = round (MMhold);
     if (MMhold<1) | (MMhold>maxinhorz)
         disp('')
         disp(' NOT A VALID SELECTION, MUST BE WITHIN SPECIFIED RANGE')
         disp(' PRESS ENTER TO CONTINUE')
         pause;
         
     else
         MM = MMhold;
     end
end

elseif mm == 4
Q1hold = input(' Input the DMC Weighting on the MV 1 Change: ' );
if isempty(Q1hold)~= 1
     if(Q1hold<0)
        disp('')
        disp(' WEIGHT MUST BE GREATER THAN ZERO')
        disp(' PRESS ENTER TO CONTINUE')
        pause;
     else
        Q1 = Q1hold;
     end
end

elseif mm ==5
Q2hold = input(' Input the DMC Weighting on the MV 2 Change: ' );
if isempty(Q2hold)~= 1
     if(Q2hold<0)
        disp('')
        disp(' WEIGHT MUST BE GREATER THAN ZERO')
        disp(' PRESS ENTER TO CONTINUE')
        pause;
     else
        Q2 = Q2hold;
     end
end

elseif mm == 6 

NNhold = input(' Input the DMC Output (CV) Horizon: ');
if isempty(NNhold)~=1
     NNhold = round (NNhold);
     if (NNhold<1) | (NNhold>maxouthorz)
         disp('')
         disp(' NOT A VALID SELECTION, MUST BE WITHIN SPECIFIED RANGE')
         disp(' PRESS ENTER TO CONTINUE')
         pause;
     else
         NN = NNhold;
     end
end

elseif mm == 7

W1hold = input(' Input the DMC Weighting on the CV 1 Deviation: ' );
if isempty(W1hold)~= 1
     if(W1hold<0);
        disp('')
        disp(' WEIGHT MUST BE GREATER THAN ZERO')
        disp(' PRESS ENTER TO CONTINUE')
        pause;
     else
        W1 = W1hold;
     end
end

elseif mm == 8
W2hold = input(' Input the DMC Weighting on the CV 2 Deviation: ' );
if isempty(W2hold)~= 1
     if(W2hold<0);
        disp('')
        disp(' WEIGHT MUST BE GREATER THAN ZERO')
        disp(' PRESS ENTER TO CONTINUE')
        pause;
     else
        W2 = W2hold;
     end
end

elseif mm == 9              %  DESIGN DMC

    dmc_diff                %  difference equations
    dmc_coef                %  "A" matrix
    dmc_des                 %  controller calculation
    dmccalc = 1;            %  set variable indicating design completed

elseif mm == 10

break

clc 

end % IF

end     % WHILE


