function pwr_kml_3d(Name,TLL,TDR)
%pwr_kml_3d(Name,TLL,TDR)
%
%Description:
% Converts a track and time-depth record to a 3D google earth
% path. the input variable TDR defines the date range and resolution.
%
%Inputs:
% Name: a string containing the desired filename (without the '.kml'
% extension)
%
% TLL: a matrix containing [Time Latitude Longitude]. Time is in the
% standard matlab serial format
%
% TDR: a matrix containing [Time Depth].
%
%Outputs:
% A KMZ (compressed KML) files.
%
%Comments:
% -Google earth has a limitation with respect to the amount of data
% visible at any given time. Files containing more than ~75,000 points
% may cause problems when viewing the entire track.
%
% -If the tracks do not appear 3D, be sure the "terrain" setting in
% google earth is activated
%
%Credit:
% Patrick Robinson
% 2012-05-26 V1.0
%create header and footer XML
header='<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2"><Folder> <StyleMap id="default"><Pair><key>normal</key><styleUrl>#default0</styleUrl></Pair><Pair><key>highlight</key><styleUrl>#hl</styleUrl></Pair></StyleMap><Style id="hl"><IconStyle><Icon></Icon></IconStyle><ListStyle></ListStyle></Style><Style id="default0"><IconStyle><Icon></Icon></IconStyle><ListStyle></ListStyle></Style><Placemark><styleUrl>#default</styleUrl><gx:Track><altitudeMode>absolute</altitudeMode>';
footer='</gx:Track></Placemark></Folder></kml>';
%Calculate a geographic position for each depth reading
TLL=yt_interpol_linear_2(TLL,TDR(:,1));
%Create a single variable with location and depth data
TLLD=[TLL TDR(:,2)];
%Create XML text data for each time stamp and each position/depth pair
TimeData=[repmat('<when>',size(TLLD,1),1) datestr(TLLD(:,1),'yy-mm-dd') repmat('T',size(TLLD,1),1) datestr(TLL(:,1),'HH:MM:SS') repmat('Z</when>',size(TLLD,1),1)];
LocData=[repmat('<gx:coord>',size(TLLD,1),1) num2str(TLLD(:,3)) repmat(' ',size(TLLD,1),1) num2str(TLLD(:,2)) repmat(' ',size(TLLD,1),1) num2str(-TLLD(:,4)) repmat('</gx:coord>',size(TLLD,1),1)];
%Create file to deposit data and write headers
fid = fopen([Name '.kml'], 'wt');
fprintf(fid, '%s \n',header);
fprintf(fid, '%s \n', rot90(flipud(TimeData),-1));
fprintf(fid, '%s \n', rot90(flipud(LocData),-1));
fprintf(fid, '%s', footer);
fclose(fid)
%Convert file from KML to KMZ
zip(Name,[Name '.kml']);
copyfile([Name '.zip'],[Name '.kmz']);
delete([Name '.zip']);
delete([Name '.kml']);