populating an array [message #48167] |
Thu, 30 March 2006 07:34  |
subir.vasanth
Messages: 5 Registered: March 2006
|
Junior Member |
|
|
Greetings!
I was wondering if there was a more efficient way to populate an array
created using the MAKE_ARRAY function. This is how I am populating the
array right now -
data = BYTARR(202000L)
; populate byte array with valid data from some input source
array = MAKE_ARRAY(1000,101, Type = 2)
offset = 0L
FOR k = 0L, 100999L DO BEGIN
array(k) = FIX(data, offset)
offset = offset + 2
ENDFOR
Is there a way I can populate 'array' without using a loop to populate
each element, and instead do a array = FIX(data)??
Thanks,
subir
|
|
|
Re: populating an array [message #48209 is a reply to message #48167] |
Thu, 06 April 2006 13:38  |
subir.vasanth
Messages: 5 Registered: March 2006
|
Junior Member |
|
|
Thanks for your response Greg. I was trying to read a stream of bytes
from a socket and populate an array with that data. I think CP's
suggestion is what I was looking for .
Thanks!
|
|
|
Re: populating an array [message #48221 is a reply to message #48167] |
Thu, 06 April 2006 06:24  |
greg michael
Messages: 163 Registered: January 2006
|
Senior Member |
|
|
Looks to me like you have an array of integers which you accidentally
read into a byte array, and now you'd like to put things back in order.
The best way would be to read the data into an intarr of the right
dimensions in the first place. If it's too late, write out your byte
array to a file:
openw,1,filename
writeu,1,data
close,1
and read it back how you want it:
array = MAKE_ARRAY(1000,101, Type = 2)
openr,1,filename
readu,1,array
close,1
You may need to use swap_endian if it comes out byte-swapped.
regards,
Greg
|
|
|