LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read a data file combining strings and data

Solved!
Go to solution

Hello,

I'm having a data file combining strings and datas to read. I'm trying to read the filename, time, constants and comments into four seperate string indicators (the lines for the comments varies for different files). And read the data into a 2-D numeric array. How can I do this? Is there any function that can serch special characters in the spreadsheet file so I can exactly locate where I should start reading the specific data. The following is how the data file appears. Thank you very much.

 

Best,

Richard

 

 

 

filename.dat
14:59:00 12/31/2009
--------------------------------------------------
Sample = 2451
Frequency = 300, Wait time = 2500
Temperature = 20
--------------------------------------------------
some comments
some comments
some comments
some comments
some comments
--------------------------------------------------

7.0000E+2    1.5810E-5
7.0050E+2    1.5400E-5
7.0100E+2    1.5500E-5
7.0150E+2    1.5180E-5

....

Message Edited by Richard1017 on 10-02-2009 03:10 PM
0 Kudos
Message 1 of 13
(3,580 Views)

No reply?

It's the first time I post a question here. Did I do something wrong?

 

Richard

0 Kudos
Message 2 of 13
(3,559 Views)

Richard,

 

Twenty minutes on a Friday afternoon is not a long time for a reply.  Most of the participants on the Forum are volunteers, so the response time may vary.

 

You will not find a single VI or function which will do the entire job in one step.  Here is one way to get started:

 

1. Read the file as a string.

2. Search for lines containing the separator "-------"

3. The portion of the string before the first occurrence of the separator has the file name and timestamp information.

4. The section between the first and second separators contains the header information.

5. The section between the second and third separators contains the comments.

6. The remainder is your data and can be converted to numeric values by using the Spreadsheet String to Array function.

 

Lynn 

Message 3 of 13
(3,549 Views)

Lynn,

 

Thank you very much. Reading into one tring is a good point. I just tried to read from spreadsheet file and I got a 2-D array string. Hadling this 2-D array string is really frustrated. I'll try your method. Thank you.

 

Richard

0 Kudos
Message 4 of 13
(3,546 Views)

Hi,

     I'm fairly new to the NI forums too and I think you just have to wait longer.  Your post was done right.  I do a similiar function as to what you are talking about except I read in numbers from a file.  I create an ini file (just a notepad file of type *.ini) that is is set up with sections inside brackets [] and keys with whatever name followed by an = sign.  You may be able to use a *.dat file too, I just haven't.  Then the vi attached goes to that file and reads the keys from those sections.  You just repeat for the different sections and keys you want to read.  You can use similar provide VI's to write to that same file or create it.  Let me know how that works. 

Download All
0 Kudos
Message 5 of 13
(3,533 Views)

Hi asb9ab,

 

You example is quiet straight forward and insteresting. But it is dealing with a .ini file with keys already being setup. I don't know if it works for my .dat files. I think maybe I can use this if I starting writing the data into a .ini file format. But the problem is, so far I still have a lot of datas in the old format and in my data file, there are strings, numerical numbers and even a 2-D array. I'm still trying to figure out how to read this kind of data. Anyway, your suggestion gave me a good hint and it's hard to tell I can't find a solution for my current problem by digging into the mechanics of your example. I appreciate your help. Thank you.

 

Richard

0 Kudos
Message 6 of 13
(3,524 Views)
Solution
Accepted by topic author Richard1017

Here is a (big) hint.

 

ParseStringEx.png

 

I'd give you a snippet but I haven't updated this machine yet.  That's a pretty annoying delimiter, if you know what is good for you, you'll start using commas, tabs or single spaces (my order of preference).  It is way too easy to start adding or removing spaces and then you'll have to resort to more complicated methods to get the spreadsheet data.

0 Kudos
Message 7 of 13
(3,518 Views)

Hi Darin,

 

Your method exactly solved my problem and it's running now! Thank you so much!

 

Richard

0 Kudos
Message 8 of 13
(3,504 Views)

Hi Darin,

 

Still a small question for you. I tried "7.0000E+2" for the search term and successfully got the data array seperated from the file and the whole thing before the data as a string. But when I try "--------------------------------------------------" for the search term, I got no luck. The first part of string (before the first -------) gets in to element, but the rest just all streamed into the Data array. I don't know why seems that the for loop just executed once. I'm still trying to figure out this. Anyway, your hint solved my major problem and the rest will be easy for me. Thank you very much.

 

Richard

0 Kudos
Message 9 of 13
(3,494 Views)
I'll wager you put one too many '-' in your search string.  BTW, the [] in the regular expression are left over from an old example, you don't really need an alternative when there is only one character, "--+\n" should work as well.  I'd use two '-''s in case you have negative numbers or dashes in your comments.  You've got the idea, and the detailed help is very useful.
Message Edited by Darin.K on 10-02-2009 06:43 PM
0 Kudos
Message 10 of 13
(3,490 Views)