DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Import data from txt-file and give name to the channels

Solved!
Go to solution

Hello,

 

I want to import data from an txt-file (see attachement). Well, no proplem, but I want also read the information about the channel names and  the units and rename the imported channels. Is it possible to do so? Its also important that the number of channels can vary.

 

Can anyone give me some example code?

 

Thanks a lot

Gabriel

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

Hello fischerg,

 

please find attached a dataplugin which will read your file.

All you need to do is download the file to your machine, unzip it and double click the ".uri" file.

This installs the dataplugin automatically. Once this is done (no reboot required) you can drag&drop the files like any other DIAdem internal file like TDM

 

If you want to use it to index the files with Datafinder, please make sure DataFinder is configured to use it.

 

I configured the dataplugin to read the channel names and channel units from the file. If you are interested, take a look at the source code, its pretty short.

The key element is using regular expressions to describe the pattern used for the channel headers. This makes teh remaining code very straightforward.

 

If you find a file which does not work, please provide the file so that we can check for the problem.

 

Andreas

Message 2 of 7
(5,599 Views)

Hello Andreas,

 

Thanks for the plugin. But I'm sorry, it doesn't work. I atach the file, maybe you can help me and find out why it doesn't work?

 

Thanmks

Gabriel

 

Message 3 of 7
(5,587 Views)

Hello fischerg,

 

Looking at your second file, I immediately saw the problem. I was under the assumption that the channel names always had a certain number of "."'s in the name. I now simplified the pattern for the file name. As a result this is more stable now. I have attached the updated Dataplugin.

It would be possible to split the channel names further, e.g.. to remove elements which are the same for each channel (like "Gabelstapler.Last_Run" which repeats in every channel name). To do so, one need to know whether this is helpful and what assumptions can be made for all of your files.

 

Andreas

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

Hello Andreas,

 

Thanks a lot for the new plugin. it works fine.

 

Yes, I wan't the channel names. The first channel in the file aways will be"A.  .Gabelstapler.Last_Run.TIME (sec)" ad should be named as "Time. The follwowing channels in the file have the name like

 "B.  .Gabelstapler.Last_Run.MEA_Messmarker_Antriebsachse.Q (mm/sec**2)".

 

The ".Gabelstapler.Last_Run." is always the same (for one simulation). In general, it will be" .[Modelname].Last_Run.", so all the characters between the first 3 dots. The "MEA_" could be usefull, so I will cut the string by my own (Can you tell me the function to use?)

The ".Q" at the end is needless (but only channel 2 to n, the first channel ends with TIME!!)

 

Is it possible to run a skript automatically in DIAdem after opening an file? I wrote a skript, which eliminates needless data so that the time steps are all equal an creates waveform-channels.

 

Thanks

Gabriel

 

0 Kudos
Message 5 of 7
(5,555 Views)
Hello fischerg, I think the best way to adjust the channelnames to your needs is to edit the source code for the DataPlugin. It's in fact a simpel script like all the other scripts in DIAdem. To edit the DataPlugin Script, please open the module "SCRIPT" and in the menu go to "Einstellungen=>Optionen=>Erweiterungen=>DataPlugins". In the dialog, select your plugin and click on "Eigenschaften...". In the dialog which is displayed, select "Script bearbeiten" This will open the DataPlugin script in the editor. I have attached an updated version of the plugin which calls a function "AdjustChannelname" to process the channel name which is read from the file before it is used to create the channel in DIAdem Please go down in the code until you find the function. Currently the function splits the raw channel name into the pieces between the "."'s (sgaTokens = Split(sgRawName,".")) It then combines the pieces using "_" between the pieces. (See the loop following the above statement) Doing so it skips the first two pieces. (lFirst = 2) The second parameter gives you the channel number. With that information you could easily skip the last piece for all channels following the first channel. I didn't do that for the example because in your first example you provided, all the channel names had only three elements. If I skip the first two and omit the last one, the channel name would be empty. I provided the example code but commented it out (If ( 0 < ChannelNo ) Then lLast = UBound(sgaTokens) -1) Andreas
0 Kudos
Message 6 of 7
(5,545 Views)
Solution
Accepted by fischerg

Hello Andreas,

 

Thanks for your work. I'll adjust the code.

 Gabriel

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