Reading Values into Individual Array Elements [message #5927] |
Tue, 12 March 1996 00:00  |
Rolando Raqueno
Messages: 5 Registered: March 1996
|
Junior Member |
|
|
Hello,
I am trying to read values into an idl array and ran into the following
behavior.
I tried reading directly into an array using the following steps
IDL> a=make_array(5)
IDL> print,a
0.00000 0.00000 0.00000 0.00000 0.00000
IDL> read,a
: 1 2 3 4 5
IDL> print,a
1.00000 2.00000 3.00000 4.00000 5.00000
Which works as I expected.
However, when I try to use a specific element in the array as an
argument to the READ statement, IDL no longer prompts me for the
value but returns value of the element as shown below.
IDL> read,a(3)
4.00000IDL>
A workaround would be to use a scalar temporary variable and then
assign it to the specific element, but that seemed a bit circuitous
and not unlike other languages.
Is there something I am missing in this situation?
Thanks
Rolando Raqueno
|
|
|
Re: Reading Values into Individual Array Elements [message #5991 is a reply to message #5927] |
Fri, 15 March 1996 00:00   |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
In article <4i2qfi$3et@news.isc.rit.edu>, Rolando Raqueno <rvrpci@cis.rit.edu> writes:
|>
[...snip...]
|>
|> However, when I try to use a specific element in the array as an
|> argument to the READ statement, IDL no longer prompts me for the
|> value but returns value of the element as shown below.
|>
|> IDL> read,a(3)
|> 4.00000IDL>
Since IDL passes subscripted array elements by value and not by reference,
a(3) is effectively a constant to READ, because READ cannot change
the value of a(3). What you are saying to IDL is therefore basically the
same as:
IDL> read,"TEST"
which is supposed to show the behaviour you described.
|>
|> A workaround would be to use a scalar temporary variable and then
|> assign it to the specific element, but that seemed a bit circuitous
|> and not unlike other languages.
|>
It's a little tedious, but it's the correct solution in this case.
Stein Vidar
|
|
|
Re: Reading Values into Individual Array Elements [message #6003 is a reply to message #5927] |
Mon, 15 April 1996 00:00  |
Ken Knighton
Messages: 44 Registered: May 1995
|
Member |
|
|
Rolando Raqueno <rvrpci@cis.rit.edu> wrote:
> steinhh@amon.uio.no (Stein Vidar Hagfors Haugan) wrote:
>>
>> Since IDL passes subscripted array elements by value and not by reference,
>> a(3) is effectively a constant to READ, because READ cannot change
>> the value of a(3). What you are saying to IDL is therefore basically the
>> same as:
>>
>> IDL> read,"TEST"
>>
>> which is supposed to show the behaviour you described.
>>
>
>
> Rather odd isn't it since IDL is FORTRAN based and passes everything
> by reference
IDL is written in C. C passes everything by value, but if you pass a
pointer by value and then use the pointer value to reference memory,
you effectively pass by reference. Of course, the argument passing
convention of the implementation language used to write IDL is of little
interest since IDL has its own argument passing convention. This
convention is that everything is passed by reference except for
expressions. Expressions include: Literals, function evaluations,
arithmetic expressions, subarrays, and structure tags.
Although this argument calling convention may seem strange at first,
it makes sense in the context of the rest of IDL. In IDL, any named
variable can be changed from one type to another at any time by a
simple assignment statement or as the result of a procedure changing
one of its passed arguments internally and passing the result back to
the caller. As a result, what would happen if you had the following if pass by reference was used?
PRO test, a
a='xyz'
END
IDL> a=[1, 2]
IDL> test, a(1)
Either IDL can do type and dimension checking, or some convention has
to be used to resolve conflicts like this. I personally think that
it would be valuable to be able to lock a variable's data type and
dimension when desired. This would then generate a run time error
when code attempted to change the variable's type during an assignment
or function call. Of course, this extra checking would slow things
down a little bit.
Ken Knighton knighton@cts.com
San Diego CA
|
|
|
Re: Reading Values into Individual Array Elements [message #6006 is a reply to message #5927] |
Sat, 13 April 1996 00:00  |
Rolando Raqueno
Messages: 5 Registered: March 1996
|
Junior Member |
|
|
steinhh@amon.uio.no (Stein Vidar Hagfors Haugan) wrote:
>
> Since IDL passes subscripted array elements by value and not by reference,
> a(3) is effectively a constant to READ, because READ cannot change
> the value of a(3). What you are saying to IDL is therefore basically the
> same as:
>
> IDL> read,"TEST"
>
> which is supposed to show the behaviour you described.
>
Rather odd isn't it since IDL is FORTRAN based and passes everything
by reference
Thanks for the verification
Rolando Raqueno
|
|
|