LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read from a file line by line

Also what makes the loop keep iterating even after the EOF has been encountered?
0 Kudos
Message 11 of 13
(3,838 Views)
OK, a "file" is just a long sequence of bytes. Nothing more. The concept of a "line" is quite artificial and defined by the presence of special delimiters (e.g. /n). Do you really think that the computer reads single characters from the HD until a \n is enountered? You want to limit slow disk I/O and do all in memory. Unless the file size is gigantic, it is always best to read the entire file into memory an process from there.
 
My program is very simple:
  1. read the entire file as a string
  2. Append twenty (or however many lines fit into the display) newline characters to the string so the entire original file can scroll off the display at the end. This measn that the string has 20 extra lines past the original EOF and you don't need to worry about scrolling off later.
  3. Initialize the display shift register with an array of 20 strings containing /n, one for each line. The 20 strings are concatenated to make the current display.
  4. At each iteration, extract the next line from the string, rotate the array of 20 strings by one element and replace element 1 with the new line.
  5. The shift register keeps track of the current index.
  6. Wash, rinse, repeat.
  7. It would be easy to modify so the text scrolls in the other direction. (move the "rotate" after the "replace" and rotate by -1)

There are many ways to extract lines from a string, only one is shown. Whenever you are not sure about a tool, right-click its icon and select "help".

All clear? 🙂

 
 
 
0 Kudos
Message 12 of 13
(3,837 Views)

Hi

Thanks for the posts. It now makes perfect sense. To add to that, I also came up with code that could take input of a number (fundamental frequency) and output a corresponding note.  This part was just to simulate the data that would come out of the DSP and get converted to a note. The next part I tried to do was the comparison. I want the comparison to work in such a way that I the element at the bototm of the screen is compared to the output note from the DSP and the code I wrote. For this I created a while loop. We will be receiving about 680 inputs from the DSP every second. I want the inner while loop to work in such a way that if a match is found between the note displayed at the bottom and the note played, the seond while loop should exit. However, if there isn't a match, the checking should continue until the time that there is a change in the last element of the display. All this need to be done without messing with the original 1 second interval of notes being displayed.

I thought the one 1000 ms input on the outer while loop would limit the amt of time the inner while loop could take but that is not the case. Any suggestions?

Thanks

-Karan

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