function [ZOUT,AFTER,NOW,BEFORE] = fftstep ( ZIN, AFTER, NOW, BEFORE )

% called in FFT; carries out one step of the discrete fast Fourier transform
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
ANGLE = 2*pi/(NOW*AFTER); OMEGA = cos(ANGLE) - 1i*sin(ANGLE); ARG = 1;
ZIN = reshape(ZIN,[AFTER,BEFORE,NOW]); ZOUT = zeros(AFTER,NOW,BEFORE);
for J=1:NOW
   for IA=1:AFTER
      for IB=1:BEFORE
         value = ZIN(IA,IB,NOW);
         for IN=NOW-1:-1:1
            value = value*ARG + ZIN(IA,IB,IN);
         end
         ZOUT(IA,J,IB) = value;
      end
      ARG = ARG*OMEGA;
   end
end

  return
end

