A
Andi
Hi, I want to define the following functions before main(); I work with
2D arrays (fftw_complex) wich are arrays with array[][0] is real and
array[][1] the imaginary part of a complex number. Now I want to do
some operations like norming, swapping, coord transforms as functions.
But I don't know how to handle these 1D/2D arrays. Any advices (maybe a
book etc.?)
// the following 4 work
double getAmplitude (double arg[]) {
double amplitude=sqrt(pow(arg[0],2.)+pow(arg[1],2.));
return amplitude;
}
double getPhase (double arg[]) {
double phase=atan(arg[1]/arg[0]);
return phase;
}
double getRe (double amplitude, double phase) {
double result=amplitude*cos(phase);
return result;
}
double getIm (double amplitude, double phase) {
double result=amplitude*sin(phase);
return result;
}
// functions -- Do not work
void coord_transform (fftw_complex arg[][2]);
void norm (fftw_complex arg[][2]) {
int Dim=((int)(sizeof(arg)/(sizeof(arg[0]))));
for (int i=0;i<Dim;i++) {
double amplitude=getAmplitude(arg);
double phase=getPhase(arg);
double normamplitude=amplitude/Dim;
arg[0]=getRe(normamplitude*phase);
arg[1]=getIm(normamplitude*phase);
}
}
2D arrays (fftw_complex) wich are arrays with array[][0] is real and
array[][1] the imaginary part of a complex number. Now I want to do
some operations like norming, swapping, coord transforms as functions.
But I don't know how to handle these 1D/2D arrays. Any advices (maybe a
book etc.?)
// the following 4 work
double getAmplitude (double arg[]) {
double amplitude=sqrt(pow(arg[0],2.)+pow(arg[1],2.));
return amplitude;
}
double getPhase (double arg[]) {
double phase=atan(arg[1]/arg[0]);
return phase;
}
double getRe (double amplitude, double phase) {
double result=amplitude*cos(phase);
return result;
}
double getIm (double amplitude, double phase) {
double result=amplitude*sin(phase);
return result;
}
// functions -- Do not work
void coord_transform (fftw_complex arg[][2]);
void norm (fftw_complex arg[][2]) {
int Dim=((int)(sizeof(arg)/(sizeof(arg[0]))));
for (int i=0;i<Dim;i++) {
double amplitude=getAmplitude(arg);
double phase=getPhase(arg);
double normamplitude=amplitude/Dim;
arg[0]=getRe(normamplitude*phase);
arg[1]=getIm(normamplitude*phase);
}
}