With two arrays of unequal length the IDL language writers had to make a decision about what the meaning of "WHERE(arrayOfOneLength EQ arrayOfDifferentLength)" should mean. The logical option was to choose the meaning closest to the behavior of WHERE with two arrays of equal length: the output of WHERE would be the subscripts where array1[i] EQ array2[i]. So, if your example were:
a = [1, 4, 9, 17, 22, 25]
b = [1, 22, 25, 17, 9, 4]
then the output of "WHERE(a eq b)" would be [0, 3].
Since IDL has set WHERE to work this way, it does not have the option to also work the way you want. And there is no one-call alternative to WHERE that does the kind of INTERSECTION functionality that you would like in your example. Thus, in this case you have to make a specific for loop. Here is a routine that might be appropriate for your application.
FUNCTION intersection, set, subset
intersection = bytarr(n_elements(set)) ; Initialize boolean result array
for i = 0, n_elements(subset)-1 do begin
trueIndices = where(set eq subset[i], count)
if count ne 0 then intersection[trueIndices] = 1B
endfor
trueIndices = where(intersection eq 1B, count)
if count ne 0 then return, trueIndices else return, -1
END
James Jones
|