DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Script to auto zero channels in a TDM file with multiple channel groups

Hi friends,

 

I am trying to process some data but am having trouble modifying a script to autozero channels across multiple channel groups. The following script works to zero channels across one group. I use this script to process data in a TDM file with only one channel group. I need to be able to zero channels across multiple groups (5 groups). But the amount of groups I will have may change so I might need an option to enter the amount of groups or have the script determine the amount of groups in my TDM file. 

 

Here is the code I use to zero the data. Thanks in advance for your help!

 

Sub UserDlg_Select
Call USERDLGINIT()
USERDLGCAPTION="Auto Zero Channel Based on Specified Points "
USERDLGTXT(5)="Number of points to Average"
USERDLGCOMMAND(5)="t1"
Call USERDLGOPEN()
End Sub

Call UserDlg_Select()

T2="1-"&T1

For I= 1 To ChnNoMax 'For all data channels except time
T4=CHNNAME(I) 'Create string for Channel name (I)
T3=ChnDim(T4) 'Create text variable for channel dimension

STATSEL(6)="Yes" 'Arith mean
STATCLIPCOPY="yes"
STATCLIPVALUE="No"
Call StatBlockCalc("Channel",T2,T4) 'Calculate Stats for Channel (I)

'Subtract Mean of first (T1) points for Channel (I)
Call FormulaCalc("Ch('temp1') := CH('"&T4&"') - statarithmean")
CHNCOMMENT("temp1")=("Channel zeroed over first "&T1)+"pts" 'Add Comment
ChnDim("temp1")=T3 'Add Dimension
CHNNAME("temp1")=T4+"-Z" 'Save updated data with -Z

'Delete Stat Channels
Call CHNDEL("ArithmeticMean")
Call CHNDEL("Sum")
Next 'End For loop

 

0 Kudos
Message 1 of 4
(4,610 Views)

Hi rvillalta319,

 

Sounds like you'll need to adapt your code to use both a for loop and some implementation of the GroupCount variable (or ChannelGroups.Count) as seen here:

http://zone.ni.com/reference/en-XX/help/370858K-01/varoff/groupcount/

 

 

 

 

Michael Keane
National Instruments
0 Kudos
Message 2 of 4
(4,512 Views)

Hi villalta,

 

Here's what I'd recommend:

 

FOR Each Group In Data.Root.ChannelGroups
  FOR Each Channel In Group.Channels
    Call ChnOffset(Channel, Channel, CLng(T1), "mean value offset")
  NEXT ' Channel
NEXT ' Group

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 3 of 4
(4,505 Views)

As a side note:

CODs (simple DIAdem dialogs, USERDLG...) were depricated with DIAdem 2012 and will no longer work with DIAdem 2015.

Please consider using SUDs instead.

0 Kudos
Message 4 of 4
(4,460 Views)