LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading special file formats

I would like to read in a text file which has a different format from standard text files supported by labview (XML, lvm tdm/s etc.). Basically my interest is to be able to by pass all the uneccessary characters on the header and go right to the channel names and onwards to the actual data.

I know there is a special character that marks the beginning of the channel names in this file.

So i need labview to be able to tell what the channels are (start to end of the channel names) as well the corresponding data following the channel names, (probably by searching /parsing for this special character).

Thereafter i finally want to be able to read the file in just like one can do by using the "read from measurement file" function and output that as a dynamic data signal.

I am not conversant with parsing and reading in text files, so kindly provide as much as details as possible.

Thanks.

[BADGE NAME]

0 Kudos
Message 1 of 13
(3,374 Views)

Just read the entire file as one long string and use string parsing functions on it. Then convert the data part to a 1D or 2D array. Afterwards you can convert that to dynamic data (but why would you want dynamic data????)

0 Kudos
Message 2 of 13
(3,358 Views)

Yes if I can get that into a 2D array (which is what it actually is) that would be fine.- Doesnt necessarily have to be dynamic data. But can you explain "reading it in as a long string and then parsing". Kindly note that I am not very conversant with file I/O

[BADGE NAME]

0 Kudos
Message 3 of 13
(3,339 Views)

@blessedk wrote:

But can you explain "reading it in as a long string and then parsing". 


Let's start with "Reading it in as a long string".  Have you done any LabVIEW Programming?  Have you viewed any (and all of) the LabVIEW Tutorials referenced on the upper right of the Forum's Start page?

 

On the Files Palette, there is a function called Read from Text File.  Read its Help description (put the function on an empty Block Diagram, right-click it, and choose "Help").  You should see that if you wire a String Indicator up to its Text output and run it, it will (a) ask you for the File you want to read, and then (b) will give you the contents of the file as an array of characters (otherwise known as a "string").  You should then Close the File (there's a function for that, too).

 

Parsing a String means using the Functions on the String palette to do various things with the String, often to split it into sub-strings that you can place in a 1D Array of Strings.  Note that you probably do not want a 2D array of Characters (unless all of your Strings contain exactly the same number of characters).

 

Try doing this.  Develop some code.  It might not work, but if that is the case, come back here, post your code (which means "attach your VI" -- do not attach a picture!!), and ask for help, describing the problem you are having.

 

Note that it might also help to attach the file that you are trying to read and parse (so we'll have access to the same data that you are trying to use).

 

Bob Schor

0 Kudos
Message 4 of 13
(3,307 Views)

 

Start reading here, then folllow the links on that page.

 

Actually, it will read it as a plain string, I would leave the word "array" out of it, because it can confuse. If you want to read it as an array of strings where each array element is a line, you can switch the mode to "read lines".

And if you wire a path directly to the upper left, you don't even need to close the file. (It will open and close automatically, see the help).

Also, make sure to disable "convert EOL" if you want to read the file content "as is".

 

0 Kudos
Message 5 of 13
(3,294 Views)
How large are these files? Very large files are very inefficient to parse all loaded into memory at once.

You might also consider going through the LabVIEW tutorials.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 6 of 13
(3,281 Views)
That's one good point to note too. Potentially very large. Up to 1GB or more.

[BADGE NAME]

0 Kudos
Message 7 of 13
(3,275 Views)
OK, in that case you do not, repeat NOT, want to read them all at once.

The idea is pretty simple: once you get past the header, read in a chunk of data and process it. Then read in another chunk and process it, and so on until you reach the end of the file.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 13
(3,265 Views)

@blessedk wrote:
That's one good point to note too. Potentially very large. Up to 1GB or more.

Are you sure there is only one header in the file?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 13
(3,210 Views)

Another note...

 

Very large text files will take some time to process. I recently did an application that required reading frmo 2G plus text files and even after I converted them to raw binary files, patience was required.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 13
(3,200 Views)