comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Efficient way to split an array of strings.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Efficient way to split an array of strings. [message #56814 is a reply to message #56812] Thu, 15 November 2007 01:16 Go to previous messageGo to previous message
bberkey is currently offline  bberkey
Messages: 2
Registered: November 2007
Junior Member
On Nov 14, 3:39 pm, David Fanning <n...@dfanning.com> wrote:
> bber...@gmail.com writes:
>> have a lot of data that comes to me in tabular files with a nice mix
>> of strings and numerical data. Typically I will read the data into a
>> string array. And then loop over each line in the file calling
>> STRSPLIT repeatably.
>
>> Is there a better way to accomplish this?
>
> Why don't you just read the data from the file
> directly:
>
> OpenR, lun, 'test.dat', /Get_LUN
> rows = File_Lines('test.dat')
> struct = {f:0.0D, I:0, s:''}
> data = Replicate(struct, rows)
> ReadF, lun, data
> Free_Lun, lun
>
> Print, data.f, Format='(F10.2)'
> Print, data.I
> Print, data.s
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

David,

Thanks, I think I will start doing that from now on. But since my
last post I though of a much better way to split an array of strings.
Something like the following:
reform(strsplit(strjoin(data,delimiter),delimiter,/
extract),numstrings,rows)

I quick performance check shows that both of these methods are about
5x faster then my old method.

Thanks
-Ben
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: NaN Magic or Why Me?!
Next Topic: version 7

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 03:47:05 PDT 2025

Total time taken to generate the page: 1.59536 seconds