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

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

improvements/corrections of some *.pro headers

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