% function [out,minimum,maximum]=range(x)
%
% routine to find min and max of elements with NaN
%
function [out,minimum,maximum]=rangejm(x)

t=length(find(isnan(x)==1));

if t>0;
  minimum=min(x(find(isnan(x)~=1)));
  maximum=max(x(find(isnan(x)~=1)));
  disp([' Includes ',num2str(t),' NaNs.']);
else;
  minimum=min(x);
  maximum=max(x);
end;

% in cast we are working with 2-d arrays
if length(minimum)>1;
  minimum=min(minimum);
  maximum=max(maximum);
end;

%
out=maximum-minimum;
disp(' ');
disp(['range: ',num2str(out),' min: ',num2str(minimum),' max: ',num2str(maximum)]);
disp(' ');