function mn = mean_nan(x);
%
% function returns the mean of the non-NaN values of array x

ibad = find(isnan(x));

if isempty(ibad)
  mn = mean(x);
  return
end

igood = ~isnan(x);
x(ibad) = 0 * ibad;
mn = sum(x) ./ sum(igood);
