source: trunk/SRC/Matrix/extrac2.pro @ 134

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

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