DIAdem Help

Content Type
Programming Language
Current manual

Additional Example 2: Splitting Metadata

Additional Example 2: Splitting Metadata

The following example shows a DataPlugin for reading in the text file DataPlugin_AdditionalEx2.aex2. The DataPlugin script file is located at DataPlugin_AdditionalEx2.vbs 

Data Format Description

This text file contains metadata and channel data. The metadata includes a comment and the channel names and channel units. The first line of the file to be read in contains the comment. The second line contains an identifier, a name, and a unit for each channel. The unit is enclosed in angle brackets and is part of the channel name. The identifier and the channel name are separated by a colon as the diagram shows: Identifier1: Name1[Unit1], Identifier2: Name2[Unit2].

The channel data follows: The channel names and the channel data are separated by commas. The specified numbers use a point as the decimal symbol. The numbers do not have a thousand separator. Leading and trailing blanks are irrelevant. The end of the line is indicated by Carriage Return and Line Feed.

Special Features of the DataPlugin

  • Line feed: CrLf

  • Ignoring spaces

  • Separators: Comma

  • Decimal symbol: Point

  • Reading in the comment and saving the comment in the group properties

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

  • Extracting the channel unit, which is part of the channel name

  • Using DirectAccess channels to read in channel data

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

  ' Create channel group object and set property
  Dim oChannelGroup : Set oChannelGroup = Root.ChannelGroups.Add(oFile.Info.FileName)
  Dim sComment : sComment = oFile.GetNextLine
  Call oChannelGroup.Properties.Add("Input_File", sComment)

  ' Read channel header
  Dim saChnNameUnit : saChnNameUnit = Split(oFile.GetNextLine, ",")

  ' Get object for block stored data  
  Dim oBlock : Set oBlock = oFile.GetStringBlock() 

 ' Import all other channels with fast access
  Dim oChn, oElem, sName, sUnit

  For each oElem in saChnNameUnit
    ' Extract the channel unit, which is part of the channel name
    Call GetChnName(oElem, sName, sUnit)

    ' Create channel in string block (file)
    Set oChn = oBlock.Channels.Add(sName, eR64)
    Call oChn.Properties.Add("Unit_String", sUnit)
    
   ' Add defined channel to DIAdem channel group
    Call oChannelGroup.Channels.AddDirectAccessChannel(oChn)
  Next
End Sub
'-----------------------------------
Sub GetChnName(sNameUnit, sName, sUnit)
  'sNameUnit contains e.g. C1 (1A1): Time[s]
  sNameUnit = Trim(Mid(sNameUnit, InStr(sNameUnit, ":") + 1, len(sNameUnit)))

  If InStr(sNameUnit, "[") > 0 Then
    sName = Left(sNameUnit, InStr(sNameUnit, "[") - 1)
    sUnit = Mid(sNameUnit, InStr(sNameUnit, "[")+1, InStr(sNameUnit, "]") - InStr(sNameUnit, "[")-1)
  Else
    sName = sNameUnit
  End If
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 spaces which are not within the text. The comma separates single values. A point is the decimal symbol.

The DataPlugin then generates a new channel group whose name corresponds to the name of the file to be read in. The DataPlugin uses the GetNextLine function to read in the comment contained in the first line and saves the group property Input_File.

The second line contains an identifier, a name, and a unit for each channel. The unit is part of the channel name. A colon separates the identifier and the channel name. The DataPlugin reads in this data, uses the Split function to check the data for the colon delimiter, and stores the substrings in a one-dimensional, zero-based array. The number of arrays specifies the number of channels that the file contains.

The DataPlugin transfers the other file contents into a StringBlock. If DirectAccess channels are associated with a StringBlock, the order of the values in a row determine which value belongs to which channel. The first value of the row belongs to the first channel, the second value of the row belongs to the second channel and so on. The value limits are specified by the Delimiter property, which in this case is the colon.

The channel data is imported in a loop structure. The number of loops is specified by the size of the array which contains the channel names. Within the loop, the DataPlugin generates a new DirectAccess channel with the name that was previously read in and the associated unit. Because channels always belong to one channel group, the DataPlugin assigns the channels to the new channel group.

The channel unit is extracted from the channel name in the GetChnName procedure. This procedure receives the transfer parameter which contains the array with the identifiers and the channel names. In the first step, the procedure separates the identifier and the channel names. The identifier is irrelevant for reading in the data. In a further step, the procedure checks whether the channel name contains a unit. If this is the case, the unit is in angle brackets. The procedure returns the channel name and the channel unit in the transfer parameters sName and sUnit.

Was this information helpful?