-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sequential_Fig8.c
155 lines (101 loc) · 2.77 KB
/
Sequential_Fig8.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Sequential_Fig7.c to accompany Bull, Wichman, Krone
// types ending in 'i' are infected, others are free
// fixed-count dilution to 1000
#include <stdio.h>
#include <math.h>
FILE *fp, *fopen();
int main()
{
char out[30];
int dummy,dummy1, I,J,i,j,k,innerloop,totcycles,totaltimesteps,printcycles,K,Klim;
float
Pa, Pai, Pb, Pbi, Pg, Pgai, Pgbi,
Qa, Qai, Qb, Qbi, Qg, Qgai, Qgbi,
za, zai, zb, zbi, zg, zgai, zgbi,
BA, BB, S, r, bA, bB, bGA, bGB, kaa, kbb, kab, kba, kga, kgb, delta,
h,CA, CB,D;
printf("input h, bacterial r (usually 0.1 or 0.3) and filename for output\n");
scanf("%f %f %s",&h,&r,out);
printf("input specialist burst sizes\n");
scanf("%f %f",&bA,&bB);
fp = fopen(out,"a+");
delta = 1.0;
kaa= kbb= kga= kgb = 1E-9;
kab= kba= 0.0;
totaltimesteps = 1000;
fprintf(fp,"bGA, bGB, pA, pB, pG\n");
Klim = (int)(1.0/h);
for(bGA = 5.0; bGA<=25.0;bGA+=0.5) {
for(bGB = 5; bGB<=25;bGB+=0.5) {
Pa= Pai= Pb= Pbi= Pg= Pgai= Pgbi=0.0;
Qa= Qai= Qb= Qbi= Qg= Qgai= Qgbi=0.0;
za= zai= zb= zbi= zg= zgai= zgbi=0.0;
CA = CB = 0.0;
Pa = Pb = 1.0;
Pg = 1.0;
BA = BB = 1E7;
for(I=1;I<=totaltimesteps;I++) {
for(K=1;K<=Klim;K++) { // reciprocal of h
CA = BA + h* (BA * (r - kaa*Pa - kga*Pg));
CB = BB + h* (BB * (r - kbb*Pb - kgb*Pg));
Qai = Pai + h*(kaa*Pa*BA - delta*Pai); // don't need 'a on a' etc. Is one culture at a time
Qa = Pa + h*(bA*delta * Pai - kaa * Pa * BA );
Qbi = Pbi + h*( kbb * Pb * BB - delta * Pbi);
Qb = Pb + h*(bB *delta *Pbi - kbb * Pb * BB );
Qg = Pg + h*( - kga * Pg *BA - kgb * Pg *BB + bGA * delta * Pgai + bGB * delta * Pgbi);
Qgai = Pgai + h*( kga *Pg *BA - delta * Pgai);
Qgbi = Pgbi + h*( kgb * Pg * BB - delta *Pgbi);
BA = CA;
BB = CB;
Pai = Qai;
Pa = Qa;
Pbi = Qbi;
Pb = Qb;
Pgai = Qgai;
Pgbi = Qgbi;
Pg = Qg;
}
if (I%20 ==0) {
if (I%40==0) {
BA = 1.0E7;
BB = 0.0;
}
if ((I+20)%40==0) {
BB = 1.0E7;
BA = 0.0;
}
Pai = Pbi = Pgai = Pgbi = 0.0;
S = (Pa+ Pai+ Pb+ Pbi+ Pg+ Pgai+ Pgbi);
S /= 1000.0;
// this dilution knocks total density back to 1000 every 20 steps
Pa = (Pa )/S;
Pai = (Pai )/S;
Pb = (Pb)/S;
Pbi = (Pbi)/S;
Pg = (Pg )/S;
Pgai = (Pgai )/S;
Pgbi = Pgbi/S;
}
if (I== totaltimesteps-20) { // totaltimesteps better be evenly divisible by 20
Pai = Pbi = Pgai = Pgbi = 0.0; // kills infections
D = (Pa+ Pai+ Pb+ Pbi+ Pg+ Pgai+ Pgbi);
za = Pa /D;
zai = Pai /D;
zb = Pb /D;
zbi = Pbi /D;
zg = Pg /D;
zgai = Pgai /D;
zgbi = Pgbi/D;
}
if (I== totaltimesteps) {
Pai = Pbi = Pgai = Pgbi = 0.0;
D = (Pa+ Pai+ Pb+ Pbi+ Pg+ Pgai+ Pgbi);
fprintf(fp,"%2.1f, %2.1f, %1.3e, %1.3e, %1.3e\n",bGA,bGB,
(((Pa +Pai )/D) + za + zai )/2.0,
(((Pb +Pbi )/D) + zb + zbi )/2.0 ,
(((Pg +Pgai +Pgbi)/D) + zg + zgai + zgbi)/2.0);
}
} // end of I loop
}}
fclose(fp);
}