source: trunk/SRC/ToBeReviewed/MATRICE/colle.pro @ 327

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

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1;+
2; @file_comments
3; This concatenation function exist in IDL so long
4; as we do not try to stick with a dimension superior or equal at 4.
5;
6; @categories
7; Utilities
8;
9; @param a0 {in}{required}
10;
11; @param a1 {in}{required}
12;
13; @param a2 {in}{required}
14;
15; @param a3 {in}{required}
16;
17; @param a4 {in}{required}
18;
19; @param a5 {in}{required}
20;
21; @param a6 {in}{required}
22;
23; @param a7 {in}{required}
24;
25; @param a8 {in}{required}
26;
27; @param a9 {in}{required}
28;
29; @param a10 {in}{required}
30;
31; @param a11 {in}{required}
32;
33; @param a12 {in}{required}
34;
35; @param a13 {in}{required}
36;
37; @param a14 {in}{required}
38;
39; @param a15 {in}{required}
40;
41; @param a16 {in}{required}
42;
43; @param a17 {in}{required}
44;
45; @param a18 {in}{required}
46;
47; @param a19 {in}{required}
48;
49; @param a20 {in}{required}
50;
51; @keyword SAUVE
52; force to save the pointer array and arrays to be stuck
53;
54; @returns
55; matrice resultat
56;
57; @examples
58; IDL> print, colle(replicate(1,2,2,2),indgen(2,2,2),2)
59;                1       1
60;                1       1
61;                0       1
62;                2       3
63;
64;                1       1
65;                1       1
66;                4       5
67;                6       7
68;
69; @history
70; Sebastien Masson (smasson\@lodyc.jussieu.fr)
71;                       13/1/98
72;
73; @version
74; $Id$
75;
76;-
77FUNCTION colle, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 $
78              , a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20 $
79              , SAUVE=sauve
80;
81  compile_opt idl2, strictarrsubs
82;
83   res = -1
84;------------------------------------------------------------
85; We put in place ptrtab and direc in function of input arguments
86;------------------------------------------------------------
87   case 1 of
88      n_params() EQ 2:BEGIN     ; case where we directly give the pointer array
89         ptrtab = a0
90         direc = a1
91         if NOT keyword_set(sauve) then undefine, a0
92; on recuperate the number of array to be pasted.
93         nbretab = (size(ptrtab))[1]
94      end
95      n_params() GT 2:BEGIN
96; on recuperate the number of array to be pasted.
97         nbretab = n_params()-1
98         bidon = execute('direc = a'+strtrim(n_params()-1, 2))
99; We write the pointer array whose each element point on an array.
100         ptrtab=ptrarr(nbretab,/allocate_heap)
101         for n = 0,nbretab-1 do begin
102            bidon = execute('*ptrtab[n]=a'+strtrim(n, 2))
103            if NOT keyword_set(sauve) then bidon = execute('undefine, a'+strtrim(n, 2))
104         endfor
105         sauve = 0
106      end
107      ELSE:
108   endcase
109;------------------------------------------------------------
110; case on the direct's value.
111;------------------------------------------------------------
112   case direc of
113      1:BEGIN                   ; we paste following the dimension 1
114         res = *ptrtab[0]
115         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
116         FOR n = 1,nbretab-1 DO BEGIN
117            res = [temporary(res), *ptrtab[n]]
118            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
119         ENDFOR
120      END
121      2:BEGIN                   ; we paste following the dimension 2
122         res = *ptrtab[0]
123         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
124         FOR n = 1,nbretab-1 DO BEGIN
125            res = [[temporary(res)], [*ptrtab[n]]]
126            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
127         ENDFOR
128      END
129      3:BEGIN                   ; we paste following the dimension 3
130         res = *ptrtab[0]
131         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
132         FOR n = 1,nbretab-1 DO BEGIN
133            res = [[[temporary(res)]], [[*ptrtab[n]]]]
134            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
135         ENDFOR
136      END
137      ELSE:BEGIN
138; We transpose res in order to put the dimension to be pasted number 1
139; To this, we contain the permuter vector which give the place that dimension
140; in the transposed matrix must take.
141        siz = (size(*ptrtab[0]))[0]
142         if siz LT direc then $
143          *ptrtab[0] = reform(*ptrtab[0], [(size(*ptrtab[0]))[1:siz], replicate(1, direc-siz)], /over)
144         permute = indgen((size(*ptrtab[0]))[0])
145         permute[0] = direc-1
146         permute[direc-1] = 0
147         res = transpose(*ptrtab[0], permute)
148         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
149         FOR n = 1,nbretab-1 DO BEGIN ; we paste following the dimension 1on colle suivant la dimension 1
150            if (size(*ptrtab[n]))[0] LT direc then $
151             *ptrtab[n] = reform(*ptrtab[n], [(size(*ptrtab[n]))[1:siz], replicate(1, direc-siz)])
152            res = [temporary(res), transpose(*ptrtab[n], permute)]
153            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
154         ENDFOR
155         res = transpose(temporary(res), permute)
156      END
157   ENDCASE
158;------------------------------------------------------------
159   if NOT keyword_set(sauve) then undefine, ptrtab
160sortie:
161   return,  res
162END
Note: See TracBrowser for help on using the repository browser.