[ad_1]
Been trying to figure out this line for quite some time. “weights” is intialized as a double and this is the second (and last) time it appears in the code.
#define NPTSMX 50000
#define N_TERMS 100
double weights[NPTSMX], K, roots[N_TERMS];
void main(void)
{
FILE *fp, *fppulse, *fopen();
char *nm[NPAR], input[50];
char filename1[50]="ref_expt_centred_A1_1MHz.dat";
char filename2[50]="I0_cor_av_for_ref_expt_centred_A1_1MHz.dat";
int i,n,j,k, npts;
double s[NPTSMX], ss[NPTSMX], par[NPAR], b[NPAR],*x[NPTSMX];
fppulse = fopen(filename1, "r");
i=0;
while (fscanf(fppulse,"%lf%lf",&tp[i],&pul[i]) != EOF)
i++;
delta_i=i;
delta_tp=tp[1]-tp[0];
pulse_width=delta_tp*delta_i;
fclose(fppulse);
printf("Pulse width of %f is %f time steps wide.\n",pulse_width,1.*delta_i);
//printf("Input filename of data:");
//gets(filename);
fp = fopen(filename2, "r");
i = 0;
while (fscanf(fp,"%lf%lf",&t[i],&s[i]) != EOF)
{
weights[i++] = 1.;
}
npts = i;
t0=t[0];
fclose(fp);
.
. more stuff here
now, the files (filename1 and 2) are just .dat files with two columns of decimal numbers.
the first loop as I understand counts the number of lines, but this other one does something weird with weights[i++] = 1.; which I can’t wrap my head around.
My guess is that it take the array weights and changes every i++th entry to 1, but that seems very odd and useless. The context is quite difficult to explain as it this code later deals with solving a transcendental equation which in no other place mentions or reassigns “weights”.
I looked online for quite some time and couldn’t find anything. Thanks in advance.
[ad_2]