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_gappy_seq.dev.c
Go to the documentation of this file.
1 
2 
3 //=========================================================================
4 //Alternave version of the sequential routine for the gaps - in dev
5 //Need to change the name to gap_reduce_matrix for more explicit purpose
6 //fd@apc
7 int gstmm(double **V, int n, int m, int id0, int l, fftw_complex *T_fft, int lambda, fftw_complex *V_fft, double *V_rfft, fftw_plan plan_f, fftw_plan plan_b, int blocksize, int nfft, int *id0gap, int *lgap, int ngap)
8 {
9 
10  //routine variable
11  int i,j,k,p; //loop index
12  int idf = id0+l-1;
13  int cfirst = id0/n; //first column index
14  int clast = idf/n; //last column index
15  int clast_1 = (idf+1)/n;
16  int m_eff = clast - cfirst + 1 ; //number of columns
17  int rfirst = id0%n;
18  int rlast = idf%n;
19 
20  if (l<lambda) // test to avoid communications errors
21  return print_error_message (1, __FILE__, __LINE__);
22 
23  int nnew=0;
24  int lcolnew=0;
25  int lcol;
26  double *Vcol;
27  int icol, igap;
28 ;
29  int id0col;
30  int id0out=0;
31  int lnew;
32 
33  int nfullcol;
34  nfullcol = (l-(n-id0%n)-(id0+l)%n)/n; //check how many full columns input data have
35 
36  int ifirstgap, ilastgap;
37 
38 if (id0%n != 0) {
39 //first column if not full
40  id0out=0;
41  id0col=id0%n;
42  Vcol = (*V)+id0col;
43  lcol= n-id0col;
44 
45  //find the first and last gap on the column
46  for(k=0;k<ngap;k++) {
47  if(lgap[k] != 0 && id0col < id0gap[k]+lgap[k]) break;
48  }
49  ifirstgap = k;
50 
51  for(k=ngap-1;k>=0;k--) {
52  if(lgap[k] != 0 && id0gap[k] <= id0col) break;
53  }
54  ilastgap = k;
55 
56 
57  for (i=0 ; i<ngap; i++)
58  printf("id0gap[%d]=%d\n", i, id0gap[i]);
59  for (i=0 ; i<ngap; i++)
60  printf("lgap[%d]=%d\n", i, lgap[i]);
61 
62  printf("---\n");
63 
64  printf("lcol=%d\n", lcol);
65  for (i=0 ; i<lcol; i++)
66  printf("Vcol[%d]=%f\n", i, Vcol[i]);
67 
68 //reduce the gap to lambda zeros on the column
69  gap_reduce(&Vcol, id0col, lcol, lambda, id0gap, lgap, ngap, &lcolnew, id0out);
70 
71  id0out += lcolnew;
72 
73  printf("---\n");
74 
75  for (i=0 ; i<lcol; i++)
76  printf("Vcolout[%d]=%f\n", i, Vcol[i]);
77  printf("===\n");
78 
79  printf("---\n");
80 
81  for (i=0 ; i<l; i++)
82  printf("(*V)[%d]=%f\n", i, (*V)[i]);
83 
84 }
85 
86 //generic loop on the full column
87  for (icol=0 ; icol<nfullcol; icol++) {
88 
89  id0out= lcolnew;
90  id0col=0;
91  Vcol = (*V)+id0col;
92  lcol= n-id0col;
93 
94  gap_reduce(&Vcol, id0col, lcol, lambda, id0gap, lgap, ngap, &lcolnew, id0out);
95 
96  id0out += lcolnew;
97 
98  if (icol==0) //take the nnew directly if they is a full column
99  nnew=lcolnew;
100 
101  }
102 
103 
104 //last column if not full and more than one column
105  if (idf%n != n && m > 1) {
106 
107  id0out=0;
108  id0col=0;
109  Vcol = (*V)+id0col;
110  lcol= idf%n;
111 
112  //find the first and last gap on the column
113  ifirstgap = 0; //we already know it, no need to compute
114 
115  for(k=ngap-1;k>=0;k--) {
116  if(lgap[k] != 0 && id0gap[k] <= id0col) break;
117  }
118  ilastgap = k;
119 
120 //reduce the gap to lambda zeros on the column
121  gap_reduce(&Vcol, id0col, lcol, lambda, id0gap, lgap, ngap, &lcolnew, id0out);
122 
123  }
124 
125 
126 //cleaning the extra terms
127  if (nnew==0) { //compute the nnew if there is no full column
128  for (igap=0 ; igap<ngap; igap++)
129  nnew += id0gap[igap] - min(id0gap[igap], lambda);
130  }
131 
132  for (i=nnew*m ; i<n*m; i++)
133  (*V)[i] = 0;
134 
135  printf("===\n");
136  for (i=0 ; i<l; i++)
137  printf("(*V)[%d]=%f\n", i, (*V)[i]);
138 
139 
140 //now do the product
141 // int id0new = ..;
142 
143 // stmm( V, nnew, m, id0new, lnew, T_fft, lambda, V_fft, V_rfft, plan_f, plan_b, blocksize, nfft)
144 
145 
146 //gap extend - same thing as above and reverse gap_reduce routine
147 // gap_extend()
148 
149 //maybe create gap_blockreduce to clarify this routine.
150 
151  return 0;
152 }
153 
154 //=========================================================================
155 
157 
163 int gap_reduce(double **V, int id0, int l, int lambda, int *id0gap, int *lgap, int ngap, int *newl, int id0out)
164 {
165  //routine variables
166  int i,k, ii;
167  int lg;
168  int newid0gap_ip1;
169  int newlgap_ip1;
170 
171 
172  double *Vout;
173  Vout =(*V)-(id0-id0out);
174 
175 
176  if (id0gap[0]>id0) {
177  lg = id0gap[0]-id0;
178  printf("lg=%d\n", lg);
179  memmove(&(Vout)[0], &(*V)[0], lg*sizeof(double));
180  //to do if the first element isn't a gap
181  }
182 
183  int offset_first=id0gap[0]-id0+min(lambda,lgap[0]);
184  offset_first=max(0, offset_first);
185 
186 
187 // for (k=0; k<offset_first; k++)
188 // (Vout)[k] = 0;
189 
190  printf("offset_first=%d\n", offset_first);
191 
192  for (i=0 ; i<l; i++)
193  printf("(Vout)[%d]=%f\n", i, (Vout)[i]);
194  printf("---\n");
195 
196  printf("l=%d\n", l);
197 
198 
199  for (i=0 ; i<(ngap-1); i++) {
200  lg = id0gap[i+1]-id0-(id0gap[i]-id0+lgap[i]);
201  printf("lg=%d\n", lg);
202  memmove(&(Vout)[offset_first], &(*V)[id0gap[i]-id0+lgap[i]], lg*sizeof(double));
203 
204  for (ii=0 ; ii<l; ii++)
205  printf("(Vout)[%d]=%f\n", ii, (Vout)[ii]);
206 
207  newid0gap_ip1=offset_first+lg;
208  newlgap_ip1=min(lambda,lgap[i+1]);
209  for (k=newid0gap_ip1; k<newid0gap_ip1+newlgap_ip1; k++)
210  (Vout)[k] = 0;
211 
212  printf("lg=%d ; lambda=%d ; lgap[i+1]=%d\n", lg, lambda, lgap[i+1]);
213  offset_first += lg+min(lambda,lgap[i+1]);
214  } //end gaps loop
215 
216  printf("---\n");
217  printf("offset_first=%d\n", offset_first);
218  for (i=0 ; i<l; i++)
219  printf("(Vout)[%d]=%f\n", i, (Vout)[i]);
220 
221  i=(ngap-1);
222 
223  if (id0gap[i]-id0+lgap[i]<l) {
224  printf("toc\n");
225  lg = l-(id0gap[i]-id0+lgap[i]);
226  memmove(&(Vout)[offset_first], &(*V)[id0gap[i]-id0+lgap[i]], lg*sizeof(double));
227  offset_first += lg;
228  *newl = offset_first;
229  }
230  else {
231  *newl = offset_first-min(lambda,lgap[ngap-1])+min( lambda, (id0+l-id0gap[ngap-1]) );
232  }
233 
234  printf("---\n");
235  printf("l=%d, *newl=%d, offset_first=%d\n", l, *newl, offset_first);
236 
237  for (i=offset_first ; i<l; i++)
238  (Vout)[i] = 0;
239 
240  printf("*newl=%d\n", *newl);
241 
242 
243  return 0;
244 }
245 //=========================================================================
246 
248 
255 int gap_masking(double **V, int l, int *id0gap, int *lgap, int ngap)
256 {
257 
258  int i,k;
259  int lg;
260 
261  int offset_first=id0gap[0];
262  for (i=0 ; i<(ngap-1); i++) {
263  lg = id0gap[i+1]-(id0gap[i]+lgap[i]);
264  memmove(&(*V)[offset_first], &(*V)[id0gap[i]+lgap[i]], lg*sizeof(double));
265  offset_first += lg;
266  }
267 
268  i=(ngap-1);
269  lg = l-(id0gap[i]+lgap[i]);
270 
271  memmove(&(*V)[offset_first], &(*V)[id0gap[i]+lgap[i]], lg*sizeof(double));
272  offset_first += lg;
273 
274 
275  for (i=offset_first ; i<l; i++)
276  (*V)[i] = 0;
277 
278 
279  return 0;
280 }
281 
282 
283 //=========================================================================
284 
286 
293 int gap_filling(double **V, int l, int *id0gap, int *lgap, int ngap)
294 {
295 
296  int i,k;
297  int lg;
298 
299  int lgaptot = 0;
300  for (i=0 ; i<ngap; i++)
301  lgaptot += lgap[i];
302 
303  int id0_Vmv;
304  int offset_last;
305 
306  id0_Vmv = id0gap[ngap-1]+lgap[ngap-1];
307  offset_last = id0_Vmv - lgaptot;
308  lg = l-id0_Vmv;
309 
310  if (lg>0)
311  memmove(&(*V)[id0_Vmv], &(*V)[offset_last], lg*sizeof(double));
312 
313  for (i=ngap-2 ; i>=0; i--) {
314  id0_Vmv = id0gap[i]+lgap[i];
315  lg = id0gap[i+1]-id0_Vmv;
316  offset_last -= lg;
317 
318  memmove(&(*V)[id0_Vmv], &(*V)[offset_last], lg*sizeof(double));
319  }
320 
321  for (i=0 ; i<ngap; i++)
322  for (k=0 ; k<lgap[i]; k++)
323  (*V)[id0gap[i]+k] = 0;
324 
325  return 0;
326 }
327 
328 
329 //a naive version - in dev
330 int gap_masking_naive(double **V, int id0,int local_V_size, int m, int nrow, int *id0gap, int *lgap, int ngap)
331 {
332  int i,j,k;
333  int icol;
334 
335  int offsetV=id0;
336  k=0;
337 
338  for (i=0 ; i<local_V_size; i++) {
339  icol=(i+id0)%nrow;
340 
341  if ( icol<id0gap[k] ) {
342  (*V)[offsetV]=(*V)[i];
343  offsetV=offsetV+1;
344  }
345  else if (icol>=id0gap[k]+lgap[k]) {
346  k=k+1;
347  i=i-1;
348 // (*V)[offsetV]=(*V)[i];
349 // offsetV=offsetV+1;
350  }
351  else {//do not copy, just skip
352  }
353 
354 
355  return 0;
356 }
357 
358