DIAdem Help

Additional Example 1a: Reading in an Unspecified Number of Channels

  • Updated2024-09-12
  • 3 minute(s) read

Additional Example 1a: Reading in an Unspecified Number of Channels

The following example shows a DataPlugin for reading in the text files DataPlugin_AdditionalEx1_1.aex1 and DataPlugin_AdditionalEx1_2.aex1. The DataPlugin script file is located at DataPlugin_AdditionalEx1a.vbs 

Data Format Description

These two text files contain metadata and channel data. The metadata includes the channel name and the channel unit. The channel names are in the first line of the file to be read in and the associated units are in the second line. The channel data follows:

The names, units, and data are separated by a tabulator. The specified numbers use a point as the decimal symbol. The empty rows in the file and the leading and trailing blanks are irrelevant. The end of the line is indicated by Carriage Return and Line Feed.

The DataPlugin_AdditionalEx1_1.aex1 file contains specifications for 2 channels and the DataPlugin_AdditionalEx1_2.aex1 file specifications for 3 channels.

Special Features of the DataPlugin

  • Line feed: CrLf

  • Separators: <Tab>

  • Ignoring spaces and empty rows

  • Using the Split function to read in the channel names and the channel units. You do not need to know the number of channels to be read in before.

  • Reading in the channel data value for value.

Option Explicit
Sub ReadStore(oFile)
  ' Set string formatter
  oFile.Formatter.LineFeeds        = vbCrLf
  oFile.Formatter.TrimCharacters   = " "
  oFile.Formatter.IgnoreEmptyLines = True
  oFile.Formatter.Delimiters       = vbTab
  oFile.Formatter.DecimalPoint     = "."

  ' Read channel header
  Dim saChannelName : saChannelName = Split(oFile.GetNextLine, vbTab)
  Dim saChannelUnit : saChannelUnit = Split(oFile.GetNextLine, vbTab)

  ' Create channel group object and set property
  Dim oChannelGroup : Set oChannelGroup = Root.Channelgroups.Add(oFile.Info.FileName)

  Dim iLoop, oChn, oElem
  ' Add channels to DIAdem channel group
  iLoop = 0  
  For each oElem in saChannelName
    Set oChn = oChannelGroup.Channels.Add(oElem, eR64)
    Call oChn.Properties.Add("Unit_String", saChannelUnit(iLoop))
    iLoop = iLoop + 1
  Next

  ' Add values to each channel in the channel group
  iLoop = 0
  While not oFile.Position = oFile.Size
    iLoop = iLoop + 1
    For each oElem in oChannelGroup.Channels
      oElem.Values(iLoop) = oFile.GetNextStringValue(eR64)
    Next
    Call oFile.SkipLine()
  Wend
End Sub

DataPlugin Description

The DataPlugin first specifies the general format of the file through the File object. The DataPlugin uses the VBS constant vbCrLf as the word-wrap and ignores empty rows and spaces which are not within the text. The VBS constant vbTab separates single values. A point is the decimal symbol.

Then the DataPlugin reads in the descriptions of the channels. The first line of the file contains the names of the channels and the second line the corresponding units. The DataPlugin uses the Split function to check the read in data for the vbTab separator and stores the substrings in a one-dimensional, zero-based array. The number of arrays specifies the number of channels that the file contains.

Then the DataPlugin generates a new channel group whose name corresponds to the name of the file to be read in.

In the first loop, the DataPlugin generates new channels with the names previously read in and the associated units and then assigns these channels to the new channel group.

The channel data is imported in a second loop structure. The DataPlugin uses the GetNextStringValue function to read in the channel values. The data is read from the current position to the delimiter which is specified by the Delimiter property, which in this case is vbTab. If no delimiter is found, the data is read up to the line feed character which is specified by the Linefeeds property. When the reading of a value is complete, the GetNextStringValue function sets the file pointer according to the data type. The SkipLine function jumps to the next row in the file. The While loop reads the properties repeatedly until the file pointer reaches the end of the file.

Log in to get a better experience