;+ ; NAME: ; struct_delfield ; PURPOSE: (one line) ; delete fields from an existing structure ; DESCRIPTION: ; delete fields from an existing structure ; CATEGORY: ; util ; CALLING SEQUENCE: ; new = struct_delfield(old, tag, new_structname = new_structname) ; INPUTS: ; old - existing structure ; tag - field to be deleted ; OPTIONAL INPUT PARAMETERS: ; none ; KEYWORD INPUT PARAMETERS: ; new_structname - if the structure is to be named (not anonymous), ; the name ; KEYWORD OUTPUT PARAMETERS: ; none ; OUTPUTS: ; new - new structure with field added ; COMMON BLOCKS: ; None ; SIDE EFFECTS: ; none ; RESTRICTIONS: ; PROCEDURE: ; Constructs a call to create_struct ; Calls lexecute to execute the long string ; USAGE ; MODIFICATION HISTORY: ; 2005 Dec 31 Leslie Young ;- function struct_delfield, old, tag, new_structname = new_structname old_structname = tag_names(old, /structure_name) old_names = tag_names(old) n = n_tags(old) keep = where( strcmp(old_names, tag, /fold_case) ne 1, count ) if count eq 0 then begin return, -1 end new_names = old_names[keep] exstr = 'new = { $' if keyword_set(new_structname) then begin exstr = [exstr, new_structname + ', $'] end eol = '), $' for i=0, count-1 do begin if i eq count-1 then eol = ') $' ; no comma, last list exstr = [exstr, new_names[i] + ': old.(' + string(keep[i]) + eol] endfor exstr = [exstr, '}'] oldsav=tmpfile('struct_delfield','sav') ; get a temporary sav filename save, old, fil=oldsav ; save variables lexecute,exstr,newsav,lexecute_oldsav=oldsav restore,newsav ; restore newsav file_delete,newsav,oldsav ; cleanup ; struct_assign, old, new return, new end