;+ ; NAME: ; array2struct ; PURPOSE: (one line) ; assign tag values in a structure from an array ; DESCRIPTION: ; assign tag valuess in a structure from an array ; CATEGORY: ; utility ; CALLING SEQUENCE: ; array2struct, array, tags, struct ; INPUTS: ; array - a list of values to be assigned into the structure ; tags - a list of strings correspondint to the tag names in the structure ; struct - the structure for which the tag values will be changed ; OPTIONAL INPUT PARAMETERS: ; none ; KEYWORD INPUT PARAMETERS: ; none ; KEYWORD OUTPUT PARAMETERS: ; none ; OUTPUTS: ; struct - the structure for which the tag values will be changed ; COMMON BLOCKS: ; None ; SIDE EFFECTS: ; changes struct in place ; RESTRICTIONS: ; None ; PROCEDURE: ; MODIFICATION HISTORY: ; Written 2006 Aug 2, Leslie Young ;- pro array2struct, array, tags, struct 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. struct.(itag) = array[i] ; reference using tag index end end end