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

Last change on this file since 231 was 231, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

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