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

Home » Public Forums » archive » Re: deleting structure element
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: deleting structure element [message #20850] Fri, 28 July 2000 00:00 Go to previous message
Alex Schuster is currently offline  Alex Schuster
Messages: 124
Registered: February 1997
Senior Member
David Fanning wrote:

>> Bernard Puc (bpuc@va.aetc.com) writes:
>>
>>> Is there a neat, clever way to "delete" an element from a structure?

> On further (and more sober) reflection I would probably
> answer like this:
>
> No way, no how, if you have a named structure. If you
> have an anonymous structure you *could* (under extreme
> duress) simply redefine the structure without the
> *&%%$^ field:
>
> struct = { a:0, b:0, c:0}
> struct = { a:struct.a, b:struct.b }

I once wrote a routine for that purpose (attached). It replaces an
element (tag) of a structure by another element or deletes it. Which
doesn't work for the first element, well, if anyone wants to fix this...

struct = { a:0, b:0, c:0
replace_tag, struct, 'c', '' ; deletes tag c
or:
replace_tag, struct, 'c', 'd', 100 ; replaces tag c with d (an int
with a value of 100)

Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de
;+
; NAME:
; REPLACE_TAG
;
; PURPOSE:
; Replaces a tag in a structure by another
;
; CALLING:
; replace_tag, struct, old_tag, new_tag, value
;
; INPUTS:
; struct - the structure to be changed
; old_tag - name of the tag to be changed
; new_tag - name of the new tag
; If set to '', old_tag is deleted from the structure
; value - value of the new tag
;
; RESTRICTIONS:
; Does not work with named structures
;
; MODIFICATION HISTORY:
; Alex Schuster, MPIfnF, 8/97 - Written
;-

pro replace_tag, struct, old_tag, new_tag, value

tags = tag_names( struct )

pos = (where( tags eq strupcase( old_tag ) ))(0)
if ( pos eq -1L ) then begin
print, 'Error: Tag ', old_tag, ' not in struct.'
return
endif

if ( ( pos eq 0 ) and ( new_tag ne '' ) ) then begin
new_struct = create_struct( new_tag, value )
endif else begin
new_struct = create_struct( tags(0), struct.(0) )
for i = 1, pos-1 do $
new_struct = create_struct( new_struct, tags(i), struct.(i) )
if ( new_tag ne '' ) then $
new_struct = create_struct( new_struct, new_tag, value )
endelse
for i = pos+1, n_elements( tags )-1 do $
new_struct = create_struct( new_struct, tags(i), struct.(i) )

struct = new_struct

end
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Looking for Graffer
Next Topic: keyboard events with WIDGET_DRAW

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

Current Time: Fri Oct 10 04:31:20 PDT 2025

Total time taken to generate the page: 2.24013 seconds