-1

I am trying to perform fft in my below mentioned code but I am getting some errors which I will be mentioning at the bottom this code

#include<stdio.h>
#include<complex.h>
#include <gsl/gsl_integration.h>
#include"H.h"
#define REAL(z,i) ((z)[2*(i)])
#define IMAG(z,i) ((z)[2*(i)+1])

int
main (void)
{
  gsl_integration_workspace * w
    = gsl_integration_workspace_alloc (10000);
  double qr,error;
  double expected = -4.0;
  double a1 = 1e-14;
  double a= 150;//150;
  double pi = 3.1415;
  double T = 2500;
  double b = (315777/(1000*T));
  //printf("b = %f",b);
  double mu = (2*pi)/b;
  double om=7.15;
  double om1=7.267;
  int m;
    for( m=1; m<11; m++)
  {


  double  t = 4.14937*(m-1);

  struct har item = {t,mu};
  struct har *p_params = &item;

  gsl_function q;                               //ok
  q.function = &H;
  q.params =&t;

  gsl_integration_qags (&q, a1, a, 0,1e-7, 10000, w, &qr, &error);
  printf ("\nqtresult = % .18f\n", qr);
}

 gsl_integration_workspace_free (w);
}

user defined function H.h is as follows

#include"I.h"
#include"str.h"

    double H (double x,void * params )
    {
    double t = *(double *) params;
    //printf("%f\n",t);
    //struct har t1,z;
    //double t = z.params ->t1;
    double H  = I(x)*(sin(x*t));
    return H;
    }

structure file and I.h are as follows

double I(double x)
{
        double gamma=0.182;
        double tau=0.41493;
        double om=7.1534;
        double I=(gamma*x)/(pow((pow(om,2)-pow(x,2)),2)*(1+pow((x*tau),2))+(2*gamma*x*((pow(om,2)-pow(x,2))*x*tau)+pow((gamma*x),2)));
//double I = pow(x,2);
return I;
}

user defined function I.h is as follows

~

struct har{

double t;
double k;
double mu;

};

Above written code is running successfully until I don't include complex.h header file in code. After adding complex.h as a head file I am getting two errors which are as follows: 1. error : In file included from test.c:3:0: I.h:1:8: error: expected identifier or ‘(’ before ‘extension’ 2.called object is not a function or function pointer double

Please help me to resolve it out. Hoping you answer at earliest.

Thanks

Regards

Ramesh

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • What is complex.h? –  Jul 13 '17 at 12:02
  • 1
    Please provide [MCVE](https://stackoverflow.com/help/mcve). With your cluttered pieces of code we cannot even identiy which lines are related to your error messages – Gerhardh Jul 13 '17 at 12:02
  • @manni66 complex.h is a standard header. – Gerhardh Jul 13 '17 at 12:04
  • @manni66 Part of C99; it's optional as of C11 though – Lightness Races in Orbit Jul 13 '17 at 12:38
  • Dear all, I have few more doubt, can we use unwrap function for unwrapping of 1D phase in C language as in matlab we can perform it by typing unwrap() only. if yes then how I can use it. (2): How I can use gsl fft function to perform fft. @Gerhardh I will happy to accept your previous answer plz send me your link to do so. – Sandesh Rathi Jul 14 '17 at 07:53
  • @SandeshRathi For this new issue please post a new question. What link do you mean? My answer is just below the question... – Gerhardh Jul 14 '17 at 07:59

2 Answers2

1

Besides the duplicate usage of your function and variable names I and 'H' you should not use I at all for your own identifiers.

7.3 Complex arithmetic (complex.h)

7.3.1 Introduction

...

The macro I expands to either _Imaginary_I or _Complex_I. If _Imaginary_I is not defined, I shall expand to _Complex_I.

Community
  • 1
  • 1
Gerhardh
  • 11,688
  • 4
  • 17
  • 39
0

You have a function and a variable name of I, so the compiler is likely getting confused between the two. Change to:

double I(double x)
{
    double gamma=0.182;
    double tau=0.41493;
    double om=7.1534;
    double Ival=(gamma*x)/(pow((pow(om,2)-pow(x,2)),2)*(1+pow((x*tau),2))+(2*gamma*x*((pow(om,2)-pow(x,2))*x*tau)+pow((gamma*x),2)));
    return Ival;
}
lostbard
  • 5,065
  • 1
  • 15
  • 17