04-02-2013 02:00 PM
Hey all,
Im relatively new to labview so this may seem to be a simple question. My task is to read in a file with integers with "n" lines, until the end of file. I only need to read in the first 3 numbers of each line. Right now my code works for only one line of code, but when I try looping to iterate "n" lines, it gets stuck in an infinite loop. I am not sure how to make the while loop end at EOF. Any suggestions would be helpful. Thanks!
-Micah
04-02-2013 02:24 PM
04-02-2013 02:47 PM
This answer is a little too vague for my application so let me try to be more specific. The file I am reading from is being outputed from a prognastics reasoner algorithm. It will output 6 integer values per line, and for N amount of lines. I only need to read in the first 3 integers. The thing is, my program needs to grap the data whenever it is newly added, no matter how many lines are outputed, and only take the first 3 integers per line. Right now I am comparing the byte size of the file periodically, and if there is a difference the first 3 data points are grabbed using a for loop. My problem is, I am trying to put that for loop inside of a while loop (to iterate N lines until EOF) but it only seems to infinitally loop, even using the code from the previous comment. Oh, one more thing..after I read the data it still must be 1-D array. Thankyou!
-Micah
04-02-2013 03:04 PM - edited 04-02-2013 03:05 PM
Hi Micah,
- posting your code will help us to understand your problems much better
- when reading the file in a FOR loop you will also get an "EOF" error, you can still check the error cluster. I don't understand why you get stuck in an infinite loop when you check for errors...
- reading only the new lines is easy when you use the SetFilePosition function. You already know the file size before the new lines are added...
- my problem is: why do you add another FOR loop inside the while loop? That's not clear for me...
Post your VI!
04-02-2013 03:30 PM
Just read the whole file and toss out what you don't need. Keep it really simple. and don't intentionally cause errors-- downsteam code might miss-understand.
04-02-2013 04:00 PM
I'm with Jeff. By far the easiest way is to just read the whole file and use the Spreadsheet String to Array function to get all of the data into a numeric array. You can then just use Index Array or Array Subset to get the values you actually care about.