10-02-2009 03:09 PM - edited 10-02-2009 03:10 PM
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
....
Solved! Go to Solution.
10-02-2009 03:29 PM
No reply?
It's the first time I post a question here. Did I do something wrong?
Richard
10-02-2009 03:41 PM
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
10-02-2009 03:46 PM
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
10-02-2009 04:05 PM
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.
10-02-2009 04:35 PM
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
10-02-2009 04:42 PM
Here is a (big) hint.
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.
10-02-2009 06:07 PM
Hi Darin,
Your method exactly solved my problem and it's running now! Thank you so much!
Richard
10-02-2009 06:23 PM
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
10-02-2009 06:35 PM - edited 10-02-2009 06:43 PM