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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • 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;-
81FUNCTION extrac2, array, index1, index2, index3, index4
82;
83  compile_opt idl2, strictarrsubs
84;
85   taille = size(array)
86;------------------------------------------------------------
87; test of the number of parameters
88; and of the nature of the index (for THE case 'x')
89;------------------------------------------------------------
90   if n_params() NE taille[0]+1 THEN $
91    return, report('we need as many indexes as the number of dimensions of the input array')
92   IF n_params() GE 5 THEN BEGIN
93      if size(index4,/type) EQ 7 then index4 = lindgen(taille[4]) $
94      ELSE index4 = long(index4)
95      nt = n_elements(index4)
96   ENDIF
97   IF n_params() GE 4 THEN BEGIN
98      if size(index3,/type) EQ 7 then index3 = lindgen(taille[3]) $
99      ELSE index3 = long(index3)
100      nz = n_elements(index3)
101   ENDIF
102   IF n_params() GE 3 THEN BEGIN
103      if size(index2,/type) EQ 7 then index2 = lindgen(taille[2]) $
104      ELSE index2 = long(index2)
105      ny = n_elements(index2)
106   ENDIF
107   IF n_params() GE 2 THEN BEGIN
108      if size(index1,/type) EQ 7 then index1 = lindgen(taille[1]) $
109      ELSE index1 = long(index1)
110      nx = n_elements(index1)
111   ENDIF
112
113;------------------------------------------------------------
114; construction of an array of indexes and of results following the size of array
115;------------------------------------------------------------
116  case taille[0] of
117      1:res = array[index1]
118      2:BEGIN
119         index = index1#replicate(1, ny)+taille[1]*replicate(1, nx)#index2
120         res = array[index]
121      END
122      3:BEGIN
123         index = index1#replicate(1, ny)+taille[1]*replicate(1, nx)#index2
124         index = temporary(index[*])#replicate(1, nz) $
125          +taille[1]*taille[2]*replicate(1, nx*ny)#index3
126         res = array[reform(index, nx, ny, nz, /over)]
127      END
128      4:BEGIN
129         index = index1#replicate(1, ny)+taille[1]*replicate(1, nx)#index2
130         index = temporary(index[*])#replicate(1, nz) $
131          +taille[1]*taille[2]*replicate(1, nx*ny)#index3
132         index = temporary(index[*])#replicate(1, nt) $
133          +taille[1]*taille[2]*taille[3]*replicate(1, nx*ny*nz)#index4
134         res = array[reform(index, nx, ny, nz, nz, /over)]
135      END
136   endcase
137
138
139;------------------------------------------------------------
140;------------------------------------------------------------
141   return, res
142end
Note: See TracBrowser for help on using the repository browser.