function compare_lists,list1,list2,tf=tf ;+ ; ; COMPARE_LISTS ; A function to determine which elements from one list are present in ; a second. ; ; Call Sequence: ; Result = COMPARE_LISTS(LIST1, LIST2 [, /TF]) ; ; Inputs: ; LIST1, LIST2 - Two arrays of possibly differing lengths, but ; containing the same type of variable (e.g., not ; mixing strings and integers). ; ; Returns: ; An integer array of same length as LIST1 with -1 where that element ; does not exist in LIST2 and the index of the first occurence of that ; element if it does exist in LIST2. ; ; Keywords: ; TF - Set /TF to return a 0/1 true-false array instead an array of ; indices. ; ; Katie Peek / Nov 2006 ; ;- ; Create the integer array to be filled. n = n_elements(list1) l1 = intarr(n) ; Loop over elements in LIST1. for i=0L,n-1 do begin w = where(list2 eq list1[i]) if keyword_set(tf) then begin case 1 of (w[0] eq -1): l1[i] = 0 (w[0] ne -1): l1[i] = 1 else: print,"Don't look now, but you just broke Logic." endcase endif else l1[i] = w[0] endfor ; Return the integer array. return,l1 end