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

Last change on this file since 232 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
RevLine 
[133]1;+
2;
[136]3; @file_comments
[163]4; extraction of subdomains of matrices;
[136]5; Even if the subdomain is "pierced" (see the example)
[133]6; By default, IDL can make extractions of subdomain:
7;
[136]8;      IDL> a=indgen(5,5)
9;      IDL> print, a
[133]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
[136]15;      IDL> print, a[[0,2],3]
[133]16;            15      17
[136]17;      IDL> print, a[[0,2],*]
[133]18;             0       2
19;             5       7
20;            10      12
21;            15      17
22;            20      22
23; but
[136]24;      IDL> print, a[[0,2],[3,4]]
[133]25;            15      22
26; while
[136]27;      IDL> print, extrac2(a,[0,2],[3,4])
[133]28;            15      17
29;            20      22
30;
[157]31; @categories
32; Utilities
[133]33;
[136]34; @param array {in}{required}
35; a 1,2,3 or 4 dim input array
[133]36;
[136]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.
[133]41;
[136]42; @param index2 {in}{required}
43; the same thing that index1 but for dim 2.
[133]44;
[136]45; @param index3 {in}{required}
46; the same thing that index1 but for dim 3.
[133]47;
[136]48; @param index4 {in}{required}
49; the same thing that index1 but for dim 4.
[133]50;
[136]51; @returns
52; a matrix 1,2,3 or 4d extract from input array
[230]53; -1 in case of mistake
[133]54;
[136]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:
[133]60;
[136]61; IDL> res=extrac2(A,[2,3,7],[0,1])
[133]62;
[136]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
[133]71;
[136]72; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
[133]73;                       12/1/1999
74;                       29/4/1999: correction of a bug and complement of the heading
75;
76; @version $Id$
77;
78;-
[231]79;
[133]80FUNCTION extrac2, array, index1, index2, index3, index4
81;
82  compile_opt idl2, strictarrsubs
83;
84   taille = size(array)
85;------------------------------------------------------------
[231]86; test of the number of parameters
[133]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')
[136]91   IF n_params() GE 5 THEN BEGIN
[133]92      if size(index4,/type) EQ 7 then index4 = lindgen(taille[4]) $
93      ELSE index4 = long(index4)
[136]94      nt = n_elements(index4)
95   ENDIF
96   IF n_params() GE 4 THEN BEGIN
[133]97      if size(index3,/type) EQ 7 then index3 = lindgen(taille[3]) $
98      ELSE index3 = long(index3)
[136]99      nz = n_elements(index3)
100   ENDIF
101   IF n_params() GE 3 THEN BEGIN
[133]102      if size(index2,/type) EQ 7 then index2 = lindgen(taille[2]) $
103      ELSE index2 = long(index2)
[136]104      ny = n_elements(index2)
[133]105   ENDIF
[136]106   IF n_params() GE 2 THEN BEGIN
[133]107      if size(index1,/type) EQ 7 then index1 = lindgen(taille[1]) $
108      ELSE index1 = long(index1)
[136]109      nx = n_elements(index1)
[133]110   ENDIF
[136]111
[133]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]
[136]120      END
[133]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)]
[136]126      END
[133]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)]
[136]134      END
[133]135   endcase
136
137
138;------------------------------------------------------------
139;------------------------------------------------------------
140   return, res
141end
Note: See TracBrowser for help on using the repository browser.