# FFT Why the flag and the array are not changed？

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

here is my code：

``````int kind[0]=1;//DCT-II - kind=1
double in[10]={1,2,3,4,5,6,7,8,9,10};
double out[10]={};
TFFTComplex *fft = new TFFTComplex(10,0);
fft->Init("EX",-1,kind);//flag ="M"  sign=FFTW_FORWARD -1;    backward +1
fft->SetPoints(in);
fft->TFFTComplex::Transform(); //fplan not 0
fft->TFFTComplex::GetPoints(in,"kFALSE");
int a =fft->TFFTComplex::GetSize();
cout <<"fTotalSize= "<< a << endl;//  10
int b =fft->TFFTComplex::GetNdim();
cout <<"fNdim= "<< b << endl;//       1
int c =fft->TFFTComplex::IsInplace();
cout <<"fout= "<< c << endl;//fout---bool     1       already changed
int *d =fft->TFFTComplex::GetN();
cout <<"fn= "<< *d << endl;//         10
int e =fft->TFFTComplex::GetSign();
cout <<"fsign= "<< e << endl;//       -1      already changed
int f =fft->TFFTComplex::MapFlag();
cout <<"flag= "<< f << endl;//        0(默认构造函数)*********flag***need change************
char *g =fft->TFFTComplex::GetType();
cout <<"getType= "<< g << endl;//     C2CBackward     prove (fsign is -1)
//char *q =fft->TFFTComplex::GetTransformFlag();
//cout <<"fFlags="<< q << endl;
for (int i=0;i<10;i++)
{cout << "i= "<< i <<"        in[i]= "<< in[i] <<endl;}//******need change*****************
for (int i=0;i<10;i++)
{cout << "i= "<< i <<"        out[i]= "<< out[i] <<endl;}
``````

the output is：

``````fTotalSize= 10
fNdim= 1
fout= 1
fn= 10
fsign= -1
flag= 0
getType= C2CBackward
i= 0    in[i]= 1
i= 1    in[i]= 2
i= 2    in[i]= 3
i= 3    in[i]= 4
i= 4    in[i]= 5
i= 5    in[i]= 6
i= 6    in[i]= 7
i= 7    in[i]= 8
i= 8    in[i]= 9
i= 9    in[i]= 10
i= 0        out[i]= 0
i= 1        out[i]= 0
i= 2        out[i]= 0
i= 3        out[i]= 0
i= 4        out[i]= 0
i= 5        out[i]= 0
i= 6        out[i]= 0
i= 7        out[i]= 0
i= 8        out[i]= 0
i= 9        out[i]= 0
``````

So I don’t know why the flag and the array in[] are not change？

The best is to compile such examples. To compile and execute something in root, put it in a file and a function that have the same name. I posted the fixed code below, and this one you would put into `testFFT.cxx`.

If you did that, you could execute it as `root.exe testFFT.cxx+`. The `+` tells ROOT to compile it first, and execute afterwards. If you did that, you would have seen a couple of errors in your example.

This is what works for me now:

``````void testFFT() {
int kind[1] = {1};//DCT-II - kind=1
double in[10]={1,2,3,4,5,6,7,8,9,10};
double out[10]={};
TFFTComplex *fft = new TFFTComplex(10, false);
fft->Init("EX",-1, kind);//flag ="M"  sign=FFTW_FORWARD -1;    backward +1
fft->SetPoints(in);
fft->Transform(); //fplan not 0
fft->GetPoints(out, false);
cout <<"fTotalSize= "<< fft->GetSize() << endl;//  10
cout <<"fNdim= "<< fft->GetNdim() << endl;//       1
cout <<"fout= "<< fft->IsInplace() << endl;//fout---bool     1       already changed
int *d =fft->GetN();
cout <<"fn= "<< *d << endl;//         10
cout <<"fsign= "<< fft->GetSign() << endl;//       -1      already changed
//  int f =fft->MapFlag("EX");
//  cout <<"flag= "<< f << endl;//        0*********flag***need change************
cout <<"getType= "<< fft->GetType() << endl;//     C2CBackward     prove (fsign is -1)
//char *q =fft->TFFTComplex::GetTransformFlag();
//cout <<"fFlags="<< q << endl;
for (int i=0;i<10;i++)
{cout << "i= "<< i <<"        in[i]= "<< in[i] <<endl;}//******need change*****************
for (int i=0;i<10;i++)
{cout << "i= "<< i <<"        out[i]= "<< out[i] <<endl;}
}
``````

• When you call a function, don’t mention the name of the class. This is resolved automatically by C++.
• `MapFlag` is an internal function that you cannot call from the outside. I therefore commented it out.
• When you were “getting” the points, you put them in `in` instead of `out`.

Thanks for your reply and comments! I know how to display the flag now.But I don’t know how to display the array that being transformed ,I can just show the original array.As you can see ,the array in[] didn’t change!!
This is my changed code:

This is the output:

This is because you did not understand the difference between a boolean and a string.

May I first say again that it’s better to call functions without the class name

``````fft->GetPoints()
``````

``````fft->TFFTComplex::GetPoints()
``````

The latter might lead to surprising results or crashes if the `fft` pointer does not point to an FFTComplex object. In this case, it’s ok.

Your problem now is calling this function with `fromInput = false`:

``````void TFFTComplex::GetPoints(Double_t *data, Bool_t fromInput) const
``````

What you do is to call like

``````GetPoints(data, <string>)
``````

which passes the address of a string into the function. If you convert this to a Boolean (Wikipedia link), it is interpreted as `true`, because such an address is never 0. What you have to to is to call as:

``````GetPoints(data, false)
``````

Like this, it is really interpreted as `false`, and the output array will be copied into your array.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.