-
Notifications
You must be signed in to change notification settings - Fork 0
/
ENWATBAL.BAS
2226 lines (2133 loc) · 93.2 KB
/
ENWATBAL.BAS
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
'ENWAT2.BAS is the second module in ENWATBAL.BAS
'Use BYVAL for Microsoft Prof. BASIC ver. 7.X but eliminate it for
'QuickBASIC ver. 4.5:
'DECLARE FUNCTION ARCOS! (BYVAL xdum!)
'DECLARE FUNCTION ARSIN! (BYVAL xdum!)
'DECLARE FUNCTION AFGEN! (Table!(), BYVAL Xval!)
DECLARE FUNCTION ARCOS! (xdum!)
DECLARE FUNCTION ARSIN! (xdum!)
DECLARE FUNCTION AFGEN! (Table!(), Xval!)
DECLARE SUB SetEpson ()
DECLARE SUB RedirectOutput ()
'Variables shared with module ENWAT2.BAS:
'Strings containing file names for input data files:
COMMON InfoFile$ 'This file contains file names for input data files.
COMMON IrrPrecip$ 'Irrigation & precipitation data.
COMMON DripFile$ 'Drip irrigation rate and time data.
COMMON Constants$ 'Constants
COMMON AfGenFile$ 'Tables of functional relationships.
COMMON Meteo$ 'Weather data with periodicity less than 1 day.
COMMON Plant$ 'Daily weather & plant growth data.
COMMON InitDayFile$ 'Soil layers & their water content & temperature, 1st day.
COMMON FErr% 'Number of error when opening file, related to file name.
COMMON Mode2$ 'Mode to open output files (O=new file, A=append to old file.
COMMON Y$ 'Redirection code, F or f=file, P or p=printer
COMMON HourlyOutputFlag 'If >0 then defines period in hours for output, otherwise only daily output.
'Period of averaged input data and offset, from midnight, of center of 1st mean:
COMMON Period 'Period of weather data that is less than daily [h].
COMMON Offset 'Offset of start of weather data from midnight [h].
COMMON MIndex% '=24/Period, index to array holding weather data.
COMMON DebugDat(), di% 'Array holding debugging variables & index to array.
COMMON ErrCode 'Returned from IMPLx if error occurred. Acted on in main program:
COMMON EndDay% 'Simulation ends at midnight of this day of year.
COMMON EndYear% 'Simulation ends in this year.
COMMON sYear% 'Year that simulation starts. File extension for Plant$.
'Constants in Constants$. See subprogram Getconstants:
COMMON Zo 'Surface roughness length (m).
COMMON Z 'Reference elevation (m) for measurement of wind speed,
'air temperature and dew point temperature.
COMMON WPCrMx 'Maximum canopy water potential (m).
COMMON SRCr 'Specific crop hydraulic resistance (s).
COMMON LowBoundGrad 'Gradient for water flux - lower soil boundary condition.
COMMON ZeroCdNum% 'Day of year on which to invoke impeding layer.
COMMON DripFlag% '>0 if a buried drip emitter exists.
COMMON DetCap 'Detention capacity for ponded water (m).
COMMON Lat 'Latitude in degrees.
COMMON AvBarP 'Average barometric pressure (mbar)
COMMON TStepL, TStepH 'Lower & upper limits of time step (s).
COMMON SatCon 'Saturated conductivity for surface soil layer (m/s).
COMMON StartDay% 'Starting day of year. Equals sDay% at start of simulation
'but changes to day of restarting if simulation is stopped and restarted.
COMMON sDay% 'Starting day of year for simulation.
COMMON WMode% 'Code for source of weather data. Daily data are in file PLANT$
'and data on intervales less than 1 d are in file METEO$.
'daily (=0) data or data on intervals less than 1 d (=1).
COMMON Restart$, path$, dnum%, Hl, LH
COMMON cdnum% 'Current day of year.
COMMON TStep 'Current time step (s).
COMMON TimeS 'Time in seconds since midnight of current day.
COMMON sTime 'Time in decimal hours since midnight of current day.
COMMON hTime 'Cumulative time in decimal hours since simulation started.
COMMON EvTr 'Evapotranspiration rate (m/s).
COMMON TrC 'Transpiration rate (m/s).
COMMON LTr 'Transpiration rate (W/m^2).
COMMON Evs 'Rate of evaporation from soil surface (m/s).
COMMON LEvS 'Rate of evaporation from soil surface (W/m^2).
COMMON Infilt 'Infiltration rate (m/s).
COMMON GR 'Solar radiation (W/m^2).
COMMON Ta 'Air temperature (C).
COMMON Tl 'Canopy (big leaf) temperature (C).
COMMON TsBf 'Soil surface temperature for previous time step (C).
COMMON Ra 'Aerodynamic resistance to sensible & latent heat fluxes (s/m).
COMMON Rl 'Big leaf epidermal resistance (s/m).
COMMON Rs 'Soil surface turbulent and diffusive resistance (s/m).
COMMON WPSeff 'Effective soil water potential over root zone (m).
COMMON WPotCr 'Big leaf water potential (m).
COMMON NRBC 'Net radiation balance of the canopy (W/m^2).
COMMON SHCA 'Canopy - air sensible heat exchange (W/m^2).
COMMON NRBS 'Net radiation balance of the soil surface (W/m^2).
COMMON a 'Soil - air sensible heat flux (W/m^2).
COMMON S 'Soil heat flux (W/m^2).
COMMON CRH 'Canopy turbulent resistance (s/m).
COMMON CRV 'Canopy resistance to latent heat flux (s/m).
COMMON MGR 'Daily theoretical max. global clear sky radiation (MJ/m^2).
COMMON SkL 'Sky longwave radiance (W/m^2).
COMMON Runoff 'Runoff rate (m/s).
COMMON Detain 'Surface storage of water (m).
'Cumulative amounts at end of current day:
COMMON CumEvap 'Cumulative evaporation from soil (m).
COMMON CumTrans 'Cumulative transpiration from canopy (m).
COMMON CumET 'Cum. evapotranspiration (m).
COMMON CumPos 'Cum. positive root water uptake (m).
COMMON CumNeg 'Cum. negative root water uptake (m) (exudation).
COMMON CumRC 'Cum. root water flux (m).
COMMON CumInf 'Cum. infiltration (m).
COMMON CumPrec 'Cum. precipitation (m) (includes irrigation).
COMMON CumDrip 'Cum. drip irrigation (m).
COMMON CumDrain 'Cum. drainage (m).
COMMON CumRunoff 'Cum. runoff (m).
COMMON CumG 'Cum. soil heat flux (m of water equivalent).
COMMON CumRs 'Cum. solar radiation (J/m^2).
COMMON StorWater 'Water stored in soil profile (m).
COMMON CumRootUptake 'Cum. root water flux (m).
COMMON WBalance 'Soil profile water balance (m).
COMMON iWater 'Initial soil profile water storage (m).
COMMON Theta1Lim 'Vol. water content for potential of -0.1 m, used in time
'step setting algorithm.
'These cumulative amounts are for the end of the previous day:
COMMON CumEvBf 'Cum. evaporation from soil (m).
COMMON CumTrBf 'Cum. transpiration (m).
COMMON CumETBf 'Cum. evapotranspiration (m).
COMMON CumPosBf 'Cum. positive root water uptake (m).
COMMON CumNegBf 'Cum. negative root water uptake (m) (exudation).
COMMON CumInfBf 'Cum. infiltration (m).
COMMON CumPrecBf 'Cum. precipitation (m).
COMMON CumDripBf 'Cum. drip irrigation (m).
COMMON CumDrnBf 'Cum. drainage (m).
COMMON CumRunoffBf 'Cum. runoff (m).
COMMON CumGBf 'Cum. soil heat flux (m of water equivalent).
COMMON CumRsBf 'Cum. solar radiation (J/m^2).
COMMON CumRootUptakeBf 'Cum. root water flux (m).
COMMON nLayers% 'Number of soil layers (finite differences).
'Definitions of arrays given where arrays are dimensioned:
COMMON WInput1(), Meteo()
COMMON Dist(), BothLayerThick(), HorNum%(), Depth(), SLThick(), Porsty()
COMMON ZeroCondLayer%()
COMMON DripLayer%()
COMMON WaterOutPutFlag%()
COMMON TempOutPutFlag%()
COMMON Cond(), Kond(), ppot(), AvCond(), AvKond()
COMMON Flow(), Flux(), nFlow(), nFlux(), Theta(), VolW(), VolH(), Temp()
COMMON RF(), RC()
COMMON Header$()
COMMON ClvsWP() 'Holds data for epidermal conductance vs. leaf water potential.
COMMON ClvsGR() 'Holds data for epidermal conductance vs. solar radiation.
COMMON dummy() 'Holds data for soil water potential vs. vol. water content.
COMMON TvsP1() 'Horizon 1 data for soil water potential vs. volumetric water content.
COMMON TvsP2() 'Horizon 2 data for soil water potential vs. volumetric water content.
COMMON TvsP3() 'Horizon 3 data for soil water potential vs. volumetric water content.
COMMON TvsP4() 'Horizon 4 data for soil water potential vs. volumetric water content.
COMMON TvsP5() 'Horizon 5 data for soil water potential vs. volumetric water content.
COMMON TvsP6() 'Horizon 6 data for soil water potential vs. volumetric water content.
COMMON TvsP7() 'Horizon 7 data for soil water potential vs. volumetric water content.
COMMON TvsP8() 'Horizon 8 data for soil water potential vs. volumetric water content.
COMMON TvsP9() 'Horizon 9 data for soil water potential vs. volumetric water content.
COMMON TvsC1() 'Horizon 1 data for hydraulic conductivity vs. " " ".
COMMON TvsC2() 'Horizon 2 data for hydraulic conductivity vs. " " ".
COMMON TvsC3() 'Horizon 3 data for hydraulic conductivity vs. " " ".
COMMON TvsC4() 'Horizon 4 data for hydraulic conductivity vs. " " ".
COMMON TvsC5() 'Horizon 5 data for hydraulic conductivity vs. " " ".
COMMON TvsC6() 'Horizon 6 data for hydraulic conductivity vs. " " ".
COMMON TvsC7() 'Horizon 7 data for hydraulic conductivity vs. " " ".
COMMON TvsC8() 'Horizon 8 data for hydraulic conductivity vs. " " ".
COMMON TvsC9() 'Horizon 9 data for hydraulic conductivity vs. " " ".
COMMON TevsKO() 'Holds data for soil temperature vs. heat conductivity by vapor.
COMMON SoilAL() 'Data for soil water content (m^3/m^3) vs. soil albedo.
'Constants:
CONST Pi = 3.14159
CONST SIGMA = 5.67E-08 'Stefan-Boltzmann constant [W/m^2/K].
CONST KondS = 1.68 'Thermal conductivity of soil solids [W/m/C] multiplied by 0.4.
CONST KondW = .57 ' " " " water [W/m/C].
CONST KondA = .025 ' " " " air [W/m/C].
CONST VHCapS = 1925000! 'Volumetric heat capacity of soil solids [J/m^3/C].
CONST VHCapW = 4186000! ' " " " " water [J/m^3/C].
CONST GRAV = 9.81 'Gravitational constant [m/s].
FileOpenErr.2:
PRINT "Error number"; ERR; "in opening file."
SELECT CASE FErr%
CASE 1
IF InfoFile$ = "" THEN
PRINT "Name of file containing names of data files was not found."
ELSE
PRINT "File "; InfoFile$; " was not found. Check file name and path."
END IF
PRINT "To run ENWATBAL you must enter the following line at the DOS prompt:"
COLOR 15, 0
PRINT "ENWATBAL INFOFILE"
COLOR 7, 0
PRINT "and press <Enter>."
PRINT "ENWATBAL is the name of the program and INFOFILE is the name of a file"
PRINT "containing the names of data files needed by the program. See the"
PRINT "documentation for the number of file names needed in file INFOFILE,"
PRINT "the format of this file and the formats of the data files."
CASE 2
PRINT "Improper path or file name, or the file "; Plant$; " does not exist."
CASE 3
PRINT "Improper path or file name, or the file "; IrrPrecip$; " does not exist."
CASE 4
PRINT "Improper path or file name, or the file "; InitDayFile$; " does not exist."
CASE 5
PRINT "Improper path or file name, or the file "; Constants$; " does not exist."
CASE 6
PRINT "Improper path or file name, or the file "; Restart$; " does not exist."
CASE 7
PRINT "Incorrect path given. Cannot open file ENWATBAL.PRN"
CASE 8
PRINT "Cannot open printer as LPT1. Check cable connections and make sure"
PRINT "printer is turned on."
CASE 9
PRINT "Improper path or file name, or file "; Meteo$; " does not exist."
CASE 10
PRINT "Name of file containing initial conditions not found in file "; InfoFile$
CASE 11
PRINT "Name of file containing irrigation and precipitation data"
PRINT "for each day not found in file "; InfoFile$
CASE 12
PRINT "Name of file containing weather data for each day"
PRINT "not found in file "; InfoFile$
CASE 13
PRINT "Name of file containing constants for this run"
PRINT "not found in file "; InfoFile$
CASE 14
PRINT "Name of file containing tables for function AFGEN"
PRINT "not found in file "; InfoFile$
CASE 15
PRINT "Name of file containing half-hourly weather data"
PRINT "not found in file "; InfoFile$
CASE 16
PRINT "Redirection code in file "; InfoFile$; " was neither F for file output"
PRINT "nor P for printer output. You must specify one or the other."
'ENWATBAL.BAS, converted from CSMP simulation language (program ENWATBAL.III)
'to QuickBASIC version 4.5 and Professional BASIC version 7.1
'by S.R. Evett, December 1989 - July 1994.
CONST version$ = "Version of 19 July 1994."
DECLARE SUB FinGraphFile ()
DECLARE SUB GetTheta1Lim ()
DECLARE SUB OpenGraFile ()
DECLARE SUB OutputDay (f%)
DECLARE SUB GetConstants (Constants$)
DECLARE SUB InitProfile ()
DECLARE SUB GetDayYear ()
DECLARE SUB OpenFiles ()
DECLARE SUB RedirectOutput ()
DECLARE SUB SetEpson ()
DECLARE SUB GetFileNames ()
DECLARE SUB InitDepthDist ()
DECLARE SUB InitWeather ()
DECLARE SUB InitSoilWater ()
DECLARE SUB RestartInput ()
DECLARE SUB ReStartFile ()
DECLARE SUB PrintHeader ()
DECLARE SUB GetCommandLine ()
DECLARE SUB AFGENInit ()
DECLARE FUNCTION IMPL1! ()
'Use BYVAL for Microsoft Prof. BASIC, ver. 7.X or Visual BASIC for DOS
'but eliminate BYVAL for QuickBASIC ver. 4.5:
'DECLARE SUB INTGRL (icy!, BYVAL dxdy!)
'DECLARE FUNCTION SIGN! (BYVAL a1!, BYVAL a2!)
'DECLARE FUNCTION AMIN! (BYVAL amin1!, BYVAL amin2!)
'DECLARE FUNCTION LHfT! (BYVAL temperature!)
'DECLARE FUNCTION ARSIN! (BYVAL xdum!)
'DECLARE FUNCTION ARCOS! (BYVAL xdum!)
'DECLARE FUNCTION IMPL2! (BYVAL x1!)
'DECLARE FUNCTION IMPL3! (BYVAL x1!)
'DECLARE FUNCTION AFGEN! (Table!(), BYVAL Xval!)
DECLARE SUB INTGRL (icy!, dxdy!)
DECLARE FUNCTION SIGN! (a1!, a2!)
DECLARE FUNCTION AMIN! (amin1!, amin2!)
DECLARE FUNCTION LHfT! (temperature!)
DECLARE FUNCTION ARSIN! (xdum!)
DECLARE FUNCTION ARCOS! (xdum!)
DECLARE FUNCTION IMPL2! (x1!)
DECLARE FUNCTION IMPL3! (x1!)
DECLARE FUNCTION AFGEN! (Table!(), Xval!)
'Variables shared with module ENWAT2.BAS:
'Strings containing file names for input data files:
COMMON InfoFile$ 'This file contains file names for input data files.
COMMON IrrPrecip$ 'Irrigation & precipitation data.
COMMON DripFile$ 'Drip irrigation rate and time data.
COMMON Constants$ 'Constants
COMMON AfGenFile$ 'Tables of functional relationships.
COMMON Meteo$ 'Weather data with periodicity less than 1 day.
COMMON Plant$ 'Daily weather & plant growth data.
COMMON InitDayFile$ 'Soil layers & their water content & temperature, 1st day.
COMMON FErr% 'Number of error when opening file, related to file name.
COMMON Mode2$ 'Mode to open output files (O=new file, A=append to old file.
COMMON Y$ 'Redirection code, F or f=file, P or p=printer
COMMON HourlyOutputFlag 'If >0 then defines period in hours for output, otherwise only daily output.
'Period of averaged input data and offset, from midnight, of center of 1st mean:
COMMON Period 'Period of weather data that is less than daily [h].
COMMON Offset 'Offset of start of weather data from midnight [h].
COMMON MIndex% '=1+24/Period, index to array holding weather data.
COMMON DebugDat(), di% 'Array holding debugging variables & index to array.
COMMON ErrCode 'Returned from IMPLx if error occurred. Acted on in main program:
COMMON EndDay% 'Simulation ends at midnight of this day of year.
COMMON EndYear% 'Simulation ends in this year.
COMMON sYear% 'Year that simulation starts. File extension for Plant$.
'Constants in Constants$. See subprogram Getconstants:
COMMON Zo 'Surface roughness length (m).
COMMON Z 'Reference elevation (m) for measurement of wind speed,
'air temperature and dew point temperature.
COMMON WPCrMx 'Maximum canopy water potential (m).
COMMON SRCr 'Specific crop hydraulic resistance (s).
COMMON LowBoundGrad 'Gradient for water flux - lower soil boundary condition.
COMMON ZeroCdNum% 'Day of year on which to invoke impeding layer.
COMMON DripFlag% '>0 if a buried drip emitter exists.
COMMON DetCap 'Detention capacity for ponded water (m).
COMMON Lat 'Latitude in degrees.
COMMON AvBarP 'Average barometric pressure (mbar)
COMMON TStepL, TStepH 'Lower & upper limits of time step (s).
COMMON SatCon 'Saturated conductivity for surface soil layer (m/s).
COMMON StartDay% 'Starting day of year. Equals sDay% at start of simulation
'but changes to day of restarting if simulation is stopped and restarted.
COMMON sDay% 'Starting day of year for simulation.
COMMON WMode% 'Code for source of weather data. Daily data are in file PLANT$
'and data on intervales less than 1 d are in file METEO$.
'daily (=0) data or data on intervals less than 1 d (=1).
COMMON Restart$, path$, dnum%, Hl, LH
COMMON cdnum% 'Current day of year.
COMMON TStep 'Current time step (s).
COMMON TimeS 'Time in seconds since midnight of current day.
COMMON sTime 'Time in decimal hours since midnight of current day.
COMMON hTime 'Cumulative time in decimal hours since simulation started.
COMMON EvTr 'Evapotranspiration rate (m/s).
COMMON TrC 'Transpiration rate (m/s).
COMMON LTr 'Transpiration rate (W/m^2).
COMMON Evs 'Rate of evaporation from soil surface (m/s).
COMMON LEvS 'Rate of evaporation from soil surface (W/m^2).
COMMON Infilt 'Infiltration rate (m/s).
COMMON GR 'Solar radiation (W/m^2).
COMMON Ta 'Air temperature (C).
COMMON Tl 'Canopy (big leaf) temperature (C).
COMMON TsBf 'Soil surface temperature for previous time step (C).
COMMON Ra 'Aerodynamic resistance to sensible & latent heat fluxes (s/m).
COMMON Rl 'Big leaf epidermal resistance (s/m).
COMMON Rs 'Soil surface turbulent and diffusive resistance (s/m).
COMMON WPSeff 'Effective soil water potential over root zone (m).
COMMON WPotCr 'Big leaf water potential (m).
COMMON NRBC 'Net radiation balance of the canopy (W/m^2).
COMMON SHCA 'Canopy - air sensible heat exchange (W/m^2).
COMMON NRBS 'Net radiation balance of the soil surface (W/m^2).
COMMON a 'Soil - air sensible heat flux (W/m^2).
COMMON S 'Soil heat flux (W/m^2).
COMMON CRH 'Canopy turbulent resistance (s/m).
COMMON CRV 'Canopy resistance to latent heat flux (s/m).
COMMON MGR 'Daily theoretical max. global clear sky radiation (MJ/m^2).
COMMON SkL 'Sky longwave radiance (W/m^2).
COMMON Runoff 'Runoff rate (m/s).
COMMON Detain 'Surface storage of water (m).
'Cumulative amounts at end of current day:
COMMON CumEvap 'Cumulative evaporation from soil (m).
COMMON CumTrans 'Cumulative transpiration from canopy (m).
COMMON CumET 'Cum. evapotranspiration (m).
COMMON CumPos 'Cum. positive root water uptake (m).
COMMON CumNeg 'Cum. negative root water uptake (m) (exudation).
COMMON CumRC 'Cum. root water flux (m).
COMMON CumInf 'Cum. infiltration (m).
COMMON CumPrec 'Cum. precipitation (m) (includes irrigation).
COMMON CumDrip 'Cum. drip irrigation (m).
COMMON CumDrain 'Cum. drainage (m).
COMMON CumRunoff 'Cum. runoff (m).
COMMON CumG 'Cum. soil heat flux (m of water equivalent).
COMMON CumRs 'Cum. solar radiation (J/m^2).
COMMON StorWater 'Water stored in soil profile (m).
COMMON CumRootUptake 'Cum. root water flux (m).
COMMON WBalance 'Soil profile water balance (m).
COMMON iWater 'Initial soil profile water storage (m).
COMMON Theta1Lim 'Vol. water content for potential of -0.1 m, used in time
'step setting algorithm.
'These cumulative amounts are for the end of the previous day:
COMMON CumEvBf 'Cum. evaporation from soil (m).
COMMON CumTrBf 'Cum. transpiration (m).
COMMON CumETBf 'Cum. evapotranspiration (m).
COMMON CumPosBf 'Cum. positive root water uptake (m).
COMMON CumNegBf 'Cum. negative root water uptake (m) (exudation).
COMMON CumInfBf 'Cum. infiltration (m).
COMMON CumPrecBf 'Cum. precipitation (m).
COMMON CumDripBf 'Cum. drip irrigation (m).
COMMON CumDrnBf 'Cum. drainage (m).
COMMON CumRunoffBf 'Cum. runoff (m).
COMMON CumGBf 'Cum. soil heat flux (m of water equivalent).
COMMON CumRsBf 'Cum. solar radiation (J/m^2).
COMMON CumRootUptakeBf 'Cum. root water flux (m).
COMMON nLayers% 'Number of soil layers (finite differences).
'Definitions of arrays given where arrays are dimensioned below:
COMMON WInput1(), Meteo()
COMMON Dist(), BothLayerThick(), HorNum%(), Depth(), SLThick(), Porsty()
COMMON ZeroCondLayer%()
COMMON DripLayer%()
COMMON WaterOutPutFlag%()
COMMON TempOutPutFlag%()
COMMON Cond(), Kond(), ppot(), AvCond(), AvKond()
COMMON Flow(), Flux(), nFlow(), nFlux(), Theta(), VolW(), VolH(), Temp()
COMMON RF(), RC()
COMMON Header$()
COMMON ClvsWP() 'Holds data for epidermal conductance vs. leaf water potential.
COMMON ClvsGR() 'Holds data for epidermal conductance vs. solar radiation.
COMMON dummy() 'Holds data for soil water potential vs. vol. water content.
COMMON TvsP1() 'Horizon 1 data for soil water potential vs. volumetric water content.
COMMON TvsP2() 'Horizon 2 data for soil water potential vs. volumetric water content.
COMMON TvsP3() 'Horizon 3 data for soil water potential vs. volumetric water content.
COMMON TvsP4() 'Horizon 4 data for soil water potential vs. volumetric water content.
COMMON TvsP5() 'Horizon 5 data for soil water potential vs. volumetric water content.
COMMON TvsP6() 'Horizon 6 data for soil water potential vs. volumetric water content.
COMMON TvsP7() 'Horizon 7 data for soil water potential vs. volumetric water content.
COMMON TvsP8() 'Horizon 8 data for soil water potential vs. volumetric water content.
COMMON TvsP9() 'Horizon 9 data for soil water potential vs. volumetric water content.
COMMON TvsC1() 'Horizon 1 data for hydraulic conductivity vs. " " ".
COMMON TvsC2() 'Horizon 2 data for hydraulic conductivity vs. " " ".
COMMON TvsC3() 'Horizon 3 data for hydraulic conductivity vs. " " ".
COMMON TvsC4() 'Horizon 4 data for hydraulic conductivity vs. " " ".
COMMON TvsC5() 'Horizon 5 data for hydraulic conductivity vs. " " ".
COMMON TvsC6() 'Horizon 6 data for hydraulic conductivity vs. " " ".
COMMON TvsC7() 'Horizon 7 data for hydraulic conductivity vs. " " ".
COMMON TvsC8() 'Horizon 8 data for hydraulic conductivity vs. " " ".
COMMON TvsC9() 'Horizon 9 data for hydraulic conductivity vs. " " ".
COMMON TevsKO() 'Holds data for soil temperature vs. heat conductivity by vapor.
COMMON SoilAL() 'Data for soil water content (m^3/m^3) vs. soil albedo.
'Get name of file containing data file names from command line and find out
'if this is a restart of a simulation:
GetCommandLine
'Get names of files needed by ENWATBAL, day to stop simulation, path for
'output files, redirect some output as instructed and open output device as #6:
GetFileNames
'Find starting day and year. If this is a restart then starting day is defined
'later:
GetDayYear
'Open files:
OpenFiles 'Open some input and output files.
PRINT "OpenFiles completed": 'sleep
IF WMode% = 1 THEN MIndex% = 1 + 24! / Period
'Constants:
CONST Pi = 3.14159
CONST SIGMA = 5.67E-08 'Stefan-Boltzmann constant [W/m^2/K].
CONST KondS = 1.68 'Thermal conductivity of soil solids [W/m/C] multiplied by 0.4.
CONST KondW = .57 ' " " " water [W/m/C].
CONST KondA = .025 ' " " " air [W/m/C].
CONST VHCapS = 1925000! 'Volumetric heat capacity of soil solids [J/m^3/C].
CONST VHCapW = 4186000! ' " " " " water [J/m^3/C].
CONST GRAV = 9.81 'Gravitational constant [m/s].
CONST x1.1 = -50000! 'Lower limit for function IMPL1 (leaf water potential).
CONST x2.1 = 0! 'Upper limit for IMPL1.
CONST tol.1 = .01 'Tolerance for IMPL1.
CONST x2.2 = 100! 'Upper limit for IMPL2, lower limit is Ta.
CONST tol.2 = .01 'Tolerance for IMPL2.
CONST x2.3 = 150! 'Upper limit for IMPL3, lower limit is Ta.
CONST tol.3 = .01 'Tolerance for IMPL3.
i% = 100
DIM Header$(i%) 'Array to hold strings in user defined header.
GetConstants (Constants$) 'Get constants & header that may be changed between runs.
IF LEN(Restart$) THEN PrintHeader 'No need to print this if restarting.
'Dimensionless constant used in aerodynamic resistance [s/m] calculations;
'assumes wind speed measured at 2 m elevation; depends on Z & Zo from GetConstants:
RaConst = (LOG(Z / Zo) ^ 2) / .16
CntT = HourlyOutputFlag 'counter for number of hours.
'Definition of arrays and variables:
'nLayers% = Number of soil layers. Changed in InitProfile.
DIM SLThick(nLayers%) 'Thickness of soil layer i [m].
DIM Theta(nLayers%) 'Water content of each soil layer [m^3/m^3].
DIM Temp(nLayers%) 'Soil layer temperature [C].
DIM HorNum%(nLayers%) 'Horizon number (numbered sequentially downward starting w/ 1).
DIM ZeroCondLayer%(nLayers%) 'Flag for layer that has zero hydraulic conductivity at bottom.
DIM DripLayer%(nLayers%) 'Flag for layer with drip emitter.
DIM WaterOutPutFlag%(nLayers%) 'Flag for output of water content values in WATEROUT.
DIM TempOutPutFlag%(nLayers%) 'Flag for output of temperature values in WATEROUT.
'Read initial soil profile data and get values for number of layers
'(nLayers%), layer thicknesses [m] and initial water contents [m^3/m^3]
'and temperatures [Deg.C]:
InitProfile
PRINT "InitProfile done.": 'sleep
PRINT "There were"; nLayers%; " soil layers."
DIM RFLAIdivSRCR(nLayers%) 'Holds diurnally constant values in RC() calculation.
DIM BothLayerThick(nLayers%)'Thickness of soil layer i plus layer i-1 [m].
DIM Depth(nLayers% + 1) 'Depth to middle of soil layer I [m].
DIM Dist(nLayers% + 1) 'Distance between centers of layers I and I+1 [m].
InitDepthDist 'Initialize Depth(), Dist() & BothLayerThick() arrays.
PRINT "InitDepthDist done."
DIM RF(nLayers% + 1) 'Rooting fraction [dimensionless].
DIM ppot(nLayers% + 1) 'Soil layer matric potential [m].
DIM HPot(nLayers% + 1) 'Soil layer matric + gravitational potential [m].
DIM Cond(nLayers% + 1) 'Soil layer hydraulic conductivity [m/s].
DIM AvCond(nLayers% + 1) 'Average hydraulic conductivity between soil layers [m/s].
DIM Flux(nLayers% + 1) 'Flow of water into soil layer [m/s].
DIM RC(nLayers% + 1) 'Soil layer root uptake [m/s]. Can be + or -.
DIM VHCap(nLayers% + 1) 'Soil layer volumetric heat capacity [J/m^3/C]. ].
DIM Kond(nLayers% + 1) 'Soil layer thermal conductivity [J/m/s/C].
DIM AvKond(nLayers% + 1) 'Average thermal cond. between soil layers [J/m/s/C].
DIM Flow(nLayers% + 1) 'Flow of heat into soil layer [J/s/m^2].
DIM Porsty(9) 'Porosity of up to 9 soil horizons.
DIM Begin(i%) 'Begin times for irrig./precip. events in a 24 hour period.
DIM End1(i%) 'End times for same.
DIM PrecT(i%) 'Amounts of irrig./precip. events [mm].
DIM BeginDrip(i%) 'Begin times for drip irrig. events in a day [h].
DIM EndDrip(i%) 'End times for drip irrig. events in a day [h].
DIM DripRate(i%) 'Rates of drip irrig. events [m/s].
DIM WInput1(13, 3) '12 diurnal variables (4 for plant growth) & 3 days (yesterday, today & tomorrow).
DIM Meteo(9, MIndex% + 1) '9 weather variables, MIndex%+1 1/2 h periods (1 yesterday, MIndex% today & 1 tomorrow).
DIM DebugDat(40, 12) '20 rows of 12 variables may be saved in a circular
'data buffer here for debugging purposes.
'Variables that were dimensioned implicitly via the INTGRL function of the
'CSMP version are dimensioned explicitly here:
DIM VolW(nLayers% + 1) 'Volume of water per unit area of soil layer [m].
DIM VolH(nLayers% + 1) 'Volumetric heat content of soil layer [J/m^2].
DIM nFlow(nLayers% + 1) 'Net flow of heat into soil layer [J/s/m^2].
DIM nFlux(nLayers% + 1) 'Net flow of water into soil layer [m/s].
'The following arrays are passed to Function AfGen which returns a
'linear interpolation of one variable corresponding to another.
'These arrays are redimensioned and initialized in subprogram AFGENInit:
i% = 1
DIM ClvsWP(i%, 2) 'Holds data for epidermal conductance vs. leaf water potential.
DIM ClvsGR(i%, 2) 'Holds data for epidermal conductance vs. solar radiation.
DIM dummy(i%, 2) 'Holds data for soil water potential vs. vol. water content.
DIM TvsP1(i%, 2) 'Horizon 1 data for soil water potential vs. volumetric water content.
DIM TvsP2(i%, 2) 'Horizon 2 data for soil water potential vs. volumetric water content.
DIM TvsP3(i%, 2) 'Horizon 3 data for soil water potential vs. volumetric water content.
DIM TvsP4(i%, 2) 'Horizon 4 data for soil water potential vs. volumetric water content.
DIM TvsP5(i%, 2) 'Horizon 5 data for soil water potential vs. volumetric water content.
DIM TvsP6(i%, 2) 'Horizon 6 data for soil water potential vs. volumetric water content.
DIM TvsP7(i%, 2) 'Horizon 7 data for soil water potential vs. volumetric water content.
DIM TvsP8(i%, 2) 'Horizon 8 data for soil water potential vs. volumetric water content.
DIM TvsP9(i%, 2) 'Horizon 9 data for soil water potential vs. volumetric water content.
DIM TvsC1(i%, 2) 'Horizon 1 data for hydraulic conductivity vs. " " ".
DIM TvsC2(i%, 2) 'Horizon 2 data for hydraulic conductivity vs. " " ".
DIM TvsC3(i%, 2) 'Horizon 3 data for hydraulic conductivity vs. " " ".
DIM TvsC4(i%, 2) 'Horizon 4 data for hydraulic conductivity vs. " " ".
DIM TvsC5(i%, 2) 'Horizon 5 data for hydraulic conductivity vs. " " ".
DIM TvsC6(i%, 2) 'Horizon 6 data for hydraulic conductivity vs. " " ".
DIM TvsC7(i%, 2) 'Horizon 7 data for hydraulic conductivity vs. " " ".
DIM TvsC8(i%, 2) 'Horizon 8 data for hydraulic conductivity vs. " " ".
DIM TvsC9(i%, 2) 'Horizon 9 data for hydraulic conductivity vs. " " ".
DIM TevsKO(i%, 2) 'Holds data for soil temperature vs. heat conductivity by vapor.
DIM SoilAL(i%, 2) 'Data for soil water content (m^3/m^3) vs. soil albedo.
'Polynomial coefficients for solar declination calculation:
CONST c1.1 = .3964
CONST c1.2 = 3.631
CONST c1.3 = .03838
CONST c1.4 = .07659
CONST c1.5 = 0!
CONST c1.6 = -22.97
CONST c1.7 = -.3885
CONST c1.8 = -.1587
CONST c1.9 = -.01021
'Initialize previous soil surface temperature to equal temp. of 1st layer:
TsBf = Temp(1)
PRINT "Initial surface temperature:"; TsBf ': SLEEP
'Initialize temperature of soil at bottom of profile:
TsBottom = Temp(nLayers%)
'Initialize data in arrays for function AFGEN, get water content of 1st layer
'at -0.1 m for use in time step algorithm & get porosity for each horizon:
AFGENInit
PRINT "AFGENInit done.": 'sleep
'Find vol. water content for potential of -0.1 m:
GetTheta1Lim
PRINT "Theta1Lim"; Theta1Lim
'Get plant growth and weather data in arrays WInput1() & Meteo() for 1st 2 days:
InitWeather
PRINT "InitWeather done.": 'sleep
' IF restart$ = "" THEN
'Initialize water content and heat capacity of soil layers:
' InitSoilWater
' ELSE
'Get final values saved at end of last run that will be initial values:
IF LEN(Restart$) THEN 'If Restart$<>"".
RestartInput
PRINT "RestartInput done."
END IF
'Initialize heat capacity and depth of water in soil layers (and get total
'water content if starting):
PRINT #2, "Initial water depth, VHCap and Volumetric heat capacity:"
PRINT "Initial water depth, VHCap and Volumetric heat capacity:"
InitSoilWater
PRINT "InitSoilWater done.": 'SLEEP
'Open files for graphing:
CALL OpenGraFile 'Open files for graphing.
'Put depths (m) in water content & temperature profile output file:
IF HourlyOutputFlag > 0 THEN
FOR i% = 1 TO nLayers%
IF WaterOutPutFlag%(i%) = 1 THEN PRINT #7, Depth(i%);
NEXT i%
FOR i% = 1 TO nLayers%
IF TempOutPutFlag%(i%) = 1 THEN PRINT #7, Depth(i%);
NEXT i%
PRINT #7,
END IF
PRINT "OpenGraFile completed.": 'SLEEP
'Initialize Julian day, rank day, time, leaf temperature and internal
'humidity, time step and time in seconds, hours and cumulative hours:
cdnum% = StartDay% - 1
IF Restart$ = "" THEN
dnum% = 0 'rank day, day from start of simulation.
Tl = WInput1(4, 3) 'Leaf temp. initially equals min. air temp.
Ts = Tl
'Leaf internal absolute humidity:
Hl = 1.323 * EXP(17.27 * Tl / (237.3 + Tl)) / (273.16 + Tl)
LH = LHfT(Tl) 'Latent heat of vaporization.
TStep = 1! 'Set time step in seconds. This will change dynamically.
TimeS = 0! 'Set so that TimeS [s] will be zero initially.
sTime = 0! 'Decimal hour is zero initially.
hTime = 0! 'Cumulative decimal hour is zero initially.
END IF
eTime = TIMER 'Get start of computation time.
di% = 1 'Index for DebugDat().
'Initialize plant & weather data: Get Julian day, rank day, maximum clear sky
'solar radiation, daily data, rooting depths and densities and canopy optical
'properties for first day:
cdYearBf% = sYear%
GOSUB InitDay 'resets cdnum% to StartDay% by adding 1 to it.
IF InputErrFlag = 1 THEN GOTO MainLoopEnd
'If past ending day then quit:
IF cdnum% > EndDay% AND cdYearBf% = EndYear% THEN GOTO MainLoopEnd
IF cdnum% <= 0 THEN GOTO MainLoopEnd 'If out of data then exit program.
'Start of main loop. *********************************************************
'Flow refers to heat. Flux refers to water:
DO
1
'PRINT "Time"; sTime; "time step"; TStep; "Infilt"; Infilt; "Theta(1)"; Theta(1); "ThetaLim"; Theta1Lim
DebugDat(di%, 0) = sTime
'Update heat and water stored in each layer:
FOR i% = 1 TO nLayers%
CALL INTGRL(VolW(i%), (nFlux(i%))) 'Returns VolW().
Theta(i%) = VolW(i%) / SLThick(i%) '1st find new soil water content.
CALL INTGRL(VolH(i%), (nFlow(i%))) 'Returns VolH().
NEXT i%
'Start of code defining derivative values that are integrated in INTGRL.
2
'Update hydraulic and thermal properties:
i% = 1 'Do for 1st layer first:
'Get properties for up to 9 soil horizons:
Pors = Porsty(HorNum%(i%)) 'Soil porosity, horizon HorNum%(i%).
SoilVol = 1! - Pors 'Soil solids fraction volume, horizon HorNum%(i%).
SELECT CASE HorNum%(i%)
CASE 1
Cond(i%) = AFGEN(TvsC1(), (Theta(i%))) 'Horizon 1.
ppot(i%) = AFGEN(TvsP1(), (Theta(i%)))
CASE 2
Cond(i%) = AFGEN(TvsC2(), (Theta(i%))) 'Horizon 2.
ppot(i%) = AFGEN(TvsP2(), (Theta(i%)))
CASE 3
Cond(i%) = AFGEN(TvsC3(), (Theta(i%))) 'Horizon 3.
ppot(i%) = AFGEN(TvsP3(), (Theta(i%)))
CASE 4
Cond(i%) = AFGEN(TvsC4(), (Theta(i%))) 'Horizon 4.
ppot(i%) = AFGEN(TvsP4(), (Theta(i%)))
CASE 5
Cond(i%) = AFGEN(TvsC5(), (Theta(i%))) 'Horizon 5.
ppot(i%) = AFGEN(TvsP5(), (Theta(i%)))
CASE 6
Cond(i%) = AFGEN(TvsC6(), (Theta(i%))) 'Horizon 6.
ppot(i%) = AFGEN(TvsP6(), (Theta(i%)))
CASE 7
Cond(i%) = AFGEN(TvsC7(), (Theta(i%))) 'Horizon 7.
ppot(i%) = AFGEN(TvsP7(), (Theta(i%)))
CASE 8
Cond(i%) = AFGEN(TvsC8(), (Theta(i%))) 'Horizon 8.
ppot(i%) = AFGEN(TvsP8(), (Theta(i%)))
CASE 9
Cond(i%) = AFGEN(TvsC9(), (Theta(i%))) 'Horizon 9.
ppot(i%) = AFGEN(TvsP9(), (Theta(i%)))
CASE ELSE
PRINT "Horizon not selected in update of hydraulic properties."
PRINT "Program will end now. Press any key ..."
SLEEP: END
END SELECT
'IF Temp(i%) < 0 THEN Cond(i%) = 0! 'no flux if frozen.
'Update hydraulic properties:
HPot(i%) = ppot(i%) - Depth(i%) 'Include gravitational potential.
'Update thermal properties, vol. heat cap., temperature & thermal cond.:
'PRINT "Ta, Ts, i, Temp(i), Theta(i):"; Ta; Ts; i%; Temp(i%); Theta(i%)
VHCap(i%) = VHCapW * Theta(i%) + SoilVol * VHCapS
Temp(i%) = VolH(i%) / (VHCap(i%) * SLThick(i%))
KondV = AFGEN(TevsKO(), (Temp(i%)))
dum = (SoilVol * KondS + Theta(i%) * KondW + (Pors - Theta(i%)) * 1.4 * (KondA + KondV))
Kond(i%) = dum / (SoilVol * .4 + Theta(i%) + (Pors - Theta(i%)) * 1.4)
'For Pullman clay loam at Bushland, TX:
' Kond(i%) = -.068 + 3.3086 * Theta(i%)
' IF Kond(i%) < .15 THEN Kond(i%) = .15
FOR i% = 2 TO nLayers%
'Get properties for up to 9 soil horizons:
Pors = Porsty(HorNum%(i%)) 'Soil porosity, horizon HorNum%(i%).
SoilVol = 1! - Pors 'Soil solids fraction volume, horizon HorNum%(i%).
SELECT CASE HorNum%(i%)
CASE 1
Cond(i%) = AFGEN(TvsC1(), (Theta(i%))) 'Horizon 1.
ppot(i%) = AFGEN(TvsP1(), (Theta(i%)))
CASE 2
Cond(i%) = AFGEN(TvsC2(), (Theta(i%))) 'Horizon 2.
ppot(i%) = AFGEN(TvsP2(), (Theta(i%)))
CASE 3
Cond(i%) = AFGEN(TvsC3(), (Theta(i%))) 'Horizon 3.
ppot(i%) = AFGEN(TvsP3(), (Theta(i%)))
CASE 4
Cond(i%) = AFGEN(TvsC4(), (Theta(i%))) 'Horizon 4.
ppot(i%) = AFGEN(TvsP4(), (Theta(i%)))
CASE 5
Cond(i%) = AFGEN(TvsC5(), (Theta(i%))) 'Horizon 5.
ppot(i%) = AFGEN(TvsP5(), (Theta(i%)))
CASE 6
Cond(i%) = AFGEN(TvsC6(), (Theta(i%))) 'Horizon 6.
ppot(i%) = AFGEN(TvsP6(), (Theta(i%)))
CASE 7
Cond(i%) = AFGEN(TvsC7(), (Theta(i%))) 'Horizon 7.
ppot(i%) = AFGEN(TvsP7(), (Theta(i%)))
CASE 8
Cond(i%) = AFGEN(TvsC8(), (Theta(i%))) 'Horizon 8.
ppot(i%) = AFGEN(TvsP8(), (Theta(i%)))
CASE 9
Cond(i%) = AFGEN(TvsC9(), (Theta(i%))) 'Horizon 9.
ppot(i%) = AFGEN(TvsP9(), (Theta(i%)))
CASE ELSE
PRINT "Horizon not selected in update of hydraulic properties."
PRINT "Program will end now. Press any key ..."
SLEEP: END
END SELECT
'IF Temp(i%) < 0 THEN Cond(i%) = 0! 'no flux if frozen.
'Update hydraulic properties:
HPot(i%) = ppot(i%) - Depth(i%) 'Include gravitational potential.
'Update thermal properties, vol. heat cap., temperature & thermal cond.:
'PRINT "Ta, Ts, i, Temp(i), Theta(i):"; Ta; Ts; i%; Temp(i%); Theta(i%)
3 VHCap(i%) = VHCapW * Theta(i%) + SoilVol * VHCapS
4 Temp(i%) = VolH(i%) / (VHCap(i%) * SLThick(i%))
5 KondV = AFGEN(TevsKO(), (Temp(i%)))
dum = (SoilVol * KondS + Theta(i%) * KondW + (Pors - Theta(i%)) * 1.4 * (KondA + KondV))
Kond(i%) = dum / (SoilVol * .4 + Theta(i%) + (Pors - Theta(i%)) * 1.4)
'For Pullman clay loam at Bushland, TX:
' Kond(i%) = -.068 + 3.3086 * Theta(i%)
' IF Kond(i%) < .15 THEN Kond(i%) = .15
'Compute water flux and heat flow in the profile (between layers but not at
'the surface, i.e. AvCond(1) and AvKond(1) are left equal to zero; and not
'at the lower boundary, those are calculated further below:
dum = (Cond(i% - 1) * SLThick(i% - 1) + Cond(i%) * SLThick(i%))
AvCond(i%) = dum / BothLayerThick(i%)
IF ZeroCondLayer%(i% - 1) = 1 AND cdnum% > ZeroCdNum% THEN AvCond(i%) = 0
AvKond(i%) = (Kond(i% - 1) * SLThick(i% - 1) + Kond(i%) * SLThick(i%)) / BothLayerThick(i%)
'AvKond(i%) = BothLayerThick(i%) / (SLThick(i% - 1) / Kond(i% - 1) + SLThick(i%) / Kond(i%))
Flow(i%) = (Temp(i% - 1) - Temp(i%)) * AvKond(i%) / Dist(i%)
Flux(i%) = (HPot(i% - 1) - HPot(i%)) * AvCond(i%) / Dist(i%)
NEXT i%
BottomGrad = (HPot(nLayers% - 1) - HPot(nLayers%)) / Dist(nLayers%)
'PRINT "BottomGrad"; BottomGrad
'For water flux at lower boundary use the gradient given by LowBoundGrad.
'Typically LowBoundGrad=1 for unit gradient assumption or =0 for zero
'flux at lower boundary:
IF LowBoundGrad < -99 THEN
Flux(nLayers% + 1) = Cond(nLayers%) * BottomGrad
ELSE
Flux(nLayers% + 1) = Cond(nLayers%) * LowBoundGrad
END IF
'Assume constant temperature at lower boundary:
Flow(nLayers% + 1) = (Temp(nLayers%) - TsBottom) * Kond(nLayers%) / (SLThick(nLayers%) / 2!)
'Find soil albedo:
ALB = AFGEN(SoilAL(), (Theta(1)))
'Scale ABSS according to surface soil albedo:
ABSSa = ABSS * (1! - ALB) / .825
6
'Find drip irrigation rate [m/s]:
DripFlux = 0!
FOR i% = 1 TO NDripEvents%
IF sTime > BeginDrip(i%) AND sTime < EndDrip(i%) THEN
DripFlux = DripRate(i%) / 3600! 'convert m/h to m/s.
EXIT FOR
END IF
NEXT i%
'Find precipitation rate [m/s]:
PrecR = 0! 'Initialize precip. rate to zero.
FOR i% = 1 TO NEvents%
'Search for correct event
IF sTime > Begin(i%) AND sTime < End1(i%) THEN
'Calculate rate and leave.
'UpSlop = (4! * PrecT(i%)) / ((End1(i%) - Begin(i%)) ^ 2)
UpSlop = 4! * PrecT(i%) / ((End1(i%) - Begin(i%)) * (End1(i%) - Begin(i%)))
DwSlop = -UpSlop
MdPnt = (Begin(i%) + End1(i%)) / 2!
'Calculate precipitation rate in m/s:
IF sTime <= MdPnt THEN
PrecR = (UpSlop * (sTime - Begin(i%))) / 3600000#
ELSE
PrecR = (DwSlop * (sTime - End1(i%))) / 3600000#
END IF
EXIT FOR
END IF
NEXT i%
'Calculate weather variables by interpolation:
IF WMode% = 1 THEN
'Calculate indices for weather array assuming half-hourly average values:
'Index1% = INT(sTime / Period + Offset / Period)
Index1% = INT(sTime * 2! + .5)
Index2% = Index1% + 1
'dTime = sTime + Offset - Index1% * Period
dTime = sTime + .25 - Index1% * .5
'Calculate air temperature [C]:
'Ta = (Meteo(4, Index2%) - Meteo(4, Index1%)) / Period * dTime + Meteo(4, Index1%)
Ta = (Meteo(4, Index2%) - Meteo(4, Index1%)) / .5 * dTime + Meteo(4, Index1%)
'Calculate dew point temperature [C]:
'DPTc = (Meteo(6, Index2%) - Meteo(6, Index1%)) / Period * dTime + Meteo(6, Index1%)
DPTc = (Meteo(6, Index2%) - Meteo(6, Index1%)) / .5 * dTime + Meteo(6, Index1%)
'Calculate solar radiation [W/m^2]:
'GR = (Meteo(8, Index2%) - Meteo(8, Index1%)) / Period * dTime + Meteo(8, Index1%)
GR = (Meteo(8, Index2%) - Meteo(8, Index1%)) / .5 * dTime + Meteo(8, Index1%)
'Calculate wind speed [m/s]. Add small value to avoid division by zero:
'SA = (Meteo(3, Index2%) - Meteo(3, Index1%)) / Period * dTime + Meteo(3, Index1%)
SA = (Meteo(3, Index2%) - Meteo(3, Index1%)) / .5 * dTime + Meteo(3, Index1%)
ELSE
'Use diurnal average values:
'Find global (solar) radiation flux density [W/m^2]:
'GRConst defined in InitDay:
GR = GRConst * SIN(sTime * PIdivDL - Phase)
'Find average wind speed:
'UDayBf, UDay, UDayBFDif and UDayAfDif defined in InitDay:
IF (sTime <= 12!) THEN
SA = UDayBF + (sTime + 12!) / 24! * (UDayBfDif)
ELSE
SA = UDay + (sTime - 12!) / 24! * (UDayAfDif)
END IF
'Calculate air temperature [Deg.C]:
'TaMax, TaMin, TaBaxBf, TaAfAmp, TaBfAmp and TaAmp defined in InitDay:
IF sTime > 15! THEN
Ta = TaMax - (TaAfAmp) * (sTime - 15!) / 14!
ELSEIF sTime < 5! THEN
Ta = TaMaxBf - (TaBfAmp) * (sTime + 9!) / 14!
ELSE
Ta = TaMin + (TaAmp) * (sTime - 5!) / 10!
END IF
'Calculate dew point temperature, DPTc, [Deg.C]:
'DPMax, DPMin, DPMaxBf, DPAfAmp, DPBfAMP and DPAmp defined in InitDay:
IF sTime > 15! THEN
DPTc = DPMax - (DPAfAmp) * (sTime - 15!) / 14!
ELSEIF sTime < 5! THEN
DPTc = DPMaxBf - (DPBfAmp) * (sTime + 9!) / 14!
ELSE
DPTc = DPMin + (DPAmp) * (sTime - 5!) / 10!
END IF
END IF
IF SA < .01 THEN SA = .01 'Set lowest possible wind speed in m/s.
IF GR <= 0! THEN GR = 0! 'No negative solar radiation.
DebugDat(di%, 1) = Ta
DebugDat(di%, 2) = DPTc
DebugDat(di%, 3) = Tl
TaK = Ta + 273.16
7
'Aerodynamic resistance [s/m].
Ra = RaConst / SA 'RaConst is given in the initialization section.
'Soil surface turbulent and diffusive resistance [s/m]:
Rs = Ra * LAIRsConst 'LAIRsConst is given in subroutine InitDay.
'Find explicitly related parameters:
'Air humidity, Ha, [kg/m^3]:
Ha = 1.323 * EXP(17.27 * DPTc / (237.3 + DPTc)) / TaK
'Sensible heat capacity of the air, SH, [J/m^3/Deg.C]:
'SHConst is given in subroutine InitDay.
SH = SHConst / TaK
'Sky longwave radiance, SKL, [W/m^2], SklConst defined in InitDay:
IF WMode% = 1 THEN
'Use Idso's version (from CONSERVB) since other method requires
'knowledge of global solar rad. and max. possible solar rad.:
eo = .6178 * EXP((17.169 * DPTc) / (237.3 + DPTc))
emsky = .7 + .000595 * eo * EXP(1500! / TaK)
SkL = emsky * SIGMA * TaK * TaK * TaK * TaK
ELSE
SkL = SIGMA * TaK * TaK * TaK * TaK * (.7 + .08241 * Ha * EXP(1500! / TaK)) * SklConst
END IF
8
'Calculate the effective soil water potential:
WPSeff = 0!
FOR i% = 1 TO nLayers%
WPSeff = WPSeff + ppot(i%) * RF(i%)
NEXT i%
'Component of leaf epidermal resistance dependent on solar radiation.
Cl2 = AFGEN(ClvsGR(), GR)
IF LAI > 0! THEN
'Canopy turbulent resistance [s/m]:
CRH = Ra * LAICRHConst 'LAICRHConst is given in subroutine InitDay.
'Calculate Richardson number for canopy and correct CRH. Two methods given:
'RI = GRAV * (Z - Zo) * (Ta - Tl) / (TaK * SA ^ 2)
''Redefine CRH using stability correction from CONSERVB.
'IF RI > .08 THEN RI = .08 'Limit RI.
'CRH = CRH / (1! - 10! * RI)
'Redefine CRH using stability correction from Monteith, J.L.,
'and M.H. Unsworth. 1973. Principles of environmental
'physics, 2nd edn. Edward Arnold, London. P. 238.
'IF RI > 1! THEN RI = 1! 'Limit RI.
'IF RI < -.1 THEN
' CRH = CRH / ((1! - 16! * RI) ^ .75)
'ELSE 'IF Ri >= -.1 AND Ri <= 1 THEN
' CRH = CRH / ((1! - 5! * RI) * (1! - 5! * RI))
'END IF
'Implicitly calculate the canopy water potential, WPotCr [m], -30000 is the
'lower quess, 0.0 is the upper quess & 0.01 is the convergence criterion:
WPotCr = IMPL1!
IF ErrCode = 9 THEN GOSUB ErrDump
DebugDat(di%, 4) = WPotCr
'Implicitly calculate the leaf temperature, Tl [C], and transpiration rate.
'Air temperature, Ta, is the lower guess, 100 is the upper guess & 0.01
'is the convergence criterion:
'Tl = IMPL2!(BYVAL Ta)
Tl = IMPL2!(Ta)
IF ErrCode = 9 THEN GOSUB ErrDump
DebugDat(di%, 5) = Tl
DebugDat(di%, 6) = Hl
TrC = LTr / (1000! * LH) 'Transpiration rate [m/s].
END IF
9
'Calculate Richardson number for soil surface. Two methods given:
' RI = GRAV * (Z - Zo) * (Ta - Ts) / (TaK * SA ^ 2)
' 'Redefine Rs using stability correction from CONSERVB.
' IF RI > .08 THEN RI = .08 'Limit RI.
' Rs = Rs / (1! - 10! * RI)
' 'Redefine Rs using stability correction from
' 'Monteith, J.L., and M.H. Unsworth. 1973. Principles of environmental
' 'physics, 2nd edn. Edward Arnold, London. P. 238.
' IF RI > 1! THEN RI = 1! 'Limit RI.
' IF RI < -.1 THEN
' Rs = Rs / ((1! - 16! * RI) ^ .75)
' ELSE 'IF Ri >= -.1 AND Ri <= 1 THEN
' Rs = Rs / ((1! - 5! * RI) * (1! - 5! * RI))
' END IF
'Implicitly calculate the surface temperature, Ts [C], and evaporation rate.
'Air temperature, Ta, is the lower guess, 100 is the upper guess & 0.01 is
'the convergence criterion:
Tg = Ta
'Ts = IMPL3!(BYVAL Tg)
Ts = IMPL3!(Ta)
DelTs = ABS(Ts - TsBf)
IF DelTs > 5! THEN
PRINT #6, "Surface T changed"; Ts - TsBf; "Deg.C from"; TsBf; "to"; Ts;
PRINT #6, "in"; TStep; "s, ";
PRINT #6, sTime; " hrs, day"; cdnum%; " Air T:"; Ta
'IF Ts > TsBf THEN Ts = TsBf + 5! ELSE Ts = TsBf - 5!
END IF
IF DelTs > MaxDelTs THEN MaxDelTs = DelTs 'Find maximum change in surface temperature.
TsBf = Ts
IF ErrCode = 9 THEN GOSUB ErrDump
10
Evs = LEvS / (1000! * LH) 'Evaporation rate [m/s].
Flow(1) = S 'Get soil heat flux rate from surface energy balance [W m^-2].
G = S / (1000! * LH) 'Get soil heat flux rate [m/s].
EvTr = Evs + TrC 'ET rate equals Evap. rate plus transpiration rate.
DebugDat(di%, 7) = Temp(1)
DebugDat(di%, 8) = Kond(1)
DebugDat(di%, 9) = Ts
DebugDat(di%, 10) = Ta
DebugDat(di%, 11) = ppot(1)
DebugDat(di%, 12) = Theta(1)
'Calculate the root water uptake. It is zero if LAI is zero:
RCPos = 0!
RCNeg = 0!
RCTotal = 0!
IF LAI > 0 THEN
FOR i% = 1 TO nLayers%
'RFLAIdivSRCR(i%) defined in InitDay:
RC(i%) = (WPotCr - WPCrMx - ppot(i%)) * RFLAIdivSRCR(i%)
'Use next 7 lines to be compatible with ENWATBAL.III:
'IF RC(i%) <= 0! THEN
' 'Calculate the total negative uptake:
' RCNeg = RCNeg + RC(i%)
'ELSE
' 'Calculate the total positive uptake (exudation):