[133] | 1 | ;+ |
---|
| 2 | ; |
---|
[136] | 3 | ; @file_comments |
---|
[163] | 4 | ; extraction of subdomains of matrices; |
---|
[136] | 5 | ; Even if the subdomain is "pierced" (see the example) |
---|
[133] | 6 | ; By default, IDL can make extractions of subdomain: |
---|
| 7 | ; |
---|
[136] | 8 | ; IDL> a=indgen(5,5) |
---|
| 9 | ; IDL> print, a |
---|
[133] | 10 | ; 0 1 2 3 4 |
---|
| 11 | ; 5 6 7 8 9 |
---|
| 12 | ; 10 11 12 13 14 |
---|
| 13 | ; 15 16 17 18 19 |
---|
| 14 | ; 20 21 22 23 24 |
---|
[136] | 15 | ; IDL> print, a[[0,2],3] |
---|
[133] | 16 | ; 15 17 |
---|
[136] | 17 | ; IDL> print, a[[0,2],*] |
---|
[133] | 18 | ; 0 2 |
---|
| 19 | ; 5 7 |
---|
| 20 | ; 10 12 |
---|
| 21 | ; 15 17 |
---|
| 22 | ; 20 22 |
---|
| 23 | ; but |
---|
[136] | 24 | ; IDL> print, a[[0,2],[3,4]] |
---|
[133] | 25 | ; 15 22 |
---|
| 26 | ; while |
---|
[136] | 27 | ; IDL> print, extrac2(a,[0,2],[3,4]) |
---|
[133] | 28 | ; 15 17 |
---|
| 29 | ; 20 22 |
---|
| 30 | ; |
---|
[238] | 31 | ; @categories |
---|
[157] | 32 | ; Utilities |
---|
[133] | 33 | ; |
---|
[136] | 34 | ; @param array {in}{required} |
---|
| 35 | ; a 1,2,3 or 4 dim input array |
---|
[133] | 36 | ; |
---|
[136] | 37 | ; @param index1 {in}{required} |
---|
| 38 | ; can have 2 forms: |
---|
| 39 | ; 1)a vector containing indexes of lines we want to keep |
---|
| 40 | ; 2)the string '*' if we want to keep all lines. |
---|
[133] | 41 | ; |
---|
[136] | 42 | ; @param index2 {in}{required} |
---|
| 43 | ; the same thing that index1 but for dim 2. |
---|
[133] | 44 | ; |
---|
[136] | 45 | ; @param index3 {in}{required} |
---|
| 46 | ; the same thing that index1 but for dim 3. |
---|
[133] | 47 | ; |
---|
[136] | 48 | ; @param index4 {in}{required} |
---|
| 49 | ; the same thing that index1 but for dim 4. |
---|
[133] | 50 | ; |
---|
[136] | 51 | ; @returns |
---|
| 52 | ; a matrix 1,2,3 or 4d extract from input array |
---|
[230] | 53 | ; -1 in case of mistake |
---|
[133] | 54 | ; |
---|
[136] | 55 | ; @restrictions |
---|
| 56 | ; |
---|
| 57 | ; @examples |
---|
| 58 | ; I have a dim 2 matrix named A. I want extract a small intersection |
---|
| 59 | ; matrix 2d of the line 2,3 and 7 and of the column 0 and 1: |
---|
[238] | 60 | ; |
---|
[136] | 61 | ; IDL> res=extrac2(A,[2,3,7],[0,1]) |
---|
[133] | 62 | ; |
---|
[136] | 63 | ; other ex: |
---|
| 64 | ; IDL> print, a |
---|
| 65 | ; a b c |
---|
| 66 | ; d e f |
---|
| 67 | ; g h i |
---|
| 68 | ; IDL> print, extrac2(a,[0,2],[0,2]) |
---|
| 69 | ; a c |
---|
| 70 | ; g i |
---|
[133] | 71 | ; |
---|
[238] | 72 | ; @history |
---|
| 73 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[133] | 74 | ; 12/1/1999 |
---|
| 75 | ; 29/4/1999: correction of a bug and complement of the heading |
---|
| 76 | ; |
---|
[238] | 77 | ; @version |
---|
| 78 | ; $Id$ |
---|
[133] | 79 | ; |
---|
| 80 | ;- |
---|
[231] | 81 | ; |
---|
[133] | 82 | FUNCTION extrac2, array, index1, index2, index3, index4 |
---|
| 83 | ; |
---|
| 84 | compile_opt idl2, strictarrsubs |
---|
| 85 | ; |
---|
| 86 | taille = size(array) |
---|
| 87 | ;------------------------------------------------------------ |
---|
[231] | 88 | ; test of the number of parameters |
---|
[133] | 89 | ; and of the nature of the index (for THE case 'x') |
---|
| 90 | ;------------------------------------------------------------ |
---|
| 91 | if n_params() NE taille[0]+1 THEN $ |
---|
| 92 | return, report('we need as many indexes as the number of dimensions of the input array') |
---|
[136] | 93 | IF n_params() GE 5 THEN BEGIN |
---|
[133] | 94 | if size(index4,/type) EQ 7 then index4 = lindgen(taille[4]) $ |
---|
| 95 | ELSE index4 = long(index4) |
---|
[136] | 96 | nt = n_elements(index4) |
---|
| 97 | ENDIF |
---|
| 98 | IF n_params() GE 4 THEN BEGIN |
---|
[133] | 99 | if size(index3,/type) EQ 7 then index3 = lindgen(taille[3]) $ |
---|
| 100 | ELSE index3 = long(index3) |
---|
[136] | 101 | nz = n_elements(index3) |
---|
| 102 | ENDIF |
---|
| 103 | IF n_params() GE 3 THEN BEGIN |
---|
[133] | 104 | if size(index2,/type) EQ 7 then index2 = lindgen(taille[2]) $ |
---|
| 105 | ELSE index2 = long(index2) |
---|
[136] | 106 | ny = n_elements(index2) |
---|
[133] | 107 | ENDIF |
---|
[136] | 108 | IF n_params() GE 2 THEN BEGIN |
---|
[133] | 109 | if size(index1,/type) EQ 7 then index1 = lindgen(taille[1]) $ |
---|
| 110 | ELSE index1 = long(index1) |
---|
[136] | 111 | nx = n_elements(index1) |
---|
[133] | 112 | ENDIF |
---|
[136] | 113 | |
---|
[133] | 114 | ;------------------------------------------------------------ |
---|
| 115 | ; construction of an array of indexes and of results following the size of array |
---|
| 116 | ;------------------------------------------------------------ |
---|
| 117 | case taille[0] of |
---|
| 118 | 1:res = array[index1] |
---|
| 119 | 2:BEGIN |
---|
| 120 | index = index1#replicate(1, ny)+taille[1]*replicate(1, nx)#index2 |
---|
| 121 | res = array[index] |
---|
[136] | 122 | END |
---|
[133] | 123 | 3:BEGIN |
---|
| 124 | index = index1#replicate(1, ny)+taille[1]*replicate(1, nx)#index2 |
---|
| 125 | index = temporary(index[*])#replicate(1, nz) $ |
---|
| 126 | +taille[1]*taille[2]*replicate(1, nx*ny)#index3 |
---|
| 127 | res = array[reform(index, nx, ny, nz, /over)] |
---|
[136] | 128 | END |
---|
[133] | 129 | 4:BEGIN |
---|
| 130 | index = index1#replicate(1, ny)+taille[1]*replicate(1, nx)#index2 |
---|
| 131 | index = temporary(index[*])#replicate(1, nz) $ |
---|
| 132 | +taille[1]*taille[2]*replicate(1, nx*ny)#index3 |
---|
| 133 | index = temporary(index[*])#replicate(1, nt) $ |
---|
| 134 | +taille[1]*taille[2]*taille[3]*replicate(1, nx*ny*nz)#index4 |
---|
| 135 | res = array[reform(index, nx, ny, nz, nz, /over)] |
---|
[136] | 136 | END |
---|
[133] | 137 | endcase |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | ;------------------------------------------------------------ |
---|
| 141 | ;------------------------------------------------------------ |
---|
| 142 | return, res |
---|
| 143 | end |
---|