function s=cvstGetCoordsChoice(varargin)
% cvstGetCoordsChoice Returns preference of coordinate system.
%   S = cvstGetCoordsChoice returns MATLAB setting for the Computer Vision
%   System Toolbox coordinate system.
%
%   S = cvstGetCoordsChoice(clientName) returns double scalar S to
%   indicate preference of a coordinate system.  S is 1 for 
%   X, Y coordinates with origin at (1,1) and 0 for R, C coordinates with 
%   origin at (0,0). clientName is the name of a block, object or a 
%   function requesting its configuration.

%   Copyright 2011 The MathWorks, Inc.
%   $Revision: 1.1.6.4 $  $Date: 2011/05/09 03:47:06 $

% Notes on clientName conventions
% client name should be structured as follows:
% 'p1p2Name' where
%  p1 - vip or vis
%  p2 - blk or obj
%  Name - corresponds to the block, object or function name; for example
%         if we pick Find Local Maxima block in vipstatistics, the name
%         will be vipblkFindLocalMaxima
%

persistent wasInvoked;
mlock; % prevent the persistent variable from being easily cleared

newCoords = 1;
oldCoords = 0;

narginchk(0,1);

s = cvstSetCoordsChoice; % get persistent variable inside the set function

if nargin > 0 % process response for individual clients    
    clientName = varargin{1};
    
    validateattributes(clientName, {'char'},{'vector'});
    
    if strncmp(clientName, 'visblk', 6)
        s = newCoords; % vision blocks are always in new coords
        isWarning = false;
    elseif strncmp(clientName, 'vipblk', 6)
        s = oldCoords; % vip blocks are always in old coords
        isWarning = true;
    else
        % functions & objects respect the MLCoords preference
        isWarning = true; % always issue a warning
    end
    
    if isempty(wasInvoked) % Issue the warning only once per MATLAB session
        wasInvoked = true;
        
        usingDesktop = usejava('desktop') && desktop('-inuse') ...
            && feature('hotlinks');
        
        if usingDesktop
            link = sprintf('%s','<a href="matlab:vision.internal.showCoordRelNote">R2011b Release Notes</a>');
        else
            link = 'R2011b Release Notes';
        end
        
        if isWarning
            warning...
                ('vision:transition:usesOldCoordinates', ...
                ['The Computer Vision System Toolbox coordinate system changed. ',...
                'You invoked a function, System object, or block affected by ',...
                'the change. See ', link, ' for details.']);
        end
    end
else
    % Simply return the global MATLAB setting for the toolbox coordinate
    % system choice. Don't trigger the warning.    
end
