Re: Arrays of Structures [message #20450] |
Thu, 22 June 2000 00:00 |
promashkin
Messages: 169 Registered: December 1999
|
Senior Member |
|
|
Sorry if I repeat some of the things said above. The following should
work, because, just like Ben said, despite S1 and S2 are both anonimous
for the user, they are internally different for IDL. Make S2 the same as S1:
IDL> S1 = {a:0, b:.1, c:''}
IDL> S2 = S1
S2.a = 3 & S2.b = 7 & S2.c = 'x'
IDL> A = Replicate(S1,3)
IDL> A[1] = S2 ; can replace a structure.
Cheers,
Pavel
> Ah, that was easy!
>
> Now here's 'How come #2'
> I know that I can replace a given field in one of the structures.
> How come I can't replace Array element X with an identical structure (as
> I would with a named structure?)
>
> IDL> S1 = {a:0, b:.1, c:''}
> IDL> S2 = {a:3, b:7., c:'x'}
> IDL> A = Replicate(S1,3)
> IDL> A(1).c = 'q' ;replace a field value without a
> problem
> IDL> A[1] = S2 ; can't replace a structure.
> % Conflicting data structures: S2,A.
> % Execution halted at: $MAIN$
>
> Thanks,
> Ben
|
|
|
Re: Arrays of Structures [message #20465 is a reply to message #20450] |
Wed, 21 June 2000 00:00  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
The function STRUCT_ASSIGN was created in newer versions of IDL to
perform so-called "relaxed" structure assignments -- exactly what you
want. Alas, I do not believe it will work on array elements since
they are pass-by-value.
Craig
Ben Tupper <tupper@seadas.bigelow.org> writes:
> Ah!
>
> I think I get it. Anonymous means anonymous... but it is still unique (until
> redefined).
>
> S1 = {a:0, b:.1, c:''}
> A = Replicate(S1,3)
> S2 = S1
> S2.c = 'bob'
> A[1] = S2
>
> IDL> help, s1,s2,/str
> ** Structure <37d658>, 3 tags, length=16, refs=3:
> A INT 0
> B FLOAT 0.100000
> C STRING ''
> ** Structure <37d658>, 3 tags, length=16, refs=3:
> A INT 0
> B FLOAT 0.100000
> C STRING 'bob'
>
> IDL> S1 = {X:1, Y:'y'}
> IDL> help, s1,/str
> ** Structure <37fda8>, 2 tags, length=12, refs=1:
> X INT 1
> Y STRING 'y'
>
> Thanks,
>
> Ben
>
>
> --
> Ben Tupper
>
> Bigelow Laboratory for Ocean Science
> tupper@seadas.bigelow.org
>
> pemaquidriver@tidewater.net
>
>
>
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Arrays of Structures [message #20467 is a reply to message #20465] |
Wed, 21 June 2000 00:00  |
Ben Tupper
Messages: 186 Registered: August 1999
|
Senior Member |
|
|
Ah!
I think I get it. Anonymous means anonymous... but it is still unique (until
redefined).
S1 = {a:0, b:.1, c:''}
A = Replicate(S1,3)
S2 = S1
S2.c = 'bob'
A[1] = S2
IDL> help, s1,s2,/str
** Structure <37d658>, 3 tags, length=16, refs=3:
A INT 0
B FLOAT 0.100000
C STRING ''
** Structure <37d658>, 3 tags, length=16, refs=3:
A INT 0
B FLOAT 0.100000
C STRING 'bob'
IDL> S1 = {X:1, Y:'y'}
IDL> help, s1,/str
** Structure <37fda8>, 2 tags, length=12, refs=1:
X INT 1
Y STRING 'y'
Thanks,
Ben
--
Ben Tupper
Bigelow Laboratory for Ocean Science
tupper@seadas.bigelow.org
pemaquidriver@tidewater.net
|
|
|
Re: Arrays of Structures [message #20468 is a reply to message #20465] |
Wed, 21 June 2000 00:00  |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
Ben Tupper <tupper@seadas.bigelow.org> wrote in message
news:39511D37.96A7BF8B@seadas.bigelow.org...
> Jared wrote:
>
>> Ben,
>>
>> An array of anonymous structures can be made. For example:
>>
>> a = replicate( {a:0, b:.1, c:''}, 10)
>>
>> makes a 10 element array of anonymous structures. Hope this helps.
>>
>> Jared
>
> Thanks,
>
> Ah, that was easy!
>
> Now here's 'How come #2'
> I know that I can replace a given field in one of the structures.
> How come I can't replace Array element X with an identical structure (as
> I would with a named structure?)
>
>
> IDL> S1 = {a:0, b:.1, c:''}
> IDL> S2 = {a:3, b:7., c:'x'}
> IDL> A = Replicate(S1,3)
> IDL> A(1).c = 'q' ;replace a field value without a
> problem
> IDL> A[1] = S2 ; can't replace a structure.
> % Conflicting data structures: S2,A.
> % Execution halted at: $MAIN$
>
> Thanks,
> Ben
>
> --
> Ben Tupper
>
> Bigelow Laboratory for Ocean Science
> tupper@seadas.bigelow.org
>
> pemaquidriver@tidewater.ne
Because they are not identical. They are not the same "type" of
structure, where by "type" I mean they get different tags.
IDL> help,s1,s2,/st
** Structure <1321598>, 3 tags, length=16, refs=2:
A INT 0
B FLOAT 0.100000
C STRING ''
** Structure <13272f8>, 3 tags, length=16, refs=1:
A INT 3
B FLOAT 7.00000
C STRING 'x'
Here the names are different (<1321598> and <13272f8>), so presumably IDL
does not know they are the same structure (I guess they don't do the
overhead of
parsing thorugh the structure to see if they really are the same).
Note that you can do the following (i.e. you can replace a structure element
if
it has the same tag):
; make the structure different
A.c ='bob'
print,a
A[1] = S1
print,a
Cheers.
bob
|
|
|
Re: Arrays of Structures [message #20469 is a reply to message #20465] |
Wed, 21 June 2000 00:00  |
Ben Tupper
Messages: 186 Registered: August 1999
|
Senior Member |
|
|
Jared wrote:
> Ben,
>
> An array of anonymous structures can be made. For example:
>
> a = replicate( {a:0, b:.1, c:''}, 10)
>
> makes a 10 element array of anonymous structures. Hope this helps.
>
> Jared
Thanks,
Ah, that was easy!
Now here's 'How come #2'
I know that I can replace a given field in one of the structures.
How come I can't replace Array element X with an identical structure (as
I would with a named structure?)
IDL> S1 = {a:0, b:.1, c:''}
IDL> S2 = {a:3, b:7., c:'x'}
IDL> A = Replicate(S1,3)
IDL> A(1).c = 'q' ;replace a field value without a
problem
IDL> A[1] = S2 ; can't replace a structure.
% Conflicting data structures: S2,A.
% Execution halted at: $MAIN$
Thanks,
Ben
--
Ben Tupper
Bigelow Laboratory for Ocean Science
tupper@seadas.bigelow.org
pemaquidriver@tidewater.net
|
|
|
Re: Arrays of Structures [message #20471 is a reply to message #20465] |
Wed, 21 June 2000 00:00  |
Jared Crossley
Messages: 3 Registered: June 2000
|
Junior Member |
|
|
Ben,
An array of anonymous structures can be made. For example:
a = replicate( {a:0, b:.1, c:''}, 10)
makes a 10 element array of anonymous structures. Hope this helps.
Jared
|
|
|