LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rearrange TDMS

So we are writing data to TDMS, and then doing post-processing and reporting in Excel.  Someone asked me if it would be possible to swap a few columns in Excel.  That means rearrangeing the order of the channels in the TDMS data.  Normally the answer is nope can't do it.  TDMS is write only and you can't edit it.  But then I realized well that's not entirely true you can read the whole file, then re-order the data and write a new file but that will take a while and very memory intensive if the data size is large.

 

But I thought of another way to rearange the data.  TDMS has what I think is an undocumented features, which allows you to perform a binary copy function, combining multiple TDMS files into one.  The channel order will be defined by the first file in the combine function.  So I made two TDMS files, one with a channel Time at the beginning, and one with Time at the end.  If I perform a "copy /b File2.tdms + File1.tdms Output.tdms" the order will be changed.  The down side is that the data from File2 will be at the beginning of the new file.  So I tried making a "Header.tdms" which contained no data, only the order by setting properties of the channels.  This does create the proper order in the Header file, but when I combine them the file is corrupted and can't be opened.

 

Attatched is my example.  Run the VI, reorder the channels then click Save.  It will make Header.tdms (which is fine) and then it will combine Header.tdms and Temp.tdms into Broken.tdms which can't be opened.  But If I simply combine Temp2.tdms and Temp.tdms (there is a button for this) the output is reordered and good.

 

So my question (finally I know), is there a way to reorder the TDMS channels?  Other than reading and writing the whole file, and other than controlling how the TDMS file is first made (by writing the correct order first).  I feel like I am close because I can do this if data gets appended, but don't want new data in front of Temp.tdms I just want the new order.  Thanks.

Message 1 of 9
(6,023 Views)

Sorry I didn't mean to reply to my own post but I found the problem.  Temp.tdms and Temp2.tdms were created with TDMS version 1.0 and the new ones were being made with 2.0.  Combining them caused issues.  So this method does appear to actually work if you have a TDMS 2.0 file.  This technique could also be used to insert data into a TDMS file between any existing channels.

0 Kudos
Message 2 of 9
(6,020 Views)

Hi

I just tried running your example and i am having some problems.

First of all the first "TDMS open" gives an error because its trying to open the temp.tdms file that does not exist.

So I changed this to "open or create".

 

The second problem is that I do not see the groups being dsiplayed, so I cant modify anything.

The original file path is set to the tdms file I want to edit...

 

 

Thanks!!

0 Kudos
Message 3 of 9
(5,935 Views)

Ok I fixed his problem...but where is the modified tdms file saved? I cant seem to find it.

does it overwrite the original one?

0 Kudos
Message 4 of 9
(5,927 Views)

I think you are confused about several things.  When you unzip the file, the VI must be in the same directory as the other TDMS files.  This is why the intent was to open the existing file.  Because you selected to create a new file, this new file has no groups or channels, so that is why you have none to display.

 

Also the example breaks slightly because as I posted before the temp.tdms, and temp2.tdms are saved in TDMS 1.0 versions while the new Header and Broken TDMS files are version 2.0 which is why the combine fails.  The new Broken and Header TDMS files are saved in the same directory as the VI (same as the temp.tdms and temp2.tdms) and the originals are not touched.

0 Kudos
Message 5 of 9
(5,917 Views)

Hi Hooovahh,

The columns order displayed in Excel is determined by the channel order logged in the first segment of the TDMS file. This explains why you make a new TDMS file with different order and concatenates with the original TDMS file and the order can be changed to the header TDMS file. Unfortunately, as far as I know, there is no other way to accomplish that except for rewriting the TDMS file or appending new header. 

 

However, I think your VI is a good solution to such requirement.

0 Kudos
Message 6 of 9
(5,900 Views)

@deppSu wrote:

Hi Hooovahh,

The columns order displayed in Excel is determined by the channel order logged in the first segment of the TDMS file. This explains why you make a new TDMS file with different order and concatenates with the original TDMS file and the order can be changed to the header TDMS file. Unfortunately, as far as I know, there is no other way to accomplish that except for rewriting the TDMS file or appending new header. 

 

However, I think your VI is a good solution to such requirement.


I realize where the order comes from, which is why I made this example.  I also realize that this is the most efficent way of doing this because I don't have to recreate the TDMS file.  Imagine if my temp.tdms was several GB in size.  It would take a long time to read all the data channel by channel, group by group to recreate it with a new order.

0 Kudos
Message 7 of 9
(5,889 Views)

Hi Hooovahh, 

 

Can you post your example program to our Community Example Forums? I think that this would be very helpful to other users! Here are the instructions on how to: https://forums.ni.com/t5/Using-the-NI-Community/Example-Programs-Submission-Process/ta-p/3698613

 

Best, 

Danielle

0 Kudos
Message 8 of 9
(4,731 Views)
0 Kudos
Message 9 of 9
(4,721 Views)