function [output]=nancumsum(input);
%
% function [output]=nancumsum(input);
%
% This function is designed to find the cumulative sum of each column in an
% array that includes NaNs.  (If the input array has no NaNs the
% function will still work but in not as efficient as the Matlab "cumsum"
% function.)  If you wish to use this on a vector make sure it is a 
% column vector or it will not work.
%
[m,n]=size(input);
output=NaN*ones(m,n);
for i=1:n
  dummy=input(:,i);
  ii=find(~isnan(dummy));
  output(ii,i)=cumsum(dummy(ii));
end
