LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read and sort the text file

Hi everyone, I'm very new to a LabVIEW program and I'm trying to learn about it but seemingly I'm currently struggling to extract and sort the string data into the array. Ultimately, I'd like to be able to extract and sort the data and covert into a numeric array to do a further analysis. Do anyone have any suggestions on this issues? 

 

Regards. 

0 Kudos
Message 1 of 5
(138 Views)

Hi libra,

 


@librathedrowsy wrote:

I'm currently struggling to extract and sort the string data into the array. Ultimately, I'd like to be able to extract and sort the data and covert into a numeric array to do a further analysis. Do anyone have any suggestions on this issues?


What have you tried and where are you stuck?

 

You have a structured text file and need to parse its content.

Fortunately its structured very simple like:

 

[1.1.1.1.1 - Trace Data]
Sweep  Data(mV)<1000>=-19.8100,21.3733,…,0.3650,0.3133/
0.3117,0.2517,…,0.1133,0.1133/
0.1083,0.1117,…,0.0667,0.0667/
…
-0.0183,-0.0117,-0.0083,-0.0167,-0.0183

 

  • I guess there are 1000 samples in this SweepData block (I didn't count them).
  • Each line ends with a "/" to indicate there are more samples in the next line.
  • When there is no "/" at the end then you have found the last line of the trace data samples.
  • The numeric data are separated by commas.
  • The numbers use "English" separator (aka point).

I would:

  1. Find the data I need using their Section header (like "[1.1.1.1.1 - Trace Data]").
  2. Then get all the line with numeric data, as described above.
  3. Append all lines into one string and replace the "/" by commas (and remove all additional EndOfLine chars)
  4. Use SpreadsheetStringIntoArray to get a numeric array with all samples…

The file content looks very similar to an INI file, so you could even try to use the ConfigFile functions on your file.

Just tried that on my own and it failed. Stick with string functions instead…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(106 Views)

@GerdW wrote:

tent looks very similar to an INI file, so you could even try to use the ConfigFile functions on your file.

Just tried that on my own and it failed. Stick with string functions instead…


Probably because multibyte chars inside. Quick and dirty something like that should work:

Snippet.png

Message 3 of 5
(100 Views)

What are you struggling with specifically?

 

Since your file is encoded in UTF16, you need the NI Unicode Tools (vipm, forum post) to convert it to ASCII text.

 

Then you can use the config file VIs to read keys.

 

snip.png

 

 

You have to read arrays as strings and convert them using spreadsheet string to array.

 

Edit: Ok, arrays split across lines are not recognized, so unfortunately the config file VIs are out.

 

 

Message 4 of 5
(96 Views)

Hi,

 

maybe the OP just edited/saved the attached text file using Windows notepad, which is often converting plain ASCII text files into UTF-encoded text files.

I would guess the original software ("Synergy v.12.2") writes simple ASCII text files…

 

So before converting Unicode to ASCII I would ask the OP for clarification on this topic!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 5
(71 Views)