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

Last change on this file since 375 was 371, checked in by pinsard, 16 years ago

improvements of headers (alignments of IDL prompt in examples)

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