11-07-2014 10:15 AM
Hi All,
I am trying to convert multiple TDMS files to an Excel format with a reduced sample rate. The TDMS files are sampled at 25kHz and I would like the Excel files to be 2.5 kHz.
I can do this manually for each file by loading the TDMS file, using the script below, deleting the original group and resaving the file as an Excel. Here is the script:
Call GroupCreate("Reduced Channels")
Call GroupDefaultSet(GroupCount)
ReducVal = 10 'Reduction value (total reduction = original/this value.
CalcXChn = 1 'Time base channel.
CalcYChn = "2-6" 'Channels in group to be reduced.
ClassNo = ChnLength(CalcXChn)\ReducVal
Call ChnClassXRedXY(CalcXChn, CalcXChn, CalcYChn, "Automatic", "Mean")
FOR i = 1 TO GroupChnCount(GroupCount)
ChnName(CNoXGet(GroupCount, i)) = ChnName(CNoXGet(1, i))
Next
Ideally, I would like to have a user interface which allows the user to select the file(s) and have a program to reduce the sample rate and save it as an Excel File. Unfortunately, this I have not been able to acheive yet.
I have attached an Excel file that has been converted manually. Any help would be appreciated.
Thanks
11-10-2014 06:09 PM
Hello,
Deleting the original group and saving the file as an Excel File could be automated. You can also use the FileDlgShow command to allow users to select multiple files from a dialog box, then run your script on each file in turn. Adding these steps should help streamline the process.
11-11-2014 06:02 AM
Thanks Steven,
I will give this a try.
11-12-2014 10:15 AM
OK,
Instead of converting to an Excel file, I would be satisfied with converting to a .CSV file.
I created a new script to convert the filelist to CSV, but I am not sure how to use the original file names (just replacing the .TDMS extension with the .CSV extension).
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim i
If FileDlgShow(DataReadPath,"TDM Files,*.tdm","DataSelection",True) = "IDOk" Then
For i = 0 to UBound(FileDlgNameList)
Call Data.Root.Clear()
Call DataFileLoad(FileDlgNameList(i),"TDM","Load")
Call DataFileSave(FileDlgNameList(i),"CSV")
Next
End If
In particular, the statement "Call DataFileSave(FileDlgNameList(i),"CSV")" needs to do this I assume, but I am not sure about the syntax.
Thanks for the help.
11-13-2014 09:13 AM
Hi CVfactor,
Here's the code to use the folders and file name but not the file extension:
CsvFilePath = NameSplit(FileDlgNameList(i), "P") & NameSplit(FileDlgNameList(i), "N") & ".CSV" Call DataFileSave(CsvFilePath,"CSV")
Do note that the CSV export will only export one Group from the Data Portal. If you need to export multiple groups, one to each file, then we can use the DataFileSaveSel() command.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
11-13-2014 09:28 AM
Thanks Brad, I'll give this a try.
11-20-2014 07:37 AM
I'm getting an error when trying this script (see attachment).
If anyone has any ideas what the cause of this is, I would appreciate any feedback.
Thanks,
11-20-2014 07:56 AM
Option Explicit prevents this from working.
11-21-2014 10:07 AM
From the image you attached of the error, it appears that CsvFilePath is never declared in your script (i.e. Dim CsvFilePath) and will therefore be undefined.
11-21-2014 10:10 AM
Yes, Steven you are right. Removing the "option explicit" statement also allows this script to work.