LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert ASCII to Array with multiple -space- intercolumn delimeter?

Hello,

 

I have problem that looks easy, but not for me Smiley Happy I have done some work with LabView, but still hate the ASCII and string codes stuff. Can’t find the information what all this %s, %t, \n… e.c means. Pleas link me somewhere..

And my problem is:

I have ASCII spreadsheet like file. It has 2 lines of header and then columns (47 in example file). I need to convert this file in array for further work in LabView. But the problem is that delimiter between columns is multiple –space- (see attached file) and not the same number of –space- from column to column.

I need help in this… please give me some clue how to handle it.

Thank in advance,

Vadym

0 Kudos
Message 1 of 11
(5,139 Views)

You can do it but you have to replace the space characters into a single delimiter. I have chosen the default tab character. It uses regular expressions to search the string for pattern matches then replaces any pattern matches with the tab character. This will them allow you to use the Spreadsheet String to Array function. Note that the leading spaces on each line will produce a tab which in turn leaves column 0 elements=0 so that has to be deleted after the Spreadsheet string to array function.

To demo this a have extracted the first few lines of the data section your data.

Have a look at the attached demo in LV7.1 which I hope will get you started.

David

Message 2 of 11
(5,117 Views)
Thank you, could you save it in LV 6.1 please...
0 Kudos
Message 3 of 11
(5,108 Views)

Sorry I can only go back to 7.0.

Have a look at this picture to see if you can build it up yourself from there or somebody in the forum can help downconvert.

David

Message Edited by David Crawford on 01-16-2006 05:31 AM

Message 4 of 11
(5,105 Views)
Hi Vadym,
 
Do as per David's suggestion if formatting the file to be saved is in your control.
But, if you are getting data in this format for some other application and changing its format is not possible, the option you have is to use 'scan from string.VI' form functions, strings palette and obtain your data.
I built one sample VI using it to retieve a part of data in array format.
Now you have to modify the 'format string' to get complete data.
 
Regards
 
Dev
 

Message Edited by devchander on 01-16-2006 05:40 AM

Message 5 of 11
(5,104 Views)
Thank you... Let me see.
LV 7.0 will be ok for me...
0 Kudos
Message 6 of 11
(5,099 Views)
Not sure if you wanted this in 7.0 or Dev's, which incidently does the trick, just nicely.
 
Here it is in 7.0. There was a warning that it couldn't convert Search and Replace Pattern.vi
 
David
 
 
 

Message Edited by David Crawford on 01-16-2006 06:28 AM

Message 8 of 11
(5,089 Views)

David and Dev,

Thank you very much for help and I rate it as well…

Here is my feedback; I think it will be interesting.

So, I tried and both of this vi is works well. But, when I start to convert bigger file 7-40 mb. David’s solution appears very slow. I mean to find and replace pattern \s+ is really time and CPU consuming. While Dev’s solution works fast 16 sec for 40 mb ASCII file, but I have to set all parameters for 47 channels. And if I will have different number of channel form file to file, I have to make proper set of paramiters for “Scan From String” in each case.  It’s pity that LabView don’t have some property node for “Scan From String”, and I can read from header how many channel I have and ask program to make appropriate set of “scan sequence”. What can I do, is manually set it for each case from 1 to 128 channels Smiley Happy, put them in case structure and pick-up appropriate one that will correspond to number of channels written in header. Correct me if I’m wrong. And for header is better to use Davids protocol, because it’s not constants string format as in columns (8 symbols), so it’s better to replace all SPACE to TAB or just set SPACE as a delimiter (looks like there is just one SPACE between parameters).

Thank you again,

Vadym

0 Kudos
Message 9 of 11
(5,060 Views)

Hi Vadym

That was interesting that the replacement of spaces with a tab takes a long time. The Search and Replace Pattern.vi has a free running loop without a small delay in it to keep the CPU loading down so it will be intensive on CPU time.

You will be able to build the flexibility for the number of channels in your data without resorting to case statements a bit like this.

David

Message Edited by David Crawford on 01-17-2006 05:51 AM

Message 10 of 11
(5,049 Views)