LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read file help

Hi all,
 
I have been acquiring 4 channels ( two colums for each channel) of data and have been storing them in a txt file. I'm trying to plot the waterfall plot of a specific channel data and i need to read 1024 values of the data from a specific column of the txt file. I have tried the read file example, but i'm not able to control the samples read at a time. i don't want to read the whole file, cause the size is around 80MB.
 
I'm using Labview 7.
 
Any suggestions or help is very much appreciated.
 
Aravind
0 Kudos
Message 1 of 8
(3,546 Views)
All the read file vis have a start offset input that you could use to begin the reading at a specific position, and a length input to define the size of the data chunk that has to be read.
How to use these inputs depends on the way the data were stored.
You said that you used a .txt format, but how were the data separated ? Did you save an index value, or a time stamp with each of them ? Are they taken at constant time intervals ? Did you save them as ASCII values ?
Chilly Charly    (aka CC)
0 Kudos
Message 2 of 8
(3,538 Views)


@aravind_phd wrote:
Hi all,
 
I have been acquiring 4 channels ( two colums for each channel) of data and have been storing them in a txt file. I'm trying to plot the waterfall plot of a specific channel data and i need to read 1024 values of the data from a specific column of the txt file. I have tried the read file example, but i'm not able to control the samples read at a time. i don't want to read the whole file, cause the size is around 80MB.
 
I'm using Labview 7.
 
Any suggestions or help is very much appreciated.
 
Aravind



You have to keep in mind how data is stored in a file like this. It is as if it were a one long 1D byte array. It may look formatted into columns of data when you print the file but it's just one long string of bytes to LabVIEW. To get to any one particular byte or set of bytes you need to wade through all the bytes that precede it or them.  Assuming the routine that wrote the file wrote an ordered pair of values for Ch #1, a pair for Ch #2, a pair for Ch #3, a pair for Ch #4 and then repeated, you can then use that pattern to figure out where the paired data for any reading of any given channel is stored in the file. You can then read out one pair or 1024 pairs as needed using the "read offset" parameter you can specify to the file read function. Note that while you are reading the file you will need to keep track of how the ASCII data is stored, formatted and delimited and adjust the byte count and offset accordingly to account for the extra characters. If your file data is formatted appropriately try the Read From Spreadsheet File function.

It would probably be more efficient if you were to figure out where the 1024 pairs you are interested in started for channel #1 and then read out all the pairs for channels 1-thru-4 in one read operation (8192 values). Depending on how the data is formatted in the file, the spreadsheet string to array function may help in converting the incoming byte string into ordered numeric values. Otherwise you would process the 1D byte stream data array read in to get just the data for the channel of interest. That would involve recognition of the various value delimiters (spaces and/or commas and/or end-of-line markers) and the values separated by them and decoding of the ASCII values into numeric values. 

It all starts with knowing exactly how the data is formatted throughout the file...

0 Kudos
Message 3 of 8
(3,536 Views)

I'm sorry for not mentioning the file type.. and other details..

I have used the default write file which comes with the LabVIEW 7 (Write LabVIEW Measurement File ). I have writing the data in ASCII format with tab as the Delimeter...I have copied few lines of my data file.

*****************************************************************************
0.000000 -1.820420 0.000000 -0.000915 0.000000 -0.523118
0.000250 -1.458149 1.000000 -0.004333 0.000250 -0.754687
0.000500 -1.300527 2.000000 -0.010562 0.000500 -0.870796
0.000750 -1.187986 3.000000 -0.019016 0.000750 -0.938580
*****************************************************************************

There are 3 channel data, the first column is the time stamp and the second column is the actual data of the first channel..

Thanks again..
Aravind

0 Kudos
Message 4 of 8
(3,529 Views)

If there is no change in sign (positive or negative) then it is not very difficult to calculate the offset to reach a given record.

Each line is composed of 57 chars (including the tab and return separators and the 3 negative signs).

The simplest solution is to use the Read from Spreadsheet File vi. To read the nth chunk of data, you need to read 1024 rows from byte  n x 1024 x 57. You can then separate the different colums using the index array function.

However things could be more complicated if there are sign changes or if the number of chars varies (decreasing under -9.999999 for instance !). There the best approach will be to estimate the offset, then to reacd a few lines and search for the correct time stamp. Ask if you need more help...

Message Edité par chilly charly le 12-27-2005 09:45 PM

Chilly Charly    (aka CC)
0 Kudos
Message 5 of 8
(3,528 Views)


However things could be more complicated if there are sign changes or if the number of chars varies (decreasing under -9.999999 for instance !). There the best approach will be to estimate the offset, then to reacd a few lines and search for the correct time stamp. Ask if you need more help...


Aravind,
 
Here's where you can really help make your job of reading the file easier by controlling how you write the file. If necessary, you need to modify the writing routine's format specifiers to output fixed-width values so that the reading routine can always depend on each and every line in the file to always contain exactly the same number of bytes. Consider using scientific notation with a specified field width and precision large enough to accommodate the largest numbers  your system will ever see. For example, a format like "%+15.7e" will take care of any number between  -9.9999999E+999 and +9.9999999E+999 (and all the tiny stuff in between) and it will always take exactly 15 bytes/characters per value. If, like your example, each line had three pairs of values with tabs delimiting them and the end-of-line character at the end and all the numbers were formatted with this format specifier then you'd always know each line would always contain 6*(15+1)=96 characters making it very easy to calculate where any line in the file was located when you wanted to read it.

0 Kudos
Message 6 of 8
(3,514 Views)
The data which I'm saving is that of a Rotor signal is harmonic, i had previously tried to read the data from "read from spreadsheet" VI was succesful in reading a cluster of data. I have followed your suggestion by giving an offset of 57*1024 with every increment and i'm able to read the data. I'm not able to understand the point where you mentioned about negative data (SIGN Change), cause it seem to be working fine.
 
Aravind
0 Kudos
Message 7 of 8
(3,504 Views)


@aravind_phd wrote:
I'm not able to understand the point where you mentioned about negative data (SIGN Change), cause it seem to be working fine.

The sample block of data you showed has negative values in the second, fourth and sixth columns.

  • Will all values in those columns always be negative?
  • If not, when the minus sign ASCII character is not used, does any other ASCII character take its place? An ASCII space character or an ASCII plus sign?
    Or does the line of data just have fewer than 57 characters in it?

If some of the lines don't have minus signs in in them and that causes the lines to have fewer than 57 characters per line then you cannot reliably use the value 57 to calculate file offsets. 

0 Kudos
Message 8 of 8
(3,495 Views)