From f754bc8f4c3d598822bf6dd2fae19fc75099e108 Mon Sep 17 00:00:00 2001
From: "ankostis@host:STUW025" <ankostis@gmail.com>
Date: Mon, 23 Jun 2014 17:54:11 +0200
Subject: [PATCH] Use Exceptions instead of CancelAsync() and error-flags in
 calc-routines and input.vb.

* Remove unused distVincenty() func.
---
 CHANGES.md                                  |   5 +-
 CSE/Calculation/Minor_routines_calculate.vb |  78 +----------
 CSE/Calculation/Signal_identification.vb    |  21 +--
 CSE/Calculation/main_calculation_call.vb    | 136 ++++++++------------
 CSE/Classes/cFile_v3.vb                     |   6 +-
 CSE/GUI/F_Main.vb                           |   6 +-
 CSE/IO/cVehicle.vb                          |   1 -
 CSE/IO/input.vb                             | 109 ++++------------
 8 files changed, 93 insertions(+), 269 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index ed19527..8c46935 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -23,6 +23,7 @@ Mostly JRC contributions (see VECTO-29 & VECTO-35):
   * Sporadic fixes to work with filenames having 2-part extensions (ie `some_file.csjob.json`).
   * Log: Improve logging-API so now a single log-routine is used everywhere(instead of 3 different ones).
   * async: Stop abusing worker-Thread with Globals, use DoWorkEventArgs instead.
+  * async: Start using Exceptions instead of CancelAsync() and error-flags.
   * General restructuring of the folders and names in the project.
 
 
@@ -30,10 +31,12 @@ Mostly JRC contributions (see VECTO-29 & VECTO-35):
 More analytically:
 
 #### 2014-06-23: v2.0.1-pre3 ####
-TUG improvements:
+TUG & JRC improvements:
 
   * Changed comment symbol in CSV files from 'c' --> '#'
   * Unify hunits into header labels.
+  * Use Exceptions instead of CancelAsync() and error-flags in calc-routines and input.vb.
+  * Remove unused distVincenty() func.
 
 
 #### 2014-06-04: v2.0.1-pre2 ####
diff --git a/CSE/Calculation/Minor_routines_calculate.vb b/CSE/Calculation/Minor_routines_calculate.vb
index b40edd1..fae4621 100644
--- a/CSE/Calculation/Minor_routines_calculate.vb
+++ b/CSE/Calculation/Minor_routines_calculate.vb
@@ -353,9 +353,7 @@
             vline = FileInAlt.ReadLine
 
             If dist < vline(0) Then
-                logme(9, False, "The distance is lower then the minimum in the altitude file")
-                BWorker.CancelAsync()
-                fAltInterp = 0
+                Throw New Exception(format("The distance({0}) is lower then the minimum({1}) in the altitude file!", dist, vline(0)))
             End If
 
             Do While Not FileInAlt.EndOfFile
@@ -380,80 +378,6 @@
         End Using
     End Function
 
