Changeset 223 for trunk/SRC/Matrix
- Timestamp:
- 03/14/07 18:13:39 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/Matrix/make_selection.pro
r163 r223 1 1 ;+ 2 2 ; 3 ; file_comments3 ; @file_comments 4 4 ; Convert an array of selected values to an index 5 ; array that identifies the selected values in a list 6 ; or data array. 5 ; array that identifies the selected values in a list or data array. 7 6 ; 8 ; categories tools 9 ; 10 ; @param NAMES {in}{required} A list or array of values to choose from 7 ; @categories 8 ; tools 11 9 ; 12 ; @param SELNAMES {in}{required} A list of selected values 10 ; @param NAMES {in}{required} 11 ; A list or array of values to choose from 13 12 ; 14 ; @keyword ONLY_VALID Return only indexes of found values. Values not 15 ; found are skipped. Default is to return 1 index value for 16 ; each SELNAME, which is -1 if SELNAME is not contained in 17 ; NAMES. If ONLY_VALID is set, the -1 values will be deleted, 18 ; and a value of -1 indicates that no SELNAME has been found 19 ; at all. 13 ; @param SELNAMES {in}{required} 14 ; A list of selected values 20 15 ; 21 ; @keyword REQUIRED Normally, MAKE_SELECTION will return indexes for 22 ; all values that are found, simply ignoring the selected 23 ; values that are not in the NAMES array (although an error 24 ; message is displayed). Set this keyword to return with 25 ; -1 as soon as a selected value is not found. 16 ; @keyword ONLY_VALID 17 ; Return only indexes of found values. Values not 18 ; found are skipped. Default is to return 1 index value for 19 ; each SELNAME, which is -1 if SELNAME is not contained in 20 ; NAMES. If ONLY_VALID is set, the -1 values will be deleted, 21 ; and a value of -1 indicates that no SELNAME has been found 22 ; at all. 26 23 ; 27 ; @keyword QUIET Suppress printing of the error message if a 28 ; selected value is not found (the error condition will 29 ; still be set). 24 ; @keyword REQUIRED 25 ; Normally, MAKE_SELECTION will return indexes for 26 ; all values that are found, simply ignoring the selected 27 ; values that are not in the NAMES array (although an error 28 ; message is displayed). Set this keyword to return with 29 ; -1 as soon as a selected value is not found. 30 30 ; 31 ; @returns A (long) array with indexes to reference the selected values 32 ; in the NAMES array. 31 ; @keyword QUIET 32 ; Suppress printing of the error message if a 33 ; selected value is not found (the error condition will 34 ; still be set). 33 35 ; 34 ; @restrictions If the NAMES array contains multiple entries of the same value, 35 ; only the index to the first entry will be returned. 36 ; @returns 37 ; A (long) array with indexes to reference the selected values 38 ; in the NAMES array. 36 39 ; 37 ; A selection can contain multiple instances of the same value.38 ; The index array will contain one entry per selected item39 ; (See example below)40 ; @restrictions 41 ; If the NAMES array contains multiple entries of the same value, 42 ; only the index to the first entry will be returned. 40 43 ; 41 ; @examples names = [ 'Alfred','Anton','Peter','John','Mary'] 44 ; A selection can contain multiple instances of the same value. 45 ; The index array will contain one entry per selected item 46 ; (See example below) 47 ; 48 ; @examples 49 ; names = [ 'Alfred','Anton','Peter','John','Mary'] 42 50 ; index = MAKE_SELECTION(names,['Peter','Mary']) 43 51 ; print,index … … 57 65 ; ; prints -1 58 66 ; 59 ; @history mgs, 28 Aug 1998: VERSION 1.00 60 ; mgs, 29 Aug 1998: - changed behavior and added ONLY_VALID keyword 67 ; @history 68 ; mgs, 28 Aug 1998: VERSION 1.00 69 ; mgs, 29 Aug 1998: - changed behavior and added ONLY_VALID keyword 61 70 ; 62 ; @version $Id$ 71 ; @version 72 ; $Id$ 63 73 ; 64 74 ;- … … 81 91 compile_opt idl2, strictarrsubs 82 92 ; 83 84 85 86 ; return an index array with a number for each element in 93 ; return an index array with a number for each element in 87 94 ; selnames that is found in names. 88 95 ; Set the REQUIRED keyword to return -1 if one element is 89 ; not found, otherwise -1 will only be returned, if no 96 ; not found, otherwise -1 will only be returned, if no 90 97 ; element is found. 91 98 92 99 ; reset error state to 0 93 100 message,/reset 94 101 95 102 quiet = keyword_set(quiet) 96 103 result = -1L 97 104 98 105 for i=0,n_elements(selnames)-1 do begin 99 106 test = where(names eq selnames[i]) 100 result = [ result, test[0] ] 107 result = [ result, test[0] ] 101 108 if (test[0] lt 0) then begin 102 109 if (keyword_set(ONLY_VALID) OR keyword_set(REQUIRED)) then $ … … 106 113 endif 107 114 endfor 108 115 109 116 if (n_elements(result) gt 1) then result = result[1:*] 110 117 … … 114 121 else result = -1L 115 122 endif 116 123 117 124 return,result 118 125 119 126 end
Note: See TracChangeset
for help on using the changeset viewer.