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

Home » Public Forums » archive » Re: Assigning structure variables
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: Assigning structure variables [message #67955] Thu, 03 September 2009 05:27
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Sep 3, 9:09 am, Bernhard Reinhardt
<wirdseltengele...@freisingnet.de> wrote:
> pp wrote:
>> On Sep 3, 5:22 am, Bernhard Reinhardt
>> <wirdseltengele...@freisingnet.de> wrote:
>>> Hi,
>
>>> I just ran into a problem when I tried to assign the minimum-index
>>> returned by the min()-function to an array-element I_LON[i].
>
>>> a=min(ABS(GLON - PLON[i]),I_LON[i])
>>> Attempt to store into an expression: <LONG     (           0)>.
>
>>> IDL> help, I_LON
>>> I_LON           LONG      = Array[126236]
>
>>> a=min(ABS(GLON - PLON[i]),b)
>>> I_LON[i]=b
>>> works
>
>>> Well, I read Davids tips on precedence and Assigning Structure Values
>>> but they are all about pointers and nested structures. To me it seems
>>> I_LON is a plain array. I guess I haven't yet understood how variables
>>> are exchanged with functions/procedures.
>
>>> Anyone can shed a light on this?
>
>>> Regards
>
>>> Bernhard
>
>> a=min(ABS(GLON - PLON[i]),I_LON[i]) does not work because subscripted
>> arrays are passed to routines by value, instead of by reference. So an
>> argument that is a subscripted array works to pass values to the
>> routine, but the routine cannot pass anything back to it, which is
>> what min is trying to do, and causes the error.
>
>> To say it another way, the error happens because that line is
>> essentially equivalent to
>> a=min(ABS(GLON - PLON[i]),0L), which obviously makes no sense, and
>> that is why IDL complains you are trying to store a value into a
>> constant (<LONG     (           0)>).
>
>> It is easy to forget it because usually arguments are passed by value
>> in IDL, which is what happens in a=min(ABS(GLON - PLON[i]),b), and is
>> why it works. But subscripted arrays and structure members are passed
>> by value.
>
> Thanks for your explanation. So would you say that
>
>   a=min(ABS(GLON - PLON[i]),b)
>   I_LON[i]=b
>
> is an appropriate workaround?

That is the way to do it.
Re: Assigning structure variables [message #67956 is a reply to message #67955] Thu, 03 September 2009 05:09 Go to previous message
Bernhard Reinhardt is currently offline  Bernhard Reinhardt
Messages: 26
Registered: October 2008
Junior Member
pp wrote:
> On Sep 3, 5:22 am, Bernhard Reinhardt
> <wirdseltengele...@freisingnet.de> wrote:
>> Hi,
>>
>> I just ran into a problem when I tried to assign the minimum-index
>> returned by the min()-function to an array-element I_LON[i].
>>
>> a=min(ABS(GLON - PLON[i]),I_LON[i])
>> Attempt to store into an expression: <LONG ( 0)>.
>>
>> IDL> help, I_LON
>> I_LON LONG = Array[126236]
>>
>> a=min(ABS(GLON - PLON[i]),b)
>> I_LON[i]=b
>> works
>>
>> Well, I read Davids tips on precedence and Assigning Structure Values
>> but they are all about pointers and nested structures. To me it seems
>> I_LON is a plain array. I guess I haven't yet understood how variables
>> are exchanged with functions/procedures.
>>
>> Anyone can shed a light on this?
>>
>> Regards
>>
>> Bernhard
>
> a=min(ABS(GLON - PLON[i]),I_LON[i]) does not work because subscripted
> arrays are passed to routines by value, instead of by reference. So an
> argument that is a subscripted array works to pass values to the
> routine, but the routine cannot pass anything back to it, which is
> what min is trying to do, and causes the error.
>
> To say it another way, the error happens because that line is
> essentially equivalent to
> a=min(ABS(GLON - PLON[i]),0L), which obviously makes no sense, and
> that is why IDL complains you are trying to store a value into a
> constant (<LONG ( 0)>).
>
> It is easy to forget it because usually arguments are passed by value
> in IDL, which is what happens in a=min(ABS(GLON - PLON[i]),b), and is
> why it works. But subscripted arrays and structure members are passed
> by value.

Thanks for your explanation. So would you say that

a=min(ABS(GLON - PLON[i]),b)
I_LON[i]=b

is an appropriate workaround?

Regards

Bernhard
Re: Assigning structure variables [message #67957 is a reply to message #67956] Thu, 03 September 2009 03:09 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Sep 3, 7:04 am, pp <pp.pente...@gmail.com> wrote:
> It is easy to forget it because usually arguments are passed by value
> in IDL, which is what happens in a=min(ABS(GLON - PLON[i]),b), and is
> why it works. But subscripted arrays and structure members are passed
> by value.

Oops. I meant to say that arguments are usually passed by reference.
Re: Assigning structure variables [message #67958 is a reply to message #67957] Thu, 03 September 2009 03:04 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Sep 3, 5:22 am, Bernhard Reinhardt
<wirdseltengele...@freisingnet.de> wrote:
> Hi,
>
> I just ran into a problem when I tried to assign the minimum-index
> returned by the min()-function to an array-element I_LON[i].
>
> a=min(ABS(GLON - PLON[i]),I_LON[i])
> Attempt to store into an expression: <LONG     (           0)>.
>
> IDL> help, I_LON
> I_LON           LONG      = Array[126236]
>
> a=min(ABS(GLON - PLON[i]),b)
> I_LON[i]=b
> works
>
> Well, I read Davids tips on precedence and Assigning Structure Values
> but they are all about pointers and nested structures. To me it seems
> I_LON is a plain array. I guess I haven't yet understood how variables
> are exchanged with functions/procedures.
>
> Anyone can shed a light on this?
>
> Regards
>
> Bernhard

a=min(ABS(GLON - PLON[i]),I_LON[i]) does not work because subscripted
arrays are passed to routines by value, instead of by reference. So an
argument that is a subscripted array works to pass values to the
routine, but the routine cannot pass anything back to it, which is
what min is trying to do, and causes the error.

To say it another way, the error happens because that line is
essentially equivalent to
a=min(ABS(GLON - PLON[i]),0L), which obviously makes no sense, and
that is why IDL complains you are trying to store a value into a
constant (<LONG ( 0)>).

It is easy to forget it because usually arguments are passed by value
in IDL, which is what happens in a=min(ABS(GLON - PLON[i]),b), and is
why it works. But subscripted arrays and structure members are passed
by value.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Tools to search this group, now that Google has screwed up their search?
Next Topic: Error message opening a file in IDL script

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

Current Time: Mon Dec 01 08:35:13 PST 2025

Total time taken to generate the page: 1.11667 seconds