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

Last change on this file since 378 was 373, checked in by pinsard, 16 years ago

improvements of headers (examples and results)

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