function gfactor=m5346gfact(x,Ngust,errorcheck)
%
% function gfact=gfact(x,Ngust)
%
% Calculates a gust factor for signal x.  This version of the gust factor is the
% maximum of the ratio of the mean of a small window (size Ngust) and a
% large window (size length(x));
%
% Inputs:
%
% x  a column vector of wind speeds.  The length(x)
%    is used as the window length.
%
% Ngust  Integer number of samples used for gust mean
%
% errorcheck  Set errorcheck==1 to test for parameter mistakes.
%
% Outputs:
%
% gfact=gust factor which is 
%
%      max( max over all intervals of length Ngust)/mean(x)
%
% Note that the longer analysis window is determined by the length of x.
%

Nmax=length(x)-Ngust+1;

xmat=zeros([Nmax Ngust]);

for k=1:Ngust   % Stack data for mean calculation
   xmat(:,k)=x(k:(Nmax+k-1));
end % end of k loop

gfactor=max(max(xmat'))/mean(x);
