function [out,out1]=mkl_utils(varargin); %#ok<STOUT>

%	Place holder for the corresponding mex file used in time domain
%       enhanced performance based on Intel MKL calls
%
%   mkl_utils('residual',out,model,u,v,a,opt,Case)
%
%   To force the use of the M file implementation, use
%   opt=feutilb('mkl_utilsm',opt);
%   which edits the residual to use a call of the form
%   'opt.mkl(''residual'',out,model,u,v,a,opt,Case)'


%       Etienne Balmes, Guillaume Vermot des Roches
%       Copyright (c) 1990-2016 by SDTools, All Rights Reserved.
%       Use mkl_utils('cvs') for revision information

%#ok<*NOSEM>

if exist(['mkl_utils.' mexext],'file');
    error(['You should use the mkl_utils.%s file \n'...
     'check that your current directory is not the SDT base directory.'],mexext)
end
if nargin==0; CAM=''; Cam=''; else; [CAM,Cam]=comstr(varargin{1},1); end 

if comstr(Cam,'residual')
 out=varargin{2}; model=varargin{3};
 u=varargin{4}; v=varargin{5}; a=varargin{6};  
 opt=varargin{7}; %Case=varargin{8};  %
 if nargin>7; Case=varargin{8}; else; Case.uva=[]; end
 if isstruct(model); K=model.K; elseif iscell(model); K=model; end
 if length(K)~=3; error('model.K must be a 3*1 cell array'); end
 if isstruct(opt)
  try; Rayleigh=opt.Rayleigh; catch; Rayleigh=[0 0]; end
 elseif length(opt)==2;
  Rayleigh=opt;
 else
  Rayleigh=[0 0]; % alphaM + betaK
 end
  if isfield(model,'NL')
   r=evalin('caller','r'); %#ok<NASGU>
   out=nl_spring('fnlcompute');
  end
 if isempty(a) % static
  r=K{3}*u+out;
 elseif isfield(opt,'HHTalpha') % HHT formulation
  aNum=opt.HHTalpha; iaNum=1-aNum; uva=Case.uva;
  r=K{1}*(a+iaNum*(Rayleigh(1)*v)+aNum*Rayleigh(1)*uva(:,2))+...
      K{3}*(iaNum*(u+Rayleigh(2)*v)+aNum*(uva(:,1)+Rayleigh(2)*uva(:,2)))+...
      iaNum*out+aNum*uva(:,4);
 else % nlnewmark
  r=K{1}*(a+Rayleigh(1)*v)+K{2}*v+K{3}*(u+Rayleigh(2)*v)+out;
 end
 sp_util('setinput',out,r,zeros(1));%int32(1:length(out)),int32(1));

elseif comstr(Cam,'cvs')
    out='$Revision: 1.18 $  $Date: 2016/02/02 15:30:07 $';
elseif isempty(Cam)
    out=0;
else
    error('%s non supported by mkl_utils.m',CAM);
end