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

Last change on this file since 238 was 238, 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
73; Sebastien Masson (smasson\@lodyc.jussieu.fr)
74;                       12/1/1999
75;                       29/4/1999: correction of a bug and complement of the heading
76;
77; @version
78; $Id$
79;
80;-
81;
82FUNCTION extrac2, array, index1, index2, index3, index4
83;
84  compile_opt idl2, strictarrsubs
85;
86   taille = size(array)
87;------------------------------------------------------------
88; test of the number of parameters
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')
93   IF n_params() GE 5 THEN BEGIN
94      if size(index4,/type) EQ 7 then index4 = lindgen(taille[4]) $
95      ELSE index4 = long(index4)
96      nt = n_elements(index4)
97   ENDIF
98   IF n_params() GE 4 THEN BEGIN
99      if size(index3,/type) EQ 7 then index3 = lindgen(taille[3]) $
100      ELSE index3 = long(index3)
101      nz = n_elements(index3)
102   ENDIF
103   IF n_params() GE 3 THEN BEGIN
104      if size(index2,/type) EQ 7 then index2 = lindgen(taille[2]) $
105      ELSE index2 = long(index2)
106      ny = n_elements(index2)
107   ENDIF
108   IF n_params() GE 2 THEN BEGIN
109      if size(index1,/type) EQ 7 then index1 = lindgen(taille[1]) $
110      ELSE index1 = long(index1)
111      nx = n_elements(index1)
112   ENDIF
113
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]
122      END
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)]
128      END
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      END
137   endcase
138
139
140;------------------------------------------------------------
141;------------------------------------------------------------
142   return, res
143end
Note: See TracBrowser for help on using the repository browser.