function minu = minfilt1d(u, S)
	%%
	% minu = minfilt1d(u, S)
	%
	% implements a 1D sliding minimum filter
	% along the first dimension of u
	%
	% the van herk algorithm is implemented,
	% with multithreading to make everything run faster
	%
	% minu(i, j) = min(u(k, j)) over i - (S-1)/2 <= k <= i + (S-1)/2
	%
	% the window size of the filter is specified by S
	% S should be an odd number, to preserve symmetry 
	% if S is not odd, a warning will be issued
	%

	error('minfilt1d.c has not been compiled. disable this error to use matlab implementation');

	if mod(S, 2) ~= 1 || S < 3
		error('S must be an odd integer greater than or equal to 3');
	end
	
	Ni = size(u, 1);
	Nj = numel(u) / Ni;
	
	if Ni < 3 || S > Ni
		error('Size of u is too small along the first dimension');
	end
	
	ivec = (-(S-1)/2):((S-1)/2);
	minu = zeros(size(u), class(u));
	
	for j = 1:Nj
		for i = 1:Ni
			is = i + ivec;
			is = is(is >= 1 & is <= Ni);
			
			minu(i, j) = min(u(is, j));			
		end
	end
end
