;+ ; NAME: ; matchfirst ; PURPOSE: (one line) ; return the index of the first match of an element to an array ; DESCRIPTION: ; ; CATEGORY: ; Util ; CALLING SEQUENCE: ; match = firstmatch(elem, array) ; INPUTS: ; element - the element to be match ; list - the list into which an index should be returned ; OPTIONAL INPUT PARAMETERS: ; none ; KEYWORD INPUT PARAMETERS: ; none ; KEYWORD OUTPUT PARAMETERS: ; none ; OUTPUTS: ; long, same dimensions as elem. ; -1 if elem[i] is not in array ; array(match[i]) = elem[i], if match[i] ne -1 ; COMMON BLOCKS: ; None ; SIDE EFFECTS: ; RESTRICTIONS: ; None ; PROCEDURE: ; MODIFICATION HISTORY: ; 2009 Sept 4 Leslie Young SwRI ;- function matchfirst, elem, list if isarray(elem) then begin n = n_elements(elem) if size(elem, /tname) eq 'STRING' then begin res = long(elem eq '') ; to get the right dimensions. endif else begin res = long(elem) ; to get the right dimensions. endelse ; Fix first, in case res is a string. for i = 0L, n-1 do res[i] = (where(elem[i] eq list))[0] return, res endif else begin return, (where(elem eq list))[0] endelse end