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

Home » Public Forums » archive » Re: Reading in a bunch of bytes
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Reading in a bunch of bytes [message #6455] Wed, 03 July 1996 00:00
peter is currently offline  peter
Messages: 80
Registered: February 1994
Member
Phil Williams (williams@irc.chmcc.org) wrote:

: I have a binary file of 2 256x128x64 arrays of longs that are
: interleaved by rows. Here's what I do to try and read it:

: openr,1,'file'
: s = fstat(1)
: data = bytarr(s.size) ; s.size = 8388608 = 256*128*64*4
: readu,1,data
: close,1

: xsize = 256
: ysize = 128
: zsize = 64

: junk1 = fltarr(xsize,ysize,zsize)
: junk2 = fltarr(xsize,ysize,zsize)

: offset = xsize*4. ; 4 bytes/pixel
: k = 0

: for i = 0,zsize-1 do begin
: for j = 0,ysize-1 do begin
: off1 = offset*long(k)
: off2 = offset*long(k+1)
: junk1 = long(data,off1,xsize)
: junk2 = long(data,off2,xsize)
: k = k + 2
: endfor
: endfor

: end

: Everything looks good to me, but I always end up offsetting past the end
: of the data. Any help would be greatly apreciated!

Phil,

Many inconsistencies in the above. If your file is 2 256x128x64 arrays
of longs, then the size should be 256*128*64*4 * 2 (a long is 4 bytes,
right?). Why are junk1 and junk2 declared as fltarr, not lonarr? Are
you sure that the file isn't really ints (2 byte ints)?

But that is all beside the point. If the file is longs, then read it as
longs, not as bytes. The following should be *much* faster.

data = lonarr(256,2,128,64)
readu,1,data
data1 = reform(data(*,0,*,*),256,128,64)
data2 = reform(data(*,1,*,*),256,128,64)

You are also getting to the size of data (16M, from your description)
that you may not be able to afford to casually allocate twice the space
you need, as the above does. You might be better off reading things in
a plane at a time, and de-interleaving each plane into the two
destination arrays. This carries a memory overhead of 1/64 of the
original, but loops only 64 times, which shouldn't be too bad.

data1 = lonarr(256,128,64)
data2 = lonarr(256,128,64)
plane = lonarr(256,2,128)
for z=0,63 do begin
readu,1,plane
data1(*,*,z) = plane(*,0,*)
data2(*,*,z) = plane(*,1,*)
endfor

Hope this helps,

Peter

--------------------------------
Peter Webb, HP Labs Medical Dept
E-Mail: peter_webb@hpl.hp.com
Phone: (415) 813-3756
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Simple MODULO question.
Next Topic: Sun Angle Calculation

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

Current Time: Wed Oct 08 15:21:30 PDT 2025

Total time taken to generate the page: 0.00507 seconds