function doCNRDiff(Compiled);
%
% Compiled - (=0) Called by Matlab; (=1) Standalone application.
%            If the compiled flag is ommitted it will assume the
%            application is not compiled
%

FALSE      = 0;
TRUE       = 1;
ASCII_ZERO = 48 ;
ASCII_ONE  = 49 ;

% Check for input parameters, and convert from strings to numbers for
% the compiled version.
%
% First must check if using compiled StandAlone version. This passes
% parameters as strings (parameters from Matlab are numbers).
% Note: if the Compiled version uses no parameters, this is an error
% that cannot be detected (defaults to "not compiled").
%
if( nargin == 1 )
  if( Compiled == ASCII_ZERO )
    % Compiled application passing "not compiled". This is an error.
    fprintf( 'ERROR! Compiled Application must set flag\n' ) ;
    return ;
  elseif( Compiled == ASCII_ONE )
    Compiled = TRUE ;
  else
    % Running Matlab and passing 0 or 1 (as a number).
    % To 'simulate' running the Compiled version from Matlab, the
    % parameter 'Compiled' must be passed as the string '1'. See header.
    Compiled = FALSE ;
  end
else
  % Default to not compiled if there are 2 or fewer input parameters
  Compiled = FALSE;
end

% L1 
figure('Visible','off');
PlotCNRDiff(1, Compiled);

%L2
figure('Visible','off');
PlotCNRDiff(2, Compiled);

%
% Now clean up and exit
%

if( Compiled == TRUE)
  % The compiled version of Matlab does not internally support .png.
  % Therefore the graphics are saved as bitmaps and converted here using
  % an external freeware utility.
  dos(['bmp2png *.bmp'])
  dos(['erase *.bmp'])
  
  % Graphs displayed during processing, but must close now to enable the
  % compiled version to terminate back to DOS.
  close all
end

exit;


