DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract single channel information from file group

Solved!
Go to solution

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

0 Kudos
Message 1 of 7
(5,227 Views)

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.

Message 2 of 7
(5,213 Views)
Solution
Accepted by topic author Mark_A

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.

 

Maximum.png

 

I hope that helps...

Derrick S.
Product Manager
NI DIAdem
National Instruments
Message 3 of 7
(5,211 Views)

Many thanks to both for the quick responses. I will work with these examples.

 

Mark

0 Kudos
Message 4 of 7
(5,201 Views)

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
0 Kudos
Message 5 of 7
(5,044 Views)

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:

 

Function: CCh

Calculates the characteristic values of a data channel.

ReturnValue = CCh(ChannelName,StatValueIndex)

Input Parameters

ChannelName Specifies the name of a data channel.
StatValueIndex Specifies the index of the characteristic value to be calculated.
Index Characteristic value
0 Mean value
1 Minimum
2 Maximum
3 Range
4 Total

Return Parameters

ReturnValue Returns characteristic values of a data channel.
Otmar D. Foehner
Message 6 of 7
(5,022 Views)

Great! Thank you very much Otmar

0 Kudos
Message 7 of 7
(5,010 Views)