% **************************************************************************
% CASCADE-FEEDFORWARD CONTROL SIMULATOR 
% COPYRIGHT (C) 1994, T.E. MARLIN
%
% FILENAME : CFFGRAPH.M
% WRITTEN BY : F.BOUDREAU
% VERSION : 2.0
% LAST UPDATED : NOVEMBER 1994
% DESCRIPTION OF FILE :
%    PLOTS SIMULATION RESULTS. NO MATTER WHAT IS THE CURRENT VALUE 
%    OF THE CONTROL STRUCTURE FLAG (CASCADE OR SINGLE-LOOP), THE PLOTS
%    ARE SHOWN IN THE FORMAT APPROPRIATE FOR THE MODE OF THE LAST
%    SIMULATION.  'CASCADEsave' CONTAINS THE VALUE OF 'CASCADE' DURING
%    THE LAST SIMULATION. 
% 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
% **************************************************************************

if CASCADEsave == 1   % i.e. IF LAST SIMULATION WAS USING CASCADE
   % FIRST SCREEN:
   clg;
   axis('auto')

   % PLOT PRIMARY CONTROLLED VARIABLE AND ITS SET-POINT:
   subplot(2,2,1), plot(t(ind),Y1m(ind),'-g',t(ind),SP1(ind),'--r');
   title(['IAE = ',num2str(IAE1),' ISE = ',num2str(ISE1)]);
%  xlabel('Time'); 
   ylabel(Y1nam);
   % PLOT SECONDARY CONTROLLED VARIABLE AND ITS SET-POINT:
   subplot(2,2,3), plot(t(ind),Y2m(ind),'-g',t(ind),SP2(ind),'--r');
   title(['IAE = ',num2str(IAE2),' ISE = ',num2str(ISE2)]);
   xlabel('Time');ylabel(Y2nam);
   % PLOT MANIPULATED VARIABLE:
   subplot(2,2,4), plot(t(ind),C2(ind),'-g');
   title(['SAM = ',num2str(SAM2),' SSM = ',num2str(SSM2)]);
   xlabel('Time'); ylabel(MVnam);
   figure (1)
   pause;

   % SECOND SCREEN:
   clg;
   % PLOT PRIMARY CONTROLLED VARIABLE AND ITS SET-POINT:
   subplot(2,2,1), plot(t(ind),Y1m(ind),'-g',t(ind),SP1(ind),'--r');
   title(['IAE = ',num2str(IAE1),' ISE = ',num2str(ISE1)]);
%  xlabel('Time'); 
   ylabel(Y1nam);
   % PLOT SECONDARY CONTROLLED VARIABLE AND ITS SET-POINT:
   subplot(2,2,2), plot(t(ind),Y2m(ind),'-g',t(ind),SP2(ind),'--r');
   title(['IAE = ',num2str(IAE2),' ISE = ',num2str(ISE2)]);
%  xlabel('Time');
   ylabel(Y2nam);
   % PLOT PRIMARY DISTURBANCE:
   subplot(2,2,3), plot(t(ind),D1m(ind),'-g')
   xlabel('Time'); ylabel(D1nam);
   % PLOT SECONDARY DISTURBANCE
   subplot(2,2,4), plot(t(ind),D2(ind),'-g')
   xlabel('Time'); ylabel(D2nam);
   figure (1)
   pause
   close all

else          % show plots for single-loop control

   % FIRST SCREEN:
   clg;
   % PLOT CONTROLLED VARIABLE AND ITS SET-POINT:
   subplot(2,1,1), plot(t(ind),Y1m(ind),'-g',t(ind),SP1(ind),'--r');
   title(['IAE = ',num2str(IAE1),' ISE = ',num2str(ISE1)]);
%  xlabel('Time'); 
   ylabel(Y1nam);
   % PLOT MANIPULATED VARIABLE:
   subplot(2,1,2), plot(t(ind),C2(ind),'-g');
   title(['SAM = ',num2str(SAM2),' SSM = ',num2str(SSM2)]);
   xlabel('Time'); ylabel(MVnam);
   figure (1)
   pause;

   % SECOND SCREEN:
   clg;
   % PLOT CONTROLLED VARIABLE AND ITS SET-POINT:
   subplot(2,2,1), plot(t(ind),Y1m(ind),'-g',t(ind),SP1(ind),'--r');
   title(['IAE = ',num2str(IAE1),' ISE = ',num2str(ISE1)]);
%  xlabel('Time'); 
   ylabel(Y1nam);
   % PLOT PRIMARY DISTURBANCE:
   subplot(2,2,3), plot(t(ind),D1m(ind),'-g')
   xlabel('Time'); ylabel(D1nam);
   % PLOT SECONDARY DISTURBANCE
   subplot(2,2,4), plot(t(ind),D2(ind),'-g')
   xlabel('Time'); ylabel(D2nam);
   figure (1)
   pause   
   close all

end % if
return



