forked from ChrisBeaumont/beaumont-idl-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
union.pro
57 lines (54 loc) · 1.2 KB
/
union.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;+
; PURPOSE:
; This function returns the union of two vectors. The union is the
; set of numbers present in either vector.
;
; CATEGORY:
; Utilities
;
; CALLING SEQUENCE:
; result = union(vec1, vec2)
;
; INPUTS:
; vec1: A 1D vector of integers
; vec2: A 1D vector of integers
;
; OUTPUTS:
; A 1D vector of the integers present in either vec1 or vec2
;
; MODIFICATION HISTORY:
; July 2009: Written by Chris Beaumont
;-
function union, vec1, vec2
if n_params() ne 2 then begin
print, 'union calling sequence:'
print, ' result = union(vec1, vec2)'
return, !values.f_nan
endif
;- make sure vec1 and vec2 are integers
type = size(vec1, /tname)
case type of
'BYTE':
'INT':
'LONG':
'UINT':
'ULONG':
'LONG64':
'ULONG64': break
else: message, 'first vector not an integer data type'
endcase
if size(vec1, /n_dim) ne 1 then message, 'first vector not a 1D array'
type = size(vec2, /tname)
case type of
'BYTE':
'INT':
'LONG':
'UINT':
'ULONG':
'LONG64':
'ULONG64': break
else: message, 'second vector not an integer data type'
endcase
result = [vec1, vec2]
return, result[uniq(result, sort(result))]
end