Code covered by the BSD License  

Highlights from
mexPutVariableSharedDataCopy

image thumbnail

mexPutVariableSharedDataCopy

by

 

This C routine puts a shared data copy of a variable into a workspace from a mex routine

mexPutVariableSDCtest(varargin)
%  Y = mexPutVariableSDCtest(X) tests the mexPutVariableSharedDataCopy function
% /*************************************************************************************
%  *
%  * MATLAB (R) is a trademark of The Mathworks (R) Corporation
%  *
%  * Filename:    mexPutVariableSDCtest.c
%  * Programmer:  James Tursa
%  * Version:     1.00
%  * Date:        June 13, 2013
%  * Copyright:   (c) 2013 by James Tursa, All Rights Reserved
%  *
%  *  This code uses the BSD License:
%  *
%  *  Redistribution and use in source and binary forms, with or without 
%  *  modification, are permitted provided that the following conditions are 
%  *  met:
%  *
%  *     * Redistributions of source code must retain the above copyright 
%  *       notice, this list of conditions and the following disclaimer.
%  *     * Redistributions in binary form must reproduce the above copyright 
%  *       notice, this list of conditions and the following disclaimer in 
%  *       the documentation and/or other materials provided with the distribution
%  *      
%  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
%  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
%  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
%  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
%  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
%  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
%  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
%  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
%  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
%  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
%  *  POSSIBILITY OF SUCH DAMAGE.
%  *
%  *  This file is a test mex routine for the mexPutVariableSharedDataCopy function.
%  *  It is typically self-building as long as this file and the associated m-file
%  *  mexPutVariableSDCtest.m are in the same directory somewhere on the MATLAB
%  *  path. The signature is as follows:
%  *
%  *  Y = mexPutVariableSDCtest( X )
%  *
%  *  The input variable X is any variable. The output variable Y will be a shared
%  *  data copy of X.  Also, a variable called 'sdc' will be put directly into
%  *  the caller workspace that is a shared data copy of X.
%  *
%  * Change Log:
%  * 2013/Jun/13 --> 1.00, Initial Release
%  *
%  ****************************************************************************/

function varargout = mexPutVariableSDCtest(varargin)
fname = 'mexPutVariableSDCtest';
disp(' ');
disp(['Detected that the mex routine for ' fname ' is not yet built.']);
disp('Attempting to do so now ...');
disp(' ');
try
    mname = mfilename('fullpath');
catch
    mname = fname;
end
cname = [mname '.c'];
if( isempty(dir(cname)) )
    disp(['Cannot find the file ' fname '.c in the same directory as the']);
    disp(['file ' fname '.m. Please ensure that they are in the same']);
    disp('directory and try again. The following file was not found:');
    disp(' ');
    disp(cname);
    disp(' ');
    error(['Unable to compile ' fname '.c']);
else
    disp(['Found file ' fname '.c in ' cname]);
    disp(' ');
    disp('Now attempting to compile ...');
    disp('(If prompted, please press the Enter key and then select any C/C++');
    disp('compiler that is available, such as lcc.)');
    disp(' ');
    disp(['mex(''' cname ''',''-output'',''',mname,''')']);
    disp(' ');
    try
        mex(cname,'-output',mname);
        disp([ fname ' mex build completed ... you may now use ' fname '.']);
        disp(' ');
    catch
        disp(' ');
        error(['Unable to compile ' fname ' ... Contact author.']);
    end
    varargout{1} = '(Use up-arrow and reissue the command you just entered ...)';
%   [varargout{1:nargout}] = mexPutVariableSDCtest(varargin{:});
end
end

Contact us