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

Home » Public Forums » archive » renaming a variable without making a copy
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: renaming a variable without making a copy [message #69146 is a reply to message #68935] Fri, 11 December 2009 08:38 Go to previous messageGo to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Dec 11, 11:22 am, alx <lecacheux.al...@wanadoo.fr> wrote:
> Look at the following:
>
> define some structure:
> IDL> a={n:1L,x:2.0}
>
> build its binary content as a byte chain:
> IDL> b=[byte(a.n,0,4),byte(a.x,0,4)]
> IDL> print,b
>    1   0   0   0   0   0   0  64
>
> define a void structure to get the result:
> IDL> aa={n:0L,x:0.0}
>
> then :
> IDL> reads,b,aa
> IDL> print,aa
> {           1     0.000000}
> does not provide the right result.


Good example. In case anybody is wondering why that happens, the reads
is getting the first field of a from the string "1", and the second
field from the string "0" (the string representations of the first and
second elements of the byte array b).

To properly obtain aa from the bytes in b, it is necessary to know
exactly how the fields are aligned, as David mentioned. Which in this
particular case would be:

IDL> aa.n=long(b,0)
IDL> aa.x=float(b,4)
IDL> print,aa
{ 1 2.00000}

Somebody also talked about using (real) pointers in IDL. Ronn Kling's
DLM book has a useful trick (by Nigel Wade), to use a memory copy to
hold a pointer's value in an IDL byte array of the proper size.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Vectorize procedure
Next Topic: array subscripting problem

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

Current Time: Wed Oct 08 19:26:29 PDT 2025

Total time taken to generate the page: 0.00403 seconds