lat = 36.805:-(36.805-36.782)/100:36.782;
lon = -121.792:-(-121.792-(-121.878))/100:-121.878;

timeNow = now - (5 / (24 * 60));
for i=1:101;
    lat(i) = lat(i) + 0.001 * (rand - 0.5);
    lon(i) = lon(i) + 0.001 * (rand - 0.5);
    timeOfFix(i) = timeNow + (i / (24*3600));
end

numPts = 10;
firstPt = 1;
for j=1:101-numPts
    j
    lastPt = firstPt + numPts;

    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,'   <NetworkLink>\n');
%     fprintf(fid,'      <flyToView>1</flyToView>\n');
%     fprintf(fid,'      <refreshVisibility>0</refreshVisibility>\n');
%     fprintf(fid,'   </NetworkLink>\n\n');

    fprintf(fid,'   <Placemark>\n');
    fprintf(fid,'      <gx:Track>\n');
    for i=firstPt:lastPt
        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>Paragon</name>\n');
    fprintf(fid,'     <Model id="Paragon">\n');
    fprintf(fid,'        <Location id="Paragon Model Location">\n');
    fprintf(fid,'           <longitude>%3.9f</longitude>\n',lon(lastPt));
    fprintf(fid,'           <latitude>%3.9f</latitude>\n',lat(lastPt));
    fprintf(fid,'           <altitude>0</altitude>\n');
    fprintf(fid,'        </Location>\n');
    fprintf(fid,'        <Orientation>\n');
    fprintf(fid,'           <heading>180</heading>\n');
    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,'       <Camera>\n');
    fprintf(fid,'          <longitude>%3.9f</longitude>\n',lon(lastPt));
    fprintf(fid,'          <latitude>%3.9f</latitude>\n',lat(lastPt));
    fprintf(fid,'          <altitude>5000</altitude>\n');
 %  fprintf(fid,'          <tilt>0</tilt>\n');
 %  fprintf(fid,'          <heading>0</heading>\n');
    fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    fprintf(fid,'       </Camera>\n\n');

    fprintf(fid,'</Document>\n');
    fprintf(fid,'</kml>\n');
    
    fclose(fid);
    firstPt =firstPt + 1;
    pause(2);
end