summaryrefslogtreecommitdiff
path: root/src/c/signalProcessing/ifft/diffbi_lavraie.c
blob: d71dc8c7ffc8855c34ee7068a35adf9ac8d4cd09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 *  Copyright (C) 2008-2008 - INRIA - Allan SIMON
 *
 *  This file must be used under the terms of the CeCILL.
 *  This source file is licensed as described in the file COPYING, which
 *  you should have received as part of this distribution.  The terms
 *  are also available at
 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include "max.h"
#include "ifft_internal.h"

void difftbi ( double* a , double* b , int nseg , int n    , int nspn  ,
              int isn   , int ierr  , int lout , int lnow , int lused ,
              int lmax  , int lbook , double* rstak , int* istak )
{

   int nfac[15] ;
   int i ;
   int in ;
   int j = 3 ;
   int j2 = 3 ;
   int j3 = 3 ;
   int jj = 9;
   int m = 0 ;
   int k ;
   int kt ;
   int kkk ;
   int nspan ;
   int nitems ;
   int ntot ;
   int maxp  = 0;
   int maxf ;
   int itype;
   int istkgt ;
   int isize[] = {1,1,1,2,2} ;

   int nf = abs ( n ) ;

   ierr = 0 ;
  printf ( "debut de dfftbi \n" );
   /*determine the factors of n */


   if ( nf == 1)
      return ;

   k = nf ;

   nspan = abs ( nf*nspn ) ;
   ntot  = abs ( nspan*nseg) ;

   if ( isn*ntot == 0 )
      {
      ierr = 1 ;
      return  ;
      }

printf ("un petit test  kplop %d\n" , k - (int)(k/16)*16 )  ;

   while ( (k- (int)(k/16)*16 ) == 0 )
      {
         m++;
         printf ("m %d ,k %d ,k2 %d\n" , m , k ,(int) (k/16)*16 );
         nfac[m-1] = 4 ;
         k = k >> 4 ;
      }

printf ("avant ploa k %d\n\n" , k );
   do
      {
      while ( k%jj == 0 )
         {
            m++;
            nfac[m-1] = j ;
            k /= jj ;
             printf ("\nm %d ,k %d j %f jj %d\n" , m , k ,j , jj);
         }

         j+=2;
         jj= j*j ;

      }while ( jj <= k);


printf ( "ploa\n" );


  if ( k <= 4)
     {
      kt = m;
      nfac[m+1] = k;
      if ( k != 1 )
         m++;
      }
   else
     {
       if ( (k & 7) != 0 )
         {
            m++;
            nfac[m-1] = 2 ;
            k = k >> 2 ;
          }

   /*all square factor out now but k >= 5 still */
       kt = m ;
       maxp = max ( (kt+1)*2 , k-1);
       j=2;
        printf ( "plob\n" );
      do
        {
         if ( k%j == 0 )
            {
               m++;
               nfac[m-1] = j ;
               k /= j ;
            }

          j = (j+1) | 1 ;

         }while ( j <= k );

      }

   if ( m <= ( kt+1) )
      maxp = m + kt + 1  ;

   if ( m + kt > 15)
    {
      ierr = 2 ;
      printf ( "argh return 5 \n" );
      return ;
    }
   if ( kt != 0 )
      {
         j = kt ;

         do{
            m++;
            nfac[m-1] = nfac[j-1];
            j--;
           }while ( j != 0) ;
      }

    maxf = nfac[m-kt-1] ;

   if ( kt > 0 )
      maxf = max ( nfac[kt-1] , maxf );

   for ( kkk = 1 ; kkk < m ; kkk++ )
      maxf = max ( maxf , nfac[kkk-1]);

 nitems = maxf * 4 ;
 itype = 4 ;

 istkgt = ( lnow*isize[1] -1)/isize[itype-1] + 2;

 i = ( (istkgt - 1 + nitems) * isize[itype-1] -1) / isize[1] + 3 ;
 printf ("i %d ,\n lmax %d\n istkgt %d\n lnow %d \n", i , lmax , istkgt , lnow ) ;



   if ( i > lmax )
      {
         ierr = -i ;
         printf ( "argh return 4 -i %d \n" , -i );
         return ;
      }

   istak[i-2] = itype ;
   istak[i-1] = lnow  ;
   lout ++ ;
   lnow = i ;
   lused = max ( lused , lnow );

   j = istkgt ;
   jj = j + maxf ;
   j2 = jj+ maxf ;
   j3 = j2+ maxf ;

   nitems = maxp ;
   itype  = 2 ;

 istkgt = ( lnow*isize[1] -1)/isize[itype-1] + 2;

 i = ( (istkgt - 1 + nitems) * isize[itype-1] -1) / isize[1] + 3 ;

   if ( i > lmax )
      {
         ierr = -i ;
         printf ( "argh return 4 -i %d \n" , -i );
         return ;
      }

   istak[i-2] = itype ;
   istak[i-1] = lnow  ;
   lout ++ ;
   lnow = i ;
   lused = max ( lused , lnow );

   k = istkgt ;

/*
c     la carte suivante est a supprimer si simple precision
c     next instruction commented by FD&MG (simulog residue?)
c    ********************************************
c      k=2*k-1
c    *********************************************
*/

   printf ( "dfftmx  me voilà tayoooooooo \n" );
   difftmx( a , b , ntot , nf , nspan , isn , m , kt , &rstak[j-1] , &rstak[jj-1] , &rstak[j2-1] , &rstak[j3-1] , &istak[k-1] , nfac);

   k =2 ;

   in = 2 ;

   if (!( lbook <= lnow &&  lnow <= lused && lused <=  lmax ))
      {
         ierr = 3 ;
         printf ( "argh return 6 \n" );
         return ;
      }

   while ( in > 0)
      {
         if ( lbook > istak[lnow-1] || istak[lnow-1] >=  lnow-1)
         {
            ierr = 4 ;
         }

         lout-- ;
         lnow = istak[lnow-1] ;
         in-- ;
      }
      printf ( "fin de dfftbi \n" );
   return ;
}