Ignore:
Timestamp:
07/07/06 11:57:27 (18 years ago)
Author:
navarro
Message:

english and nicer header (1)

Location:
trunk/SRC/Matrix
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/SRC/Matrix/cmapply.pro

    r132 r133  
     1;; Utility function, adapted from CMPRODUCT 
    12;+ 
    2 ; NAME: 
    3 ;   CMAPPLY 
    4 ; 
    5 ; AUTHOR: 
    6 ;   Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 
    7 ;   craigm@lheamail.gsfc.nasa.gov 
    8 ; 
    9 ; PURPOSE: 
    10 ;   Applies a function to specified dimensions of an array 
    11 ; 
    12 ; MAJOR TOPICS: 
    13 ;   Arrays 
    14 ; 
    15 ; CALLING SEQUENCE: 
    16 ;   XX = CMAPPLY(OP, ARRAY, DIMS, [/DOUBLE], [TYPE=TYPE]) 
    17 ; 
    18 ; DESCRIPTION: 
    19 ;   CMAPPLY will apply one of a few select functions to specified  
     3; @todo seb 
     4;- 
     5; 
     6function cmapply_product, x 
     7; 
     8  compile_opt idl2, strictarrsubs 
     9; 
     10  sz = size(x) 
     11  n = sz[1] 
     12 
     13  while n GT 1 do begin 
     14      if (n mod 2) EQ 1 then x[0,*] = x[0,*] * x[n-1,*] 
     15      n2 = floor(n/2) 
     16      x = x[0:n2-1,*] * x[n2:*,*] 
     17      n = n2 
     18  endwhile 
     19  return, reform(x[0,*], /overwrite) 
     20end 
     21 
     22;; Utility function, used to collect collaped dimensions 
     23;+ 
     24; @todo seb 
     25;- 
     26; 
     27pro cmapply_redim, newarr, dimapply, dimkeep, nkeep, totcol, totkeep 
     28; 
     29  compile_opt idl2, strictarrsubs 
     30; 
     31  sz = size(newarr) 
     32  ;; First task: rearrange dimensions so that the dimensions 
     33  ;; that are "kept" (ie, uncollapsed) are at the back 
     34  dimkeep = where(histogram(dimapply,min=1,max=sz[0]) ne 1, nkeep) 
     35  if nkeep EQ 0 then return 
     36 
     37  newarr = transpose(temporary(newarr), [dimapply-1, dimkeep]) 
     38  ;; totcol is the total number of collapsed elements 
     39  totcol = sz[dimapply[0]] 
     40  for i = 1, n_elements(dimapply)-1 do totcol = totcol * sz[dimapply[i]] 
     41  totkeep = sz[dimkeep[0]+1] 
     42  for i = 1, n_elements(dimkeep)-1 do totkeep = totkeep * sz[dimkeep[i]+1] 
     43 
     44  ;; this new array has two dimensions: 
     45  ;;   * the first, all elements that will be collapsed 
     46  ;;   * the second, all dimensions that will be preserved 
     47  ;; (the ordering is so that all elements to be collapsed are 
     48  ;;  adjacent in memory) 
     49  newarr = reform(newarr, [totcol, totkeep], /overwrite) 
     50end 
     51 
     52;; Main function 
     53;+ 
     54; 
     55; @file_comments  
     56; Applies a function to specified dimensions of an array 
     57; 
     58;   Description: 
     59; 
     60;      CMAPPLY will apply one of a few select functions to specified  
    2061;   dimensions of an array.  Unlike some IDL functions, you *do* have 
    2162;   a choice of which dimensions that are to be "collapsed" by this 
     
    59100;   elements is large. 
    60101; 
    61 ; 
    62 ; INPUTS: 
    63 ; 
    64 ;   OP - The operation to perform, as a string.  May be upper or lower 
     102; @categories Arrays 
     103; 
     104; @param OP {in}{required} The operation to perform, as a string.  May be upper or lower 
    65105;        case. 
    66106; 
     
    69109;        the user-defined function. 
    70110; 
    71 ;   ARRAY - An array of values to be operated on.  Must not be of type 
     111; @param ARRAY {in}{required} An array of values to be operated on.  Must not be of type 
    72112;           STRING (7) or STRUCTURE (8). 
    73113; 
    74 ; OPTIONAL INPUTS: 
    75 ; 
    76 ;   DIMS - An array of dimensions that are to be "collapsed", where 
     114; @param DIMS {in}{optional}{default=1 (ie, first dimension)}  
     115;          An array of dimensions that are to be "collapsed", where 
    77116;          the the first dimension starts with 1 (ie, same convention 
    78117;          as IDL function TOTAL).  Whereas TOTAL only allows one 
     
    84123;          DEFAULT: 1 (ie, first dimension) 
    85124; 
    86 ; KEYWORDS: 
    87 ; 
    88 ;   DOUBLE - Set this if you wish the internal computations to be done 
     125; @keyword DOUBLE Set this if you wish the internal computations to be done 
    89126;            in double precision if necessary.  If ARRAY is double  
    90127;            precision (real or complex) then DOUBLE=1 is implied. 
    91128;            DEFAULT: not set 
    92129; 
    93 ;   TYPE - Set this to the IDL code of the desired output type (refer 
     130; @keyword TYPE Set this to the IDL code of the desired output type (refer 
    94131;          to documentation of SIZE()).  Internal results will be 
    95132;          rounded to the nearest integer if the output type is an 
     
    97134;          DEFAULT: same is input type 
    98135; 
    99 ;   FUNCTARGS - If OP is 'USER:...', then the contents of this keyword 
     136; @keyword FUNCTARGS If OP is 'USER:...', then the contents of this keyword 
    100137;               are passed to the user function using the _EXTRA 
    101138;               mechanism.  This way you can pass additional data to 
     
    104141;               DEFAULT: undefined (i.e., no keywords passed by _EXTRA) 
    105142; 
    106 ; RETURN VALUE: 
    107 ; 
    108 ;   An array of the required TYPE, whose elements are the result of 
     143; @returns An array of the required TYPE, whose elements are the result of 
    109144;   the requested operation.  Depending on the operation and number of 
    110145;   elements in the input array, the result may be vulnerable to 
    111146;   overflow or underflow. 
    112147; 
    113 ; EXAMPLES: 
    114 ;   Shows how CMAPPLY can be used to total the second dimension of the 
     148; @examples  
     149;    
     150;   First example:  Shows how CMAPPLY can be used to total the second dimension of the 
    115151;   array called IN.  This is equivalent to OUT = TOTAL(IN, 2) 
    116152; 
     
    120156;   OUT             INT       = Array[5] 
    121157; 
    122 ;   Second example.  Input is assumed to be an 5x100 array of 1's and 
     158;   Second example:  Input is assumed to be an 5x100 array of 1's and 
    123159;   0's indicating the status of 5 detectors at 100 points in time. 
    124160;   The desired output is an array of 100 values, indicating whether 
     
    134170;   although there would have been more loop iterations). 
    135171; 
    136 ;   Third example.  Shows sum over first and third dimensions in an 
     172;   Third example:  Shows sum over first and third dimensions in an 
    137173;   array with dimensions 4x4x4: 
    138174; 
     
    142178;        408     472     536     600 
    143179; 
    144 ;   Fourth example. A user-function (MEDIAN) is used: 
     180;   Fourth example: A user-function (MEDIAN) is used: 
    145181; 
    146182;   IDL> IN = RANDOMN(SEED,10,10,5) 
     
    151187;   (OUT[i,j] is the median value of IN[i,j,*]) 
    152188; 
    153 ; MODIFICATION HISTORY: 
    154 ;   Mar 1998, Written, CM 
     189; @history Mar 1998, Written, CM 
    155190;   Changed usage message to not bomb, 24 Mar 2000, CM 
    156191;   Signficant rewrite for *, MIN and MAX (inspired by Todd Clements 
     
    163198;   Correct bug in MAX/MIN initialization of RESULT, CM, 05 Dec 2002 
    164199; 
    165 ;  $Id$ 
     200;  Author: Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 
     201;  craigm@lheamail.gsfc.nasa.gov 
     202; 
     203; @version $Id$ 
    166204; 
    167205;- 
    168 ; Copyright (C) 1998, 2000, 2002, Craig Markwardt 
    169 ; This software is provided as is without any warranty whatsoever. 
    170 ; Permission to use, copy, modify, and distribute modified or 
    171 ; unmodified copies is granted, provided this copyright and disclaimer 
    172 ; are included unchanged. 
    173 ;- 
    174  
    175 ;; Utility function, adapted from CMPRODUCT 
    176 function cmapply_product, x 
    177 ; 
    178   compile_opt idl2, strictarrsubs 
    179 ; 
    180   sz = size(x) 
    181   n = sz[1] 
    182  
    183   while n GT 1 do begin 
    184       if (n mod 2) EQ 1 then x[0,*] = x[0,*] * x[n-1,*] 
    185       n2 = floor(n/2) 
    186       x = x[0:n2-1,*] * x[n2:*,*] 
    187       n = n2 
    188   endwhile 
    189   return, reform(x[0,*], /overwrite) 
    190 end 
    191  
    192 ;; Utility function, used to collect collaped dimensions 
    193 pro cmapply_redim, newarr, dimapply, dimkeep, nkeep, totcol, totkeep 
    194 ; 
    195   compile_opt idl2, strictarrsubs 
    196 ; 
    197   sz = size(newarr) 
    198   ;; First task: rearrange dimensions so that the dimensions 
    199   ;; that are "kept" (ie, uncollapsed) are at the back 
    200   dimkeep = where(histogram(dimapply,min=1,max=sz[0]) ne 1, nkeep) 
    201   if nkeep EQ 0 then return 
    202  
    203   newarr = transpose(temporary(newarr), [dimapply-1, dimkeep]) 
    204   ;; totcol is the total number of collapsed elements 
    205   totcol = sz[dimapply[0]] 
    206   for i = 1, n_elements(dimapply)-1 do totcol = totcol * sz[dimapply[i]] 
    207   totkeep = sz[dimkeep[0]+1] 
    208   for i = 1, n_elements(dimkeep)-1 do totkeep = totkeep * sz[dimkeep[i]+1] 
    209  
    210   ;; this new array has two dimensions: 
    211   ;;   * the first, all elements that will be collapsed 
    212   ;;   * the second, all dimensions that will be preserved 
    213   ;; (the ordering is so that all elements to be collapsed are 
    214   ;;  adjacent in memory) 
    215   newarr = reform(newarr, [totcol, totkeep], /overwrite) 
    216 end 
    217  
    218 ;; Main function 
    219206function cmapply, op, array, dimapply, double=dbl, type=type, $ 
    220207                  functargs=functargs, nocatch=nocatch 
Note: See TracChangeset for help on using the changeset viewer.