Imports System.DateTime Public Class SID Public filename As String Public freqs()() As Double Public bg() As Double Public stationids As String Public indices()() As Integer Public bgindices() As Integer Public integrationtime As Double Public obs As ObservatoryData Public starttime As DateTime Shared fileformat As String = "yyyyMMddTHHmmss\S\I\D\.\c\s\v" Shared dateformat As String = "yyyy-MM-dd HH:mm:ss.ff" Public path As String Public Sub New( _ ByVal specfreq1 As Double, ByVal specfreq2 As Double, ByVal specfreqcount As Double, _ ByVal filepath As String, _ ByVal inttime As Double, _ ByVal obst As ObservatoryData _ ) path = filepath obs = obst integrationtime = inttime If freqs Is Nothing Then freqs = obs.sidfreqlist() bg = obs.sidbg stationids = obs.sidstations End If newfile() Dim linecount = freqs.Length ReDim indices(linecount - 1) For i As Integer = 0 To linecount - 1 Dim t1() As Double = freqs(i) ' unaliased spectral channels Dim t2 As Integer = CInt((t1(0) - t1(1) / 2 - specfreq1) / (specfreq2 - specfreq1) * (specfreqcount - 1)) Dim t3 As Integer = CInt((t1(0) + t1(1) / 2 - specfreq1) / (specfreq2 - specfreq1) * (specfreqcount - 1)) indices(i) = New Integer() {t2, t3} Next If bg IsNot Nothing Then Dim t4 As Integer = CInt((bg(0) - specfreq1) / (specfreq2 - specfreq1) * (specfreqcount - 1)) Dim t5 As Integer = CInt((bg(1) - specfreq1) / (specfreq2 - specfreq1) * (specfreqcount - 1)) bgindices = New Integer() {t4, t5} End If End Sub Public Sub newfile() starttime = UtcNow filename = starttime.ToString(SID.fileformat) If path IsNot Nothing Then filename = My.Computer.FileSystem.CombinePath(path, filename) 'Dim r As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(".", FileIO.SearchOption.SearchTopLevelOnly, filename.Substring(0, 9) & "*.csv") ' If r.Count = 1 Then ' filename = r.Item(0) ' Else Dim stn As String = "# StationId = " & freqs(0)(0).ToString For i As Integer = 1 To freqs.Length - 1 stn &= " " & freqs(i)(0).ToString Next ' SID file header - not all fields filled in With obs.data Dim s As String = "# Site = " & obs.data.observatory & vbNewLine s &= "# Contact = " & .observer & " " & .email & vbNewLine s &= "# Longitude = " & .longitude.ToString & vbNewLine s &= "# Latitude = " & .latitude.ToString & vbNewLine s &= "# " & vbNewLine s &= "# UTC_Offset = " & .timezone.ToString & vbNewLine s &= "# TimeZone = " & vbNewLine s &= "# " & vbNewLine s &= "# UTC_StartTime = " & starttime.ToString(SID.dateformat) & vbNewLine s &= "# LogInterval = " & vbNewLine s &= "# LogType = " & vbNewLine s &= "# MonitorID = " & vbNewLine s &= "# SampleRate = " & (1.0 / integrationtime).ToString & vbNewLine s &= stn & vbNewLine s &= "#UTC_EndTime = " & vbNewLine s &= "#DataMin=" & vbNewLine s &= "#DataMax=" & vbNewLine s &= "#dataquality_average_v0.1=" & vbNewLine s &= "#dataquality_max_v0.1=" & vbNewLine My.Computer.FileSystem.WriteAllText(filename, s, False, System.Text.Encoding.ASCII) End With ' End If End Sub Public WriteOnly Property spectrum() As Double() Set(ByVal spec() As Double) Dim currenttime As DateTime = UtcNow If currenttime.DayOfYear > starttime.DayOfYear Then newfile() ' each time stamp marks the end of the integration Dim txt As String = currenttime.ToString(SID.dateformat) ' backgound to subtract Dim t As Double = 0 If bg IsNot Nothing Then If bgindices IsNot Nothing Then For i As Integer = bgindices(0) To bgindices(1) t += 10.0 ^ (spec(i) / 10.0) Next t /= (bgindices(1) - bgindices(0) + 1) End If End If ' compute the line intensities For i As Integer = 0 To indices.Length - 1 Dim t1() As Integer = indices(i) Dim s As Double = 0 For j As Integer = t1(0) To t1(1) s += 10.0 ^ (0.1 * spec(j)) - t Next txt &= ", " & s.ToString("0.0####") Next My.Computer.FileSystem.WriteAllText(filename, txt & vbNewLine, True, System.Text.Encoding.ASCII) End Set End Property End Class