MIDAPACK - MIcrowave Data Analysis PACKage  1.1b
Parallel software tools for high performance CMB DA analysis
 All Data Structures Files Functions Variables Typedefs Groups Pages
toeplitz_rshp.c
Go to the documentation of this file.
1 
57 #include "toeplitz.h"
58 
59 //r1.1 - Frederic Dauvergne (APC)
60 //This is the reshaping routines to build the optimal data structure when needed.
61 //The index functions find the right index number of the data location for a choosen
62 //transformation.
63 
64 
65 int fctid_mat2vect(int i, int id0, int n, int lambda)
66 {
67  int I,J, i_out;
68  int distcorrmin= lambda-1;
69  int rfirst=id0%n;
70 
71  if (i==-1)
72  return (-1);
73 
74 
75  I = (i+rfirst)%(n+distcorrmin);
76  J = (i+rfirst)/(n+distcorrmin);
77 
78  if (I<n)
79  i_out = I-rfirst+J*n;
80  else
81  i_out = -1; //not defined. value is zero.
82 
83 
84  return i_out;
85 }
86 
87 
88 int fctid_mat2vect_inv(int i, int id0, int n, int lambda)
89 {
90  int I,J, i_out;
91  int distcorrmin= lambda-1;
92  int rfirst=id0%n;
93 
94  if (i==-1)
95  i_out = -1; //not defined. value is zero.
96 
97  I = (i+rfirst)%(n);
98  J = (i+rfirst)/(n);
99 
100  i_out = I-rfirst+J*(n+distcorrmin);
101 
102  return i_out;
103 }
104 
105 
106 int fctid_concatcol(int i, int id0, int n, int m, int l, int lconc, int lambda, int *nocol, int nbcol)
107 {
108  int I,J, i_out;
109  int distcorrmin= lambda-1;
110  int rfirst=id0%n;
111 
112  if (i==-1)
113  return (-1);
114 
115  if (i>=lconc)
116  return (-2);//this indice not define. It shouldn't be used
117 
118  I = (i+rfirst)%(n);
119  J = (i+rfirst)/(n);
120 
121  i_out = I-rfirst+nocol[J]*(n);
122 
123 
124  return i_out;
125 }
126 
127 
128 int fctid_concatcol_inv(int i, int id0, int n, int m, int l, int lconc, int lambda, int *nocol_inv, int nbcol)
129 {
130  int I,J, i_out;
131  int distcorrmin= lambda-1;
132  int rfirst=id0%n;
133 
134  if (i==-1)
135  return (-1);
136 
137  if (i>=l)
138  return (-2);//this indice not define. It shouldn't be used
139 
140  I = (i+rfirst)%(n);
141  J = (i+rfirst)/(n);
142 
143  if (nocol_inv[J]==(-1))
144  i_out = -1;
145  else
146  i_out = I-rfirst+nocol_inv[J]*(n);
147 
148 
149  return i_out;
150 }
151 
152 
153 
154 int fctid_vect2nfftblock(int i, int v1_size, int fft_size, int nfft, int lambda)
155 {
156 
157  int I,J, i_out;
158  int distcorrmin= lambda-1;
159 
160  if (i==-1)
161  return (-1);
162 
163  I = (i)%(fft_size);
164  J = (i)/(fft_size);
165 
166  i_out = (I-distcorrmin) + J*(fft_size-2*distcorrmin) ;
167 
168  if (i_out<0 || i_out>=v1_size)
169  i_out = -1;
170 
171 
172  return i_out;
173 }
174 
175 
176 int is_needconcat(int *nocol, int nbcol)
177 {
178  int i;
179  int ip=nocol[0];
180  for(i=1;i<nbcol;i++) {
181  if (nocol[i]!=(ip+i))
182  return 1;
183  }
184 
185 
186  return 0;
187 }
188 
189 
190 int fctid_vect2nfftblock_inv(int i, int v1_size, int fft_size, int nfft, int lambda)
191 {
192 
193  int I,J, i_out;
194  int distcorrmin= lambda-1;
195 
196  if (i<0 || i>=v1_size)
197  return (-2);
198 
199  I = (i)%(fft_size-2*distcorrmin);
200  J = (i)/(fft_size-2*distcorrmin);
201 
202  i_out = (I+distcorrmin) + J*(fft_size) ;
203 
204  return i_out;
205 }
206 
207 
208 int define_rshp_size(int flag_format_rshp, int fft_size, int nfft, int v1_size, int vedge_size, int *nrshp, int *mrshp, int *lrshp)
209 {
210 
211  if (flag_format_rshp==2) {
212  *nrshp=fft_size;
213  *mrshp=nfft;
214  *lrshp=(*nrshp)*(*mrshp);
215  }
216  else if (flag_format_rshp==1) {
217  *nrshp=v1_size;
218  *mrshp=1;
219  *lrshp=(*nrshp)*(*mrshp);
220  }
221  else if (flag_format_rshp==0) { //this case appear only if flag_shortcut_nbcol_eq_1==0
222  *nrshp=vedge_size;
223  *mrshp=1;
224  *lrshp=vedge_size;
225  }
226  else {//error not a good flag_format_rshp
227  }
228 
229  return 0;
230 }
231 
232 
233 int build_nocol_inv(int *nocol, int nbcol, int m) //ncol_inv to define as parameters
234 {
235  int i;
236  int *nocol_inv;
237  nocol_inv = (int *) calloc(m, sizeof(double));
238 
239  for(i=0;i<m;i++)
240  nocol_inv[i]=-1;
241  for(i=0;i<nbcol;i++)
242  nocol_inv[nocol[i]]=i;
243 
244 
245  return 0;
246 }
247 
248 
249 int build_reshape(double *Vin, int *nocol, int nbcol, int lconc, int n, int m, int id0, int l, int lambda, int nfft, double *Vrshp, int nrshp, int mrshp, int lrshp, int flag_format_rshp)
250 {
251 
252  int i;
253  int rfirst=id0%n;
254  int i_out1, i_out2, i_out3;
255  int distcorrmin=lambda-1;
256 
257  int v1_size;
258  int fft_size;
259 
260  int idf = id0+l-1;
261  int lconc0;
262 
263  FILE *file;
264  file = stdout;
265 
266  v1_size=lconc+(distcorrmin)*(nbcol-1);
267  fft_size = ceil(1.0*v1_size/nfft)+2*distcorrmin;
268 
269  //used transformation
270 if (VERBOSE) {
271  fprintf(file, "fctid_concatcol: \t %d\n", (is_needconcat(nocol, nbcol)==1));
272  fprintf(file, "fctid_mat2vect: \t %d\n", (nbcol>1));
273  fprintf(file, "fctid_vect2nfftblock \t %d\n", (nfft>1));
274 }
275 
276 
277  for(i=0;i<lrshp;i++) {
278 
279  if (nfft>1)
280  i_out1 = fctid_vect2nfftblock( i, v1_size, fft_size, nfft, lambda);
281  else
282  i_out1 = i;
283 
284  if (nbcol>1)
285  i_out2 = fctid_mat2vect(i_out1 , rfirst, n, lambda);
286  else
287  i_out2 = i_out1;
288 
289  if (is_needconcat(nocol, nbcol)==1)
290  i_out3 = fctid_concatcol(i_out2, id0, n, m, l, lconc, lambda, nocol, nbcol);
291  else
292  i_out3 = i_out2;
293 
294 
295  if (i_out3==-1)
296  Vrshp[i]=0;
297  else
298  Vrshp[i]=Vin[i_out3];
299 
300  }//end for
301 
302 
303  return 0;
304 }
305 
306 
307 int extract_result(double *Vout, int *nocol, int nbcol, int lconc, int n, int m, int id0, int l, int lambda, int nfft, double *Vrshp, int nrshp, int mrshp, int lrshp, int flag_format_rshp)
308 {
309 
310  int i;
311  int rfirst=id0%n;
312  int i_out1, i_out2, i_out3;
313  int i_in1;
314  int distcorrmin=lambda-1;
315 
316  int v1_size;
317  int fft_size;
318 
319  FILE *file;
320  file = stdout;
321 
322  v1_size=lconc+(distcorrmin)*(nbcol-1);
323  fft_size = ceil(1.0*v1_size/nfft)+2*distcorrmin;
324 
325  //used transformation
326 if (VERBOSE) {
327  fprintf(file, "fctid_concatcol: \t %d\n", (is_needconcat(nocol, nbcol)==1));
328  fprintf(file, "fctid_mat2vect: \t %d\n", (nbcol>1));
329  fprintf(file, "fctid_vect2nfftblock \t %d\n", (nfft>1));
330 }
331 
332  int lcol;
333  int j,k;
334 
335  for(i=0;i<lconc;i++) {
336 
337  if (is_needconcat(nocol, nbcol)==1)
338  i_in1=fctid_concatcol(i, id0, n, m, l, lconc, lambda, nocol, nbcol);
339  else
340  i_in1 = i;
341 
342  if (nbcol>1)
343  i_out2 = fctid_mat2vect_inv(i , rfirst, n, lambda);
344  else
345  i_out2 = i_out1;
346 
347  if (nfft>1)
348  i_out3 = fctid_vect2nfftblock_inv(i_out2, v1_size, fft_size, nfft, lambda);
349  else
350  i_out3 = i_out2;
351 
352  if (i_out3==-1)
353  Vout[i]=-1;
354  else if (i_out3==-2)
355  Vout[i]=-2;
356  else
357  Vout[i_in1] = Vrshp[i_out3];
358  }
359 
360 
361  return 0;
362 }
363