function matchem, aa, bb, unmatch=unmatch, quiet=quiet ;+ ; NAME: ; matchem ; ; PURPOSE: ; To find the common or not-common indices between arrays aa and bb. ; Return -1 if criteria not met. ; ; INPUT ; aa,bb - 2 vectors of numbers, any format. ; ; OUTPUT ; unmatch eq 0: vector of numbers common to aa & bb. ; unmatch eq 1: vector of numbers in the larger of aa & bb ; which are not common with the other. ; Return -1 if either case fails to find an output. ; ; OPTION KEYWORD INPUT ; unmatch - if not set return common numbers. ; if set, return the unmatching numbers. ; /quiet - don't print out messages. ; ; CALLING SEQUENCE: ; iiaa = matchem(aa,bb) ; ; PROCEDURES CALLED ; delind ; ; HISTORY: ; Written by LWA on 3-Jan-96. ; Rewritten using delind, LWA, 1/13/96. ; Updated header, LWA, 1/15/96 ; Handled case of aa larger than bb. ; Handled case of no common elements. ; Case of non-unique elements, LWA, 1/27/96. ; Replaced delind with kill_index, LWA, 8/02/00. ; Back to use of delind.pro, now that it is fixed. LWA 10/25/05 ; Handle case of all common elements. ; added unmatch capability ; added keyword quiet. LWA 8/3/2007. ; return -1 for case of unmatch=1 and all elements in common. 8/7/07. ; 31-Oct-2008 LWA Handle case of unmatched indices all outside the ; range of the shorter array. ;- ; Larger array must be the bb array. unmatch=keyword_set(unmatch) quiet=keyword_set(quiet) aa1=aa(uniq(aa(sort(aa)))) bb1=bb(uniq(bb(sort(bb)))) asiz=n_elements(aa1) bsiz=n_elements(bb1) case 1 of asiz gt bsiz : begin aaa=bb1 bbb=aa1 end asiz eq bsiz : begin yy=double(aa1)-double(bb1) nz=where(yy ne 0,nzi) if nzi eq 0 then begin if not quiet then print,$ ' ***** All elements are common to the 2 input arrays. ****' if not unmatch then out=aa1 else out=-1 return,out endif else begin aaa=aa1 bbb=bb1 endelse end asiz lt bsiz : begin aaa=aa1 bbb=bb1 end endcase cc=[aaa,bbb] cc=cc(sort(cc)) dd=uniq(cc) ; Handle case of no common elements. if n_elements(dd) eq n_elements(cc) then begin if not quiet then print,$ ' ***** There are no elements in common to the 2 input arrays. ****' return,[-1] endif if not unmatch then out=delind(delind(aaa,cc),bbb) $ else out=delind(bbb,aaa) return,out end