Re: Getting memory overflow on array concat; why? [message #3423] |
Wed, 25 January 1995 06:54 |
ryba
Messages: 33 Registered: October 1992
|
Member |
|
|
In article <3g3oem$r43@umd5.umd.edu>, bleau@umdsp.umd.edu writes:
|> Here's the relevant code fragment, which is within a loop:
|> READF, 1, temp
|> IF first THEN BEGIN
|> data = temp
|> first = ''
|> ENDIF ELSE BEGIN
|> data = [data,temp]
|> ENDELSE
Larry (and others),
A few IDL tips....
1) Use the TEMPORARY() function whenever possible when handling large
arrays. Read the docs for the details, but the line:
data = [temporary(data),temp]
in place of what you have will halve your memory usage.
2) To reduce fragmentation, allocate in blocks...using code like:
data = fltarr(50, npar)
cursize = 50L ; Note use of longs here....
npts = 0L
while not eof(1) then begin
readf, 1, temp
data(npts, *) = temp
npts = npts + 1
if npts eq cursize then begin
data = [temporary(data), fltarr(50, npar)]
cursize = cursize + 50
endif
endwhile
data = (temporary(data))(0:npts, *)
3) You may wish to use a more general-purpose reader routine, like
DDREAD written by Fred Knight. I believe it's now in the meteo
archive; if not, mail me and I'll post it. It will read any tabular
file, skipping over comment lines, etc. with optional arguments
specifying rows and columns to pick out...I use it constantly.
--
Dr. Marty Ryba | Generation X:
MIT Lincoln Laboratory | Too young to be cynical,
ryba@ll.mit.edu | too old to be optimistic.
Of course nothing I say here is official policy, and Laboratory affiliation is
for identification purposes only, blah, blah, blah....
|
|
|