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

Home » Public Forums » archive » Delete element from the structure inside another structure
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
Delete element from the structure inside another structure [message #88936] Sun, 06 July 2014 16:37 Go to next message
Andrii is currently offline  Andrii
Messages: 7
Registered: March 2014
Junior Member
Hello everybody!

I'd like to ask you about one thing which is generally already discussed in other groups.

But my question is a bit more specific.

I have a structure inside another structure like this one:

a = { f1: 0, f2: { x: FltArr(10,10,10), y: 0}}

My question is, how can I delete just an array x, or to replace an array x with the array y = FltArr(5,5,5)?

Thank you!
Re: Delete element from the structure inside another structure [message #88943 is a reply to message #88936] Mon, 07 July 2014 01:50 Go to previous messageGo to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
Hi Andrii,

I think you can't do that directly. You have two choices: either create a new structure in the shape you want, and explicitly copy over the elements you want to retain (struct_assign), or -- probably the better solution -- use a pointer in the first place, so that:

a = { f1: 0, f2: { x: ptr_new(FltArr(10,10,10)), y: 0}}

then you could set a.f2.x=ptr_new(FltArr(5,5,5)) and access with

print,*(a.f2.x)

If you want to be able to change all the values, put the pointers at the lowest level, and recreate the structures each time:

a=ptrarr(2)
a[0]=ptr_new(0)
a[1]=ptr_new({ x: ptr_new(FltArr(10,10,10)), y: 0})

or

a[1]=ptr_new({ x: ptr_new(FltArr(5,5,5)), y: 0})

cheers,
Greg
Re: Delete element from the structure inside another structure [message #88944 is a reply to message #88943] Mon, 07 July 2014 01:57 Go to previous messageGo to next message
Andrii is currently offline  Andrii
Messages: 7
Registered: March 2014
Junior Member
Hi Greg,

Thanks a lot. I will try!

Cheers,
Andrii


> Hi Andrii,
>
>
>
> I think you can't do that directly. You have two choices: either create a new structure in the shape you want, and explicitly copy over the elements you want to retain (struct_assign), or -- probably the better solution -- use a pointer in the first place, so that:
>
>
>
> a = { f1: 0, f2: { x: ptr_new(FltArr(10,10,10)), y: 0}}
>
>
>
> then you could set a.f2.x=ptr_new(FltArr(5,5,5)) and access with
>
>
>
> print,*(a.f2.x)
>
>
>
> If you want to be able to change all the values, put the pointers at the lowest level, and recreate the structures each time:
>
>
>
> a=ptrarr(2)
>
> a[0]=ptr_new(0)
>
> a[1]=ptr_new({ x: ptr_new(FltArr(10,10,10)), y: 0})
>
>
>
> or
>
>
>
> a[1]=ptr_new({ x: ptr_new(FltArr(5,5,5)), y: 0})
>
>
>
> cheers,
>
> Greg
Re: Delete element from the structure inside another structure [message #88945 is a reply to message #88943] Mon, 07 July 2014 02:02 Go to previous messageGo to next message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
actually, I should have written:

a=ptrarr(2)
a[0]=ptr_new(0)
a[1]=ptr_new({ x: FltArr(10,10,10), y: 0})

or

a[1]=ptr_new({ x: FltArr(5,5,5), y: 0})

greg
Re: Delete element from the structure inside another structure [message #88946 is a reply to message #88945] Mon, 07 July 2014 02:27 Go to previous messageGo to next message
Andrii is currently offline  Andrii
Messages: 7
Registered: March 2014
Junior Member
Thanks!

Could you please also write me, how to completely delete a[1] ?

If I want to print x, should I do it in the next way: print,*a[1].x ?


> actually, I should have written:
>
>
>
> a=ptrarr(2)
>
> a[0]=ptr_new(0)
>
> a[1]=ptr_new({ x: FltArr(10,10,10), y: 0})
>
>
>
> or
>
>
>
> a[1]=ptr_new({ x: FltArr(5,5,5), y: 0})
>
>
>
> greg
Re: Delete element from the structure inside another structure [message #88947 is a reply to message #88945] Mon, 07 July 2014 02:38 Go to previous messageGo to next message
Andrii is currently offline  Andrii
Messages: 7
Registered: March 2014
Junior Member
Thanks!

Could you please also write me, how to completely delete a[1].x ?

As I understand, in order to delete a[1] I have to do it in the next way:
ptr_free, a[1].

If I want to print x, should I do it in the next way: print,*(a[1].x) ?
Re: Delete element from the structure inside another structure [message #88948 is a reply to message #88947] Mon, 07 July 2014 02:49 Go to previous messageGo to next message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
If you have IDL8+ you can use dictionnaries instead of structures:


IDL> a = dictionary('f1', 0, 'f2', dictionary('x', FltArr(3), 'y', 0))
IDL> print, a.f2.x
0.00000 0.00000 0.00000
IDL> a.f2.x = 2
IDL> print, a.f2.x
2
IDL> ok = (a.f2)->remove('x')
IDL> print, a.f2.x
% Key does not exist: "X"
% Execution halted at: $MAIN$

Cheers,

Fabien
Re: Delete element from the structure inside another structure [message #88949 is a reply to message #88946] Mon, 07 July 2014 02:51 Go to previous message
greg.addr is currently offline  greg.addr
Messages: 160
Registered: May 2007
Senior Member
> Could you please also write me, how to completely delete a[1] ?

I would probably do this:

a[1]=ptr_new() ;this sets a null pointer

and then test for it in the code:

if ptr_valid(a[i]) then...

> If I want to print x, should I do it in the next way: print,*a[1].x ?

print,(*a[1]).x

cheers,
greg
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: multi-layer tiff file
Next Topic: Plotting the region of interest from satellite image

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

Current Time: Wed Oct 08 15:10:21 PDT 2025

Total time taken to generate the page: 0.00541 seconds