function ArrayOut = NegTrunc(ArrayIn)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Truncate the first n rows of an nxm array of data so that the first
% column, assumed to be monotonically increasing, does not have any negative
% values.  
% AUTHOR:  Rob McEwen
% DATE:    00/6/1
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

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

 negIndx = find(ArrayIn(:,1)<0);
 if isempty(negIndx)
   ArrayOut = ArrayIn;
   return
 end
 
 ArrayOut=ArrayIn(max(negIndx)+1:length(ArrayIn(:,1)),:);

 return;