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

Home » Public Forums » archive » Re: Reading files with unknown amount of data
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: Reading files with unknown amount of data [message #1355 is a reply to message #1354] Thu, 04 November 1993 08:09 Go to previous messageGo to previous message
alans is currently offline  alans
Messages: 12
Registered: September 1991
Junior Member
I always thought the best approach to the "growing array" problem was to
"cache" the data in an array of a KByte or so. When the "cache" is full,
append to array. So, rewriting the previously posted example program this
way yields:

function read_vl_file, filename

; yes, I *did* test this, but didn't benchmark it...
a = 0.0
i = 0
csize = 1024
cache = fltarr (csize)
openr, lun, filename, /get_lun
while (not eof (lun)) do begin
readf, lun, a
cache(i) = a
i = (i + 1) mod csize
if (i eq 0) then $
if ((size (out))(0) gt 0) then $
out = [temporary (out),cache] else $
out = cache
endwhile

close, lun
free_lun, lun

; grab the rest of the cache.

if (i gt 0) then $
if ((size (out))(0) gt 0) then $
out = [temporary (out),cache(0:i-1)] else $
out = cache(0:i-1)
return, out
end

Anyway, if there are better ways to do this, I'd sure love to hear about
them.
--
Alan J.Stein MIT/Lincoln Laboratory alans@LL.mit.edu
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Calling External programm
Next Topic: Re: Reading files with unknown amount of dat

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

Current Time: Sat Oct 11 07:41:59 PDT 2025

Total time taken to generate the page: 1.92141 seconds