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

Home » Public Forums » archive » Re: array concatenation and optimization
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: array concatenation and optimization [message #26791 is a reply to message #26790] Wed, 26 September 2001 12:59 Go to previous messageGo to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Sean Raffuse wrote:
>
> Hello.
>
> I am trying to read a bunch of data from a file to a structure array. I'm
> not sure many data entries the file will have until I have read it and so I
> am increasing the size of the structure array after reading each line.

Count the number of lines first, then create your arrays the required size. (I'm assuming your
file is ASCII data).

> This is working but it has increased the processing time of my loop by an
> order of magnitude. Is there a better way to do this? Is there a reason
> this is so slow?

A while back someone else in this newsgroup more knowledgable than me (I think Craig?)
explained why this is a bad method when the number of points is very large. Suffice it to say
for something like up to maybe a couple hundred points, concatenation is o.k. Any more and
you'd be needlessly sucking up CPU cycles shifting/concatenating large blocks of data on the
fly.

I changed some of my IDL code that reads a huge binary file from the concat method to
estimating the number of points, added some slop and then read it all in a chunk (or in your
case, a line) at a time, counting the points as I went. Before returning I simply truncate the
array. Sped up my code by at least an order of magnitude.

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: IDL 5.4 and win2000 problems
Next Topic: IDL for Windows and MAC...

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

Current Time: Sun Oct 12 04:39:21 PDT 2025

Total time taken to generate the page: 0.08032 seconds