function ArrayOut = PosTrunc(ArrayIn, maxTime)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Truncate an nxm array of data so that the first column, assumed
% to be monotonically increasing, does not go past the specified value.  
% AUTHOR:  Rob McEwen
% DATE:    00/6/1, revised 14/3/10.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

 ArrayDim = size(size(ArrayIn),2);
 if ArrayDim > 2
   ArrayOut = ArrayIn;
   disp 'PosTrunc. Error: Dimension of Array is > 2.'
   return
 end
 
 if ~isempty(find(diff(ArrayIn(:,1))<0))
   ArrayOut = ArrayIn;
   disp 'PosTrunc. Error: Time is not monotonic.'
   return
 end

 indx = find(ArrayIn(:,1)<=maxTime);
 if isempty(indx)
   ArrayOut = ArrayIn;
   return
 end
 
 ArrayOut=ArrayIn(indx,:);

 return;
