topcmset_op
Array
Return value
The resulting set as a one-dimensional array. The set may be
represented by either an array of data values (default), or an
array of indexes (if INDEX is set). Duplicate elements, if any,
are removed, and element order may not be preserved.
The empty set is represented as a return value of -1L, and COUNT
is set to zero. Note that the only way to recognize the empty set
is to examine COUNT.
SEE ALSO:
SET_UTILS.PRO by RSI
Parameters
a
in
required
op0
in
required
type: string
b
in
required
Keywords
NOT1
NOT2
COUNT
EMPTY1
EMPTY2
MAXARRAY
INDEX
Examples
Utility function, similar to UNIQ, but allowing choice of taking
first or last unique element, or non-unique elements.
Unfortunately this doesn't work because of implementation dependent
versions of the SORT() function.
function cmset_op_uniq, a, first=first, non=non, count=ct, sort=sortit
if n_elements(a) LE 1 then return, 0L
sh = (2L*keyword_set(first)-1L)*(-2L*keyword_set(non)+1)
if keyword_set(sortit) then begin
;; Sort it manually
ii = sort(a) & b = a[ii]
if keyword_set(non) then wh = where(b EQ shift(b, sh), ct) $
else wh = where(b NE shift(b, sh), ct)
if ct GT 0 then return, ii[wh]
endif else begin
;; Use the user's values directly
if keyword_set(non) then wh = where(a EQ shift(a, sh), ct) $
else wh = where(a NE shift(a, sh), ct)
if ct GT 0 then return, wh
endelse
if keyword_set(first) then return, 0L else return, n_elements(a)-1
end
Simplified version of CMSET_OP_UNIQ which sorts, and takes the
"first" value, whatever that may mean.
Version history
Version
$Id: cmset_op.pro 372 2008-08-08 12:31:53Z pinsard $
History
Written, CM, 23 Feb 2000
Added empty set capability, CM, 25 Feb 2000
Documentation clarification, CM 02 Mar 2000
Incompatible but more consistent reworking of EMPTY keywords, CM,
04 Mar 2000
Minor documentation clarifications, CM, 26 Mar 2000
Corrected bug in empty_arg special case, CM 06 Apr 2000
Add INDEX keyword, CM 31 Jul 2000
Clarify INDEX keyword documentation, CM 06 Sep 2000
Made INDEX keyword always force SLOW_SET_OP, CM 06 Sep 2000
Added CMSET_OP_UNIQ, and ability to select FIRST_UNIQUE or
LAST_UNIQUE values, CM, 18 Sep 2000
Removed FIRST_UNIQUE and LAST_UNIQUE, and streamlined
CMSET_OP_UNIQ until problems with SORT can be understood, CM, 20
Sep 2000 (thanks to Ben Tupper)
Still trying to get documentation of INDEX and NOT right, CM, 28
Sep 2000 (no code changes)
Correct bug for AND case, when input sets A and B each only have
one unique value, and the values are equal. CM, 04 Mar 2004
(thanks to James B. jbattat at cfa dot harvard dot edu)
Add support for the cases where the input data types are mixed,
but still compatible; also, attempt to return the same data
type that was passed in; CM, 05 Feb 2005
Fix bug in type checking (thanks to "marit"), CM, 10 Dec 2005
Work around a stupidity in the built-in IDL HISTOGRAM routine,
which tries to "help" you by restricting the MIN/MAX to the
range of the input variable (thanks to Will Maddox), CM, 16 Jan 2006
Author: Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770
craigm@lheamail.gsfc.nasa.gov
Statistics
McCabe cyclic | 62 |
McCabe essential | 12 |
McCabe modular design | 1 |