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

Last change on this file since 231 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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