On my Linux computer, I am using the command:
gcc programname.c -lm
for the following code:
Code:
#include<time.h>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(void)
{
int p, d, h, what, end, steps;
double i, n, M, c, w, q, measure;
end = 2000;
steps = 1000;
double average1[end][2], average2[end][2];
int width[end][steps];
//w is equal to the possible number of ways to choose a reactant molecule,
// which in our case is equal to how many molecules exist in the system
w = 0;
what = 10000;
measure = 0.01;
//c defines the propensity of the reaction (change to 0.5, 1.0, and 10)
c = 10;
q = 0;
//concentration
int cnctrn;
cnctrn = 1000;
srand((unsigned int)time(NULL));
for (d = 0; d < end; d++){
for (h = 0; h < 2; h++){
average1[d][h] = 0;
average2[d][h] = 0;
}
}
for (p = 0; p < end; p++){
for (d = 0; d < steps; d++){
width[p][d] = 0;
}
}
for (p = 1; p < steps; p++){
width[0][p] = cnctrn;
}
//PLotting in Matlab
FILE * pFile;
char name [100];
pFile = fopen ("Gillespie.txt","w");
n = 0;
d = 0;
for (h = 0; h < steps; h++){
while (i < what && cnctrn > 1){
q = double((rand())/(double(RAND_MAX + 1)));
for (d = 0; d < end; d = d+1){
if ( i < (d+1)*measure && i >= d*measure){
width[d][h] = cnctrn;
}
}
//exact data comparison
w = cnctrn*c;
M = -log(q)/w;
cnctrn = cnctrn-1;
i = i + M;
n = n + 1;
fprintf(pFile, "%f %i\n ", i, cnctrn);
}
}
for (p = 1; p < end; p++){
for (d = 0; d < steps; d++){
if (width[p][d] == 0){
width[p][d] = width[p][d-1];
}
}
}
fclose (pFile);
for (d = 0; d < end; d++){
average1[d][0] = d*measure;
average2[d][0] = d*measure;
}
for (d = 0; d < end; d++){
for (h = 0; h<steps; h++){
average1[d][1] = average1[d][1] + double(width[d][h])/double(steps);
average2[d][1]=average2[d][1]+
double(width[d][h])*double(width[d][h])/double(steps);
}
}
pFile = fopen ("average.txt","w");
for (d = 0; d < end; d++){
fprintf(pFile, "%f %f\n ", average1[d][0], average1[d][1]);
}
fclose (pFile);
pFile = fopen ("averagesquared.txt","w");
for (d = 0; d < end; d++){
fprintf(pFile, "%f %f\n ", average2[d][0], average2[d][1]);
}
fclose (pFile);
}
I keep getting this error for the lines I put in bold:
syntax error before 'double'
Putting (double) in parenthesis gets rid of the error, but outputs the wrong text files. How do I fix this error without just putting the (double) in parenthesis to get the correct output?
Any help with this would be very very appreciated! Thanks!