unit gpxunit; {$mode objfpc}{$H+} interface uses Classes, SysUtils, mystringlistunit; type tTrkPt = record lat,lon,ele,time: string; end; tTrack = record name: string; trkPts: array of tTrkPt; end; tGpxInhalt = record kopf: string; trks: array of tTrack; end; tGpxFile = class prefix: tMyStringList; gpx: array of tGpxInhalt; constructor create; destructor destroy; override; function loadFromFile(s: string): boolean; procedure saveToFile(s: string); end; implementation uses lowlevelunit, dialogs; constructor tGpxFile.create; begin inherited create; prefix:=tMyStringList.create; setLength(gpx,0); end; destructor tGpxFile.destroy; begin prefix.free; setLength(gpx,0); inherited destroy; end; function tGpxFile.loadFromFile(s: string): boolean; var f: tMyStringList; m: longint; t,u: string; begin result:=false; prefix.clear; setLength(gpx,0); f:=tMyStringList.create; f.loadFromFile(s); f.splitLines('<','>'); m:=0; t:=''; f.rewind; while f.readln(t) do case m of 0: if startetMit(''); inc(m); end else prefix.add(t); 1: if t='' then begin setLength(gpx[length(gpx)-1].trks,length(gpx[length(gpx)-1].trks)+1); gpx[length(gpx)-1].trks[length(gpx[length(gpx)-1].trks)-1].name:=''; setLength(gpx[length(gpx)-1].trks[length(gpx[length(gpx)-1].trks)-1].trkPts,0); inc(m); end else if t='' then dec(m); 2: if t='' then begin t:=''; u:=''; repeat t:=t+#10+u; if not f.readln(u) then exit; until u=''; delete(t,1,2); gpx[length(gpx)-1].trks[length(gpx[length(gpx)-1].trks)-1].name:=t; end else if t='' then inc(m) else if t='' then dec(m); 3: if startetMit('',t)>0 then dec(m); end{of Case}; f.free; result:=true; end; procedure tGpxFile.saveToFile(s: string); var f: textFile; i,j,k: longint; begin assignFile(f,s); rewrite(f); writeln(f,prefix.text); for i:=0 to length(gpx)-1 do begin writeln(f,''); for j:=0 to length(gpx[i].trks)-1 do begin writeln(f,' '); while pos('<',gpx[i].trks[j].name)>0 do gpx[i].trks[j].name[pos('<',gpx[i].trks[j].name)]:='-'; while pos('>',gpx[i].trks[j].name)>0 do gpx[i].trks[j].name[pos('>',gpx[i].trks[j].name)]:='+'; writeln(f,' '+gpx[i].trks[j].name+''); writeln(f,' '); for k:=0 to length(gpx[i].trks[j].trkPts)-1 do begin writeln(f,' '); writeln(f,' '+gpx[i].trks[j].trkPts[k].ele+''); writeln(f,' '); writeln(f,' '); end; writeln(f,' '); writeln(f,' '); end; writeln(f,''); end; closeFile(f); end; end.