-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcs.f
2717 lines (2709 loc) · 80.5 KB
/
cs.f
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c COVID-19 epidemic simulator, april 25 2020
c S-E1-E2-E3-E4-I-W-B-R where E2,E3 and I are infecterious,
c and B=ICU beds of average of 12 days.
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
common/sizes1/ worksize,famsize,frsize,crossize,schoolsize
common/weights/ workinf,school,faminf,frinf,crosinf,ainf(9,9)
common/weights1/ grandpar
common/param1/ Nsize,konec,kmax
common/society/ iage(1500000),iwork(200000,0:50),
q ifam(0:1000000,0:12),
q ifriend(0:500000,0:20)
common/society1/ jwork(1500000),
q jfam(1500000),jfriend(1500000),jcross(1500000)
common/society2/ Ncomp,Nschool
common/links/ Kon(1100000),K(1100000,100)
common/links1/ Kiden(1100000,100)
common/strength/ SK(1100000,100)
common/ages/ jgroup(9,0:200000)
common/persons/ eta(1500000),agescal(10),actpers(1500000)
common/persons1/ actpmax,etamax,agemaxx,actpave,etaave
common/persons2/ beta0,dt,actu,actp,unspec
common/persons3/ agescal0(10)
common/mossong/ polymod(9),polymodg(5)
common/hospitals/ hospital(10),death(10)
common/hospitals1/ agecount(10),bedsicu(10)
common/super1/ superfreq,superpow,cut
common/super2/ Nsupermax,Nsuperlim,Nsuper(1500000)
common/super3/ histsuper(0:10000)
common/super4/ ssuper(1500000)
common/bbc/ datamat(7,0:10,0:10)
common/hospitalization/ lockdown1,inhosp(-300:1000)
common/sweeden/ lockdowns1,insw(-300:1000),ideaths(-300:1000)
dimension N(1500000)
dimension tf(-10000:10000),tserial(-10000:10000)
dimension its(1500000),ipointer(1500000),iserial(1500000)
dimension ts(-10000:10000)
dimension itfirst(1500000),istart(1500000)
dimension gamma(150)
dimension hist(0:550),histinf(0:550),histw(0:550),histpos(0:550)
dimension infected(1500000)
dimension infected0(1500000)
dimension statage(10),statcross(10,10)
dimension statsub(8,10,10)
dimension statgroup(10)
dimension attack(10),sick(10),hos(10),fat(10)
dimension resp(10)
dimension work(0:100)
dimension isource(1500000)
dimension nacc(0:10000),iacc(0:10000),nncc(0:10000)
dimension trajech(-200:3000),trajecicu(-200:3000)
dimension trajw(-200:3000),trajoth(-200:3000)
dimension trajsick(-200:3000),trajdead(-200:3000)
dimension icontraj(-200:3000)
dimension histacc(0:10000)
dimension chi2(-50:50)
dimension ntrajech(-200:3000),ntrajdead(-200:3000)
dimension atrajech(-200:3000),xtrajech(-200:3000)
dimension ytrajech(-200:3000)
dimension xxtrajech(-200:3000),yytrajech(-200:3000)
dimension atrajdead(-200:3000),xtrajdead(-200:3000)
dimension ytrajdead(-200:3000)
c
idum=199729
call data
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c gfortran -fcheck=bounds r.f -o r
c gfortran -mcmodel=medium -fcheck=bounds r.f -o r
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
chibest=9988888
c
do i=-200,1000
ntrajech(i)=0
ntrajdead(i)=0
atrajech(i)=0
xtrajech(i)=0
xxtrajech(i)=0
ytrajech(i)=99899.
yytrajech(i)=99899.
atrajdead(i)=0
xtrajdead(i)=0
ytrajdead(i)=99899.
enddo
c
fudgemin=1.
fudgemax=0
fudgesmin=1.
fudgesmax=0
conmin=1
conmax=0
nparam=1
facacc=5.
c parameter scan for fitting to data
c default is that we only use one set of parameters
do 889 iparam=1,nparam
do 887 jparam=1,1
do 886 kparam=1,1
chisum=0
chisum2=0
avekk=0
kkkmax=0
if(iparam.gt.1) kkkmax=0
do 888 kkkc=0,kkkmax
c
sickfree=0
sickdays=0
atest=0.
iamax=0
attacmax=0
C Basic system size and simulation time parameters:
Nsize=1000000
size=Nsize
nday=24
dt=1./float(nday) !timestep in unit of days.
nt=150./dt
c
c.....size of groups to connect to (-1 because self membership)
worksize=8.-1
schoolsize=18.-1
famsize=2.3-1
crossize=10. !normally 10
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c.....Basic supnetworks for infection:
c unspec=0 correspond to set the random encounters=0
c workinf=0 correspond to eliminate work contacts
c feminf=0.2 assign 20% of standard interaction within household
c crosinf=0.1 means that 10% of interactios go to wider social network
c
c
c
c.....Default parameters, not to be changed (see later, search for aa)
c secure that different sectors equally social:
unspec=0.82
faminf=0.54
grandpar=0
crosinf=0
workinf=0.89
school=0.89 !
c
unspec0=unspec
faminf0=faminf
grandpar0=grandpar
crosinf0=crosinf
workinf0=workinf
school0=school
c
c.....Super spreader option, Nsupermax=inf. activity of superspreader relative to base
c..... superfreq=probability that an agent is assigned to be superspreader
c..... As Nsupermax is increased, then bet0 should be decreased
c..... to fix growth rate of disease.
c.....10% doing 50 times more
Nsupermax=50
superfreq=0.10
Nsupermax=1
beta0=1.0
superfreq=0
superpow=-2.5
c.....Normal parameters
c
Nsupermax=1
superfreq=0.
beta0=1.1
helpfac=1.
c.....Gamma distributed superspreader
beta0=1
Nsuperlim=5000
superpow=0.9 !=1-k, with k=formfactor in gamma distribution
Rep0=0.9 !superpow=0.8, Rep0=0.9, cv**2=5.4
Rep0=1.1 !superpow=0.9, Rep0=1.1
cut=Rep0/(1.-superpow)
helpfac=10
c write(72,*) '#cut=',cut,' if cut=xk what then beta0=',betacorr/Rep0
c.....aaa
c.....
c option for child less infectious (child=2 means child half infectious)
child=1
c option for child less exposed (child=2 means child half exposed)
childinf=1
c
c superpow<0 then dont call power laws/gamma distribution
c 0=<superpow<1: gamma distribution
c superpoe>1 power law
c
c.....initialize social setting and rates
call initialize(idum)
c.....Call gamma distribution, output Nsuper() and ssuper()
if(superpow.gt.0) call sspower(idum)
c.....rates adjusted for group sizes, and stored
workinf0=workinf !cluster (0.3)
school0=school
faminf0=faminf !cluster (0.2)
grandpar0=grandpar !cluster to two clusters (0.1)
crosinf0=crosinf !networks of friends (0.1)
c
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c.....to colect statistics on how age groups interact
do i=1,Nsize
istart(i)=0
itfirst(i)=0
infected(i)=0
infected0(i)=0
isource(i)=0
enddo
do i=1,10
statage(i)=0
do j=1,10
statcross(i,j)=0
do kk=1,8
statsub(kk,i,j)=0
enddo
enddo
statgroup(i)=0
enddo
c
c.....social network connectivity distribution:
do i=0,550
hist(i)=0
histw(i)=0
histinf(i)=0
histpos(i)=0
enddo
do i=1,Nsize
kk=Kon(i)
hist(kk)=hist(kk)+1
enddo
do i=0,150
write(8,*) i,hist(i)
enddo
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c BASIC DISEASE PARAMETERS:
c.....distribution of infection rates
c
c.....latency time, IE steps that each are exponential
c basic disease parameters:
IE=4
c N()=0 =susceptible
C N()=1 =E1 !exposed 1
C N()=2 =E2 !exposed 2
C N()=3 =E3 !infectious, presymptomatic
C N()=4 =E4=IE !infectious presymptomatic
C N()=IE+1 !infectious
C N()=IE+2 !hospital before ICU (not infecting)
C N()=IE+3 !ICU, say 12 days
C N()=IE+4 !removed
C
atime=0
do i=1,IE
gamma(i)=0.8 !rate of leaving each of IE presymptomatic state
atime=1/gamma(i)+atime
enddo
agamma=1./atime
delta=0.3333 !rate to leave I state (IE=5)
hosp=0.5 !time to hospitalization after infecterous
cwww here we made a delay from symptom to hospitalization, now 9 days instead of 5
hospstay=0.2 !time to hospitalization
serious=1./12. !12 days in ICU in Norway
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c.....start condition with 10 infected people (age between 21 and 40)
do i=1,Nsize
N(i)=0
enddo
Nsize9=Nsize/9
do i1=1,100 !50 !50
i=2*Nsize9+4*ran2(idum)*Nsize9
N(i)=IE+1
enddo
c
c.....Quarantine Strategies:
c
icontact=0 !=1, only person, =2 also persons connections
contact=0.0 !0.1 or delta !rate of contact tracing
intcheck=200./dt
ncheck=0
c.....
c
c.....write out parameters:
R0=abeta/delta
alow=0
ahigh=0
write(6,110) abeta,dbeta,agamma,delta,IE,R0,
q alow,ahigh,icontact,contact,
q intcheck,ncheck,ak
c write(16,110) abeta,dbeta,agamma,delta,IE,R0,
c q alow,ahigh,icontact,contact,
c q intcheck,ncheck,ak
c write(26,110) abeta,dbeta,agamma,delta,IE,R0,
c q alow,ahigh,icontact,contact,
c q intcheck,ncheck,ak
110 format('# beta,gamma,delta=',4F7.3,I4,F7.2,
q ' pop=',2F6.3,' icontact=',I2,F6.3,' test=',2I4,
q ' ave k=',3F7.2)
c.....
do i=0,10000
tf(i)=0
tf(-i)=0
tserial(i)=0
tserial(-i)=0
enddo
c.....
c
c.....special analysis for super spreaders:
itest=0
testlim=0.005
do i=0,100
work(i)=0
enddo
c
c.....basic analysis
sumspec=0
sumunspec=0
sttac=0
hospinl=0
bedsmax=0
sickmax=0
hospmax=0
testmax=0
bedssum=0
infsum0=0
xsum0=0
fatsum=0
superinf=0
suminf=0
suminf2=0
baseinf=0
c
countf=0
earlyinf=0
infectf=0
infectf2=0
noinfectf=0
already=0
already2=0
do i=0,10000
iacc(i)=0
nacc(i)=0
nncc(i)=0
enddo
do i=-200,3000
trajoth(i)=1
trajw(i)=1
icontraj(i)=-1
trajech(i)=0
trajecicu(i)=0
trajsick(i)=0
trajdead(i)=0
enddo
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c actual parameters to run with:
czzzaaa
unspec=unspec0
faminf=faminf0 !cluster (0.2)
workinf=workinf0 !cluster (0.3)
school=school0
grandpar=grandpar0 !cluster to two clusters (0.1)
crosinf=crosinf0 !networks of friends (0.1)
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c.....specific has weight spec*actpave, spec=friends if no Mitigation
c.....public has weight unspec*etaave, unspec=1-friends if no M.
actu=unspec*etaave
acts=actpave
write(72,169) actu,acts,
q etamax,actpmax,etaave,actpave
write(41,169) actu,acts,
q etamax,actpmax,etaave,actpave
write(71,169) actu,acts,
q etamax,actpmax,etaave,actpave
actu=actu*dt
acts=acts*dt
write(72,169) actu,acts,
q actu*helpfac,acts*helpfac
169 format('# actu,acts=',2F7.3,' etam,actp=',4F8.3)
acturemove=0
actunorm=0
actsremove=0
actsnorm=0
c
c.....if containlim1>1 then no mitigation is attempted
c.....otherwise mitigitation start when accumulated cases containlim1
icon=0
containlim1=0.01
tcountlim1=30
tcountlim2=70
tcountlim3=200
tcountlim1=200
tcount=0
detailmax=0
c.....kstat=0 is standard, kstat= is only for samling group activity
c.....independent of disease parameters
fudge0=1.
fudges0=1.0
kstat=0
xaaa=0
yaaa=0
ymean=0
yvar=0
do 999 it=1,nt
c.........to measure R0, R:
if(nday*(it/nday).eq.it) then
infsum=0
xsum=0
endif
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c progress of disease for all (infected) agents
c.........id=1,2,3,...IE,IE+1 (controlled by gamma)
c
hospinl=0
do i=1,Nsize
id=N(i)
if(id.ge.1.and.id.le.IE) then
if(ran2(idum).lt.gamma(id)*dt) N(i)=id+1
if(N(i).eq.IE+1) then
iii=it-itfirst(i)
tf(iii)=tf(iii)+1
istart(i)=it
endif
endif
enddo
c
c.........Disease can be cured
c.........id=IE+1,IE+2 (controlled by delta)
c.........id=IE+2,IE+3 (controlled by hosp)
c.........id=IE+3,IE+4 (controlled by serious=1/12 in Noway data)
c
do ig=1,10
hos(ig)=0 !hospital arrival in age group ig
fat(ig)=0 !fatality in age group ig
enddo
do i=1,Nsize
id=N(i)
ig=iage(i)
if(id.eq.IE+1) then
if(ran2(idum).lt.delta*dt) then
N(i)=IE+2
xaaa=xaaa+1
xsum=xsum+1
xsum0=xsum0+1
infsum=infsum+infected(i)
iiii=infected(i)
jjjj=Nsuper(i)
histacc(jjjj)=histacc(jjjj)+iiii
if(sttac.gt.0.05*Nsize.and.
q sttac.lt.0.09*Nsize) then
yaaa=yaaa+1
ymean=ymean+iiii
yvar=yvar+iiii**2
nncc(iiii)=nncc(iiii)+1
iacc(iiii)=iacc(iiii)+iiii
endif
infsum0=infsum0+infected0(i)
infsum00=infsum00+infected0(i)**2
endif
else if(id.eq.IE+2) then
if(ran2(idum).lt.hosp*dt) then
N(i)=IE+3
hos(ig)=hos(ig)+hospital(ig)
hospinl=hospinl+hospital(ig)*agecount(ig)
endif
else if(id.eq.IE+3) then
if(ran2(idum).lt.hospstay*dt) then
N(i)=IE+4
ig=iage(i)
fat(ig)=fat(ig)+1.0*death(ig)
cpeople below 70 go t0 ICU
cpeople above 70 die. i.e. approximate with deth bedor ICU
endif
else if(id.eq.IE+4) then
if(ran2(idum).lt.serious*dt) then
N(i)=IE+5
ig=iage(i)
fat(ig)=fat(ig)+0.*death(ig)
endif
endif
enddo
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c Main infection loop, done with
c propability=activity for each agent:
c
do 998 index=1,Nsize
c
c...... Agent infect specifically:
c...... do infections with probability = acts
c...... (and then chose person with prop actpers(i))
c
if(ran2(idum).lt.acts*helpfac) then
c...... chose a person to infect from
83 i=ran2(idum)*Nsize+1
ig=iage(i)
if(actpers(i).gt.1) write(6,*) 'wwwp'
c................actpers() is normalized to maximum, just chose
c................one agent here weighted with actpers()
if(ran2(idum).gt.actpers(i)) goto 83
id=N(i)
indc=0
c...... Need to be infectious
if(id.eq.IE+1.or.id.eq.IE.or.
q id.eq.IE-1.or.kstat.eq.1) then
c.................................................................
c
c loop in case agen i is a super spreader:
c
do 990 isuper=1,Nsuper(i)
if(ran2(idum)*Nsuper(i)*helpfac.lt.ssuper(i)) then
c in case of child>1 the children (ig=1,ig=2) is less infectious
if(ig.gt.2.or.child*ran2(idum).lt.1) then
85 j1=ran2(idum)*Kon(i)+1
j=K(i,j1)
if(ran2(idum).gt.SK(i,j1)) goto 85
jg=iage(j)
Kii=Kiden(i,j1)
c
c................Age profile, less active persons will be less infected
actsnorm=actsnorm+1
if(ran2(idum).gt.agescal(jg)) goto 991
actsremove=actsremove+1
c
c................Heterogenous agents, the minimum sets the interaction:
if(eta(j).lt.eta(i)) then
zzz=eta(j)/eta(i)
if(ran2(idum).gt.zzz) goto 991
endif
c................Disease state of agent j:
jd=N(j)
jg=iage(j)
if(jg.le.2.and.childinf*ran2(idum).gt.1) goto 991
if(Kiden(i,j1).eq.1) then
if(ran2(idum)*faminf0.gt.faminf) goto 991
endif
if(Kiden(i,j1).eq.2) then
if(ran2(idum)*grandpar0.gt.grandpar) goto 991
endif
if(Kiden(i,j1).eq.3) then
if(ran2(idum)*crosinf0.gt.crosinf) goto 991
endif
if(Kiden(i,j1).eq.4) then
if(ran2(idum)*workinf0.gt.workinf) goto 991
endif
if(Kiden(i,j1).eq.5) then
if(ran2(idum)*school0.gt.school) goto 991
endif
c................Sampling of Matrix of subgroup interactins:
if(Kii.eq.1) then
statgroup(1)=statgroup(1)+1
statsub(1,ig,jg)=statsub(1,ig,jg)+1
else if(Kii.eq.2) then
statgroup(2)=statgroup(2)+1
statsub(2,ig,jg)=statsub(2,ig,jg)+1
else if(Kii.eq.3) then
statgroup(3)=statgroup(3)+1
statsub(3,ig,jg)=statsub(3,ig,jg)+1
else if(Kii.eq.4) then
statgroup(4)=statgroup(4)+1
statsub(4,ig,jg)=statsub(4,ig,jg)+1
else if(Kii.eq.5) then
statgroup(5)=statgroup(5)+1
statsub(5,ig,jg)=statsub(5,ig,jg)+1
endif
c
c....................lock down/strategu simulation in special periods
c....................
sumspec=sumspec+1
statage(ig)=statage(ig)+1
statage(jg)=statage(jg)+1
statcross(ig,jg)=statcross(ig,jg)+1
if(isource(j).ne.i) then
infected0(i)=infected0(i)+1 !to measure R0
endif
c
if(jd.gt.0) then
if(attac.lt.0.05) then
if(Kii.eq.1) then
already=already+1
if(ifam(inum,0).eq.2) then
already2=already2+1
endif
endif
endif
endif
if(jd.eq.0) then
infected(i)=infected(i)+1 !to measure R
isource(j)=i
N(j)=1
itfirst(j)=it
isss=Nsuper(i)
c time from when i infected to subsequent infection
its(j)=it-itfirst(i)
ipointer(j)=i
sttac=sttac+1
x0sum=x0sum+1
xksum=xksum+Kon(j)
suminf=suminf+1
if(attac.lt.0.05) then
earlyinf=earlyinf+1
inum=jfam(i)
if(ifam(inum,0).eq.2) then
suminf2=suminf2+1
endif
if(Kii.eq.1) then
infectf=infectf+1
if(ifam(inum,0).eq.2) then
infectf2=infectf2+1
endif
else
noinfectf=noinfectf+1
endif
endif
if(Nsuper(i).gt.1) superinf=superinf+1
if(Nsuper(i).eq.1) baseinf=baseinf+1
endif
c this was end of infection
991 continue
endif
endif
990 continue
endif
endif
c
c...... Now agent ingfect publically:
c...... Do infections with probability=actu
if(ran2(idum).lt.helpfac*actu) then
if(actu.gt.1) write(6,*) 'wwwu'
c...... chose person to infect from (with prop eta*agescal)
84 i=ran2(idum)*Nsize+1
ig=iage(i)
c......
if(eta(i)*agescal(ig)/etamax.gt.1) write(6,*) 'uu'
if(ran2(idum)*etamax.gt.
q eta(i)*agescal(ig)) goto 84
id=N(i)
indc=0
c...... Need to be infecterous
if(id.eq.IE+1.or.id.eq.IE.or.
q id.eq.IE-1.or.kstat.eq.1) then
if(indc.eq.0) then
do 993 isuper=1,Nsuper(i)
if(ran2(idum)*Nsuper(i)*helpfac.lt.ssuper(i)) then
c................in case we have a child it may be less infectious
c (with factor ``child", when child>1):
if(ig.gt.2.or.child*ran2(idum).lt.1) then
c....................public infections (with age and quenched activity):
86 j=ran2(idum)*Nsize+1
jg=iage(j)
if(jg.le.2.and.childinf*ran2(idum).gt.1) goto 992
actunorm=actunorm+1
if(ran2(idum).gt.agescal(jg)) goto 992
if(eta(j).lt.eta(i)) then
zzz=eta(j)/eta(i)
if(ran2(idum).gt.zzz) goto 992
endif
acturemove=acturemove+1
sumunspec=sumunspec+1
statage(ig)=statage(ig)+1
statage(jg)=statage(jg)+1
statcross(ig,jg)=statcross(ig,jg)+1
statgroup(6)=statgroup(6)+1
statsub(6,ig,jg)=statsub(6,ig,jg)+1
jd=N(j)
if(isource(j).ne.i) infected0(i)=infected0(i)+1
if(jd.eq.0.or.kstat.eq.1) then
infected(i)=infected(i)+1
isource(j)=i
N(j)=1
isss=Nsuper(i)
nacc(isss)=nacc(isss)+1
itfirst(j)=it
its(j)=it-itfirst(i)
ipointer(j)=i
sttac=sttac+1
x0sum=x0sum+1
xksum=xksum+Kon(j)
suminf=suminf+1
if(attac.lt.0.05) then
earlyinf=earlyinf+1
inum=jfam(i)
if(ifam(inum,0).eq.2) then
suminf2=suminf2+1
endif
noinfectf=noinfectf+1
endif
if(Nsuper(i).gt.1) superinf=superinf+1
if(Nsuper(i).eq.1) baseinf=baseinf+1
endif
992 continue
endif
endif
993 continue
endif
endif
c end of quarentine
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
995 continue
endif
998 continue
c
c infections during timestep dt finished
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c
c.........statistics at time it*dt:
infect=0
infecf=1
attac=0
expos=0
karan=1
do ig=1,10
resp(ig)=0
sick(ig)=0
attack(ig)=0
enddo
do i=1,Nsize
ig=iage(i)
if(N(i).gt.0.and.N(i).le.IE) expos=expos+1
if(N(i).eq.IE+1.or.N(i).eq.IE+2) then
infect=infect+1
sick(ig)=sick(ig)+1
endif
if(N(i).eq.IE+4) then
c people that goes into ICU (stay there 12 days)
resp(ig)=resp(ig)+1
endif
if(N(i).eq.IE+1) then
infecf=infecf+1
endif
if(N(i).ge.IE+1) then
attac=attac+1
attack(ig)=attack(ig)+1
endif
enddo
sickfree=sickfree+infecf*dt
sickdays=sickdays+infect*dt
if(infect.gt.attacmax) then
iamax=it
attacmax=infect
endif
xksum=0
if(x0sum.gt.0) xksum=xksum/x0sum
Rnow=0
if(xsum.gt.0) Rnow=infsum/xsum
if(xsum0.gt.0) then
Rnow0=infsum0/xsum0
Vnow0=0.0
if(Rnow0.gt.0) then
Vnow0=(infsum00/xsum0-Rnow0**2)/Rnow0**2
endif
endif
c
c.........fraction of involved population in each age group:
Nsize9=Nsize/9
do ig=1,10
resp(ig)=resp(ig)/Nsize9
sick(ig)=sick(ig)/Nsize9
attack(ig)=attack(ig)/Nsize9
hos(ig)=hos(ig)/Nsize9
fat(ig)=fat(ig)/Nsize9
enddo
c
c.........Estimate of young sick people:
sickyoung=sick(1)*agecount(1)
q +sick(2)*agecount(2)
q +sick(3)*agecount(3)
attyoung=attack(1)*agecount(1)
q +attack(2)*agecount(2)
q +attack(3)*agecount(3)
attyoung=attyoung/(agecount(1)+agecount(2)+agecount(3))
c
c.........ICU weights from official norwegian model:
beds=0
sickall=0
hospinl=0
fatality=0
do ig=1,9
sickall=sickall+sick(ig)*agecount(ig)
beds=beds+resp(ig)*bedsicu(ig)*agecount(ig)
hospinl=hospinl+hos(ig)*agecount(ig)
fatality=fatality+fat(ig)*agecount(ig)
enddo
fatsum=fatsum+fatality
hospinl=hospinl/dt
fatality=fatality/dt
fatold=fatality
hosold=hospinl
if(beds.gt.bedsmax) bedsmax=beds
if(sickall.gt.sickmax) sickmax=sickall
if(hospmax.lt.hospinl) hospmax=hospinl
bedssum=bedssum+beds*dt
attac=attac/Nsize
sickold=sick(8)*agecount(8)+agecount(9)*sick(9)
sickold=sickold/(agecount(8)+agecount(9))
attold=attack(8)*agecount(8)+attack(9)*agecount(9)
attold=attold/(agecount(8)+agecount(9))
if(iparam.eq.1.and.kkkc.le.3) then
trajwww=(5*workinf+2*school)/(5*workinf0+2*school0)
trajooo=unspec/unspec0
write(6,125) it*dt,fatality,sickall,
q attac,sickyoung,sick(7),
q sickold,
q sickall,hospinl,beds,attyoung,
q trajwww,trajwww+trajooo,attold,
q Rnow,Rnow0,icon,Vnow0
itt=it*dt
trajw(itt)=(5*workinf+2*school)/(5*workinf0+2*school0)
trajoth(itt)=unspec/unspec0
endif
itt=it*dt
icontraj(itt)=icon
pop=5728769
trajech(itt)=trajech(itt)+hospinl*pop*dt
trajecicu(itt)=trajecicu(itt)+beds*pop*dt
trajsick(itt)=trajsick(itt)+sickall*pop*dt
trajdead(itt)=trajdead(itt)+fatality*pop*dt
c
c.........special testing for superspreaders
if(attac.gt.testlim.and.itest.eq.0) then
itest=1
sumh=0
do inum=Nschool+1,Nschool+Ncomp
infec=0
ipos=0
isum=0
c if(iwork(inum,0).gt.5.and.iwork(inum,0).le.15) then
if(iwork(inum,0).gt.0) then
do kk=1,iwork(inum,0)
i=iwork(inum,kk)
ig=iage(i)
id=N(i)
if(id.ge.IE-1.and.id.le.IE+2) infec=infec+1
if(id.ge.IE-1) ipos=ipos+1
isum=isum+1
enddo
endif
histw(isum)=histw(isum)+1
histinf(infec)=histinf(infec)+1
histpos(ipos)=histpos(ipos)+1
sumh=sumh+1
enddo
do ix=0,150
histw(ix)=histw(ix)/sumh
histinf(ix)=histinf(ix)/sumh
histpos(ix)=histpos(ix)/sumh
enddo
endif
c.........end statistics
c
c.........Oossibility to impose special rules
c when attac is large than som limit, and some
c time passed after that (here 30 days)
c
if(attac.gt.containlim1.and.icon.eq.0) then
c 3.5 million-->1.6million->2.1million work
c 1.3 million-->0 ->0.5million
c 4.8 million-->1.6million->2.6million
write(72,372) it*dt,attac,sickall
modellock1=it*dt
372 format('# t=',F8.1,' attac,sick=',2F9.4)
fudge=fudge0
fudges=fudges0
icon=1
tcount=0
unspec=unspec0*fudges
faminf=faminf0
workinf=workinf0*fudge !real data, 0.45
school=school0*fudge !real data, 0.0
grandpar=grandpar0*fudge
crosinf=crosinf0*fudge
actu=unspec*etaave*dt
acts=actpave*dt
xsum0=0
infsum0=0
do i=1,9
agescal(i)=agescal0(i)
enddo
c agescal(8)=agescal0(8)/10
c agescal(9)=agescal0(9)/10
endif
if(tcount.gt.tcountlim1.and.icon.eq.1) then
write(72,372) it*dt,attac,sickall
fudge=fudge0
fudges=fudges0
icon=2
unspec=unspec0*fudges
faminf=faminf0
workinf=workinf0*fudge !*0.60 !real data, physical work fraction in april
school=school0*fudge !*0.45
grandpar=grandpar0*fudge
crosinf=crosinf0*fudge
actu=unspec*etaave*dt
acts=actpave*dt
xsum0=0
infsum0=0
do i=1,9
agescal(i)=agescal0(i)
enddo
c agescal(8)=agescal0(8)/10
c agescal(9)=agescal0(9)/10
endif
if(tcount.gt.tcountlim2.and.icon.eq.2) then
write(72,372) it*dt,attac,sickall
fudge=fudge0
fudges=fudges0
icon=3
unspec=unspec0*fudges
faminf=faminf0
workinf=workinf0*fudge
school=school0*fudge
grandpar=grandpar0*fudge
crosinf=crosinf0*fudge
actu=unspec*etaave*dt
acts=actpave*dt
xsum0=0
infsum0=0
do i=1,9
agescal(i)=agescal0(i)
enddo
endif
if(tcount.gt.tcountlim3.and.icon.eq.3) then
write(72,372) it*dt,attac,sickall
fudge=fudge0
fudges=1
icon=4
unspec=unspec0*fudges
faminf=faminf0
workinf=workinf0*fudge
school=school0*fudge
grandpar=grandpar0*fudge
crosinf=crosinf0*fudge
actu=unspec*etaave*dt
acts=actpave*dt
xsum0=0
infsum0=0
do i=1,9
agescal(i)=agescal0(i)
enddo
endif
tcount=tcount+dt
999 continue
125 format(' ',F7.2,F10.7,6F9.6,2F12.8,F11.5,3F8.5,
q 2F6.2,I2,2F8.4)
126 format('# Attac fraction=',F9.4,
q ' max number in IE+1,IE+2=',F9.4,
q ' # max ICU beds=',F10.6,
q ' total ICU bed days=',F9.6,
q ' indl=',F9.6,' Death=',2F9.6)
acturemove=acturemove/actunorm
actsremove=actsremove/actsnorm
weightx=(actu*acturemove+acts*actsremove)
weightr=5.5*(actu*acturemove+acts*actsremove)/dt
weights=(actu*acturemove+acts*actsremove)/(acts+actu)
timeinf=1/delta+1/gamma(IE)+1/gamma(IE-1)
write(72,168) acturemove,actsremove,weightx,
q weightr,weightr/beta0,weights,
q timeinf,dt
168 format('# removal factors: actu,acts=',2F7.3,
q ' weights=',2F8.3,' weight/beta0=',
q F8.3,' chance to remove=',F8.3,' tinf=',2F6.2)
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c distribution of latency times:
if(kkkc.eq.0) then
xserial=0
do j=1,Nsize
i=ipointer(j)
if(i.gt.0) then
jdif=istart(j)-istart(i)
tserial(jdif)=tserial(jdif)+1
xserial=xserial+1
endif
enddo
xtime=0.1
atime=0
stime=0.1
xstime=0
ctime=0.1
astime=0
do i=-10000,10000
ts(i)=0
enddo
sum=0.01