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