function writeKMLFile(lat, lon, heading, GEZoom)
    fid = fopen('kmlTrackTest.kml', 'w');
    
    fprintf(fid,'<?xml version="1.0" encoding="UTF-8"?>\n');
    fprintf(fid,'<kml xmlns="http://www.opengis.net/kml/2.2"\n');
    fprintf(fid,' xmlns:gx="http://www.google.com/kml/ext/2.2">\n');
   
    fprintf(fid,'<Document>\n');

    fprintf(fid,'   <Placemark>\n');
    fprintf(fid,'      <gx:Track>\n');
    for i=1:length(lon)
        fprintf(fid,'         <gx:coord>%3.9f %2.9f %3f </gx:coord>\n',lon(i), lat(i), 10);
    end
    
    fprintf(fid,'      </gx:Track>\n');
    
    fprintf(fid,'  </Placemark>\n\n');
    
%     fprintf(fid,'  <Placemark>\n');
%     fprintf(fid,'     <name>CPF003</name>\n');
%     fprintf(fid,'     <Model id="CPF003">\n');
%     fprintf(fid,'        <Location id="CPF003 Model Location">\n');
%     fprintf(fid,'           <longitude>%3.9f</longitude>\n', lon(end));
%     fprintf(fid,'           <latitude>%3.9f</latitude>\n', lat(end));
%     fprintf(fid,'           <altitude>0</altitude>\n');
%     fprintf(fid,'        </Location>\n');
%     fprintf(fid,'        <Orientation>\n');
%     fprintf(fid,'           <heading>%f</heading>\n', mod(heading + 180, 360));
%     fprintf(fid,'           <tilt>0</tilt>\n');
%     fprintf(fid,'           <roll>0</roll>\n');
%     fprintf(fid,'        </Orientation>\n');
%     fprintf(fid,'        <Scale>\n');
%     fprintf(fid,'           <x>1</x>\n');
%     fprintf(fid,'           <y>1</y>\n');
%     fprintf(fid,'           <z>1</z>\n');
%     fprintf(fid,'        </Scale>\n');
%     fprintf(fid,'        <Link>\n');
%     fprintf(fid,'           <href>Paragon.dae</href>\n');
%     fprintf(fid,'        </Link>\n');
%     fprintf(fid,'     </Model>\n');
%     fprintf(fid,'  </Placemark>\n\n');

    fprintf(fid,'       <LookAt>\n');
    fprintf(fid,'          <longitude>%3.9f</longitude>\n', lon(end));
    fprintf(fid,'          <latitude>%3.9f</latitude>\n', lat(end));
    fprintf(fid,'          <altitude>%f</altitude>\n', GEZoom);
    fprintf(fid,'       </LookAt>\n\n');

    fprintf(fid,'</Document>\n');
    fprintf(fid,'</kml>\n');
    
    fclose(fid);
end