Imports System.IO
Module mod_Maths_Functions
Public CRSC As CRS_Creator.frmMain
Function DeviationCalculation()
Dim sWriter As StreamWriter
Dim strTemp As String
Dim arrTemp(19) As Double
Dim arrDev As Array
Dim i, j As Integer
'This bit is to create two file in the temp directory for use, then store the name of the file for
'furture ADO.Net Use.
tempFileBaseLoad = CreateTempFile() 'create a new temp file for use....
FileBaseLoadname = tempFileBaseLoad.Substring(tempPathString.Length, tempFileBaseLoad.Length - tempPathString.Length)
tempFileMSG = CreateTempFile() 'create a new temp file for use....
FileMSGname = tempFileMSG.Substring(tempPathString.Length, tempFileMSG.Length - tempPathString.Length)
'Need to delete the old files if they exist
Try
If IO.File.Exists(tempFileBaseLoad) = True Then
File.Delete(tempFileBaseLoad)
End If
If IO.File.Exists(tempFileMSG) = True Then
File.Delete(tempFileMSG)
End If
Catch ex As Exception
End Try
sWriter = IO.File.CreateText(tempFileBaseLoad)
sWriter.WriteLine("Time,GTload,Dev1,Dev2,Dev3,Dev4,Dev5,Dev6,Dev7,Dev8,Dev9,Dev10,Dev11,Dev12,Dev13,Dev14,Dev15,Dev16,Dev17,Dev18")
sWriter.Close()
sWriter = IO.File.CreateText(tempFileMSG)
sWriter.WriteLine("Time,GTload,Dev1,Dev2,Dev3,Dev4,Dev5,Dev6,Dev7,Dev8,Dev9,Dev10,Dev11,Dev12,Dev13,Dev14,Dev15,Dev16,Dev17,Dev18")
sWriter.Close()
Dim progressCounter, progressIncrement As Single
progressIncrement = 100 / dt.Rows.Count
Dim prog As ProgressBar
prog = CRSC.progBar1
For j = 1 To dt.Rows.Count - 1
Application.DoEvents()
For i = 0 To 19
arrTemp(i) = dt.Rows(j)(i)
Next
strTemp = CanDeviation(arrTemp)
If arrTemp(1) >= 200 Then 'checks if it is at baseload
sWriter = IO.File.AppendText(tempFileBaseLoad)
Else
sWriter = IO.File.AppendText(tempFileMSG)
End If
sWriter.WriteLine(strTemp)
sWriter.Close()
progressCounter += progressIncrement
prog.Value = progressCounter
Next
End Function
Function CanDeviation(ByRef arrInput As Array) As String
Dim i As Integer
Dim arrOutput(19) As Single
Dim sngCanTempSum As Single
Dim sngCanAverage As Single
Dim strTemp As String
For i = 2 To 19
sngCanTempSum += arrInput(i)
Next
'Now we have the total can Temp
sngCanAverage = sngCanTempSum / 18
'Divide by 18 to get can average temp
For i = 0 To 1 'Put the Time and GTload back in
arrOutput(i) = arrInput(i)
Next
For i = 2 To 19 'Now get the deviation from mean
arrOutput(i) = ((arrInput(i) - sngCanAverage) / sngCanAverage) * 100
Next
For i = 0 To arrOutput.Length - 1
strTemp &= arrOutput(i) & ","
Next
Return strTemp
End Function
End Module