Changeset 136 for trunk/SRC/Matrix/cmapply.pro
- Timestamp:
- 07/10/06 17:20:19 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/Matrix/cmapply.pro
r134 r136 1 ;; Utility function, adapted from CMPRODUCT2 1 ;+ 2 ; @file_comments 3 ; Utility function, adapted from CMPRODUCT 4 ; 5 ; @version $Id$ 6 ; 3 7 ; @todo seb 4 8 ;- … … 20 24 end 21 25 22 ;; Utility function, used to collect collaped dimensions23 26 ;+ 27 ; @file_comments 28 ; cmapply_redim : Utility function, used to collect collaped dimensions 29 ; 24 30 ; @todo seb 25 31 ;- … … 53 59 ;+ 54 60 ; 55 ; @file_comments 61 ; @file_comments 56 62 ; Applies a function to specified dimensions of an array 57 63 ; 58 ; 59 ; 60 ; CMAPPLY will apply one of a few select functions to specified61 ; 62 ; 63 ; function. Iterative loops are avoided where possible, for64 ; 64 ; Description: 65 ; 66 ; CMAPPLY will apply one of a few select functions to specified 67 ; dimensions of an array. Unlike some IDL functions, you *do* have 68 ; a choice of which dimensions that are to be "collapsed" by this 69 ; function. Iterative loops are avoided where possible, for 70 ; performance reasons. 65 71 ; 66 72 ; The possible functions are: (and number of loop iterations:) … … 102 108 ; @categories Arrays 103 109 ; 104 ; @param OP {in}{required} The operation to perform, as a string. May be upper or lower 105 ; case. 106 ; 107 ; If a user-defined operation is to be passed, then OP is of 108 ; the form, 'USER:FUNCTNAME', where FUNCTNAME is the name of 109 ; the user-defined function. 110 ; 111 ; @param ARRAY {in}{required} An array of values to be operated on. Must not be of type 112 ; STRING (7) or STRUCTURE (8). 113 ; 114 ; @param DIMS {in}{optional}{default=1 (ie, first dimension)} 115 ; An array of dimensions that are to be "collapsed", where 116 ; the the first dimension starts with 1 (ie, same convention 117 ; as IDL function TOTAL). Whereas TOTAL only allows one 118 ; dimension to be added, you can specify multiple dimensions 119 ; to CMAPPLY. Order does not matter, since all operations 120 ; are associative and transitive. NOTE: the dimensions refer 121 ; to the *input* array, not the output array. IDL allows a 122 ; maximum of 8 dimensions. 123 ; DEFAULT: 1 (ie, first dimension) 124 ; 125 ; @keyword DOUBLE Set this if you wish the internal computations to be done 126 ; in double precision if necessary. If ARRAY is double 127 ; precision (real or complex) then DOUBLE=1 is implied. 128 ; DEFAULT: not set 129 ; 130 ; @keyword TYPE Set this to the IDL code of the desired output type (refer 131 ; to documentation of SIZE()). Internal results will be 132 ; rounded to the nearest integer if the output type is an 133 ; integer type. 134 ; DEFAULT: same is input type 135 ; 136 ; @keyword FUNCTARGS If OP is 'USER:...', then the contents of this keyword 137 ; are passed to the user function using the _EXTRA 138 ; mechanism. This way you can pass additional data to 139 ; your user-supplied function, via keywords, without 140 ; using common blocks. 141 ; DEFAULT: undefined (i.e., no keywords passed by _EXTRA) 142 ; 143 ; @returns An array of the required TYPE, whose elements are the result of 144 ; the requested operation. Depending on the operation and number of 145 ; elements in the input array, the result may be vulnerable to 146 ; overflow or underflow. 147 ; 148 ; @examples 149 ; 110 ; @param OP {in}{required} 111 ; The operation to perform, as a string. May be upper or lower case. 112 ; 113 ; If a user-defined operation is to be passed, then OP is of 114 ; the form, 'USER:FUNCTNAME', where FUNCTNAME is the name of 115 ; the user-defined function. 116 ; 117 ; @param ARRAY {in}{required} 118 ; An array of values to be operated on. 119 ; Must not be of type STRING (7) or STRUCTURE (8). 120 ; 121 ; @param dimapply {in}{optional}{default=1 (ie, first dimension)} 122 ; An array of dimensions that are to be "collapsed", where 123 ; the the first dimension starts with 1 (ie, same convention 124 ; as IDL function TOTAL). Whereas TOTAL only allows one 125 ; dimension to be added, you can specify multiple dimensions 126 ; to CMAPPLY. Order does not matter, since all operations 127 ; are associative and transitive. NOTE: the dimensions refer 128 ; to the *input* array, not the output array. IDL allows a 129 ; maximum of 8 dimensions. 130 ; 131 ; @keyword DOUBLE {default=not set} 132 ; Set this if you wish the internal computations to be done 133 ; in double precision if necessary. If ARRAY is double 134 ; precision (real or complex) then DOUBLE=1 is implied. 135 ; 136 ; @keyword TYPE 137 ; Set this to the IDL code of the desired output type (refer 138 ; to documentation of SIZE()). Internal results will be 139 ; rounded to the nearest integer if the output type is an 140 ; integer type. 141 ; DEFAULT: same is input type 142 ; 143 ; @keyword FUNCTARGS 144 ; If OP is 'USER:...', then the contents of this keyword 145 ; are passed to the user function using the _EXTRA 146 ; mechanism. This way you can pass additional data to 147 ; your user-supplied function, via keywords, without 148 ; using common blocks. 149 ; DEFAULT: undefined (i.e., no keywords passed by _EXTRA) 150 ; 151 ; @returns 152 ; An array of the required TYPE, whose elements are the result of 153 ; the requested operation. Depending on the operation and number of 154 ; elements in the input array, the result may be vulnerable to 155 ; overflow or underflow. 156 ; 157 ; @examples 158 ; 150 159 ; First example: Shows how CMAPPLY can be used to total the second dimension of the 151 160 ; array called IN. This is equivalent to OUT = TOTAL(IN, 2) … … 190 199 ; Changed usage message to not bomb, 24 Mar 2000, CM 191 200 ; Signficant rewrite for *, MIN and MAX (inspired by Todd Clements 192 ; <Todd_Clements @alumni.hmc.edu>); FOR loop indices are now type201 ; <Todd_Clements\@alumni.hmc.edu>); FOR loop indices are now type 193 202 ; LONG; copying terms are liberalized, CM, 22, Aug 2000 194 203 ; More efficient MAX/MIN (inspired by Alex Schuster), CM, 25 Jan … … 199 208 ; 200 209 ; Author: Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 201 ; craigm @lheamail.gsfc.nasa.gov210 ; craigm\@lheamail.gsfc.nasa.gov 202 211 ; 203 212 ; @version $Id$ … … 293 302 if newop EQ 'MIN' then return, min(newarr) 294 303 endif 295 304 296 305 ;; Next task: create result array 297 306 result = make_array(totkeep, type=type) 298 307 299 308 ;; Now either iterate over the number of output elements, or 300 309 ;; the number of collapsed elements, whichever is smaller. … … 302 311 ;; Iterate over the number of collapsed elements 303 312 result[0] = reform(newarr[0,*],totkeep,/overwrite) 304 case newop of 313 case newop of 305 314 'MAX': for i = 1L, totcol-1 do $ 306 315 result[0] = result > newarr[i,*] … … 310 319 endif else begin 311 320 ;; Iterate over the number of output elements 312 case newop of 321 case newop of 313 322 'MAX': for i = 0L, totkeep-1 do result[i] = max(newarr[*,i]) 314 323 'MIN': for i = 0L, totkeep-1 do result[i] = min(newarr[*,i]) … … 332 341 return, call_function(functname, newarr) 333 342 endif 334 343 335 344 ;; Next task: create result array 336 345 result = make_array(totkeep, type=type) 337 346 338 347 ;; Iterate over the number of output elements 339 348 if n_elements(functargs) GT 0 then begin … … 349 358 end 350 359 351 360 352 361 endcase 353 362 … … 363 372 return, call_function(castfns[type], newarr) 364 373 end 365
Note: See TracChangeset
for help on using the changeset viewer.