Reputation: 4318
I wrote this function in C which import a two column file in two arrays and then finds the linear interpolation between two successive points if the input value of the function lies between them.
double Prevot_redden(double wave, double Av)
{
int i,j;
const double Rv = 2.75; /* Set by Prevot */
double micron, r = 0.;
micron = wave * 1e6; /* convert to micron */
/*Prevot reddening counters*/
int raw_prevot_size=4002;
/*data array for raw Prevot reddening */
double *raw_prevot_wave_data,*raw_prevot_data;
/*allocate space for raw Prevot reddening*/
raw_prevot_wave_data=(double *)calloc(raw_prevot_size,sizeof(double *));
raw_prevot_data=(double *)calloc(raw_prevot_size,sizeof(double *));
/*reading a file*/
char *f_prevot=fopen("SMC_prevot.dat","r");
if (f_prevot==NULL )
{
fprintf(stderr,"Can not open reddening file !\n");
exit(-1);
}
for (i=0;i<raw_prevot_size;i++)
{
sscanf(f_prevot,"%lf %lf",&raw_prevot_wave_data[i],&raw_prevot_data[i]);/*Wavelength and E(lambda-V)/E(B-V)*/
/* convert to micron */
raw_prevot_wave_data[i]*=1e-4;
}
for (j = 0; j < raw_prevot_size-2; j++)
{
if ((micron>raw_prevot_wave_data[j]) &&(micron<=raw_prevot_wave_data[j+1]))
{
r= lininterp(raw_prevot_wave_data[j],
raw_prevot_wave_data[j+1],
raw_prevot_data[j],
raw_prevot_data[j+1],
micron);
}
}
r *= Av;
r /= Rv;
r /= -2.5;
r = pow(10, r);
return(r);
}
When I compile the code, for the line with the command fopen, I get this warning message. Can somebody explain what the reason is for the message?!!
In function 'Prevot_redden':
14: warning: initialization from incompatible pointer type
Upvotes: 1
Views: 255
Reputation: 5935
char *f_prevot=fopen("SMC_prevot.dat","r");
fopen() returns FILE*, not char*
Upvotes: 0
Reputation: 60014
you need
FILE *f_prevot=fopen("SMC_prevot.dat","r");
·..
if (fscanf(f_prevot,"%lf %lf",&raw_prevot_wave_data[i],&raw_prevot_data[i]) == 2)
...
fclose(f_prevot);
Upvotes: 1
Reputation: 382
FILE *f_prevot=fopen("SMC_prevot.dat","r");
would be my first try as fopen returns a pointer of FILE * type
Upvotes: 0