function [file_sort,nfile]=dir_sort(file_suf)
%
% Does a directory listing of files matching file_suf and sorts them from oldest to newest
%
% Call  [file_sort,nfile]=dir_sort(file_suf), where
% file_suf      = File suffix or prefix, using asterisk(s) as wildcards.
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
D=dir(file_suf); nfile=length(D); if nfile==0, file_sort=[]; end
Jday_dec=zeros(1,nfile);
for jfile=1:nfile,
    date=D(jfile).date;
    day=str2num(date(1:2)); month=date(4:6); year=str2num(date(8:11)); 
    hour=str2num(date(13:14)); minute=str2num(date(16:17)); second=str2num(date(19:20));
    Jday=date_to_Jday(month,day,year);
    if jfile==1, year0=year; end
    Jday_dec(jfile)=(year-year0)*365 + Jday + (hour + minute/60 + second/3600)/24;
end
%
[Jday_sort,ii_sort]=sort(Jday_dec);
%
file_sort=cell(nfile,1);
for jfile=1:nfile,
    file_sort{jfile}=D(ii_sort(jfile)).name;
end
