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

Last change on this file since 136 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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