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

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

improvements/corrections of some *.pro headers

  • 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;-
77;
78FUNCTION colle, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, SAUVE = sauve
79;
80  compile_opt idl2, strictarrsubs
81;
82   res = -1
83;------------------------------------------------------------
84; We put in place ptrtab and direc in function of input arguments
85;------------------------------------------------------------
86   case 1 of
87      n_params() EQ 2:BEGIN     ; case where we directly give the pointer array
88         ptrtab = a0
89         direc = a1
90         if NOT keyword_set(sauve) then undefine, a0
91; on recuperate the number of array to be pasted.
92         nbretab = (size(ptrtab))[1]
93      end
94      n_params() GT 2:BEGIN
95; on recuperate the number of array to be pasted.
96         nbretab = n_params()-1
97         bidon = execute('direc = a'+strtrim(n_params()-1, 2))
98; We write the pointer array whose each element point on an array.
99         ptrtab=ptrarr(nbretab,/allocate_heap)
100         for n = 0,nbretab-1 do begin
101            bidon = execute('*ptrtab[n]=a'+strtrim(n, 2))
102            if NOT keyword_set(sauve) then bidon = execute('undefine, a'+strtrim(n, 2))
103         endfor
104         sauve = 0
105      end
106      ELSE:
107   endcase
108;------------------------------------------------------------
109; case on the direct's value.
110;------------------------------------------------------------
111   case direc of
112      1:BEGIN                   ; we paste following the dimension 1
113         res = *ptrtab[0]
114         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
115         FOR n = 1,nbretab-1 DO BEGIN
116            res = [temporary(res), *ptrtab[n]]
117            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
118         ENDFOR
119      END
120      2:BEGIN                   ; we paste following the dimension 2
121         res = *ptrtab[0]
122         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
123         FOR n = 1,nbretab-1 DO BEGIN
124            res = [[temporary(res)], [*ptrtab[n]]]
125            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
126         ENDFOR
127      END
128      3:BEGIN                   ; we paste following the dimension 3
129         res = *ptrtab[0]
130         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
131         FOR n = 1,nbretab-1 DO BEGIN
132            res = [[[temporary(res)]], [[*ptrtab[n]]]]
133            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
134         ENDFOR
135      END
136      ELSE:BEGIN
137; We transpose res in order to put the dimension to be pasted number 1
138; To this, we contain the permuter vector which give the place that dimension
139; in the transposed matrix must take.
140        siz = (size(*ptrtab[0]))[0]
141         if siz LT direc then $
142          *ptrtab[0] = reform(*ptrtab[0], [(size(*ptrtab[0]))[1:siz], replicate(1, direc-siz)], /over)
143         permute = indgen((size(*ptrtab[0]))[0])
144         permute[0] = direc-1
145         permute[direc-1] = 0
146         res = transpose(*ptrtab[0], permute)
147         if NOT keyword_set(sauve) then ptr_free, ptrtab[0]
148         FOR n = 1,nbretab-1 DO BEGIN ; we paste following the dimension 1on colle suivant la dimension 1
149            if (size(*ptrtab[n]))[0] LT direc then $
150             *ptrtab[n] = reform(*ptrtab[n], [(size(*ptrtab[n]))[1:siz], replicate(1, direc-siz)])
151            res = [temporary(res), transpose(*ptrtab[n], permute)]
152            if NOT keyword_set(sauve) then ptr_free, ptrtab[n]
153         ENDFOR
154         res = transpose(temporary(res), permute)
155      END
156   ENDCASE
157;------------------------------------------------------------
158   if NOT keyword_set(sauve) then undefine, ptrtab
159sortie:
160   return,  res
161END
Note: See TracBrowser for help on using the repository browser.