function nav_from_carolyn2(txt_root,adi_dir,z0,BATHY)
%
% Call nav_from_carolyn(xls_root,adi_dir,z0,BATHY);
%
% Converts text files containing CC NAV to NAV files
%
% Example call:     nav_from_carolyn('CC_Phase2_all',GUI.adi_dir,6,BATHY);
%
% 10/7/2002 11:50	41 23.094 N	72 05.416 W	
%
% 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([txt_root,'*.txt']), nfile=length(D);
%
fmt = '%f%c%f%c%f%f%c%f%f%f%c%f%f%c';
%
for jfile=1:nfile,
    [month,sl1,day,sl2,year,hour,colon,minute,lat_deg,lat_min,NS,long_deg,long_min,EW]= ...
        textread(D(jfile).name,fmt,-1);
    Jday=date_to_Jday(month,day,year);
    iisg_ns=1; if strcmp(NS(1),'S'), iisg_ns=-1; end
    iisg_ew=1; if strcmp(EW(1),'W'), iisg_ew=-1; end
    NAV.nav_file=[D(jfile).name(1:end-4),'_',int2str(Jday(1)),'_NAV'];
    NAV.log_file=D(jfile).name;
	NAV.jday=Jday(1);
	hour=(Jday - Jday(1))*24 + hour + minute/60;
    [hour_sort,ii0]=unique(hour);
    ii1=find(diff(hour_sort)>0); ii=ii0(ii1);
    NAV.hour=hour(ii);
	NAV.min=(NAV.hour-NAV.hour(1) ) * 60;		% Minute after start of file
	NAV.lat=iisg_ns*(lat_deg(ii) + lat_min(ii)/60);
	NAV.long=iisg_ew*(long_deg(ii) + long_min(ii)/60);
	NAV.bathy_root=BATHY.bathy_root;
	[NAV.xkm,NAV.ykm]=bathy_ll2xy(NAV.lat,NAV.long);
    NAV.z=z0*ones(size(NAV.xkm));
	vx=gradient(NAV.xkm,NAV.hour); vy=gradient(NAV.ykm,NAV.hour);
	v=sqrt(vx.^2 + vy.^2) * (1000/3600);
    NAV.v=v;
    NAV.phi=atan2(vx,vy);
%
    str=['save ',adi_dir,NAV.nav_file,' NAV']; disp(str); eval(str);
end