-    ' Length calculation out of coordinates MM.MM (Not used at the moment)
-    Public Function distVincenty(ByVal lat1 As Double, ByVal lon1 As Double, ByVal lat2 As Double, ByVal lon2 As Double, Optional ByVal Dist As Boolean = False) As Double
-        ' Declaration
-        Dim i As Integer
-        Dim L, C, U1, U2, sinU1, cosU1, sinU2, cosU2, lambda, lambdap, sinLambda, sinSigma, sinAlpha, cosLambda, cosSigma, cosSqAlpha, cos2SigmaM, sigma, deltaSigma As Double
-        Dim uSq, Ai, Bi, s, fwdAz, revAz As Double
-
-        ' Constant declarations
-        Const a = 6378137.0          ' WGS-84 ellipsoid params (major axis of the ellipsoid)
-        Const b = 6356752.314245     ' WGS-84 ellipsoid params (minor axes of the ellipsoid)
-        Const f = 1 / 298.257223563  ' WGS-84 ellipsoid params (Falttening)
-        Const iMax = 100             ' Maximum of iterrations
-        Const toRad = Math.PI / 180
-
-        ' Initialisation
-        L = (lon2 - lon1) * toRad
-        U1 = Math.Atan((1 - f) * Math.Tan(lat1 * toRad))
-        U2 = Math.Atan((1 - f) * Math.Tan(lat2 * toRad))
-        sinU1 = Math.Sin(U1)
-        cosU1 = Math.Cos(U1)
-        sinU2 = Math.Sin(U2)
-        cosU2 = Math.Cos(U2)
-        i = iMax
-        lambda = L
-        lambdap = lambda + 1
-
-        ' Calculate lambda
-        Do Until (Math.Abs(lambda - lambdap) < 0.000000000001 Or i = 0)
-            sinLambda = Math.Sin(lambda)
-            cosLambda = Math.Cos(lambda)
-            sinSigma = Math.Sqrt((cosU2 * sinLambda) ^ 2 + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) ^ 2)
-
-            If (sinSigma = 0) Then Return 0 ' co-incident points
-
-            cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda
-            sigma = Math.Atan2(sinSigma, cosSigma)
-            sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma
-            cosSqAlpha = 1 - sinAlpha * sinAlpha
-            cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha
-
-            If (IsNothing(cos2SigmaM)) Then cos2SigmaM = 0 ' equatorial line: cosSqAlpha=0 (§6)
-
-            C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha))
-            lambdap = lambda
-
-            lambda = L + (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)))
-            i -= 1
-        Loop
-
-        ' Erreor message wehen lambda can not be calculated
-        If i = 0 Then
-            logme(9, False, "Was not able to calculate the distance and bearing between koordinates.")
-            BWorker.CancelAsync()
-            Return 0  ' formula failed to converge
-        End If
-
-        ' Calculate the distance
-        If Dist Then
-            uSq = cosSqAlpha * (a ^ 2 - b ^ 2) / (b ^ 2)
-            Ai = 1 + uSq / 16384 * (4096 + uSq * (-768 + uSq * (320 - 175 * uSq)))
-            Bi = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq)))
-            deltaSigma = Bi * sinSigma * (cos2SigmaM + Bi / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - Bi / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)))
-            s = b * Ai * (sigma - deltaSigma)
-            Return s
-        Else
-            ' Calculate the bearings
-            fwdAz = Math.Atan2(cosU2 * sinLambda, cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * 1 / toRad    ' Forward azimut
-            revAz = Math.Atan2(cosU1 * sinLambda, -sinU1 * cosU2 + cosU1 * sinU2 * cosLambda) * 1 / toRad   ' Bering in direction P1--> P2
-
-            ' Correct the Angle
-            If revAz < 0 Then revAz = 360 + revAz
-            Return revAz
-        End If
-    End Function
 
     ' Calculate the UTM coordinates
     Function UTM(ByVal Lat As Double, ByVal Lon As Double) As cUTMCoord
diff --git a/CSE/Calculation/Signal_identification.vb b/CSE/Calculation/Signal_identification.vb
index 1648012..5882c5d 100644
--- a/CSE/Calculation/Signal_identification.vb
+++ b/CSE/Calculation/Signal_identification.vb
@@ -2,7 +2,7 @@
 Module Signal_identification
 
     ' Divide the signal into there directions
-    Public Function fIdentifyMS(ByVal MSC As cMSC, ByRef vMSC As cVirtMSC, Optional ByVal virtMSC As Boolean = True, Optional ByVal SectionDev As Boolean = True) As Boolean
+    Public Sub fIdentifyMS(ByVal MSC As cMSC, ByRef vMSC As cVirtMSC, Optional ByVal virtMSC As Boolean = True, Optional ByVal SectionDev As Boolean = True)
         If virtMSC Then
             ' Calculation of the virtual MSC points
             fvirtMSC(MSC, vMSC)
@@ -18,9 +18,7 @@ Module Signal_identification
             ' Leap in time control
             If JumpPoint <> -1 Then
                 If CalcData(tCompCali.SecID)(JumpPoint) <> 0 Then
-                    logme(9, False, "The detected leap in time is inside a measurement section. This is not allowed!")
-                    BWorker.CancelAsync()
-                    Return False
+                    Throw New Exception(format("The detected leap in time({0}) is not allowed to be inside a measurement section!", CalcData(tCompCali.SecID)(JumpPoint)))
                 End If
             End If
 
@@ -30,9 +28,7 @@ Module Signal_identification
             ' Calculate the section overview
             fSecOverview(MSC)
         End If
-
-        Return True
-    End Function
+    End Sub
 
     ' Calculation of the virtual trigger points
     Function fvirtMSC(ByVal MSCOrg As cMSC, ByRef MSCVirt As cVirtMSC) As Boolean
@@ -724,10 +720,8 @@ Module Signal_identification
             ' Temprature, Pressure, Humidity
             For j = 0 To InputWeatherData(tCompWeat.t).Count - 1
                 If j = 0 Then
-                    If CalcData(tCompCali.t)(i) < InputWeatherData(tCompWeat.t)(j) And j = 0 Then
-                        logme(9, False, "The test time is outside the range of the data from the stationary weather station.")
-                        BWorker.CancelAsync()
-                        Return False
+                    If CalcData(tCompCali.t)(i) < InputWeatherData(tCompWeat.t)(j) Then
+                        Throw New Exception(format("The test time({0}) is outside the range of the data from the stationary weather station({1}).", CalcData(tCompCali.t)(i), InputWeatherData(tCompWeat.t)(j)))
                     ElseIf CalcData(tCompCali.t)(i) >= InputWeatherData(tCompWeat.t)(j) And CalcData(tCompCali.t)(i) < InputWeatherData(tCompWeat.t)(j + 1) Then
                         CalcData(tCompCali.t_amp_stat)(i) = InterpLinear(InputWeatherData(tCompWeat.t)(j), InputWeatherData(tCompWeat.t)(j + 1), InputWeatherData(tCompWeat.t_amb_stat)(j), InputWeatherData(tCompWeat.t_amb_stat)(j + 1), CalcData(tCompCali.t)(i))
                         CalcData(tCompCali.p_amp_stat)(i) = InterpLinear(InputWeatherData(tCompWeat.t)(j), InputWeatherData(tCompWeat.t)(j + 1), InputWeatherData(tCompWeat.p_amp_stat)(j), InputWeatherData(tCompWeat.p_amp_stat)(j + 1), CalcData(tCompCali.t)(i))
@@ -743,9 +737,7 @@ Module Signal_identification
                     End If
                 End If
                 If j = InputWeatherData(tCompWeat.t).Count - 1 Then
-                    logme(9, False, "The test time is outside the range of the data from the stationary weather station.")
-                    BWorker.CancelAsync()
-                    Return False
+                    Throw New Exception(format("The test time is outside the range of the data from the stationary weather station."))
                 End If
             Next j
         Next i
@@ -775,6 +767,7 @@ Module Signal_identification
                                 CalcData(tCompCali.slope_deg)(i) = 0
                                 logme(9, False, "Standstill or loss of vehicle speed signal inside MS not permitted (Error at line " & i & ")")
                                 BWorker.CancelAsync()
+                                ' XXXX: What is absolutely neccessary to run afterwards, and cannot return immediately here??
                             Else
                                 CalcData(tCompCali.slope_deg)(i) = (Math.Asin((CalcData(tCompCali.alt)(i + 1) - CalcData(tCompCali.alt)(i - 1)) / (CalcData(tCompCali.dist_root)(i + 1) - CalcData(tCompCali.dist_root)(i - 1)))) * 180 / Math.PI
                             End If
diff --git a/CSE/Calculation/main_calculation_call.vb b/CSE/Calculation/main_calculation_call.vb
index 49d9268..8ec333e 100644
--- a/CSE/Calculation/main_calculation_call.vb
+++ b/CSE/Calculation/main_calculation_call.vb
@@ -1,7 +1,7 @@
 Public Module main_calculation_call
 
     ' Main calculation
-    Function calculation(ByVal isCalibrate As Boolean) As Boolean
+    Sub calculation(ByVal isCalibrate As Boolean)
         ' Declaration
         Dim i As Integer
 
@@ -26,7 +26,7 @@
             ReadDataFile(Job.calib_run_fpath, MSC)
 
             ' Exit function if error is detected
-            If BWorker.CancellationPending Then Return False
+            If BWorker.CancellationPending Then Return
 
             ' Output on the GUI
             logme(7, False, "Calculating the calibration run...")
@@ -35,23 +35,23 @@
             fIdentifyMS(MSC, vMSC)
 
             ' Exit function if error is detected
-            If BWorker.CancellationPending Then Return False
+            If BWorker.CancellationPending Then Return
 
             ' Output on the GUI
             logme(6, False, "Calculating the calibration run parameter")
 
-            ' Calculate the results from the calibration test
-            fCalcCalib(MSC, vehicle)
+            Try
+                ' Calculate the results from the calibration test
+                fCalcCalib(MSC, vehicle)
 
-            ' Exit function if error is detected
-            'If BWorker.CancellationPending Then Return False
-
-            ' Output on the GUI
-            logme(7, False, "Writing the output files...")
+            Finally
+                ' Output on the GUI
+                logme(7, False, "Writing the output files...")
 
-            ' Output
-            fOutDataCalc1Hz(Job.calib_run_fpath, isCalibrate)
-            fOutCalcRes(isCalibrate)
+                ' Output
+                fOutDataCalc1Hz(Job.calib_run_fpath, isCalibrate)
+                fOutCalcRes(isCalibrate)
+            End Try
         Else
             Dim MSC As New cMSC
             Dim vMSC As New cVirtMSC
@@ -69,7 +69,7 @@
             fIdentifyMS(MSC, vMSC, , False)
 
             ' Exit function if error is detected
-            If BWorker.CancellationPending Then Return False
+            If BWorker.CancellationPending Then Return
 
             ' Output which test are calculated
             For i = 0 To UBound(Job.coasting_fpaths)
@@ -90,19 +90,19 @@
                 ReadDataFile(Job.coasting_fpaths(i), MSC)
 
                 ' Exit function if error is detected
-                If BWorker.CancellationPending Then Return False
+                If BWorker.CancellationPending Then Return
 
                 ' Identify the signal measurement sections
                 fIdentifyMS(MSC, vMSC, False)
 
                 ' Exit function if error is detected
-                If BWorker.CancellationPending Then Return False
+                If BWorker.CancellationPending Then Return
 
                 ' Calculate the run
                 fCalcRun(MSC, vehicle, i)
 
                 ' Exit function if error is detected
-                If BWorker.CancellationPending Then Return False
+                If BWorker.CancellationPending Then Return
 
                 ' Output on the GUI
                 logme(6, False, "Writing the output files...")
@@ -114,7 +114,7 @@
                 fSaveDic(i)
 
                 ' Exit function if error is detected
-                If BWorker.CancellationPending Then Return False
+                If BWorker.CancellationPending Then Return
 
                 ' Clear the dictionaries
                 InputData = Nothing
@@ -126,23 +126,18 @@
                 UnitsUndef = Nothing
             Next i
 
-            ' Check if the LS/HS test run is valid
-            fCheckLSHS()
+            Try
+                ' Check if the LS/HS test run is valid
+                fCheckLSHS()
+
+                ' Calculate the regressions
+                fCalcReg(vehicle)
+            Finally
 
-            ' Exit function if error is detected
-            If BWorker.CancellationPending Then
                 ' Write the summerised output file
                 logme(7, False, "Writing the summarised output file...")
                 fOutCalcRes(isCalibrate)
-                Return False
-            End If
-
-            ' Calculate the regressions
-            fCalcReg(vehicle)
-
-            ' Write the summerised output file
-            logme(7, False, "Writing the summarised output file...")
-            fOutCalcRes(isCalibrate)
+            End Try
 
             ' Check if all is valid
             For i = 0 To ErgValuesReg(tCompErgReg.SecID).Count - 1
@@ -168,12 +163,10 @@
             InputWeatherData = Nothing
             UnitsWeat = Nothing
         End If
-
-        Return True
-    End Function
+    End Sub
 
     ' Calculate the calibration test parameter
-    Function fCalcCalib(ByVal MSCX As cMSC, ByVal vehicleX As cVehicle) As Boolean
+    Sub fCalcCalib(ByVal MSCX As cMSC, ByVal vehicleX As cVehicle)
         ' Declaration
         Dim run As Integer
         Dim Change As Boolean
@@ -220,15 +213,10 @@
 
             ' Error
             If run > 10 Then
-                logme(9, False, "The calibration is not possible because iteration for valid datasets does not converge (n>10)")
-                Change = False
-                BWorker.CancelAsync()
-                Return False
+                Throw New Exception("The calibration is not possible because iteration for valid datasets does not converge (n>10)!")
             End If
         Loop
-
-        Return True
-    End Function
+    End Sub
 
     ' Calculate the speed run parameter
     Function fCalcRun(ByVal MSCX As cMSC, ByVal vehicleX As cVehicle, ByVal coastingSeq As Integer) As Boolean
@@ -254,7 +242,7 @@
     End Function
 
     ' Function to calibrate fv_veh
-    Function ffv_veh(ByVal MSCX As cMSC) As Boolean
+    Sub ffv_veh(ByVal MSCX As cMSC)
         ' Declaration
         Dim i, j, CalcX(0), VSec(0), num As Integer
         Dim ave_vz(0), ave_vz2(0), ave_vn(0) As Double
@@ -308,9 +296,7 @@
         ' error message if the CAN velocity is 0
         For i = 0 To UBound(CalcX)
             If ave_vn(i) = 0 And VSec(i) = 1 Then
-                logme(9, False, "The measured vehicle velocity (v_veh_CAN) is 0 in section: " & CalcX(i))
-                BWorker.CancelAsync()
-                Return False
+                Throw New Exception("The measured vehicle velocity (v_veh_CAN) is 0 in section: " & CalcX(i))
             End If
         Next i
 
@@ -332,9 +318,7 @@
         ' Calculate the average over all factors
         fv_veh = fv_veh / num
         fv_veh_opt2 = fv_veh_opt2 / num
-
-        Return True
-    End Function
+    End Sub
 
     Function ffvpeBeta() As Boolean
         ' Declaration
@@ -465,7 +449,7 @@
     End Function
 
     ' Function to check if the calibration run is valid
-    Function fCheckCalib(ByVal Run As Integer, ByRef Change As Boolean) As Boolean
+    Sub fCheckCalib(ByVal Run As Integer, ByRef Change As Boolean)
         ' Declaration
         Dim i, j, k, anz As Integer
         Dim control As Boolean
@@ -551,9 +535,7 @@
 
         ' Ceck if enough sections are detected
         If SecCount.AnzSec.Count - 1 < 1 Then
-            logme(9, False, "Insufficent numbers of valid measurement sections available")
-            BWorker.CancelAsync()
-            Return False
+            Throw New Exception(format("Insufficent numbers of valid measurement sections({0}) available!", SecCount.AnzSec.Count))
         End If
 
         ' Check if enough valid sections in both directionsection
@@ -612,9 +594,7 @@
             End If
         Next i
         If anz < 2 Then
-            logme(9, False, "Insufficent numbers of valid measurement sections available")
-            BWorker.CancelAsync()
-            Return False
+            Throw New Exception(format("Insufficent numbers of valid measurement sections({0}) available!", anz))
         End If
 
         ' Look if something have changed
@@ -627,12 +607,10 @@
         Else
             Change = True
         End If
-
-        Return True
-    End Function
+    End Sub
 
     ' Function to check if the calibration run is valid
-    Function fCheckLSHS() As Boolean
+    Sub fCheckLSHS()
         ' Declaration
         Dim i, j, k, anz, anzHS1, anzHS2 As Integer
         Dim control, FirstIn As Boolean
@@ -700,9 +678,7 @@
 
         ' Ceck if enough sections are detected
         If SecCount.AnzSec.Count - 1 < 1 Then
-            logme(9, False, "Insufficent numbers of valid measurement sections in the low speed test available")
-            BWorker.CancelAsync()
-            Return False
+            Throw New Exception(format("Insufficent numbers of valid measurement sections({0}) in the low speed test available!", SecCount.AnzSec.Count))
         End If
 
         ' Check if enough valid sections in both directionsection
@@ -741,6 +717,7 @@
                         End If
                     Else
                         logme(9, False, "Not enough valid data for low speed tests available in section " & Trim(Mid(SecCount.NameSec(i), 1, InStr(SecCount.NameSec(i), "(") - 2)))
+                        ' FIXME: is this an error?
                     End If
                 End If
             Next j
@@ -816,9 +793,7 @@
 
         ' Ceck if enough sections are detected
         If SecCount.AnzSec.Count - 1 < 1 Then
-            logme(9, False, "Insufficent numbers of valid measurement sections in the high speed test available")
-            BWorker.CancelAsync()
-            Return False
+            Throw New Exception(format("Insufficent numbers of valid measurement sections({0}) in the high speed test available!", SecCount.AnzSec.Count))
         End If
 
         ' Check if enough valid sections in both directionsection
@@ -828,19 +803,17 @@
                     ' If enought sections in both directions are detected
                     If SecCount.AnzSec(i) >= Crt.segruns_min_HS And SecCount.AnzSec(j) >= Crt.segruns_min_HS Then
                         ' Count the valid tests per HeadID
-                        Select Case Trim(Mid(SecCount.NameSec(i), InStr(SecCount.NameSec(i), ",") + 1, InStr(SecCount.NameSec(i), ")") - (InStr(SecCount.NameSec(i), ",") + 1)))
+                        Dim headId = Trim(Mid(SecCount.NameSec(i), InStr(SecCount.NameSec(i), ",") + 1, InStr(SecCount.NameSec(i), ")") - (InStr(SecCount.NameSec(i), ",") + 1)))
+                        Select Case headId
                             Case 1
                                 anzHS1 += SecCount.AnzSec(i) + SecCount.AnzSec(j)
                             Case 2
                                 anzHS2 += SecCount.AnzSec(i) + SecCount.AnzSec(j)
                             Case Else
-                                logme(9, False, "headID not known")
-                                BWorker.CancelAsync()
-                                Return False
+                                Throw New Exception(format("Unknown headID({0})!", headId))
                         End Select
                     Else
-                        logme(9, False, "Not enough valid data for high speed tests available in section " & Trim(Mid(SecCount.NameSec(i), 1, InStr(SecCount.NameSec(i), "(") - 2)))
-                        BWorker.CancelAsync()
+                        Throw New Exception(format("Not enough valid data({0}) for high speed tests available in section({1})!", SecCount.AnzSec(i), Trim(Mid(SecCount.NameSec(i), 1, InStr(SecCount.NameSec(i), "(") - 2))))
                     End If
                 End If
             Next j
@@ -848,9 +821,7 @@
 
         ' Ceck if enough sections are detected
         If anzHS1 < Crt.segruns_min_head_MS Or anzHS2 < Crt.segruns_min_head_MS Then
-            logme(9, False, "Number of valid high speed datasets too low")
-            BWorker.CancelAsync()
-            'Return False
+            Throw New Exception(format("Number of valid high speed datasets({0}) too low!", anzHS1))
         End If
 
         ' Set to equal Values
@@ -886,12 +857,10 @@
                 Next i
             End If
         End If
-
-        Return True
-    End Function
+    End Sub
 
     ' Evaluate the Valid sections
-    Function fCalcValidSec(ByVal MSCX As cMSC, ByVal coastingSeq As Integer) As Boolean
+    Sub fCalcValidSec(ByVal MSCX As cMSC, ByVal coastingSeq As Integer)
         ' Declaration
         Dim i As Integer
 
@@ -958,11 +927,10 @@
                 Next i
         End Select
 
-        Return True
-    End Function
+    End Sub
 
     ' Save the Dictionaries
-    Function fSaveDic(ByVal coastingSeq As Integer) As Boolean
+    Sub fSaveDic(ByVal coastingSeq As Integer)
         ' Declaration
         Dim sKV As New KeyValuePair(Of tCompErg, List(Of Double))
         Dim sKVUndef As New KeyValuePair(Of String, List(Of Double))
@@ -994,7 +962,5 @@
                 ErgValuesUndefComp(sKVUndef.Key).AddRange(ErgValuesUndef(sKVUndef.Key))
             Next
         End If
-
-        Return True
-    End Function
+    End Sub
 End Module
diff --git a/CSE/Classes/cFile_v3.vb b/CSE/Classes/cFile_v3.vb
index 5be19fd..cab3463 100644
--- a/CSE/Classes/cFile_v3.vb
+++ b/CSE/Classes/cFile_v3.vb
@@ -205,7 +205,7 @@ lb10:
         Next
         ' Abfrage ob Datei blockiert
         If IsNothing(StrWrter) Then
-            BWorker.CancelAsync()
+            BWorker.CancelAsync() ' FIXME: Totaly unrelated here, file-io should not know anything about the worker-thread.
             FileBlock = True
             Exit Sub
         End If
@@ -216,7 +216,9 @@ lb10:
     Public Sub WriteLine(ByVal x As String)
         ' Polling if the file is blocked
         If IsNothing(StrWrter) Then
-            If BWorker IsNot Nothing Then BWorker.CancelAsync()
+            If BWorker IsNot Nothing Then
+                BWorker.CancelAsync() ' FIXME: Totaly unrelated here, file-io should not know anything about the worker-thread.
+            End If
             FileBlock = True
             Exit Sub
         End If
diff --git a/CSE/GUI/F_Main.vb b/CSE/GUI/F_Main.vb
index 64ab2f7..cfa2170 100644
--- a/CSE/GUI/F_Main.vb
+++ b/CSE/GUI/F_Main.vb
@@ -157,11 +157,11 @@ Public Class F_Main
         Handles BackgroundWorkerVECTO.RunWorkerCompleted
         ' If an Error is detected
         If e.Error IsNot Nothing Then
-            logme(8, False, format("Backround operation ended with exception: {0}", e.Error.Message), e.Error)
+            logme(8, False, format("Background operation ended with exception: {0}", e.Error.Message), e.Error)
         ElseIf e.Cancelled Then
-            logme(7, False, "Backround operation  aborted by user.")
+            logme(7, False, "Background operation aborted by user.")
         Else
-            logme(7, False, "Backround operation ended OK.")
+            logme(7, False, "Background operation ended OK.")
             Dim asyncJob As cAsyncJob = e.Result
             If asyncJob.IsCalibration Then Me.ButtonEval.Enabled = True
         End If
diff --git a/CSE/IO/cVehicle.vb b/CSE/IO/cVehicle.vb
index 41dd8c6..4692b02 100644
--- a/CSE/IO/cVehicle.vb
+++ b/CSE/IO/cVehicle.vb
@@ -147,7 +147,6 @@ The generic parameters for classes are stored in the GenShape.shp",
         '' The configuration was not found!
         ''
         validateMsgs.Add(format("The vehicle (class: {0}, configuration {1}) was not found in the generic shape file. \n\iPlease add it in .", Me.classCode, Me.configuration))
-        BWorker.CancelAsync()
     End Sub
 
 
diff --git a/CSE/IO/input.vb b/CSE/IO/input.vb
index 0c5d850..8aa9121 100644
--- a/CSE/IO/input.vb
+++ b/CSE/IO/input.vb
@@ -1,7 +1,7 @@
 ' Read the input data
 Public Module input
     ' Read the measurement section config file
-    Function ReadInputMSC(ByRef MSCX As cMSC, ByVal MSCfile As String, Optional ByVal calibration As Boolean = True) As Boolean
+    Sub ReadInputMSC(ByRef MSCX As cMSC, ByVal MSCfile As String, Optional ByVal calibration As Boolean = True)
         ' Declarations
         Dim i As Integer
         Dim RefHead As Double
@@ -13,11 +13,7 @@ Public Module input
             logme(5, False, "Read MS configuration file")
 
             ' Open the MSC spezification file
-            If Not FileInMSCSpez.OpenRead(MSCfile) Then
-                ' Error if the file is not available
-                logme(9, False, "Can´t find the MS configuration specification file: " & MSCfile)
-                Return False
-            End If
+            FileInMSCSpez.OpenReadWithEx(MSCfile)
 
             ' Determine the trigger status 
             MSCX.tUse = FileInMSCSpez.ReadLine(0)
@@ -40,9 +36,7 @@ Public Module input
                 Loop
             Catch ex As Exception
                 ' Falls kein gültiger Wert eingegeben wurde
-                logme(9, False, "Invalid value in the trigger data file: " & fName(MSCfile, True))
-                BWorker.CancelAsync()
-                Return False
+                Throw New Exception(format("Invalid value in the trigger data file({0}) due to: {1})", fName(MSCfile, True), ex.Message, ex))
             End Try
 
         End Using
@@ -63,9 +57,7 @@ Public Module input
                         MSCX.headID.Add(2)
                         Continue For
                     Else
-                        logme(9, False, "Measurement section with invalid headings identified (test track not parallel) at line: " & i)
-                        BWorker.CancelAsync()
-                        Return False
+                        Throw New Exception("Measurement section with invalid headings identified (test track not parallel) at line: " & i)
                     End If
                 End If
             Next i
@@ -74,16 +66,12 @@ Public Module input
             For i = 1 To MSCX.meID.Count - 1
                 If Crt.gradient_correction Then
                     If MSCX.AltPath(i) = Nothing Then
-                        logme(9, False, "Altitude correction = on, missing altitude file at line: " & i)
-                        BWorker.CancelAsync()
-                        Return False
+                        Throw New Exception("Altitude correction = on, missing altitude file at line: " & i)
                     End If
 
                     If fPath(MSCX.AltPath(i)) = Nothing Then MSCX.AltPath(i) = joinPaths(fPath(MSCfile), MSCX.AltPath(i))
                     If Not FileIO.FileSystem.FileExists(MSCX.AltPath(i)) Then
-                        logme(9, False, "Altitude correction = on, altitude file doesen´t exist: " & MSCX.AltPath(i))
-                        BWorker.CancelAsync()
-                        Return False
+                        Throw New Exception("Altitude correction = on, altitude file doesen´t exist: " & MSCX.AltPath(i))
                     End If
                 End If
             Next i
@@ -92,12 +80,10 @@ Public Module input
                 MSCX.headID.Add(1)
             Next i
         End If
-
-        Return True
-    End Function
+    End Sub
 
     ' Read the wather data
-    Public Function ReadWeather(ByVal Datafile As String) As Boolean
+    Public Sub ReadWeather(ByVal Datafile As String)
         ' Declaration
         Using FileInWeather As New cFile_V3
             Dim Line() As String
@@ -113,19 +99,8 @@ Public Module input
             InputWeatherData = New Dictionary(Of tCompWeat, List(Of Double))
             UnitsWeat = New Dictionary(Of tCompWeat, List(Of String))
 
-            'Abort if there's no file
-            If Datafile = "" OrElse Not IO.File.Exists(Datafile) Then
-                logme(9, False, "Weather data file not found (" & Datafile & ") !")
-                BWorker.CancelAsync()
-                Return False
-            End If
-
             'Open file
-            If Not FileInWeather.OpenRead(Datafile) Then
-                logme(9, False, "Failed to open file (" & Datafile & ") !")
-                BWorker.CancelAsync()
-                Return False
-            End If
+            FileInWeather.OpenReadWithEx(Datafile)
 
             ' Build check key
             WeathCheck.Add(tCompWeat.t, False)
@@ -147,9 +122,7 @@ Public Module input
                 Else
                     ' Check if component is already defined
                     If WeathCheck(Comp) Then
-                        logme(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1)
-                        BWorker.CancelAsync()
-                        Return False
+                        Throw New Exception(format("Column {0}: Component({1}) already defined!", i + 1, Line(i)))
                     End If
 
                     ' Set the defined component true and save the position
@@ -163,9 +136,7 @@ Public Module input
             ' Check if all required data is given
             For Each sKVW In WeathCheck
                 If Not WeathCheck(sKVW.Key) Then
-                    logme(9, False, "Missing signal for " & fCompName(sKVW.Key))
-                    BWorker.CancelAsync()
-                    Return False
+                    Throw New Exception("Missing signal for " & fCompName(sKVW.Key))
                 End If
             Next
 
@@ -184,18 +155,14 @@ Public Module input
                     Next sKV
                 Loop
             Catch ex As Exception
-                logme(9, False, "Error during file read! Line number: " & tdim + 1 & " (" & Datafile & ")")
-                BWorker.CancelAsync()
-                Return False
+                Throw New Exception(format("Exception while reading file({0}), line({1}) due to: {2}!: ", Datafile, tdim + 1, ex.Message), ex)
             End Try
 
         End Using
-
-        Return True
-    End Function
+    End Sub
 
     ' Read the data file
-    Public Function ReadDataFile(ByVal Datafile As String, ByVal MSCX As cMSC) As Boolean
+    Public Sub ReadDataFile(ByVal Datafile As String, ByVal MSCX As cMSC)
         ' Declarations
         Using FileInMeasure As New cFile_V3
             Dim Line(), txt As String
@@ -226,9 +193,6 @@ Public Module input
                 OptPar(i) = True
             Next i
 
-            ' Exit if an errer was detected
-            If BWorker.CancellationPending Then Return False
-
             ' Generate the calculation dictionary variables
             'For Each EnumStr In System.Enum.GetValues(GetType(tCompErg))
             '    CalcData.Add(EnumStr, New List(Of Double))
@@ -237,19 +201,8 @@ Public Module input
                 CalcData.Add(EnumStr, New List(Of Double))
             Next
 
-            'Abort if there's no file
-            If Datafile = "" OrElse Not IO.File.Exists(Datafile) Then
-                logme(9, False, "Measurement data file not found (" & Datafile & ") !")
-                BWorker.CancelAsync()
-                Return False
-            End If
-
             'Open file
-            If Not FileInMeasure.OpenRead(Datafile) Then
-                logme(9, False, "Failed to open file (" & Datafile & ") !")
-                BWorker.CancelAsync()
-                Return False
-            End If
+            FileInMeasure.OpenReadWithEx(Datafile)
 
             ' Build check key
             MeasCheck.Add(tComp.t, False)
@@ -285,9 +238,7 @@ Public Module input
 
                     ' Check if the component is already defined
                     If InputUndefData.ContainsKey(txt) Then
-                        logme(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1)
-                        BWorker.CancelAsync()
-                        Return False
+                        Throw New Exception(format("Column {0}: Component({1}) already defined!", i + 1, Line(i)))
                     End If
 
                     ' Add the component to the dictionary
@@ -297,9 +248,7 @@ Public Module input
                 Else
                     ' Check if component is already defined
                     If MeasCheck(Comp) Then
-                        logme(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1)
-                        BWorker.CancelAsync()
-                        Return False
+                        Throw New Exception(format("Column {0}: Component({1}) already defined!", i + 1, Line(i)))
                     End If
 
                     ' Set the defined component true and save the position
@@ -316,9 +265,7 @@ Public Module input
                     Select Case sKVM.Key
                         Case tComp.trigger
                             If MSCX.tUse Then
-                                logme(9, False, "No trigger signal detected, but trigger_used in MS config activated!")
-                                BWorker.CancelAsync()
-                                Return False
+                                Throw New Exception("No trigger signal detected, but trigger_used in MS config activated!")
                             End If
                             OptPar(0) = False
                         Case tComp.p_tire
@@ -328,9 +275,7 @@ Public Module input
                         Case tComp.user_valid
                             valid_set = True
                         Case Else
-                            logme(9, False, "Missing signal for " & fCompName(sKVM.Key))
-                            BWorker.CancelAsync()
-                            Return False
+                            Throw New Exception("Missing signal for " & fCompName(sKVM.Key))
                     End Select
                 End If
             Next
@@ -351,9 +296,7 @@ Public Module input
                                 If tDim >= 2 Then
                                     If Math.Abs((InputData(sKV.Key)(tDim - 1) - InputData(sKV.Key)(tDim - 2)) / (1 / HzIn) - 1) * 100 > Crt.delta_Hz_max Then
                                         If ErrDat Then
-                                            logme(9, False, "The input data is not recorded at " & HzIn & "Hz at line: " & JumpPoint & " and " & tDim)
-                                            BWorker.CancelAsync()
-                                            Return False
+                                            Throw New Exception("The input data is not recorded at " & HzIn & "Hz at line: " & JumpPoint & " and " & tDim)
                                         Else
                                             ErrDat = True
                                             JumpPoint = tDim - 1
@@ -421,9 +364,7 @@ Public Module input
                     Next
                 Loop
             Catch ex As Exception
-                logme(9, False, "Error during file read! Line number: " & tDim + 1 & " (" & Datafile & ")")
-                BWorker.CancelAsync()
-                Return False
+                Throw New Exception(format("Exception while reading file({0}), line({1}) due to: {2}!: ", Datafile, tdim + 1, ex.Message), ex)
             End Try
 
 
@@ -444,18 +385,14 @@ Public Module input
                     CalcData(tCompCali.longi_UTM)(i) = UTMCoord.Easting
                 Next i
                 If Zone1CentralMeridian > 180 Then
-                    logme(9, False, "The adjustment is not possible because the data lie to far away from each other to fit into one UTM stripe")
-                    BWorker.CancelAsync()
-                    Return False
+                    Throw New Exception("The adjustment is not possible because the data lie to far away from each other to fit into one UTM stripe")
                 End If
             Loop
 
             'Developer export of input data converted from MM.MM to UTM
             'fOuttest(Datafile)
         End Using
-
-        Return True
-    End Function
+    End Sub
 
 
     ' Function to read the generic shape file
-- 
GitLab