After optimizing the reading loop with using double array variables for counting and recompiling a complicate mathfunction for distance calculation with Andrews MathRecompiler I managed to speed up the loading of the file amazingly (before optimization: 32 secods, after: 15 seconds).
I extracted the reading of the binary file to a small test program and after using double array variables in this test program too the loading of a 480kB file just took about 4 seconds on my ASUS A696. I think that's OK.
So in my application I have 4 seconds for reading of the file and 11 seconds for processing the data.
If you are interested, here is my complete Reading function now:
Code:
Sub Globals
Dim minMaxLatLon(4) As Double
Dim latLon(2) As Double
Dim oldLatLon(2) As Double
Dim numPts(2) As Double
Dim distpoints(2) As Double
End Sub
Public Sub ReadTrack(pFileName)
distPoints(0) = Settings.prefs.OptimizeGPXMinDistance
distPoints(1)=0
oldLatLon(0)=0
oldLatLon(1)=0
numPts(0) = 0
numPts(1) = 0
DataSource.numWayPts = 0
minMaxLatLon(0) = 99999999
minMaxLatLon(1) = -99999999
minMaxLatLon(2) = 99999999
minMaxLatLon(3) = -99999999
WaitCursor(True)
DoEvents
FileOpen(c1, pFileName, cRandom)
br.New1(c1, True)
br.Position = 0
Utils.InitProgress("Main.fMain", "Loading Training", 0, Round(br.Length/1024))
br.ReadString
fileVersion = br.ReadInt32
br.Offset(32)
DataSource.sqlcon.BeginTransaction
Do While br.Position < br.Length
br.ReadInt32 'entryType
latLon(0) = br.ReadDouble 'latitude
latLon(1) = br.ReadDouble 'longitude
If fileVersion >= 230 Then
br.Offset(72)
Else If fileVersion >= 229
br.Offset(56)
Else
br.Offset(40)
End If
If Settings.prefs.OptimizeGPX = 1 Then
If oldLatLon(0) <> 0 Then
distPoints(1) = GPXUtil.Distance_AsDouble(oldLatLon(0), oldLatLon(1), latLon(0), latLon(1))
Else
numPts(1) = numPts(1) + DataSource.AddLatLon(latLon(0), latLon(1), "trkpt")
oldLatLon(0)=latLon(0)
oldLatLon(1)=latLon(1)
SetMinMax
End If
If distPoints(1) > distPoints(0) Then
numPts(1) = numPts(1) + DataSource.AddLatLon(latLon(0), latLon(1), "trkpt")
oldLatLon(0)=latLon(0)
oldLatLon(1)=latLon(1)
SetMinMax
End If
Else
numPts(1) = numPts(1) + DataSource.AddLatLon(latLon(0), latLon(1), "trkpt")
SetMinMax
End If
numPts(0) = numPts(0) + 1
If numPts(0) Mod 100 = 0 Then
Utils.SetProgress(Round(br.Position/1024), "Koords: " & numPts(0))
Main.hw.KeepAlive
End If
Loop
DataSource.sqlcon.EndTransaction
DataSource.minLat = minMaxLatLon(0)
DataSource.maxLat = minMaxLatLon(1)
DataSource.minLon = minMaxLatLon(2)
DataSource.maxLon = minMaxLatLon(3)
DataSource.numTrkPts = numPts(0)
DataSource.numUnique = numPts(1)
WaitCursor(False)
FileClose(c1)
Utils.ClearProgress
Return True
End Sub
Sub SetMinMax
If minMaxLatLon(0) > latLon(0) Then
minMaxLatLon(0) = latLon(0)
Else If minMaxLatLon(1) < latLon(0) Then
minMaxLatLon(1) = latLon(0)
End If
If minMaxLatLon(2) > latLon(1) Then
minMaxLatLon(2) = latLon(1)
Else If minMaxLatLon(3) < latLon(1) Then
minMaxLatLon(3) = latLon(1)
End If
End Sub
If you find something that I can do better please inform me. I still need to have a look at the DataSource.AddLatLon() function which adds the koordinates to a SQL table. Perhaps there is again some potential for optimizing.
I have attached my test program also so if you have some ideas of improving the speed while reading ... every second counts in my program.
Thanks,
Markus