1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME:extrait |
---|
6 | ; |
---|
7 | ; PURPOSE:extraction de sous domaines de matrices. Meme si le sous |
---|
8 | ; domaine est "troue". cf. : l''exemple |
---|
9 | ; Par defaut IDL peut faire des extractions de sous domaines: |
---|
10 | ; |
---|
11 | ; IDL> a=indgen(5,5) |
---|
12 | ; IDL> print, a |
---|
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 |
---|
18 | ; IDL> print, a[[0,2],3] |
---|
19 | ; 15 17 |
---|
20 | ; IDL> print, a[[0,2],*] |
---|
21 | ; 0 2 |
---|
22 | ; 5 7 |
---|
23 | ; 10 12 |
---|
24 | ; 15 17 |
---|
25 | ; 20 22 |
---|
26 | ; mais |
---|
27 | ; IDL> print, a[[0,2],[3,4]] |
---|
28 | ; 15 22 |
---|
29 | ; alors que |
---|
30 | ; IDL> print, extrait(a,[0,2],[3,4]) |
---|
31 | ; 15 17 |
---|
32 | ; 20 22 |
---|
33 | ; |
---|
34 | ; CATEGORY:bidouille avec les matrices |
---|
35 | ; |
---|
36 | ; CALLING SEQUENCE:res=extrait(tab,indicex[,indicey[,indicez,[indicet]]]) |
---|
37 | ; |
---|
38 | ; INPUTS: |
---|
39 | ; tab: un tableau 1,2,3 ou 4 d |
---|
40 | ; |
---|
41 | ; indicex: indicex peut avoir deux formes: |
---|
42 | ; 1)un vecteur contenant les indices des lignes a garder |
---|
43 | ; 2)le string '*' dans ce cas touts les lignes sont |
---|
44 | ; gardees |
---|
45 | ; |
---|
46 | ; indicey/z/t: la meme chose que indicex mais pour les |
---|
47 | ; dimensions 2,3 et 4. |
---|
48 | ; |
---|
49 | ; rq: il faut autant de vecteurs indice que tab a de dimensions |
---|
50 | ; |
---|
51 | ; KEYWORD PARAMETERS: |
---|
52 | ; |
---|
53 | ; OUTPUTS: |
---|
54 | ; res: une matice 1,2,3 ou 4d extraite a partir de tab |
---|
55 | ; |
---|
56 | ; COMMON BLOCKS: |
---|
57 | ; |
---|
58 | ; SIDE EFFECTS:res=-1 en cas d''erreur |
---|
59 | ; |
---|
60 | ; RESTRICTIONS: |
---|
61 | ; |
---|
62 | ; EXAMPLE: |
---|
63 | ; j''ai une matrice A de dim 2. je veux en extraire une petite matrice |
---|
64 | ; 2d interscetion de la ligne 2,3 et 7 et de la colonne 0 et 1 |
---|
65 | ; |
---|
66 | ; res=extrait(A,[2,3,7],[0,1]) |
---|
67 | ; |
---|
68 | ;autre ex: |
---|
69 | ; IDL> print, a |
---|
70 | ; a b c |
---|
71 | ; d e f |
---|
72 | ; g h i |
---|
73 | ; IDL> print, extrait(a,[0,2],[0,2]) |
---|
74 | ; a c |
---|
75 | ; g i |
---|
76 | ; |
---|
77 | ; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
78 | ; 12/1/1999 |
---|
79 | ; 29/4/1999: correction d''un bug et complement |
---|
80 | ; de l''en-tete |
---|
81 | ;- |
---|
82 | ;------------------------------------------------------------ |
---|
83 | ;------------------------------------------------------------ |
---|
84 | ;------------------------------------------------------------ |
---|
85 | FUNCTION extrait, tab, indicex, indicey, indicez, indicet |
---|
86 | ;------------------------------------------------------------ |
---|
87 | taille = size(tab) |
---|
88 | ;------------------------------------------------------------ |
---|
89 | ; test du nombre de parametres |
---|
90 | ; et de la nature de indice (pour LE cas 'x') |
---|
91 | ;------------------------------------------------------------ |
---|
92 | if n_params() NE taille[0]+1 THEN $ |
---|
93 | return, report('il faut autant d''indices que de dimension du tableau') |
---|
94 | IF n_params() GE 5 THEN BEGIN |
---|
95 | if size(indicet,/type) EQ 7 then indicet = lindgen(taille[4]) $ |
---|
96 | ELSE indicet = long(indicet) |
---|
97 | nt = n_elements(indicet) |
---|
98 | ENDIF |
---|
99 | IF n_params() GE 4 THEN BEGIN |
---|
100 | if size(indicez,/type) EQ 7 then indicez = lindgen(taille[3]) $ |
---|
101 | ELSE indicez = long(indicez) |
---|
102 | nz = n_elements(indicez) |
---|
103 | ENDIF |
---|
104 | IF n_params() GE 3 THEN BEGIN |
---|
105 | if size(indicey,/type) EQ 7 then indicey = lindgen(taille[2]) $ |
---|
106 | ELSE indicey = long(indicey) |
---|
107 | ny = n_elements(indicey) |
---|
108 | ENDIF |
---|
109 | IF n_params() GE 2 THEN BEGIN |
---|
110 | if size(indicex,/type) EQ 7 then indicex = lindgen(taille[1]) $ |
---|
111 | ELSE indicex = long(indicex) |
---|
112 | nx = n_elements(indicex) |
---|
113 | ENDIF |
---|
114 | |
---|
115 | ;------------------------------------------------------------ |
---|
116 | ; construction du tableau d''indice et du resultat suivant la taille |
---|
117 | ; de tab |
---|
118 | ;------------------------------------------------------------ |
---|
119 | case taille[0] of |
---|
120 | 1:res = tab[indicex] |
---|
121 | 2:BEGIN |
---|
122 | indice = indicex#replicate(1, ny)+taille[1]*replicate(1, nx)#indicey |
---|
123 | res = tab[indice] |
---|
124 | END |
---|
125 | 3:BEGIN |
---|
126 | indice = indicex#replicate(1, ny)+taille[1]*replicate(1, nx)#indicey |
---|
127 | indice = temporary(indice[*])#replicate(1, nz) $ |
---|
128 | +taille[1]*taille[2]*replicate(1, nx*ny)#indicez |
---|
129 | res = tab[reform(indice, nx, ny, nz, /over)] |
---|
130 | END |
---|
131 | 4:BEGIN |
---|
132 | indice = indicex#replicate(1, ny)+taille[1]*replicate(1, nx)#indicey |
---|
133 | indice = temporary(indice[*])#replicate(1, nz) $ |
---|
134 | +taille[1]*taille[2]*replicate(1, nx*ny)#indicez |
---|
135 | indice = temporary(indice[*])#replicate(1, nt) $ |
---|
136 | +taille[1]*taille[2]*taille[3]*replicate(1, nx*ny*nz)#indicet |
---|
137 | res = tab[reform(indice, nx, ny, nz, nz, /over)] |
---|
138 | END |
---|
139 | endcase |
---|
140 | |
---|
141 | |
---|
142 | ;------------------------------------------------------------ |
---|
143 | ;------------------------------------------------------------ |
---|
144 | return, res |
---|
145 | end |
---|