LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine the lines in a file?

Hi,
 
I have a VI that reads the lines in a file and then I am using a for loop to analyze the data.
Is there a way to determine the number of lines in the file so that I can feed it in the N value of the for loop?
 
I tried the command EOF in the read lines VI with no success.
 
Let me know,
 
Fede
 
0 Kudos
Message 1 of 24
(4,106 Views)

As a quick fix, you would need to use a WHILE loop and stop once the first match pattern returns a -1 as offset.

Somwhow, your code looks very inefficient. How big are these files typically?

0 Kudos
Message 2 of 24
(4,080 Views)
All you need to do is to take the output of your "Read Lines From File" function and feed it to a "Spreadsheet String to Array" function. This will create a 1D array of your individual lines using the newline as your separator for lines. The size of the array is the number of lines in the file:




Addendum: After looking at your VI again you may want to look at using the "Read from Spreadhseet File" as that will give you a 2D array with the rows being the lines in your file and the column being the individual columns separated at tabs, which is what you seem to be doing in your VI.

Message Edited by smercurio_fc on 02-22-2006 09:03 AM

Message Edited by smercurio_fc on 02-22-2006 09:08 AM

0 Kudos
Message 3 of 24
(4,063 Views)

It is not not finalize yet.

I usually solve with what I know and then go back and maximaze.

The file could have up to 120000 lines

thanks for the help.

I used format into file because I do not know any other way to save the numbers in an text file

0 Kudos
Message 4 of 24
(4,052 Views)

It looks like your file is a tab delimited 2D array of numbers.  As has been mentioned, if you use the "Read from Spreadsheet File.vi" you will get a 2D numeric array.  This eliminates all of the parsing of data that you're doing inside the vi (at least it would appear that way).  All you would need to do is use autoindexing and then pull out the appropriate number from the 1D array (row) inside the loop. 

Also, is there a reason that you're writing unaltered data to a new file?  It would seem that you're just making a new copy of the file (maybe I'm missing something here, I've not gone through your program extensively).  There is no data in the second file that's not in the first file.  Are you cutting out some columns?  This just seems like a waste of disk space to me.

0 Kudos
Message 5 of 24
(4,044 Views)

I think I understand what you are saying.

You think I should reorgabize the array witout using the shift registers and using the read from spreadsheet vi.

I am not saving the same file.

I am trying to save the data in 3 different formats. I am eliminating the time stamp and saving it in order to use later on in my graphs. Then I am saving the raw data before I concatenate the first 4 bits and after I concatenate the the first 4 bits.

If I use autoindexing I will not need the shift registers,right? Can I then save the while the program is running or I have to save at the end of the process.

I am familiar with operations with strings but I am still a bit weak on array and string working toghether.

I attach what I am doing.

Thanks

Download All
0 Kudos
Message 6 of 24
(4,040 Views)
0 Kudos
Message 7 of 24
(4,037 Views)
Since your source file contains lines that are separated by tabs or spaces and since some of the columns are hex values the "Read From Spreadsheet File" VI won't work for you. You will need to use the little technique I showed you before and you can use that to autoindex. You can then process each line by replacing multiple spaces with tabs and then using the "Spreadsheet String to Array" function to give you an array that you can easily process. Attached is a snippet of code based on reading the source file. The intention here is to allow you to get the values without having to do all that string subsetting that you're doing.

Note: I used the "Array to Cluster" function to provide a convenient way to break out the individual columns. I set the size of the cluster by right-clicking on it and setting the size to 11, which is the number of columns in your dataset.
0 Kudos
Message 8 of 24
(4,021 Views)
Back to your first question: It seems that your file is very structured and there is a constant number of characters/line. Thus, you can easily calculate the number of lines from the file size. 😉
 
If you want to do plain parsing, I recommend "scan strings for tokens", because it automatically contracts consecutive seperators into one by default. The attached simple example (LV7.1) gets the lines in the FOR loop, then slices each line in the inner FOR loop. You should be able to easily adapt it for your exact purpose, e.g. rewrite the data subsets to new files.
 
 
Message 9 of 24
(3,999 Views)
Here is a VI that does it. The last line must end in \n.
0 Kudos
Message 10 of 24
(3,991 Views)