Re: update variable in structure [message #66928] |
Wed, 17 June 2009 10:01  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
R.G. Stockwell schrieb:
> "M. Suklitsch" <martin@suklitsch.at> wrote in message
> news:308ff1f9-67da-493e-bde1-46d29e3f63cf@a7g2000yqk.googleg roups.com...
>> Hi everybody!
>>
>>
>> Today I have a question regarding the update of variables within a
>> structure, which does not work as I would expect.
>>
>> Say we have a very simple program:
>>
>> ===============
>> PRO update_value, input
>>
>> input = input MOD 5
>>
>> END
>> ===============
> ...
>> And now the rather simple question: how come this doesn't work?
>
>
> Passs the structure, then inside modify the field you need modified:
>
> PRO update_value, input
>
> input.test = 13
>
> END
>
> data = {test:2, str:'hello'}
>
> update_value, data
>
> print,data
>
> end
>
>
> Note: you can get very fancy if you want a general routine,
> perhaps pass in the field name and use that string in an execute call,
> or pass the field number you want to modify, and access the
> structure like input.(0) = 2
>
> cheers,
> bob
>
Hi
the easiest thing is to convert the structure params to pointers
and afterwards back to a structure without pointers if you don't like
pointers.
http://www.fz-juelich.de/icg/icg-1/idl_icglib/idl_source/idl _html/dbase/struct2ptr_struct_dbase.pro.html
http://www.fz-juelich.de/icg/icg-1/idl_icglib/idl_source/idl _html/dbase/ptr_struct2struct_dbase.pro.html
struct={A:1,b:findgen(10)}
help,struct,/str
** Structure <1d5bbd8>, 2 tags, length=44, data length=42, refs=1:
A INT 1
B FLOAT Array[10]
result=struct2ptr_struct(struct)
help,result,/str
** Structure <10551e8>, 2 tags, length=8, refs=1:
A POINTER <PtrHeapVar1>
B POINTER <PtrHeapVar2>
*result.b = "don't get fancy"
struct = ptr_struct2struct(result,/free)
help, struct ,/str
** Structure <1d5bd18>, 2 tags, length=24, data length=18, refs=1:
A INT 1
B STRING 'don't get fancy'
cheers
Reimar
>
>
>
>
>
|
|
|