-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditions.f90
815 lines (704 loc) · 31.5 KB
/
conditions.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
subroutine conditions (ob_cur, idtbl)
!current conditions include: w_stress, n_stress, phu_plant, phu_base0, soil_water, jday, month, vol
! year_rot, year_cal, year_seq, prob, land_use
!target variables include: w_stress -> wp, fc, ul; vol -> pvol, evol
use conditional_module
use climate_module
use time_module
use hru_module, only : hru
use soil_module
use plant_module
use reservoir_module
use reservoir_data_module
use sd_channel_module
use hydrograph_module
use output_landscape_module
use aquifer_module
use organic_mineral_mass_module
use mgt_operations_module
use water_allocation_module
implicit none
integer, intent (in) :: ob_cur ! |
integer, intent (in) :: idtbl !none |
integer :: ob_num ! |object number
integer :: nbz = 748932582 ! |
integer, dimension(1) :: seed = (/3/) ! |
integer :: ic !none |counter
integer :: ialt !none |counter
integer :: iac !none |counter
integer :: iob ! |
real :: targ_val ! |
real :: ran_num ! |
real :: aunif ! |
integer :: ires ! |
integer :: ipl ! |
integer :: iipl ! |
integer :: id ! |
integer :: isched ! |
integer :: iauto ! |
integer :: ivar_cur
integer :: ivar_tbl
real :: targ ! |
integer :: pl_sum !none |number of plants growing
integer :: days_tot !none |
integer :: iwgn !units |
integer :: ly !units |soil layer
real :: strs_sum !none |sum of stress (water or n) of all growing plants
real :: prob_cum ! |
real :: prob_apply ! |
real :: hru_exp_left ! |number of hru's expected to still be applied (uniform or normal distr)
real :: hru_act_left ! |number of hru's actually still to be applied
real :: flo_m3
real :: wt_tot
real :: p_lab_tot
real :: p_lab_ppm
real :: rto
real :: var_cur
character(len=1) :: pl_chk
d_tbl%act_hit = "y"
do ic = 1, d_tbl%conds
select case (d_tbl%cond(ic)%var)
!water stress
case ("w_stress")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
!! find average water stress of all growing plants
pl_sum = 0
strs_sum = 0.
do ipl = 1, pcom(ob_num)%npl
if (pcom(ob_num)%plcur(ipl)%gro == "y") then
pl_sum = pl_sum + 1
strs_sum = strs_sum + pcom(ob_num)%plstr(ipl)%strsw
end if
end do
if (pl_sum > 0) then
strs_sum = strs_sum / pl_sum
else
strs_sum = 1.
end if
call cond_real (ic, strs_sum, d_tbl%cond(ic)%lim_const, idtbl)
!nitrogen stress
case ("n_stress")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
!! find average water stress of all growing plants
pl_sum = 0
strs_sum = 0.
do ipl = 1, pcom(ob_num)%npl
if (pcom(ob_num)%plcur(ipl)%gro == "y") then
pl_sum = pl_sum + 1
strs_sum = strs_sum + pcom(ob_num)%plstr(ipl)%strsn
end if
end do
if (pl_sum > 0) strs_sum = strs_sum / pl_sum
call cond_real (ic, strs_sum, d_tbl%cond(ic)%lim_const, idtbl)
!phosphorus stress
case ("p_stress")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
!! find average water stress of all growing plants
pl_sum = 0
strs_sum = 0.
do ipl = 1, pcom(ob_num)%npl
if (pcom(ob_num)%plcur(ipl)%gro == "y") then
pl_sum = pl_sum + 1
strs_sum = strs_sum + pcom(ob_num)%plstr(ipl)%strsp
end if
end do
if (pl_sum > 0) strs_sum = strs_sum / pl_sum
call cond_real (ic, strs_sum, d_tbl%cond(ic)%lim_const, idtbl)
!potential heat units - plant based
case ("phu_plant")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
do ialt = 1, d_tbl%alts
!if no plants in the community - set action to no
if (pcom(ob_num)%npl == 0) then
d_tbl%act_hit(ialt) = "n"
else
!if more than one plant in community - use first one that is growing
ipl = 1
do iipl = 1, pcom(ob_num)%npl
if (pcom(ob_num)%plcur(iipl)%phuacc > 1.e-6) then
ipl = iipl
exit
end if
end do
end if
end do
call cond_real (ic, pcom(ob_num)%plcur(ipl)%phuacc, d_tbl%cond(ic)%lim_const, idtbl)
!potential heat units - base zero
case ("phu_base0")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
if (d_tbl%cond(ic)%ob == "hru") then
iob = sp_ob1%hru + ob_num - 1
end if
if (d_tbl%cond(ic)%ob == "hlt") then
iob = sp_ob1%hru_lte + ob_num - 1
end if
iwst = ob(iob)%wst
call cond_real (ic, wst(iwst)%weat%phubase0, d_tbl%cond(ic)%lim_const, idtbl)
!precip on current day
case ("precip_cur")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
if (d_tbl%cond(ic)%ob == "hru") then
iob = sp_ob1%hru + ob_num - 1
end if
if (d_tbl%cond(ic)%ob == "hlt") then
iob = sp_ob1%hru_lte + ob_num - 1
end if
iwst = ob(iob)%wst
call cond_real (ic, wst(iwst)%weat%precip, d_tbl%cond(ic)%lim_const, idtbl)
!precip on next day day
case ("precip_next")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
if (d_tbl%cond(ic)%ob == "hru") then
iob = sp_ob1%hru + ob_num - 1
end if
if (d_tbl%cond(ic)%ob == "hlt") then
iob = sp_ob1%hru_lte + ob_num - 1
end if
iwst = ob(iob)%wst
call cond_real (ic, wst(iwst)%weat%precip_next, d_tbl%cond(ic)%lim_const, idtbl)
!plant growing
case ("plant_gro")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
ipl = Max (Int(d_tbl%cond(ic)%lim_const), 1)
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then !determine if growing (y) or not (n)
if (pcom(ob_num)%plcur(ipl)%gro /= d_tbl%cond(ic)%lim_var) then
d_tbl%act_hit(ialt) = "n"
end if
end if
end do
!specific plant growing
case ("plant_name_gro")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
ipl = 0
do iipl = 1, pcom(ob_num)%npl
if (d_tbl%cond(ic)%lim_var == pcom(ob_num)%pl(iipl)) then
ipl = iipl
end if
end do
!plant not in community of ipl = 0
if (ipl == 0) then
d_tbl%act_hit(ialt) = "n"
else
!if plant is in the community - check to see if it is growing
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then !determine if growing (y) or not (n)
if (pcom(ob_num)%plcur(ipl)%gro == "n") then
d_tbl%act_hit(ialt) = "n"
end if
end if
end do
end if
!days since last plant
case ("days_plant")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
ivar_cur = pcom(ob_num)%days_plant
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!days since last harvest
case ("days_harv")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
ivar_cur = pcom(ob_num)%days_harv
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!days since last action
case ("days_act")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
iac = d_tbl%con_act(ic)
ivar_cur = pcom(ob_num)%dtbl(idtbl)%days_act(iac)
ivar_tbl = int(d_tbl%cond(ic)%lim_const) + 2
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!days since first simulation day of year
case ("day_start")
ivar_cur = time%day_start
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!slope
case ("slope")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, hru(ob_num)%topo%slope, d_tbl%cond(ic)%lim_const, idtbl)
!soil water
case ("soil_water")
!determine target variable
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
targ_val = 0.
select case (d_tbl%cond(ic)%lim_var)
case ("wp") !wilting point
targ_val = 0.
case ("fc") !field capacity
targ_val = soil(ob_num)%sumfc
case ("ul") !upper limit (porosity)
targ_val = soil(ob_num)%sumul
end select
!perform operation on target variable to get target
select case ((d_tbl%cond(ic)%lim_op))
case ("*")
targ = targ_val * d_tbl%cond(ic)%lim_const
case ("+")
targ = targ_val + d_tbl%cond(ic)%lim_const
case ("-")
targ = targ_val - d_tbl%cond(ic)%lim_const
case ("/")
targ = targ_val / d_tbl%cond(ic)%lim_const
end select
call cond_real (ic, soil(ob_num)%sw, targ, idtbl)
!julian day
case ("jday")
ivar_cur = time%day
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!month
case ("month")
ivar_cur = time%mo
!LEstrada
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
!var_cur = ivar_cur + float (time%day_mo) / float (ndays_noleap(ivar_cur+1) &
! - ndays_noleap(ivar_cur))
!call cond_real (ic, var_cur, d_tbl%cond(ic)%lim_const, idtbl)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!rotation year
case ("year_rot")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
ivar_cur = pcom(ob_num)%rot_yr
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!growth year of perennials
case ("year_gro")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
ivar_cur = pcom(ob_num)%plcur(1)%curyr_mat
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!calendar year
case ("year_cal")
ivar_cur = time%yrc
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!sequential year of simulation
case ("year_seq")
ivar_cur = time%yrs
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!current years of maturity for perennial plants
case ("cur_yrs_mat")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
ivar_cur = pcom(ob_num)%plcur(1)%curyr_mat
ivar_tbl = int(d_tbl%cond(ic)%lim_const)
call cond_integer (ic, ivar_cur, ivar_tbl, idtbl)
!above ground biomass
case ("biomass")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, pl_mass(ob_num)%ab_gr_com%m, d_tbl%cond(ic)%lim_const, idtbl)
!leaf area index
case ("leaf_area")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, pcom(ob_num)%lai_sum, d_tbl%cond(ic)%lim_const, idtbl)
!total ground cover - above ground biomass + surface residue
case ("ground_cov")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, pl_mass(ob_num)%ab_gr_com%m, d_tbl%cond(ic)%lim_const, idtbl)
!usle conservation practice P factor
case ("p_factor")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, hru(ob_num)%lumv%usle_p, d_tbl%cond(ic)%lim_const, idtbl)
!usle soil erodibility K factor
case ("k_factor")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, soil(ob_num)%ly(1)%usle_k, d_tbl%cond(ic)%lim_const, idtbl)
!hydrologic soil group
case ("hyd_soil_group")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
if (soil(ob_num)%hydgrp /= d_tbl%cond(ic)%lim_var) then
d_tbl%act_hit(ialt) = "n"
end if
end if
end do
!precip/pet ratio
case ("p_pet")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
iwst = ob(ob_num)%wst
iwgn = wst(iwst)%wco%wgn
call cond_real (ic, wgn_pms(iwgn)%p_pet_rto, d_tbl%cond(ic)%lim_const, idtbl)
!soil labile phosphorus of first layer
case ("p_lab_150")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
!! use labile P concentration of upper (10 mm) layer
wt_tot = soil(ob_num)%phys(1)%bd * soil(ob_num)%phys(1)%thick / 100. ! mg/kg => kg/ha
p_lab_tot = soil1(ob_num)%mp(1)%lab / wt_tot
do ly = 2, soil(ob_num)%nly
if (soil(ob_num)%phys(ly)%d > 150.) then
rto = (150. - soil(ob_num)%phys(ly-1)%d) / (soil(ob_num)%phys(ly)%d - soil(ob_num)%phys(ly-1)%d)
else
rto = 1.
end if
wt_tot = wt_tot + soil(ob_num)%phys(ly)%bd * soil(ob_num)%phys(ly)%thick / 100. ! mg/kg => kg/ha
p_lab_tot = p_lab_tot + soil1(ob_num)%mp(ly)%lab
exit
end do
p_lab_ppm = p_lab_tot / wt_tot
call cond_real (ic, p_lab_ppm, d_tbl%cond(ic)%lim_const, idtbl)
!soil temperature of second layer
case ("soil_temp2")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, soil(ob_num)%phys(2)%tmp, d_tbl%cond(ic)%lim_const, idtbl)
!soil organic carbon of first layer
case ("soil_carbon")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, soil1(ob_num)%cbn(1), d_tbl%cond(ic)%lim_const, idtbl)
!is the hru tiled - 0 = no; >0 = yes
case ("tile_drained")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
if (hru(ob_num)%tiledrain /= Int(d_tbl%cond(ic)%lim_const)) then
d_tbl%act_hit(ialt) = "n"
end if
end if
if (d_tbl%alt(ic,ialt) == "/") then
if (hru(ob_num)%tiledrain == Int(d_tbl%cond(ic)%lim_const)) then
d_tbl%act_hit(ialt) = "n"
end if
end if
end do
!probability
case ("prob")
!generate random number
ran_num = Aunif(rndseed_cond)
call cond_real (ic, ran_num, d_tbl%cond(ic)%lim_const, idtbl)
!probability of event within a defined period assuming uniform distribution
case ("prob_unif")
!! set application day if first day of application window
if (time%day == d_tbl%cond(ic)%ob_num) then
!period falls within a calendar year - ob_num is first and lim_const is last day
if (d_tbl%cond(ic)%lim_const > d_tbl%cond(ic)%ob_num) then
!set the application day
ran_num = Aunif(rndseed_cond)
if (ran_num < d_tbl%frac_app) then
days_tot = d_tbl%cond(ic)%lim_const - d_tbl%cond(ic)%ob_num + 1
ran_num = Aunif(rndseed_cond)
pcom(ob_cur)%dtbl(idtbl)%apply_day = int(ran_num * days_tot) + d_tbl%cond(ic)%ob_num + 1
else
pcom(ob_cur)%dtbl(idtbl)%apply_day = 0.
end if
else
!period falls over a calendar year - ob_num is first and lim_const is last day
ran_num = Aunif(rndseed_cond)
if (ran_num < d_tbl%frac_app) then
if (time%day >= d_tbl%cond(ic)%lim_const) then
days_tot = time%day_end_yr - d_tbl%cond(ic)%ob_num + 1
ran_num = Aunif(rndseed_cond)
pcom(ob_cur)%dtbl(idtbl)%apply_day = int(ran_num * days_tot) + d_tbl%cond(ic)%ob_num + 1
else
days_tot = d_tbl%cond(ic)%lim_const
ran_num = Aunif(rndseed_cond)
pcom(ob_cur)%dtbl(idtbl)%apply_day = int(ran_num * days_tot) + 1
end if
else
pcom(ob_cur)%dtbl(idtbl)%apply_day = 0.
end if
end if
end if
if (time%day /= pcom(ob_cur)%dtbl(idtbl)%apply_day) then
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
d_tbl%act_hit(ialt) = "n"
end if
end do
end if
!probability of event within a defined period assuming uniform distribution
case ("prob_unif1")
!! update cumulative probability if new day
if (time%day /= d_tbl%day_prev .and. d_tbl%days_prob > 0) then
!! reset if first day of window
if (time%day == d_tbl%cond(ic)%ob_num) then
d_tbl%days_prob = d_tbl%cond(ic)%lim_const
d_tbl%prob_cum = 0.
end if
d_tbl%day_prev = time%day
!! check if winow is over - days_prob are the number of days left in window
if (d_tbl%days_prob >= 1) then
!! cumulative prob of uniform distribution on current day of the window
d_tbl%prob_cum = 1. / float(d_tbl%days_prob)
d_tbl%days_prob = d_tbl%days_prob - 1
else
d_tbl%days_prob = 0.
d_tbl%prob_cum = 0.
end if
end if
ran_num = Aunif(rndseed_cond)
if (ran_num > d_tbl%prob_cum) then
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
d_tbl%act_hit(ialt) = "n"
end if
end do
end if
!probability of event within a defined period assuming uniform distribution across a land use
case ("prob_unif_lu")
prob_cum = 0.
!check if period falls over a calendar year - ob_num is first and lim_const is last day
if (d_tbl%cond(ic)%lim_const > d_tbl%cond(ic)%ob_num) then
if (time%day <= d_tbl%cond(ic)%lim_const .and. time%day >= d_tbl%cond(ic)%ob_num) then
!cumulative prob of uniform distribution on current day of the window
prob_cum = (time%day - d_tbl%cond(ic)%ob_num + 1) / (d_tbl%cond(ic)%lim_const - d_tbl%cond(ic)%ob_num)
end if
else
if (time%day >= d_tbl%cond(ic)%lim_const .or. time%day <= d_tbl%cond(ic)%ob_num) then
days_tot = time%day_end_yr - d_tbl%cond(ic)%lim_const + d_tbl%cond(ic)%ob_num
if (time%day >= d_tbl%cond(ic)%lim_const) then
!cumulative prob of uniform distribution on current day of the window
prob_cum = (time%day - d_tbl%cond(ic)%lim_const) / days_tot
else
!cumulative prob of uniform distribution on current day of the window
prob_cum = (time%day_end_yr - d_tbl%cond(ic)%lim_const + time%day + 1) / days_tot
end if
end if
end if
if (prob_cum > 0.) then
ran_num = Aunif(rndseed_cond)
hru_exp_left = d_tbl%hru_lu - (prob_cum * d_tbl%hru_lu)
hru_act_left = d_tbl%hru_lu - d_tbl%hru_lu_cur
prob_apply = (hru_act_left - hru_exp_left) / (hru_act_left + 1)
!prob_apply = (prob_cum * d_tbl%hru_lu - d_tbl%hru_lu_cur + 1) / d_tbl%hru_lu
if (ran_num > prob_apply) then
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
d_tbl%act_hit(ialt) = "n"
end if
end do
else
!if (pcom(ob_cur)%dtbl(idtbl)%num_actions(iac) <= Int(d_tbl%act(iac)%const2)) then
! d_tbl%hru_lu_cur = d_tbl%hru_lu_cur + 1
! d_tbl%hru_ha_cur = d_tbl%hru_ha_cur + hru(ob_cur)%area_ha
!end if
ipl = 1
end if
else
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
d_tbl%act_hit(ialt) = "n"
end if
end do
end if
if (time%day > d_tbl%cond(ic)%lim_const) then
d_tbl%hru_lu_cur = 0
d_tbl%hru_ha_cur = 0.
end if
!channel flow
case ("channel_flo")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
!ob_num is channel number - need object number
iob = sp_ob1%chandeg + ob_num - 1
flo_m3 = ob(iob)%hd(1)%flo / 86400.
call cond_real (ic, flo_m3, d_tbl%cond(ic)%lim_const, idtbl)
!tile flow
case ("tile_flo")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, hwb_d(ob_num)%qtile, d_tbl%cond(ic)%lim_const, idtbl)
!irrigation demand
case ("irr_demand")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, irrig(ob_num)%demand, d_tbl%cond(ic)%lim_const, idtbl)
!irrigation demand
case ("irr_demand_wro")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, wallo(ob_num)%tot%demand, d_tbl%cond(ic)%lim_const, idtbl)
!aquifer depth below surface
case ("aqu_dep")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
call cond_real (ic, aqu_d(ob_num)%dep_wt, d_tbl%cond(ic)%lim_const, idtbl)
!land use and management
case ("land_use")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
if (hru(ob_num)%dbsc%land_use_mgt /= d_tbl%cond(ic)%lim_var) then
d_tbl%act_hit(ialt) = "n"
end if
end if
end do
!tillage system - name of tillage decision table in lum.dtl
case ("tillage")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
do ialt = 1, d_tbl%alts
pl_chk = "n"
if (d_tbl%alt(ic,ialt) == "=") then
isched = hru(ob_num)%mgt_ops
do iauto = 1, sched(isched)%num_autos
id = sched(isched)%num_db(iauto)
if (dtbl_lum(id)%name == d_tbl%cond(ic)%lim_var) then
pl_chk = "y"
end if
end do
end if
if (pl_chk == "n") d_tbl%act_hit(ialt) = "n"
end do
!plants - if plant is in the cummunity
case ("plant")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
do ialt = 1, d_tbl%alts
!don't check if "-"
if (d_tbl%alt(ic,ialt) /= "-") then
!for equal condition - set "n" if not in community
if (d_tbl%alt(ic,ialt) == "=") then
pl_chk = "n"
do ipl = 1, pcom(ob_num)%npl
if (pcom(ob_num)%pl(ipl) == d_tbl%cond(ic)%lim_var) then
pl_chk = "y"
end if
end do
if (pl_chk == "n") d_tbl%act_hit(ialt) = "n"
end if
!for not equal condition - set to "n" if in the plant community
if (d_tbl%alt(ic,ialt) == "/") then
do ipl = 1, pcom(ob_num)%npl
if (pcom(ob_num)%pl(ipl) == d_tbl%cond(ic)%lim_var) then
d_tbl%act_hit(ialt) = "n"
end if
end do
end if
end if
end do
!channel management
case ("ch_use")
ob_num = d_tbl%cond(ic)%ob_num
if (ob_num == 0) ob_num = ob_cur
do ialt = 1, d_tbl%alts
if (d_tbl%alt(ic,ialt) == "=") then
if (sd_ch(ob_num)%order /= d_tbl%cond(ic)%lim_var) then
d_tbl%act_hit(ialt) = "n"
end if
end if
end do
!reservoir volume
case ("vol")
!determine target variable
ires = d_tbl%cond(ic)%ob_num
if (ires == 0) ires = ob_cur
select case (d_tbl%cond(ic)%lim_var)
case ("e-pv") !emergency minus prinicpal storage volume
targ_val = res_ob(ires)%pvol
targ = targ_val + (res_ob(ires)%evol - res_ob(ires)%pvol) * d_tbl%cond(ic)%lim_const
case ("pvol") !prinicpal storage volume
targ_val = res_ob(ires)%pvol
!perform operation on target variable to get target
select case ((d_tbl%cond(ic)%lim_op))
case ("*")
targ = targ_val * d_tbl%cond(ic)%lim_const
case ("+")
targ = targ_val + 10000. * d_tbl%cond(ic)%lim_const
case ("-")
targ = targ_val - 10000. * d_tbl%cond(ic)%lim_const !convert ha-m to m3
end select
case ("evol") !emergency storage volume
targ_val = res_ob(ires)%evol
!perform operation on target variable to get target
select case ((d_tbl%cond(ic)%lim_op))
case ("*")
targ = targ_val * d_tbl%cond(ic)%lim_const
case ("+")
targ = targ_val + 10000. * d_tbl%cond(ic)%lim_const
case ("-")
targ = targ_val - 10000. * d_tbl%cond(ic)%lim_const !convert ha-m to m3
end select
!LEstrada
case ("avol") !absolute volume
targ = 10000. * d_tbl%cond(ic)%lim_const !convert ha-m to m3
end select
!check alternatives
call cond_real (ic, res(ires)%flo, targ, idtbl)
!reservoir inflow
case ("res_in")
!determine target variable
ires = d_tbl%cond(ic)%ob_num
if (ires == 0) ires = ob_cur
icmd = res_ob(ires)%ob
call cond_real (ic, ob(icmd)%hin%flo, d_tbl%cond(ic)%lim_const, idtbl)
!impounded water depth -paddy average water depth of water
case ("wet_depth")
!determine target variable
ires = d_tbl%cond(ic)%ob_num
if (ires == 0) ires = ob_cur
!set limit constant if comparing to weir height
if (d_tbl%cond(ic)%lim_var == "hwater") then
targ = d_tbl%cond(ic)%lim_const/1000. !m
else
targ = wet_ob(ires)%weir_hgt
end if
!check alternatives
call cond_real (ic, wet_ob(ires)%depth, targ, idtbl)
!paddy weir height
case ("weirh")
!determine target variable
ires = d_tbl%cond(ic)%ob_num
if (ires == 0) ires = ob_cur
!set limit constant if comparing to weir height
targ = d_tbl%cond(ic)%lim_const/1000. !m
!check alternatives
call cond_real (ic, wet_ob(ires)%weir_hgt, targ, idtbl)
!paddy storage volume - stored on an hru
!water volume - stored on an hru
case ("vol_wet")
!determine target variable
ires = d_tbl%cond(ic)%ob_num
if (ires == 0) ires = ob_cur
select case (d_tbl%cond(ic)%lim_var)
case ("pvol") !prinicpal storage volume
targ_val = wet_ob(ires)%pvol
case ("evol") !emergency storage volume
targ_val = wet_ob(ires)%evol
end select
!perform operation on target variable to get target
select case ((d_tbl%cond(ic)%lim_op))
case ("*")
targ = targ_val * d_tbl%cond(ic)%lim_const
case ("+")
targ = targ_val + d_tbl%cond(ic)%lim_const
case ("-")
targ = targ_val - d_tbl%cond(ic)%lim_const
case ("/")
targ = targ_val / d_tbl%cond(ic)%lim_const
end select
!check alternatives
call cond_real (ic, wet(ires)%flo, targ, idtbl)
end select
end do
return
end subroutine conditions