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 
Switch to threaded view of this topic Create a new topic Submit Reply
renaming a variable without making a copy [message #68935] Tue, 08 December 2009 03:51 Go to next message
David Higgins is currently offline  David Higgins
Messages: 13
Registered: August 2009
Junior Member
Can I rename a variable to a more approrpriate name, instead of making
a copy of the variable

I'm using /OVERWRITE to save memory, through a number of operations on
a large multi-dimensional array. I'd like to keep my code readable and
rename the variable to reflect what the data currently are.

Thanks,
Dave
Re: renaming a variable without making a copy [message #68975 is a reply to message #68935] Thu, 10 December 2009 08:56 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
On 10 déc, 17:30, alx <lecacheux.al...@wanadoo.fr> wrote:
> On 10 déc, 16:36, Reimar Bauer <R.Ba...@fz-juelich.de> wrote:
>
>> alx schrieb:
>
>> IDL> a=findgen(2,2)
>> IDL> b=dblarr(4)
>> IDL> reads,a,b
>> IDL> print,b
>>        0.0000000       1.0000000       2.0000000       3.0000000
>
>> btw. just seen that reads, 1 seems to be valid, but what does it do?
>
>
Unfortunately, that does not work as you said: "reads" (cf. IDL doc)
converts
your 'a' array to an array of strings, then 'read' it to 'b' by using
implicit formatting.
That is actually not a "memory read" and, likely, does not work with
structures.
Re: renaming a variable without making a copy [message #68976 is a reply to message #68935] Thu, 10 December 2009 08:30 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
On 10 déc, 16:36, Reimar Bauer <R.Ba...@fz-juelich.de> wrote:
> alx schrieb:
>
> IDL> a=findgen(2,2)
> IDL> b=dblarr(4)
> IDL> reads,a,b
> IDL> print,b
>        0.0000000       1.0000000       2.0000000       3.0000000
>
> btw. just seen that reads, 1 seems to be valid, but what does it do?
>

I did not realize so far that 'reads' could actually mean "read from
memory". Thanks for the tip !
Here is an immediate application: you want to import some structure
from a COM object, written in C or whatsoever.
But the IDL COM bridge does not support passing of structure. So you
need to import it as a typecasted (variant) array
of simple type. Then, "reads" will allow to recover and use the
structure in IDL...
alain.
Re: renaming a variable without making a copy [message #68977 is a reply to message #68935] Thu, 10 December 2009 07:36 Go to previous messageGo to next message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
alx schrieb:
> On 9 d�c, 18:06, Reimar Bauer <R.Ba...@fz-juelich.de> wrote:
>
>> read about reads or execute
>>
>
> Reimar,
> I understand that 'reads' might allow a string to be read out as a
> structure by using a binary format, but such a typecast method seems
> to me quite a bit involved.

the "s" it is not only about strings

IDL> a=findgen(2,2)
IDL> b=dblarr(4)
IDL> reads,a,b
IDL> print,b
0.0000000 1.0000000 2.0000000 3.0000000


btw. just seen that reads, 1 seems to be valid, but what does it do?

> I do not understand the usage of 'execute' for such a thing.
> alain.
Re: renaming a variable without making a copy [message #68984 is a reply to message #68935] Thu, 10 December 2009 02:31 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
On 9 déc, 18:06, Reimar Bauer <R.Ba...@fz-juelich.de> wrote:

> read about reads or execute
>

Reimar,
I understand that 'reads' might allow a string to be read out as a
structure by using a binary format, but such a typecast method seems
to me quite a bit involved.
I do not understand the usage of 'execute' for such a thing.
alain.
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 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.
Re: renaming a variable without making a copy [message #69158 is a reply to message #68935] Fri, 11 December 2009 05:22 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
On 11 déc, 12:51, Reimar Bauer <R.Ba...@fz-juelich.de> wrote:

> what is that doing then?

> IDL> a=bindgen(3)
> IDL> b=ptr_new({s:intarr(3)})
> IDL> reads,a,*b
> IDL> print,*b
> {       0       1       2

Still the same: 'a' is implicitely converted to some string array by
'reads', then read out to *b.
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.
Re: renaming a variable without making a copy [message #69160 is a reply to message #68975] Fri, 11 December 2009 03:51 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
alx schrieb:
> On 10 d�c, 17:30, alx <lecacheux.al...@wanadoo.fr> wrote:
>> On 10 d�c, 16:36, Reimar Bauer <R.Ba...@fz-juelich.de> wrote:
>>
>>> alx schrieb:
>>> IDL> a=findgen(2,2)
>>> IDL> b=dblarr(4)
>>> IDL> reads,a,b
>>> IDL> print,b
>>> 0.0000000 1.0000000 2.0000000 3.0000000
>>> btw. just seen that reads, 1 seems to be valid, but what does it do?
>>
> Unfortunately, that does not work as you said: "reads" (cf. IDL doc)
> converts
> your 'a' array to an array of strings, then 'read' it to 'b' by using
> implicit formatting.
> That is actually not a "memory read" and, likely, does not work with
> structures.
>
>

what is that doing then?

IDL> a=bindgen(3)
IDL> b=ptr_new({s:intarr(3)})
IDL> reads,a,*b
IDL> print,*b
{ 0 1 2
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Vectorize procedure
Next Topic: array subscripting problem

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

Current Time: Wed Oct 08 15:50:20 PDT 2025

Total time taken to generate the page: 0.00692 seconds