function [out1, out2, out3] = threeDmodelstmfdsearchthree(t,x,flag,param)
%
% 

a=param(1);
eps=param(2);
gamma=param(3);
c=param(4);

v=x(1);u=x(2);w=x(3);

f=v.*(v-a).*(1-v);
scl=1;
if nargin < 3 || isempty(flag)
out1 = [u; 
        c*u/scl-f+w;
        scl*eps*(v-gamma*w)/c];
else
   switch(flag)
   case 'init'
     out1 = [0; 50];
     out2 = [0 0 0];
     out3 = []; %odeset('Vectorized', 1);
     case 'events' 
     %sec1 = (v/.1).^2+(u/.1).^2+(w/.015).^2-9; 
     %sec2 = w; 
     sec3 = w-.015; 
     out1 = [sec3];
     out2 = [1];
     out3 = [1];
   otherwise
      error(['Unknown flag ''' flag ''.']);
   end
end; 
