;+ ; NAME: ; struct2array ; PURPOSE: (one line) ; assign tag values in a structure into an array ; DESCRIPTION: ; assign tag valuess in a structure into an array ; CATEGORY: ; utility ; CALLING SEQUENCE: ; struct2array, struct, tags, array ; INPUTS: ; struct - the structure from which the tag values will be retreived ; tags - a list of strings correspondint to the tag names in the structure ; array - a list of values to be assigned from the structure ; OPTIONAL INPUT PARAMETERS: ; none ; KEYWORD INPUT PARAMETERS: ; none ; KEYWORD OUTPUT PARAMETERS: ; none ; OUTPUTS: ; array - a list of values to be assigned from the structure ; COMMON BLOCKS: ; None ; SIDE EFFECTS: ; changes array in place ; RESTRICTIONS: ; None ; PROCEDURE: ; MODIFICATION HISTORY: ; Written 2006 Aug 2, Leslie Young ;- pro struct2array, struct, tags, array structtags = tag_names(struct) ; get the array of strings that is ; the tag names for struct n = n_elements(array) ; number of elements to assign for i=0,n-1 do begin ; loop over elements itag = where(strcmp(tags[i], structtags, /fold), nmatch) ; look for a structure tag that ; matches passed tag string, and get ; the tag index (itag) if nmatch eq 1 then begin itag = itag[0] ; where returns an array. Turn into scalar. array[i] = struct.(itag) ; reference using tag index end end end