Changeset 133 for trunk/SRC/Matrix/cmset_op.pro
- Timestamp:
- 07/07/06 11:57:27 (18 years ago)
- Location:
- trunk/SRC/Matrix
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/Matrix/cmset_op.pro
r132 r133 1 1 ;+ 2 ; NAME: 3 ; CMSET_OP 4 ; 5 ; AUTHOR: 6 ; Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 7 ; craigm@lheamail.gsfc.nasa.gov 8 ; 9 ; PURPOSE: 10 ; Performs an AND, OR, or XOR operation between two sets 11 ; 12 ; CALLING SEQUENCE: 13 ; SET = CMSET_OP(A, OP, B) 14 ; 15 ; DESCRIPTION: 16 ; 17 ; SET_OP performs three common operations between two sets. The 2 ; @hidden 3 ; 4 ; @todo seb 5 ;- 6 ; 7 ;; Simplified version of CMSET_OP_UNIQ which sorts, and takes the 8 ;; "first" value, whatever that may mean. 9 function cmset_op_uniq, a 10 ; 11 compile_opt idl2, strictarrsubs 12 ; 13 if n_elements(a) LE 1 then return, 0L 14 15 ii = sort(a) & b = a[ii] 16 wh = where(b NE shift(b, +1L), ct) 17 if ct GT 0 then return, ii[wh] 18 19 return, 0L 20 ; 21 end 22 ;+ 23 ; 24 ; @file_comments 25 ; Performs an AND, OR, or XOR operation between two sets 26 ; 27 ; Description: SET_OP performs three common operations between two sets. The 18 28 ; three supported functions of OP are: 19 29 ; … … 55 65 ; benefit. 56 66 ; 57 ; INPUTS:58 ; 59 ; A, B - the two sets to be operated on. A one dimensional array of67 ; @categories array 68 ; 69 ; @param A {in}{required} The two sets to be operated on. A one dimensional array of 60 70 ; either numeric or string type. A and B must be of the same 61 71 ; type. Empty sets are permitted, and are either represented 62 72 ; as an undefined variable, or by setting EMPTY1 or EMPTY2. 63 73 ; 64 ; OP - a string, the operation to be performed. Must be one of 74 ; @param B {in}{required} See A 75 ; 76 ; @param OP {in}{required} a string, the operation to be performed. Must be one of 65 77 ; 'AND', 'OR' or 'XOR' (lower or mixed case is permitted). 66 78 ; Other operations will cause an error message to be produced. 67 79 ; 68 ; KEYWORDS: 69 ; 70 ; NOT1, NOT2 - if set and OP is 'AND', then the complement of A (for 80 ; @keyword NOT1 If set and OP is 'AND', then the complement of A (for 71 81 ; NOT1) or B (for NOT2) will be used in the operation. 72 82 ; NOT1 and NOT2 cannot be set simultaneously. 73 83 ; 74 ; EMPTY1, EMPTY2 - if set, then A (for EMPTY1) or B (for EMPTY2) are 75 ; assumed to be the empty set. The actual values 76 ; passed as A or B are then ignored. 77 ; 78 ; INDEX - if set, then return a list of indices instead of the array 84 ; @keyword NOT2 See NOT1 85 ; 86 ; @keyword EMPTY1 If set, then A (for EMPTY1) or B (for EMPTY2) are 87 ; assumed to be the empty set. The actual values 88 ; passed as A or B are then ignored. 89 ; 90 ; @keyword EMPTY2 See EMPTY1 91 ; 92 ; @keyword INDEX if set, then return a list of indices instead of the array 79 93 ; values themselves. The "slower" set operations are always 80 94 ; performed in this case. … … 85 99 ; from NA to NA+NB-1 refer to B[I-NA]. 86 100 ; 87 ; COUNT -upon return, the number of elements in the result set.101 ; @keyword COUNT upon return, the number of elements in the result set. 88 102 ; This is only important when the result set is the empty 89 103 ; set, in which case COUNT is set to zero. 90 104 ; 91 ; RETURNS: 92 ; 93 ; The resulting set as a one-dimensional array. The set may be 105 ; @returns The resulting set as a one-dimensional array. The set may be 94 106 ; represented by either an array of data values (default), or an 95 107 ; array of indices (if INDEX is set). Duplicate elements, if any, … … 104 116 ; SET_UTILS.PRO by RSI 105 117 ; 106 ; MODIFICATION HISTORY: 107 ; Written, CM, 23 Feb 2000 118 ; @history Written, CM, 23 Feb 2000 108 119 ; Added empty set capability, CM, 25 Feb 2000 109 120 ; Documentation clarification, CM 02 Mar 2000 … … 133 144 ; range of the input variable (thanks to Will Maddox), CM, 16 Jan 2006 134 145 ; 135 ; $Id: cmset_op.pro,v 1.6 2006/01/16 19:45:22 craigm Exp $ 136 ; 137 ;- 138 ; Copyright (C) 2000, 2004, 2005, 2006, Craig Markwardt 139 ; This software is provided as is without any warranty whatsoever. 140 ; Permission to use, copy, modify, and distribute modified or 141 ; unmodified copies is granted, provided this copyright and disclaimer 142 ; are included unchanged. 143 ;- 144 145 ;; Utility function, similar to UNIQ, but allowing choice of taking 146 ;; first or last unique element, or non-unique elements. 147 ;; Unfortunately this doesn't work because of implementation dependent 148 ;; versions of the SORT() function. 149 146 ; Author: Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 147 ; craigm@lheamail.gsfc.nasa.gov 148 ; 149 ; @version $Id: cmset_op.pro,v 1.6 2006/01/16 19:45:22 craigm Exp $ 150 ; 151 ; @examples Utility function, similar to UNIQ, but allowing choice of taking 152 ; first or last unique element, or non-unique elements. 153 ; Unfortunately this doesn't work because of implementation dependent 154 ; versions of the SORT() function. 155 ; 150 156 ; function cmset_op_uniq, a, first=first, non=non, count=ct, sort=sortit 151 157 ; if n_elements(a) LE 1 then return, 0L … … 168 174 ; end 169 175 170 ;; Simplified version of CMSET_OP_UNIQ which sorts, and takes the 171 ;; "first" value, whatever that may mean. 172 function cmset_op_uniq, a 173 ; 174 compile_opt idl2, strictarrsubs 175 ; 176 if n_elements(a) LE 1 then return, 0L 177 178 ii = sort(a) & b = a[ii] 179 wh = where(b NE shift(b, +1L), ct) 180 if ct GT 0 then return, ii[wh] 181 182 return, 0L 183 end 176 ; Simplified version of CMSET_OP_UNIQ which sorts, and takes the 177 ; "first" value, whatever that may mean. 178 ; 179 ;- 180 184 181 185 182 function cmset_op, a, op0, b, not1=not1, not2=not2, count=count, $
Note: See TracChangeset
for help on using the changeset viewer.