Re: [Q] Reading from file, speed [message #18911] |
Thu, 10 February 2000 00:00 |
Koen Janssens
Messages: 3 Registered: February 2000
|
Junior Member |
|
|
And indeed it is not, with your idea it only takes about a millisecond.
Thanks a lot!
Koen
David Fanning wrote:
> IDL is sometimes considered a loopy language, but
> it is definitely NOT a looping language. :-)
>
> Those FOR loops are killing you. Try something
> like this:
>
> openr, ms_dat_unit, ms_dat_file, /get_lun
> ms = bytarr(dimx,dimy,dimz)
> readu, ms_dat_unit, ms
> free_lun, ms_dat_unit
>
--
Dr. ir. Koen Janssens
Room No. F21, Institut f�r Umformtechnik, ETH Zentrum CLA
Tannenstrasse 3, CH-8092 Z�rich, Switzerland
Tel: +41-1-6320623, Fax: +41-1-6321289
E-mail: janssens@ifu.bepr.ethz.ch, www.ifu.ethz.ch
|
|
|
Re: [Q] Reading from file, speed [message #18912 is a reply to message #18911] |
Thu, 10 February 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Koen Janssens (janssens@ifu.bepr.ethz.ch) writes:
> I am looking for a better way to import data into IDL, the one I am
> using now seems very slow (about 20 secs for reading in 2 MBytes). Here
> is the script that I use:
>
> openr, ms_dat_unit, ms_dat_file
> ms = bytarr(dimx,dimy,dimz)
> for z = 0,(dimz-1) do begin
> for y = 0,(dimy-1) do begin
> for x = 0,(dimx-1) do begin
> readu, ms_dat_unit, tmp
> ms[x,y,z] = tmp
> endfor
> endfor
> endfor
> close, ms_dat_unit
> free_lun, ms_dat_unit
>
> The file I am reading contains integers in binary format (volume data
> 128^3).
IDL is sometimes considered a loopy language, but
it is definitely NOT a looping language. :-)
Those FOR loops are killing you. Try something
like this:
openr, ms_dat_unit, ms_dat_file, /get_lun
ms = bytarr(dimx,dimy,dimz)
readu, ms_dat_unit, ms
free_lun, ms_dat_unit
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: [Q] Reading from file, speed [message #18913 is a reply to message #18911] |
Thu, 10 February 2000 00:00  |
Ivan Zimine
Messages: 40 Registered: February 1999
|
Member |
|
|
Hi,
you don't need the loops
try this
ms = bytarr(dimx,dimy,dimz)
openr, lun, ms_dat_file, /get_lun
readu, lun, ms
free_lun, lun
hope this helps
Ivan
Koen Janssens wrote:
>
> I am looking for a better way to import data into IDL, the one I am
> using now seems very slow (about 20 secs for reading in 2 MBytes). Here
> is the script that I use:
>
> openr, ms_dat_unit, ms_dat_file
> ms = bytarr(dimx,dimy,dimz)
> for z = 0,(dimz-1) do begin
> for y = 0,(dimy-1) do begin
> for x = 0,(dimx-1) do begin
> readu, ms_dat_unit, tmp
> ms[x,y,z] = tmp
> endfor
> endfor
> endfor
> close, ms_dat_unit
> free_lun, ms_dat_unit
>
> The file I am reading contains integers in binary format (volume data
> 128^3).
>
> Any help is appreciated.
> Koen
--
Ivan Zimine
Dpt. of Radiology, Geneva University Hospitals
email: ivan.zimine@physics.unige.ch
tel. : (+41 22) 372 70 70
|
|
|