LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting EOF inside an indexed WHILE loop

Hi all,

Firstly, I have my problem sorted, but wanted to enquire with you guru's if there is a neater way to code what I have done.

The task is to load a text file that has previously been generated.
The text file contains a header section that describes test setup and operator info.
The actual data output is a two column TAB delimited format (frequency and amplitude) which is 'sandwiched' between the keywords DATA and END

Now, I was using a WHILE loop to read in and process the text values into floating point and I have self indexing on the loop too.
All is OK, but the last 'value' to be read in is the keyword END, ofcourse this cannot be converted to a number, but this attampted conversion is included in the indexed output.

The code below is my 'fix'; if it can be called that !! 🙂  I prepare the WHILE loop and use a shift reg to store the previous data points.

I am open to all your comments (good or bad) so feel free.... 🙂

Many thanks,
Bob.


0 Kudos
Message 1 of 2
(2,605 Views)
Some thoughts that might or might not help:

If your data file is huge, ignore this one. If not, then consider reading the whole file as a single string (forget the spreadsheet format for a moment). Something like:

L = Get EOF (File Refnum);
S = Read File (File Refnum, #bytes = L);   // read whole file
StartPoint = Search String(S, "DATA");
EndPoint = Search String (S, "END")
DataString = Substring(S,StartPoint, EndPoint - StartPoint)
SpreadsheetStringToArray(DataString);
In other words, extract just the portion you want, and THEN convert to a 2-D array.

You are parsing out the line yourself. SpreadsheetStringToArray will do that for you in a cleaner manner.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 2
(2,597 Views)