-
Notifications
You must be signed in to change notification settings - Fork 0
/
WPB_Submission.F90
4234 lines (3773 loc) · 147 KB
/
WPB_Submission.F90
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
!####################LICENSING#######################################################
!All code here in is distributed under an OSS License © 2022.
!Triad National Security, LLC. All rights reserved. This program
!was produced under U.S. Government contract 89233218CNA000001
!for Los Alamos National Laboratory (LANL), which is operated by
!Triad National Security, LLC for the U.S. Department of
!Energy/National Nuclear Security Administration. All rights
!in the program are reserved by Triad National Security, LLC,
!and the U.S. Department of Energy/National Nuclear Security
!Administration. The Government is granted for itself and others
!acting on its behalf a nonexclusive, paid-up, irrevocable worldwide
!license in this material to reproduce, prepare derivative works,
!distribute copies to the public, perform publicly and display
!publicly, and to permit others to do so.
!And a BSD license: This program is open source under the BSD-3
!License. Redistribution and use in source and binary forms, with
!or without modification, are permitted provided that the following
!conditions are met:
! 1.Redistributions of source code must retain the above copyright
!notice, this list of conditions and the following disclaimer.
!
! 2.Redistributions in binary form must reproduce the above
!copyright notice, this list of conditions and the following
!disclaimer in the documentation and/or other materials provided
! with the distribution.
! 3.Neither the name of the copyright holder
!nor the names of its contributors may be used to endorse or promote
!products derived from this software without specific prior written
!permission.
!THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
!"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
!LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
!FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
!COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
!INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
!BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
!LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
!CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
!LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
!ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
!POSSIBILITY OF SUCH DAMAGE.
! ########################End#########################################################
!Part of the IMAP-TDIA Code Base: Zachary Robbins and Chonggang Xu
! This is the fortran implementation of the IMAP and TDIA model for the western pine beetle
! as was implemented in the paper "Warming increased bark beetle mortality
! by thirty percent during an extreme drought in California"
! This was authored by Zachary Robbins and Chonggang Xu.
! This is modified from the original IMAP code authored by Devin W. Goodsman, while he was a postdoctoral researcher at
! LANL (2017-2018) except for the subroutines for fast Fourier transformations, which were
! written by Paul Swarztrauber, and the subroutines for the incomplete beta function, which
! I modified from the reference below.
!********************************************************
!* Reference: *
!* "Numerical Recipes, By W.H. Press, B.P. Flannery, *
!* S.A. Teukolsky and T. Vetterling, Cambridge *
!* University Press, 1986" [BIBLI 08]. *
!* *
!* I have refactored the incopmplete beta function code *
!* such that the functions become subroutines *
!* (Goodsman, D.W. Oct. 2, 2018). I converted these to *
!* subroutines to more easily call them from R and to *
!* more consistently call them within other Fortran *
!* programs that are subroutine-based. *
!********************************************************
! To host fortran code as a function set with python 3.x
! Ensure the numpy is installed, as is mingw64 (or similar fortran compiler_)
! This might require some path setting see https://stackoverflow.com/questions/48826283/compile-fortran-module-with-f2py-and-python-3-6-on-windows-10
! Use the following function in the python console C:\Users\username >f2py -c WPB_submission.F90 -m WPB_Module
! Load into python using traditional module loading format
! eg:
! import WPB_Module as WPB
! This is the main do loop for the length of the model run (Temperature vector -1). It handles the model set up in preparation to run
! BeetleSim which does the work of growing beetles and attacking trees.
subroutine BeetleFit(Length,Tminvec, Tmaxvec,r1,x0,x1,CWDvec,x2,SizeFactor,NtGEQ317,NtGEQ00,Tparents,NGEQ20vec,NGEQ00vec,&
FebInPopnvec,Fecoutvec, Eoutvec, L1outvec, L2outvec, Poutvec, Teoutvec, Aoutvec)
implicit none
Interface
subroutine BeetleSim(Tmax, Tmin,TminNext, Parents, FA, OE, OL1, OL2, &
NewParentstm1, OPare, Pare, ActiveParents, &
OL3, OL4, OP, OT, NewEggstm1, NewL1tm1, &
NewL2tm1, NewL3tm1, NewL4tm1, NewPtm1, NewTtm1, &
Fec, E, L1, L2, L3, L4, P, Te, A, ColdestT, &
NtGEQ317,NtGEQ00, Bt,r1,x0,x1,CWD,x2,SizeFactor,FebInPopn,&
Fecout, Eout, L1out, L2out, Pout, Teout, Aout,Flyout,EndMPBPopn,BigTreesOut,SmallTreesOut)
real(kind = 8), intent(in) :: Tmax
real(kind = 8), intent(in) :: Tmin
real(kind = 8), intent(in) :: TminNext
real(kind = 8), intent(inout) :: Parents
real(kind = 8), intent(out) :: FA
real(kind = 8), intent(in) :: CWD ! The Current Climatic water deficit
complex(kind = 8), intent(inout) :: OE(2**8)
complex(kind = 8), intent(inout) :: OL1(2**8)
complex(kind = 8), intent(inout) :: OL2(2**8)
complex(kind = 8), intent(inout) :: OL3(2**8)
complex(kind = 8), intent(inout) :: OL4(2**8)
complex(kind = 8), intent(inout) :: OP(2**8)
complex(kind = 8), intent(inout) :: OT(2**8)
complex(kind = 8), intent(inout) :: OPare(2**8)
real(kind = 8), intent(inout) :: NewParentstm1
real(kind = 8), intent(inout) :: NewEggstm1
real(kind = 8), intent(inout) :: NewL1tm1
real(kind = 8), intent(inout) :: NewL2tm1
real(kind = 8), intent(inout) :: NewL3tm1
real(kind = 8), intent(inout) :: NewL4tm1
real(kind = 8), intent(inout) :: NewPtm1
real(kind = 8), intent(inout) :: NewTtm1
real(kind = 8), intent(inout) :: NtGEQ317
real(kind = 8), intent(inout) :: NtGEQ00
real(kind = 8), intent(inout) :: Fec
real(kind = 8), intent(inout) :: ActiveParents
real(kind = 8), intent(inout) :: Pare
real(kind = 8), intent(inout) :: E
real(kind = 8), intent(inout) :: L1
real(kind = 8), intent(inout) :: L2
real(kind = 8), intent(inout) :: L3
real(kind = 8), intent(inout) :: L4
real(kind = 8), intent(inout) :: P
real(kind = 8), intent(inout) :: Te
real(kind = 8), intent(inout) :: A
real(kind = 8), intent(in) :: ColdestT
real(kind = 8), intent(out) :: Fecout
real(kind = 8), intent(out) :: Eout
real(kind = 8), intent(out) :: L1out
real(kind = 8), intent(out) :: L2out
real(kind = 8), intent(out) :: Pout
real(kind = 8), intent(out) :: Teout
real(kind = 8), intent(out) :: Aout
real(kind = 8), intent(out) :: Flyout
real(kind = 8), intent(inout) :: Bt
real(kind = 8), intent(in) :: r1 ! controls beetle clustering
real(kind = 8), intent(in) :: x0 ! The intercept on attack
real(kind = 8), intent(in) :: x1 ! x1 controls the impact CWD
real(kind = 8), intent(in) :: x2 ! x2 controls the impact of size class
real(kind = 8), intent(in) :: SizeFactor
real(kind = 8), intent(in) :: FebInPopn
real(kind = 8), intent(in) :: EndMPBPopn
real(kind = 8), intent(out) :: BigTreesOut
real(kind = 8), intent(out) :: SmallTreesOut
end subroutine BeetleSim
End Interface
! Here are the input and output variables and parameters for the main subroutine above.
! Each of the arrays is the same length as the daily temperature time series.
integer(kind = 4), intent(in) ::Length
real(kind = 8), intent(in) :: Tminvec(Length)
real(kind = 8), intent(in) :: Tmaxvec(Length)
real(kind = 8), intent(in) :: CWDvec(Length)
real(kind = 8), intent(inout) :: NtGEQ317
real(kind = 8), intent(inout) :: NtGEQ00
real(kind = 8), intent(inout) :: Tparents !Initial Conditions parents
real(kind = 8), intent(inout) :: r1 ! controls beetle clustering
real(kind = 8), intent(in) :: x0 ! The intercept on attack
real(kind = 8), intent(in) :: x1 ! x1 controls the impact CWD
real(kind = 8), intent(in) :: x2 ! x2 controls the impact of size class
real(kind = 8), intent(in) :: SizeFactor ! x2 controls the impact of size class
!real(kind = 8), intent(inout) ::NtGEQ20
real(kind = 8), intent(out) :: NGEQ20vec(Length)
real(kind =8), intent(out) :: NGEQ00vec(Length)
real(kind = 8), intent(out) :: FebInPopnvec(Length)
real(kind = 8), intent(out) :: Fecoutvec (Length)
real(kind =8), intent(out) :: Eoutvec (Length)
real(kind = 8), intent(out) :: L1outvec(Length)
real(kind = 8), intent(out) :: L2outvec (Length)
real(kind =8), intent(out) :: Poutvec (Length)
real(kind = 8), intent(out) :: Teoutvec(Length)
real(kind = 8), intent(out) :: Aoutvec (Length)
real(kind = 8) :: EndMPBPopn
real(kind = 8) :: FebInPopn
! Here are the internal parameters and variables for the MPBSim subroutine
real(kind = 8) :: Tmax
real(kind = 8) :: Tmin
real(kind = 8) :: TminNext
real(kind = 8) :: Parents
real(kind = 8) :: CWD ! The Current Climatic water deficit
real(kind = 8) :: FA
! Containers for the distributions of physiological age for each life stage
complex(kind = 8) :: OE(2**8)
complex(kind = 8) :: OL1(2**8)
complex(kind = 8) :: OL2(2**8)
complex(kind = 8) :: OL3(2**8)
complex(kind = 8) :: OL4(2**8)
complex(kind = 8) :: OP(2**8)
complex(kind = 8) :: OT(2**8)
complex(kind = 8) :: OPare(2**8)
real(kind = 8) :: BigTreesOut
real(kind = 8) :: SmallTreesOut
real(kind = 8) :: NewParentstm1
real(kind = 8) :: NewEggstm1
real(kind = 8) :: NewL1tm1
real(kind = 8) :: NewL2tm1
real(kind = 8) :: NewL3tm1
real(kind = 8) :: NewL4tm1
real(kind = 8) :: NewPtm1
real(kind = 8) :: NewTtm1
real(kind = 8) :: ActiveParents
real(kind = 8) :: Pare
real(kind = 8) :: Fec ! the expected number of pre-eggs at each time
real(kind = 8) :: E ! the expected number of eggs at each time
real(kind = 8) :: L1 ! the expected number of L1 at each time step
real(kind = 8) :: L2 ! the expected number of L2 at each time step
real(kind = 8) :: L3 ! the expected number of L3 at each time step
real(kind = 8) :: L4 ! the expected number of L4 at each time step
real(kind = 8) :: P ! the expected number of pupae at each time step
real(kind = 8) :: Te ! the expected number of tenerals at each time step
real(kind = 8) :: A ! the expected number of flying adults at each time step
real(kind = 8) :: Fecout ! the expected number of pre-eggs at each time
real(kind = 8) :: Eout
real(kind = 8) :: L1out
real(kind = 8):: L2out
real(kind = 8) :: Pout
real(kind = 8):: Teout
real(kind = 8):: Aout
real(kind = 8):: Flyout
integer(kind = 4):: TrueLength
! Winter mortality is a function of the coldest temperature to date.
real(kind = 8) :: ColdestT
real(kind = 8) :: Bt ! cumulative attacking beetles
integer(kind = 4) :: i ! iterator
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! All of the life stages must be initialized
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Opare =0.0
NewParentstm1 = 0.0
! Initializing the eggs
OE = 0.0
NewEggstm1 = 0.0
! Initializing the L1 larvae
OL1 = 0.0
NewL1tm1 = 0.0
! Initializing the L2 larvae
OL2 = 0.0
NewL2tm1 = 0.0
! Initializing the L3 larvae
OL3 = 0.0
NewL3tm1 = 0.0
! Initializing the L4 larvae
OL4 = 0.0
NewL4tm1 = 0.0
! Initializing the pupae
OP = 0.0
NewPtm1 = 0.0
! Initializing the teneral adults
OT = 0.0
NewTtm1 = 0.0
! Initializing the first element of each container
Fec = 0.0
E = 0.0
L1 = 0.0
L2 = 0.0
L3 = 0.0
L4 = 0.0
P = 0.0
Te = 0.0
A = 0.0
FA = 0.0
Bt = 0.0
! The number of initial parents equals the endemic reset.
EndMPBPopn = Tparents
NGEQ20vec(1) = NtGEQ317
NGEQ00vec(1) = NtGEQ00
FebInPopn = 0.0
ColdestT = 15.0
! The true length of the simulation is reduced by one as the each days temperature
! is calculated using that day and the next.
TrueLength=Length-1
do i = 2,TrueLength
Tmax = Tmaxvec(i)
Tmin = Tminvec(i)
TminNext=Tminvec(i+1)
CWD = CWDvec(i)
if(Tmin < ColdestT)then
ColdestT = Tmin
end if
!Computing the insect population on the initialization of the current year (October 15th).
! This resets the base population in the event of collapse
if(i== 1 .or. i == 1+365 .or. i == 1+2*365 .or. i == 1+3*365 .or. &
i == 1+4*365 .or. i == 1+5*365 .or. i == 1+6*365 .or. &
i == 1+7*365 .or. i == 1+8*365 .or. i == 1+9*365 .or. &
i == 1+10*365 .or. i == 1+11*365 .or. i == 1+12*365 .or. &
i == 1+13*365 .or. i == 1+14*365 .or. i == 1+15*365 .or. i == 1+16*365 .or. &
i == 1+17*365) then
FebInPopn = Fec + E + (L1 + L2 )/(1.0 + exp(-(ColdestT + 29.22791)/2.0)) + P + Te + A
end if
! If the total insect population on October 15th (ignoring leap years) of the year is less than
! the endemic population, we re-establish an endemic population level in October of the current year.
if(i == 2 + 365 .or. i == 2 + 2*365 .or. i == 2 + 3*365 .or. &
i == 2 + 4*365 .or. i == 2 + 5*365 .or. i == 2 + 6*365 .or. &
i == 2 + 7*365 .or. i == 2 + 8*365 .or. i == 2 + 9*365 .or. &
i == 2 + 10*365 .or. i == 2 + 11*365 .or. i == 2 + 12*365 .or. &
i == 2+13*365 .or. i == 2+14*365 .or. i == 2+15*365 .or. i == 2+16*365 .or. &
i == 2+17*365) then
if(FebInPopn < EndMPBPopn)then
Parents =EndMPBPopn
end if
end if
! On April 1st we reset the coldest temperature to date to 15.0 degrees Celsius
if(i == 184 + 365 .or. i == 184 + 2*365 .or. i == 184 + 3*365 .or. &
i == 184 + 4*365 .or. i == 184 + 5*365 .or. i == 184 + 6*365 .or. &
i == 184+ 7*365 .or. i == 184+ 8*365 .or. i == 184 + 9*365 .or. &
i == 184 + 10*365 .or. i == 184 + 11*365 .or. i == 184 + 12*365 .or. &
i == 184+13*365 .or. i == 184+14*365 .or. i == 184+15*365 .or. i == 184 +16*365 .or. &
i == 184+17*365) then
ColdestT = 15.0
end if
! On December 1 we reset the Adults and Teneral Adults to make sure there
! Populations don't live longer than expected.
if(i == 60 + 365 .or. i == 60 + 2*365 .or. i == 60 + 3*365 .or. &
i == 60 + 4*365 .or. i == 60 + 5*365 .or. i == 60+ 6*365 .or. &
i == 60 + 7*365 .or. i == 60 + 8*365 .or. i == 60+ 9*365 .or. &
i == 60 + 10*365 .or. i == 60 + 11*365 .or. i == 60+ 12*365 .or. &
i == 60+13*365 .or. i == 60 +14*365 .or. i == 60+15*365 .or. i == 60+16*365 .or. &
i == 60+17*365) then
A=0
TE=0
Bt = 0.0
FA = 0.0
end if
! I use a uniform distribution of the total number of parents for seven days
! to initialized the model.
if(i <= 7)then
ActiveParents = TParents/7
end if
! Now calling the full MPB simulation for the time step.
call BeetleSim(Tmax, Tmin,TminNext, Parents, FA, OE, OL1, OL2, &
NewParentstm1, OPare, Pare, ActiveParents, &
OL3, OL4, OP, OT, NewEggstm1, NewL1tm1, &
NewL2tm1, NewL3tm1, NewL4tm1, NewPtm1, NewTtm1, &
Fec, E, L1, L2, L3, L4, P, Te, A, ColdestT, &
NtGEQ317,NtGEQ00, Bt,r1,x0,x1,CWD,x2,SizeFactor,FebInPopn,&
Fecout, Eout, L1out, L2out,Pout, Teout, Aout,Flyout,EndMPBPopn,BigTreesOut,SmallTreesOut)
!Update the number of trees.
NtGEQ317= BigTreesOut
NtGEQ00= SmallTreesOut
! This will update E, L1, L2, L3, L4, P, Te, A, and FA
! as well as all of the physiological age arrays and
! scalars for individuals transitioning from one stage to
! another.
! These are the diagnostic outputs
NGEQ20vec(i) = BigTreesOut
NGEQ00vec(i) = SmallTreesOut
FebInPopnvec(i)=Flyout
Fecoutvec(i)= Fecout
Eoutvec(i)=Eout
L1outvec(i)=L1out
L2outvec(i)=L2out
Poutvec(i)=Pout
Teoutvec(i)=Teout
Aoutvec(i)=Aout
end do
End subroutine BeetleFit
!========================================================================================
Subroutine BeetleSim(Tmax, Tmin,TminNext, Parents, FA, OE, OL1, OL2, &
NewParentstm1, OPare, Pare, ActiveParents, &
OL3, OL4, OP, OT, NewEggstm1, NewL1tm1, &
NewL2tm1, NewL3tm1, NewL4tm1, NewPtm1, NewTtm1, &
Fec, E, L1, L2, L3, L4, P, Te, A, ColdestT, &
NtGEQ317,NtGEQ00, Bt,r1,x0,x1,CWD,x2,SizeFactor,FebInPopn,&
Fecout, Eout, L1out, L2out, Pout, Teout, Aout,Flyout, EndMPBPopn,BigTreesOut,SmallTreesOut)
! This subroutine simulates the demographic processes
! of the mountain pine beetle for a single time step including
! oviposition, the egg stage, the four larval instars,
! the pupal stage, the teneral adult stage,
! the adult stage, the flying adult stage, and then attack.
implicit none
! The subroutine calls the following subroutines.
Interface
subroutine Ovipos(Fec, Parents, med, Tmn2, NewEggs)
real(kind = 8), intent(inout) :: Fec
real(kind = 8), intent(in) :: Parents
real(kind = 8), intent(in) :: med
real(kind = 8), intent(in) :: Tmn2
real(kind = 8), intent(out) :: NewEggs
end subroutine Ovipos
subroutine EPTDev(n, avec, med, mu, sigma, Tmn2, NewEPT, NewEPTtm1, OEPT, EPTcurrent, NewNext)
integer(kind = 4), intent(in) :: n
real(kind = 8), intent(in) :: avec(n)
real(kind = 8), intent(in) :: med
real(kind = 8), intent(in) :: mu
real(kind = 8), intent(in) :: sigma
real(kind = 8), intent(in) :: Tmn2
real(kind = 8), intent(in) :: NewEPT
real(kind = 8), intent(inout) :: NewEPTtm1
complex(kind = 8), intent(inout) :: OEPT(n)
real(kind = 8), intent(out) :: EPTcurrent
real(kind = 8), intent(out) :: NewNext
end subroutine
subroutine LarvDev(n, avec, med, mu, sigma, NewL, NewLtm1, OL, Lcurrent, NewNext)
integer(kind = 4), intent(in) :: n
real(kind = 8), intent(in) :: avec(n)
real(kind = 8), intent(in) :: med
real(kind = 8), intent(in) :: mu
real(kind = 8), intent(in) :: sigma
real(kind = 8), intent(in) :: NewL
real(kind = 8), intent(inout) :: NewLtm1
complex(kind = 8), intent(inout) :: OL(n)
real(kind = 8), intent(out) :: Lcurrent
real(kind = 8), intent(out) :: NewNext
end subroutine
subroutine AdSR(NewA, Tmn2, Tmx2, Adtm1, FA)
real(kind = 8), intent(in) :: NewA
real(kind = 8), intent(in) :: Tmn2
real(kind = 8), intent(in) :: Tmx2
real(kind = 8), intent(inout) :: Adtm1
real(kind = 8), intent(out) :: FA
end subroutine
Subroutine ConvolveSR(ItemA, ItemB, AconvB)
complex(kind = 8), intent(in) :: ItemA(:)
complex(kind = 8), intent(in) :: ItemB(:)
complex(kind = 8), intent(out) :: AconvB(:)
End Subroutine ConvolveSR
Subroutine LnormPDF(x, mulog, sigmalog, PDF)
real(kind = 8), intent(in) :: x(:)
real(kind = 8), intent(in) :: mulog
real(kind = 8), intent(in) :: sigmalog
complex(kind = 8), intent(out) :: PDF(:)
End Subroutine LnormPDF
subroutine RegniereFunc(TC, TB, DeltaB, TM, DeltaM, omega, psi, DevR)
real(kind = 8), intent(in) :: TC
real(kind = 8), intent(in) :: TB
real(kind = 8), intent(in) :: DeltaB
real(kind = 8), intent(in) :: TM
real(kind = 8), intent(in) :: DeltaM
real(kind = 8), intent(in) :: omega
real(kind = 8), intent(in) :: psi
real(kind = 8), intent(out) :: DevR
end subroutine RegniereFunc
subroutine FlightFunc(TC, Flying)
real(kind = 8), intent(in) :: TC
real(kind = 8), intent(out) :: Flying
end subroutine
subroutine BeetleAttack(NtGEQ317,NtGEQ00, Bt, FA, Parents, &
r1,x0,x1,CWD,x2, SizeFactor,FebInPopn, EndMPBPopn,BigTreesOut,SmallTreesOut)
real(kind = 8), intent(in) :: NtGEQ317
real(kind = 8), intent(in) :: NtGEQ00
real(kind = 8), intent(inout) :: Bt
real(kind = 8), intent(in) :: FA
real(kind = 8), intent(out) :: Parents
real(kind = 8), intent(out) :: BigTreesOut
real(kind = 8), intent(out) :: SmallTreesOut
real(kind = 8), intent(in) ::x0 ! The intercept on attack
real(kind = 8), intent(in) ::CWD ! The Current Climatic water deficit
real(kind = 8), intent(in) ::x1 ! x1 controls the impact CWD
real(kind = 8), intent(in) ::x2 ! x2 controls the impact of size class
real(kind = 8), intent(in) ::SizeFactor
real(kind = 8), intent(in) :: r1
real(kind = 8), intent(in) :: FebInPopn
real(kind = 8), intent(in) :: EndMPBPopn
end subroutine BeetleAttack
subroutine BETAISR(A, B, X, Y)
real(kind = 8), intent(in) :: A
real(kind = 8), intent(in) :: B
real(kind = 8), intent(in) :: X
real(kind = 8), intent(out) :: Y
end subroutine BETAISR
subroutine BETACFSR(A, B, X, Z)
real(kind = 8), intent(in) :: A
real(kind = 8), intent(in) :: B
real(kind = 8), intent(in) :: X
real(kind = 8), intent(out) :: Z
end subroutine BETACFSR
subroutine GAMMLNSR(XX, YY)
real(kind = 8), intent(in) :: XX
real(kind = 8), intent(out) :: YY
end subroutine GAMMLNSR
End Interface
! Here are the input and output variables
real(kind = 8), intent(in) :: Tmax
real(kind = 8), intent(in) :: Tmin
real(kind = 8), intent(in) :: TminNext
real(kind = 8), intent(inout) :: Parents
real(kind = 8), intent(out) :: FA
complex(kind = 8), intent(inout) :: OE(2**8)
complex(kind = 8), intent(inout) :: OL1(2**8)
complex(kind = 8), intent(inout) :: OL2(2**8)
complex(kind = 8), intent(inout) :: OL3(2**8)
complex(kind = 8), intent(inout) :: OL4(2**8)
complex(kind = 8), intent(inout) :: OP(2**8)
complex(kind = 8), intent(inout) :: OT(2**8)
complex(kind = 8), intent(inout) :: OPare(2**8)
real(kind = 8), intent(inout) :: NewParentstm1
real(kind = 8), intent(inout) :: NewEggstm1
real(kind = 8), intent(inout) :: NewL1tm1
real(kind = 8), intent(inout) :: NewL2tm1
real(kind = 8), intent(inout) :: NewL3tm1
real(kind = 8), intent(inout) :: NewL4tm1
real(kind = 8), intent(inout) :: NewPtm1
real(kind = 8), intent(inout) :: NewTtm1
real(kind = 8), intent(inout) ::Pare
real(kind = 8), intent(inout) :: Fec ! the expected number of pre-eggs at each time
real(kind = 8), intent(out) :: Fecout ! the expected number of pre-eggs at each time
real(kind = 8), intent(inout) :: E ! the expected number of eggs at each time
real(kind = 8), intent(out) :: Eout
real(kind = 8), intent(inout) :: L1 ! the expected number of L1 at each time step
real(kind = 8), intent(out) :: L1out
real(kind = 8), intent(inout) :: L2 ! the expected number of L2 at each time step
real(kind = 8), intent(out) :: L2out
real(kind = 8), intent(inout) :: L3 ! the expected number of L2 at each time step
real(kind = 8), intent(inout) :: L4 ! the expected number of L2 at each time step
real(kind = 8), intent(inout) :: P ! the expected number of pupae at each time step
real(kind = 8), intent(out) :: Pout
real(kind = 8), intent(inout) :: Te ! the expected number of tenerals at each time step
real(kind = 8), intent(out) :: Teout
real(kind = 8), intent(inout) :: A ! the expected number of flying adults at each time step
real(kind = 8), intent(out) :: Aout
real(kind = 8), intent(inout) :: ActiveParents
real(kind = 8), intent(out) ::Flyout
real(kind = 8), intent(out) :: BigTreesOut
real(kind = 8), intent(out) :: SmallTreesOut
! The smallest probability of larval winter survival as a function of the lowest temperature to date.
real(kind = 8), intent(in) :: ColdestT
real(kind = 8), parameter :: medA = .125
real(kind = 8), parameter :: sigmaA = .01
real(kind = 8) :: muA ! mean of the log transformed random development rate in egg stage
! input and output variables
real(kind = 8), intent(inout) :: NtGEQ317 ! initial susceptible host trees in the >31.7+ cm dbh size class
real(kind = 8), intent(inout) :: NtGEQ00 ! initial susceptible host trees in the <31.7+ cm dbh size class
real(kind = 8), intent(inout) :: Bt ! beetles that remain in flight from the previous step
! input parameters
real(kind = 8), intent(in) :: r1 ! controls beetle clustering
real(kind = 8), intent(in) ::x0 ! The intercept on attack
real(kind = 8), intent(in) ::CWD ! The Current Climatic water deficit
real(kind = 8), intent(in) ::x1 ! x1 controls the impact CWD
real(kind = 8), intent(in) ::x2 ! x2 controls the impact of size class4
real(kind= 8), intent (in) ::SizeFactor
real(kind = 8), intent(in) :: FebInPopn ! February insect population
real(kind = 8), intent(in) :: EndMPBPopn ! endemic mountain pine beetle population
!---------------------------------------------------------------------------------
! All of the parameters below are internal parameters (internal to the subroutine)
! iterator
integer(kind = 4) :: j
! Defining the time step (1 day)
real(kind = 8), parameter :: deltat = 1.0 ! units are days
! These are the temperature-development parameter for each life stage
! parameters for oviposition rate
real(kind = 8), parameter :: sigma0 = 0.2458 ! controls rate variability
real(kind = 8), parameter :: TB0 = 7.750 ! base temperature in degrees C
real(kind = 8), parameter :: DeltaB0 = 10000
real(kind = 8), parameter :: TM0 = 34.887 ! max temperature in degree C
real(kind = 8), parameter :: DeltaM0 = 2.0
real(kind = 8), parameter :: omega0 = .0085
real(kind = 8), parameter :: psi0 = 0.013
! parameters for development rate for eggs
real(kind = 8), parameter :: sigma1=.3
real(kind = 8), parameter :: Rmax1=0.187
real(kind = 8), parameter :: Tmax1=34.741
real(kind = 8), parameter :: Tmin1= 7.267
real(kind = 8), parameter :: k1= 1056.233
real(kind = 8), parameter :: dm1 = 7.588
! parameters for development rate for larvae
real(kind = 8), parameter :: sigma2=.3
real(kind = 8), parameter :: Rmax2=.038
real(kind = 8), parameter :: VTmx2=34.701
real(kind = 8), parameter :: VTmn2= 5.167
real(kind = 8), parameter :: k2= 766.410
real(kind = 8), parameter :: dm2 = 7.566
! parameters for development rate for Prepupae
real(kind = 8), parameter :: sigma3=.3
real(kind = 8), parameter :: Rmax3=0.231
real(kind = 8), parameter :: VTmx3=37.599
real(kind = 8), parameter :: VTmn3= 4.30
real(kind = 8), parameter :: k3= 431.000
real(kind = 8), parameter :: dm3 = 11.30
! parameters for development rate for Pupae
real(kind = 8), parameter ::sigma4=.3
real(kind = 8), parameter :: Rmax4=.062
real(kind = 8), parameter :: VTmx4=31.528
real(kind = 8), parameter :: VTmn4= 5.840
real(kind = 8), parameter :: k4= 203.096
real(kind = 8), parameter :: dm4 = 10.016
! parameters for development rate for TA
real(kind = 8), parameter :: sigma5=.3
real(kind = 8), parameter :: Rmax5=.01568408
real(kind = 8), parameter :: VTmx5=50.8
real(kind = 8), parameter :: VTmn5= -0.002603655
real(kind = 8), parameter :: k5= -0.003262513
real(kind = 8), parameter :: dm5 = 0.0005461579
! Here are variables to hold the buffered under bark temperatures
real(kind = 8) :: Tmean ! mean temperature at each time step in degrees Celcius
real(kind = 8) :: Tmin2 ! the buffered under-bark minimum temperature
real(kind = 8) :: Tmax2 ! the warmer under bark maximum temperature
real(kind = 8) :: Tmeanall
! Variables that relate to the domain of the lognormal distribution
integer(kind = 4), parameter :: n = 2**8 ! input variable. Must be specified
real(kind = 8), parameter :: Mx = 2.0
real(kind = 8), parameter :: Mn = 1.0e-20
real(kind = 8), parameter :: da = (Mx - Mn)/(2.0**8.0)
real(kind = 8) :: avec(n) = (/(Mn + j*da, j=0,n-1)/) ! vector defining the domain
! parameters that change with each iteration
! The median parameters are calculated for each of 8 periods within the day then summed to
! caluclate the daily rate of development.
! Each stage will calculate t1-t8
real(kind = 8) :: med0 ! median development rate in the pre-egg stage
real(kind = 8) :: med1 ! median development rate in egg stage
real(kind = 8) :: med2 ! median development rate in L1 stage
real(kind = 8) :: med3 ! median development rate in L2 stage
real(kind = 8) :: med4 ! median development rate in L3 stage
real(kind = 8) :: med5 ! median development rate in L4 stage
real(kind = 8) :: med6 ! median development rate in Pupa stage
real(kind = 8) :: med7 ! median development rate in teneral adult stage
real(kind = 8) :: mu1 ! mean of the log transformed random development rate in egg stage
real(kind = 8) :: mu2 ! mean of the log transformed random development rate in L1 stage
real(kind = 8) :: mu3 ! mean of the log transformed random development rate in L2 stage
real(kind = 8) :: mu4 ! mean of the log transformed random development rate in L3 stage
real(kind = 8) :: mu5 ! mean of the log transformed random development rate in L4 stage
real(kind = 8) :: mu6 ! mean of the log transformed random development rate in Pupa stage
real(kind = 8) :: mu7 ! mean of the log transformed random development rate in teneral adult stage
real(kind = 8) :: med0t1 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t1 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t1 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t1 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t1 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t1 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t1 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t1 !Transfer median development rate in teneral adult stage
real(kind = 8) :: med0t2 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t2 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t2 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t2 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t2 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t2 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t2 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t2 !Transfer median development rate in teneral adult stage
real(kind = 8) :: med0t3 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t3 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t3 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t3 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t3 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t3 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t3 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t3 !Transfer median development rate in teneral adult stage
real(kind = 8) :: med0t4 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t4 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t4 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t4 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t4 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t4 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t4 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t4 !Transfer median development rate in teneral adult stage
real(kind = 8) :: med0t5 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t5 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t5 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t5 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t5 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t5 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t5 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t5 !Transfer median development rate in teneral adult stage
real(kind = 8) :: med0t6 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t6 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t6 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t6 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t6 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t6 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t6 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t6 !Transfer median development rate in teneral adult stage
real(kind = 8) :: med0t7 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t7 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t7 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t7 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t7 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t7 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t7 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t7 !Transfer median development rate in teneral adult stage
real(kind = 8) :: med0t8 !Transfer median development rate in the pre-egg stage
real(kind = 8) :: med1t8 ! Transfer median development rate in egg stage
real(kind = 8) :: med2t8 ! Transfer median development rate in L1 stage
real(kind = 8) :: med3t8 ! Transfer median development rate in L2 stage
real(kind = 8) :: med4t8 ! Transfer median development rate in L3 stage
real(kind = 8) :: med5t8 ! Transfer median development rate in L4 stage
real(kind = 8) :: med6t8 ! Transfer median development rate in Pupa stage
real(kind = 8) :: med7t8 !Transfer median development rate in teneral adult stage
! New individuals that developed into the next life stage in the
! time step (these are each scalar values)
real(kind = 8) :: NewEggs
real(kind = 8) :: NewL1
real(kind = 8) :: NewL2
real(kind = 8) :: NewL3
real(kind = 8) :: NewL4
real(kind = 8) :: NewP
real(kind = 8) :: NewT
real(kind = 8) :: NewA
real(kind = 8) :: Cmean ! mean of current day
real(kind = 8) :: Cmean2 ! Mean of next half
real(kind = 8) :: CDif ! Distance between poles
real(kind = 8) :: CDif2 ! Distance between next pole
real(kind = 8) :: fouram ! 4am Temp
real(kind = 8) :: sevenam ! 7am Temp
real(kind = 8) :: tenam ! 10am Temp
real(kind = 8) :: onepm ! 1pm Temp
real(kind = 8) :: fourpm ! 4pm Temp
real(kind = 8) :: sevenpm ! 7pm Temp
real(kind = 8) :: tenpm ! 10pm Temp
real(kind = 8) :: oneam ! 1am Temp
real(kind = 8) :: Tmin3
!--------------------------------------------------------------------------------------------------
!! We need to compute the mean phloem temperature according to the Sine
!! relationship we fit to phloem ~ daily air temperatures.
!! Each day eight periods are calculated
!!!Tmean = 0.5*(Tmax + Tmin) + 0.9 + 6.6*(Tmax - Tmin)/(2.0*24.4)
!Tmax2 = Tmax + 6.6*(Tmax - Tmin)/24.4
!Tmin2 = Tmin + 1.8
!Tmeanall=0.5*(Tmax2 + Tmin2)
!!Tmin3=TminNext
! The mean between Tmin(4am) and Tmax(4pm)
CMean=(Tmax+Tmin)/2
! The mean between Tmax(4pm) and TminNext (4am the following day)
CMean2=(Tmax+TminNext)/2
! The difference between Tmin and Tmax
CDif=(Tmax-Tmin)
! The difference between Tmax and T min Next
CDif2=(Tmax-TminNext)
! This is the implementation of the Ssine Cycle for each of the time periods in the model.
fouram=3.8532+(Tmin*.9677)
sevenam=1.86978+(.93522*(CMean+(.5*CDif*-0.7071068)))
tenam=(-.4533)+(1.00899*(CMean))
onepm=(-1.148846)+(.985801*(CMean+(.5*CDif*0.7071068)))
fourpm=(.0656866)+(.942395*(CMean+(.5*CDif*1)))
sevenpm=(-0.702683)+(.979172*(CMean2+(.5*CDif2*0.7071068)))
tenpm=.934665+(.988126*(CMean2))
oneam=3.2294+(.9842*(CMean2+(.5*CDif2*-0.7071068)))
Tmax2=fourpm
Tmin2=fouram
! Computing the median development rate for each life stage in this time step
! This is the sum of the eight periods.
! Oviposition
call RegniereFunc(fouram, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t1) ! for pre-eggs
call RegniereFunc(sevenam, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t2) ! for pre-eggs
call RegniereFunc(tenam, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t3) ! for pre-eggs
call RegniereFunc(onepm, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t4) ! for pre-eggs
call RegniereFunc(fourpm, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t5) ! for pre-eggs
call RegniereFunc(sevenpm, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t6) ! for pre-eggs
call RegniereFunc(tenpm, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t7) ! for pre-eggs
call RegniereFunc(oneam, TB0, DeltaB0, TM0, DeltaM0, omega0, psi0, med0t8) ! for pre-eggs
med0=med0t1+med0t2+med0t3+med0t4+med0t5+med0t6+med0t7+med0t8
! Eggs
call LoganFunc(fouram, Rmax1,Tmax1,Tmin1,k1,dm1, med1t1) ! 4am
call LoganFunc(sevenam, Rmax1,Tmax1,Tmin1,k1,dm1, med1t2) ! 7am
call LoganFunc(tenam, Rmax1,Tmax1,Tmin1,k1,dm1, med1t3) ! 10am
call LoganFunc(onepm, Rmax1,Tmax1,Tmin1,k1,dm1, med1t4) ! 1 pm
call LoganFunc(fourpm, Rmax1,Tmax1,Tmin1,k1,dm1, med1t5) ! 4 pm
call LoganFunc(sevenpm, Rmax1,Tmax1,Tmin1,k1,dm1, med1t6) ! 7 pm
call LoganFunc(tenpm, Rmax1,Tmax1,Tmin1,k1,dm1, med1t7) ! 10am
call LoganFunc(oneam, Rmax1,Tmax1,Tmin1,k1,dm1, med1t8) ! 1 pm
med1=med1t1+med1t2+med1t3+med1t4+med1t5+med1t6+med1t7+med1t8
! Larval stage
call LoganFunc(fouram, Rmax2,VTmx2,VTmn2,k2,dm2, med2t1) ! for L1
call LoganFunc(sevenam, Rmax2,VTmx2,VTmn2,k2,dm2, med2t2) ! for L1
call LoganFunc(tenam, Rmax2,VTmx2,VTmn2,k2,dm2, med2t3) ! for L1
call LoganFunc(onepm, Rmax2,VTmx2,VTmn2,k2,dm2, med2t4) ! 1 pm
call LoganFunc(fourpm, Rmax2,VTmx2,VTmn2,k2,dm2, med2t5) ! for L1
call LoganFunc(sevenpm, Rmax2,VTmx2,VTmn2,k2,dm2, med2t6) ! for L1
call LoganFunc(tenpm, Rmax2,VTmx2,VTmn2,k2,dm2, med2t7) ! for L1
call LoganFunc(oneam, Rmax2,VTmx2,VTmn2,k2,dm2, med2t8) ! for L1
med2=med2t1+med2t2+med2t3+med2t4+med2t5+med2t6+med2t7+med2t8
! Pre-pupal
call LoganFunc(fouram, Rmax3,VTmx3,VTmn3,k3,dm3, med3t1) ! for L2
call LoganFunc(sevenam, Rmax3,VTmx3,VTmn3,k3,dm3, med3t2) ! for L2
call LoganFunc(tenam, Rmax3,VTmx3,VTmn3,k3,dm3, med3t3) ! for L2
call LoganFunc(onepm, Rmax3,VTmx3,VTmn3,k3,dm3, med3t4) ! 1 pm
call LoganFunc(fourpm, Rmax3,VTmx3,VTmn3,k3,dm3, med3t5) ! for L2
call LoganFunc(sevenpm, Rmax3,VTmx3,VTmn3,k3,dm3, med3t6) ! for L2
call LoganFunc(tenpm, Rmax3,VTmx3,VTmn3,k3,dm3, med3t7) ! for L2
call LoganFunc(oneam, Rmax3,VTmx3,VTmn3,k3,dm3, med3t8) ! for L2
med3=med3t1+med3t2+med3t3+med3t4+med3t5+med3t6+med3t7+med3t8
! Pupal
call LoganFunc(fouram, Rmax4,VTmx4,VTmn4,k4,dm4, med4t1) ! for L2
call LoganFunc(sevenam, Rmax4,VTmx4,VTmn4,k4,dm4, med4t2) ! for L2
call LoganFunc(tenam, Rmax4,VTmx4,VTmn4,k4,dm4, med4t3) ! for L2
call LoganFunc(onepm, Rmax4,VTmx4,VTmn4,k4,dm4, med4t4) ! 1 pm
call LoganFunc(fourpm, Rmax4,VTmx4,VTmn4,k4,dm4, med4t5) ! for L2
call LoganFunc(sevenpm, Rmax4,VTmx4,VTmn4,k4,dm4, med4t6) ! for L2
call LoganFunc(tenpm, Rmax4,VTmx4,VTmn4,k4,dm4, med4t7) ! for L2
call LoganFunc(oneam, Rmax4,VTmx4,VTmn4,k4,dm4, med4t8) ! for L2
med4=med4t1+med4t2+med4t3+med4t4+med4t5+med4t6+med4t7+med4t8
!!!!!! TA
call LoganFunc(fouram, Rmax5,VTmx5,VTmn5,k5,dm5, med5t1) ! for L2
call LoganFunc(sevenam, Rmax5,VTmx5,VTmn5,k5,dm5, med5t2) ! for L2
call LoganFunc(tenam, Rmax5,VTmx5,VTmn5,k5,dm5, med5t3) ! for L2
call LoganFunc(onepm, Rmax5,VTmx5,VTmn5,k5,dm5, med5t4) ! 1 pm
call LoganFunc(fourpm, Rmax5,VTmx5,VTmn5,k5,dm5, med5t5) ! for L2
call LoganFunc(sevenpm, Rmax5,VTmx5,VTmn5,k5,dm5, med5t6) ! for L2
call LoganFunc(tenpm, Rmax5,VTmx5,VTmn5,k5,dm5, med5t7) ! for L2
call LoganFunc(oneam, Rmax5,VTmx5,VTmn5,k5,dm5, med5t8) ! for L2
med5=med5t1+med5t2+med5t3+med5t4+med5t5+med5t6+med5t7+med5t8
! The mu parameter of the lognormal distribution is given by the natural logarithm of the median
! development rate.
muA = log(medA*deltat)
mu1 = log(med1*deltat) ! for eggs
mu2 = log(med2*deltat) ! for L1
mu3 = log(med3*deltat) ! for PP
mu4 = log(med4*deltat) ! for P
mu5 = log(med5*deltat) ! for TA
!---------------------------------------------------------------------------------------------------------
! Now we can simulate each of the life stages by calling the appropriate subroutines
! Parents die at temperature less than or equal to 12.2
if(Tmin2 <= -12.2)then !pg 90 Miller and Keen
Parents=Parents*.1
OPare=OPare*.1
ActiveParents=Parents*.1
end if
!!! New parents wait 8 days to oviposit.
call EPTDev(n, avec, medA, muA, sigmaA, Tmin2, Parents, NewParentstm1, OPare, Pare, ActiveParents)
! Simulating oviposition:
call Ovipos(Fec, ActiveParents, med0, Tmin2, NewEggs)
! The output of this subroutine (NewEggs) is input for the next subroutine below.
! The Ovipos subroutine also updates the scalar value for fecundity.
! It takes as input the number of parents which comes from an initial value
! or from the BeetleAttack subroutine called at the end of this sequence.
! 50% of eggs die in the event the minimum temperature is below -20.6C
if(Tmin2 <= -20.6)then !pg 90 Miller and Keen
OE=OE*.5
E=E*.5
end if
! Simulating egg development:
call EPTDev(n, avec, med1, mu1, sigma1, Tmin2, NewEggs, NewEggstm1, OE, E, NewL1)
! The output of this subroutine (NewL1) is input for the next subroutine below.
! This updates the aging distribution (OE) and NewEggstm1 and
! outputs a scalar for the expected number of eggs.
! Simulating development of L1 larvae:
call LarvDev(n, avec, med2, mu2, sigma2, NewL1, NewL1tm1, OL1, L1, NewL2)
! The output of this subroutine (NewL2) is input for the next subroutine below.
! This updates the aging distribution (OL1) and NewL1tm1 and
! outputs a scalar for the expected number of first instar larvae (L1).
! Simulating development of PP:
call LarvDev(n, avec, med3, mu3, sigma3, NewL2, NewL2tm1, OL2, L2, NewP)
! The output of this subroutine (NewL3) is input for the next subroutine below.
! This updates the aging distribution (OL2) and NewL2tm1 and
! outputs a scalar for the expected number of second instar larvae (L2).
! These stages are not used in the Western pine beetle model
! Simulating development of L3 larvae:
! call LarvDev(n, avec, med4, mu4, sigma4, NewL3, NewL3tm1, OL3, L3, NewL4)
! The output of this subroutine (NewL4) is input for the next subroutine below.
! This updates the aging distribution (OL3) and NewL3tm1 and
! outputs a scalar for the expected number of third instar larvae (L3).
! Simulating development of L4 larvae:
!call LarvDev(n, avec, med5, mu5, sigma5, NewL4, NewL4tm1, OL4, L4, NewP)
! The output of this subroutine (NewP) is input for the next subroutine below.
! This updates the aging distribution (OL4) and NewL4tm1 and
! outputs a scalar for the expected number of fourth instar larvae (L4).
! Applying winter mortality to the larval stages.
NewP = NewP/(1.0 + exp(-(ColdestT + 29.22791)/2.0))
! NewP = NewP*0.5
! Simulating pupal development:
call EPTDev(n, avec, med4, mu4, sigma4, Tmin2, NewP, NewPtm1, OP, P, NewT)
! The output of this subroutine (NewT) is input for the next subroutine below.
! This updates the aging distribution (OP) and NewPtm1 and
! outputs a scalar for the expected number of pupae (P).
! The Pupal population is reduced to 10% in the event the temperature is below
! -20.6 C
if(Tmin2 <= -20.6)then !pg 90 Miller and Keen
OP=P*.1
P=P*.1
end if
! Simulating teneral adult development:
call EPTDev(n, avec, med5, mu5, sigma5, Tmin2, NewT, NewTtm1, OT, Te, NewA)
! The output of this subroutine (NewA) is input for the next subroutine below.
! This updates the aging distribution (OT) and NewTtm1 and
! outputs a scalar for the expected number of teneral adults (Te).
! The teneral adult population is reduced to 10% in the event the population is
! reduced below -12.2C
if(Tmin2 <= -12.2)then !pg 90 Miller and Keen
OT=OT*.1
Te=Te*.1
end if
! Simulating adult flight
! This updates the expected number of adults (A) and flying adults (FA).
call AdSR(NewA, Tmin2, Tmax, A, FA)
! This updates the output variables for model monitoring.
Flyout=FA+Bt
Fecout=Fec
Eout=E
L1out=L1
L2out=L2
Pout=P
Teout=Te
Aout=A
! If temperatures are cold, all of the flying beetles die. This prevents them
! from killing trees when they should not be. The value of -10*C is from Miller and Keen
if(Tmin < -10.0)then
Bt = 0.0
FA = 0.0
end if
! Simulating the attack of host trees
call BeetleAttack(NtGEQ317, NtGEQ00, Bt, FA, Parents, r1,x0,x1,CWD,x2,&
SizeFactor,FebInPopn,EndMPBPopn,BigTreesOut,SmallTreesOut)
! This updates the density of trees in each of the size classes, and the density of beetles that remain in
! flight and outputs a number of parents that will start the oviposition process.
End Subroutine BeetleSim
!=================================================================================================================
subroutine BeetleAttack(NtGEQ317, NtGEQ00,Bt, FA, Parents, &
r1,x0,x1,CWD,x2,SizeFactor,FebInPopn,EndMPBPopn,BigTreesOut,SmallTreesOut)
! In this subroutine we use the TDIA model to determine the number of trees that are killed using the relationship between the
! the number of beetles in flight and the amount of drought experienced by the trees and their size.
implicit none