function [zdot, isterminal, direction] = level(s, z, flag)
% LEVEL  generates the right-hand side of 
%        the differential equation for the 1-lines of
%        f(z) = 1 + z + z^2/2! + ... + z^n/n!

global n

if nargin<3 | isempty(flag),
   t = 1;  f0 = 0; f = t;
   for k = 1:n, t = t*z/k; f0 = f;  f = f + t; end;
   q = f/f0; zdot = i*q/abs(q);  
else
   switch(flag)
   case 'events'
      zdot= imag(z);
      isterminal= 1;
      direction= -1;
   otherwise
      error(['Unknown flag: ', flag]); 
   end;
end

