04-13-2012 03:16 AM
Hello All,
I want to perform a repeat operation on one channel of a large number of multi-channel files.
As a simplified example lets say I want to calculate the max value in channel 1 for each file in a group. I then want to place these values in the row of a new channel in a new file. Has anyone a similar example file I could modify or suggestions on how to do this? I am working with TDMS files.
Thanks
Mark
Solved! Go to Solution.
04-13-2012 09:10 AM
Hi,
the following script should be do what do described in your example:
Option Explicit 'Forces the explicit declaration of all the variables in a script.
'clear data portal
DataDelAll
'filtered import
call DataFileLoadSel(<filename>, "TDMS", "*/[1]","Load")
'do some calculations
Call ChnCharacterAll()
'write max values to new channel
Dim resultGrp : Set resultGrp = Data.Root.ChannelGroups.Add("Result group")
Dim resultChn : Set resultChn = resultGrp.Channels.Add("Max channel values",DataTypeFloat64)
Dim sourceChannel, i
i = 1
For each sourceChannel In Data.Root.ChannelGroups(1).Channels
resultChn.Values(i) = sourceChannel.Properties("maximum").Value
i = i+1
Next
'Remove temporary loaded channels
Data.Root.ChannelGroups.Remove(1)
Please feel free to ask if you have any question on how to adjust this script to your needs.
04-13-2012 09:28 AM - edited 04-13-2012 09:29 AM
I had a very similar approach, so here's another example in case it helps. This example loops through all files in a specified directory, and if the file is a TDMS file, it loads the first channel in the file and calculates the maximum value.
DIM MyFiles, iCount, Channel CALL Data.Root.Clear() SET Channel = Data.Root.ChannelGroups.Add("Calculated Values").Channels.Add("Maximum",DataTypeFloat64) MyFiles = DirListGet("C:\Program Files (x86)\National Instruments\DIAdem 2011\Examples\Data", "*.*", "filename", "FullFilenames") IF IsArray(MyFiles) THEN FOR iCount = LBound(MyFiles) to UBound(MyFiles) IF UCase(NameSplit(MyFiles(iCount),"E")) = "TDMS" THEN CALL DataFileLoadSel(MyFiles(iCount),,"[1]/[1]") Channel.Values(Channel.Size+1) = CCh("Calculated Values/[2]",2) CALL Data.Root.ChannelGroups("Calculated Values").Channels.Remove(2) END IF NEXT END IF
If you can calculate the channel maximum value (or whatever property you're interested in tracking) during the acquisition and saving of the file, you should store that entity to a TDMS channel property. This would allow you to run queries on the property across all of your files and then very quickly load the results as a channel into the Data Portal.
I hope that helps...
04-13-2012 09:46 AM
Many thanks to both for the quick responses. I will work with these examples.
Mark
06-07-2012 02:00 AM
Hello
From previous discussions the following script provides the maximum first channel value from a group of TDMS files. I'm now trying to modify this to provide the minimum channel value but without success. What do I need to change within this script to do this?
Thanks in advance
Mark
DIM MyFiles, iCount, Channel CALL Data.Root.Clear() SET Channel = Data.Root.ChannelGroups.Add("Calculated Values").Channels.Add("Maximum",DataTypeFloat64) MyFiles = DirListGet("C:\Program Files (x86)\National Instruments\DIAdem 2011\Examples\Data", "*.*", "filename", "FullFilenames") IF IsArray(MyFiles) THEN FOR iCount = LBound(MyFiles) to UBound(MyFiles) IF UCase(NameSplit(MyFiles(iCount),"E")) = "TDMS" THEN CALL DataFileLoadSel(MyFiles(iCount),,"[1]/[1]") Channel.Values(Channel.Size+1) = CCh("Calculated Values/[2]",2) CALL Data.Root.ChannelGroups("Calculated Values").Channels.Remove(2) END IF NEXT END IF
06-07-2012 11:14 AM
Hello Mark,
That's actually a very easy change. Simply edit the line with the CCh command and replace the last parameter (currently "2" for maximum) with the correct value for the minimum ("1" for minimum)
Channel.Values(Channel.Size+1) = CCh("Calculated Values/[2]",1)
Here is the context for the CCh function:
Calculates the characteristic values of a data channel.
ReturnValue = CCh(ChannelName,StatValueIndex)
ChannelName | Specifies the name of a data channel. | |||||||||||
StatValueIndex | Specifies the index of the characteristic value to be calculated. | |||||||||||
|
ReturnValue | Returns characteristic values of a data channel. |
06-08-2012 02:36 AM
Great! Thank you very much Otmar