From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Error Concatenating TDMS Files

Solved!
Go to solution

Hi everyone,

 

I have trouble using the provided script ChnConcatenation_Libr.vbs for appending time channels to one another. It has been working without any problems for a while now, but an error is occuring with the attached TDMS-files.

 

I have no idea what to make of it and would be happy, if someone could help me.

 

Best regards,

Jakob

Download All
0 Kudos
Message 1 of 5
(2,596 Views)
Solution
Accepted by topic author jakob.griebenow

I have a very old script that worked for those 2 files I think?  I loaded test1 and then test2:

Option Explicit  'Forces the explicit declaration of all the variables in a script.
DIM SCRIPT_NAME
SCRIPT_NAME = "concatenator: "
' GLOBALS NEEDED:
  '- numberOfGroups: how many groups are in the original file loaded
  '- timeChannelName: the name of the channel to look for when offsetting time
  '- extraTimeChannels: TRUE/FALSE to generate extra time channels?

Dim numberOfGroups: numberOfGroups = 1
Dim timeChannelName: timeChannelName = "TimeStamp"
Dim extraTimeChannels: extraTimeChannels = FALSE

Call LogFileWrite(SCRIPT_NAME & "Entered execution")
' Check if a valid number of groups is loaded
If GroupCount >= numberOfGroups * 2 Then
  If (GroupCount Mod numberOfGroups = 0) Then
  
    ' First generate extra time channels if required
    If extraTimeChannels Then
      Call LogFileWrite(SCRIPT_NAME & "Generating extra time channels")
      Dim sec, fq, hours, seconds, chnlSize, i
      For i = 1 To GroupCount Step 1 ' for each channel group
        Data.Root.ChannelGroups(i).Channels("Timestamps").Properties("displaytype").Value = "Numeric"
        ' Calculate frequencies
        sec = Str(Data.Root.ChannelGroups(i).Channels("Timestamps").Maximum)
        fq = Data.Root.ChannelGroups(i).Channels("Timestamps").Size / sec
        hours = Data.Root.ChannelGroups(i).Channels("Timestamps").Size / fq / 3600
        ' Generate numeric channels representing time
        Data.Root.ChannelGroups(i).Activate()
        chnlSize = Data.Root.ActiveChannelGroup.Channels(2).Size
        Call ChnLinGenImp("LinearGenerated",chnlSize,0, hours / Data.Root.ChannelGroups(i).Channels("Timestamps").Maximum,"")
        Data.Root.ChannelGroups(i).Channels("LinearGenerated").Name = "Hours"
      Next
      Call LogFileWrite(SCRIPT_NAME & "Done generating extra time channels")
    End If
  
    ' Concatenate!
    Dim groupToConcatenate, j, counter
    counter = 0
    groupToConcatenate = 1
    Do While GroupCount > numberOfGroups
      If groupToConcatenate > numberOfGroups Then 
        groupToConcatenate = 1
      End If
      For j = 1 To Data.Root.ChannelGroups(numberOfGroups + 1).Channels.Count Step 1 ' Concatenate all channels
        Data.Root.ChannelGroups(numberOfGroups + 1).Activate()
        If Data.Root.ChannelGroups(numberOfGroups + 1).Channels(j).Name = timeChannelName Then ' Offset and concatenate for time channel
          If Data.Root.ChannelGroups(numberOfGroups + 1).Channels(j).Values(1) = 0 Then
            Data.Root.ChannelGroups(numberOfGroups + 1).Channels(j).Values(1) = 0.001 
          End If
          Call ChnOffset("[" & numberOfGroups + 1 & "]/" & timeChannelName & "", "/" & timeChannelName & "", Data.Root.ChannelGroups(groupToConcatenate).Channels(timeChannelName).Maximum, "free offset")
          Call ChnConcat(Data.Root.ChannelGroups(numberOfGroups + 1).Channels(j), Data.Root.ChannelGroups(groupToConcatenate).Channels(j))
        ElseIf Data.Root.ChannelGroups(numberOfGroups + 1).Channels(j).Name = "Hours" Then
          Call ChnValExpand(Data.Root.ChannelGroups(numberOfGroups + 1).Channels("Hours"))
          Call ChnOffset("[" & (numberOfGroups + 1) & "]/Hours","/Hours",Data.Root.ChannelGroups(groupToConcatenate).Channels("Hours").Maximum,"free offset")
        Else ' Just concatenate
          Call ChnConcat(Data.Root.ChannelGroups(numberOfGroups + 1).Channels(j), Data.Root.ChannelGroups(groupToConcatenate).Channels(j))
        End If
      Next
      ' Clear the channel group
      Call Data.Root.ChannelGroups.Remove(numberOfGroups + 1)
      groupToConcatenate = groupToConcatenate + 1
      counter = counter + 1
'      If counter Mod (numberOfGroups * 100) = 0 Then
'OPTIONAL PRINTOUT    Call LogFileWrite(SCRIPT_NAME & "concatenated " & counter + numberOfGroups & " channel groups, that is " & (counter/numberOfGroups) + 1 & " files")
'      End If
    Loop
    Call LogFileWrite(SCRIPT_NAME & "Concatenated " & counter & " channel groups, or " & counter / numberOfGroups + 1 & " files (" & numberOfGroups & " channel groups per file)")
  Else
    Call LogFileWrite(SCRIPT_NAME & "Can't start execution with group count not being a multiple of " & numberOfGroups)
  End If
Else
  Call LogFileWrite(SCRIPT_NAME & "Can't start execution with only " & GroupCount & " groups loaded...")
End If
Call LogFileWrite(SCRIPT_NAME & "Exited execution")

You will need to define the 3 variables at the top named globals but I did it so if all the files you load are in this format you should be ok..

- Attached are the resulting tdms and the graph

Download All
0 Kudos
Message 2 of 5
(2,576 Views)

.. You can load as many groups as you wand in their chronological order (oldest first loaded) and it will concatenate all into one group.

0 Kudos
Message 3 of 5
(2,576 Views)

Thanks for your answer.

 

Unfortunately the resulting file test12.tdms has an incorrect timestamp. That is why your script won't help me much. Do you have another idea?

 

Best regards

Jakob

0 Kudos
Message 4 of 5
(2,546 Views)
Solution
Accepted by topic author jakob.griebenow

It is probably because I add offset to each time channel concatenated so it is monotonous and continuous.  Maybe try commenting out the ChnOffset() functions ??

Message 5 of 5
(2,542 Views)