-
Notifications
You must be signed in to change notification settings - Fork 0
/
ENWAT2.BAS
1811 lines (1725 loc) · 68.6 KB
/
ENWAT2.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."
CASE 17
PRINT "Improper path or file name, or the file "; DripFile$; " does not exist."
RESUME NEXT
CASE 18
PRINT "Name of file containing drip irrigation times and rates"
PRINT "not found in file "; InfoFile$
PRINT #2, "Name of file containing drip irrigation times and rates"
PRINT #2, "not found in file "; InfoFile$
RESUME NEXT
CASE ELSE
END SELECT
PRINT "Program will end now. Press any key."
SLEEP
END
ConstantInputErr:
IF i% > 0 THEN RESUME 'EndConstantInput 'Probably ran out of space in string array.
PRINT "Error in reading in constants from file: "; Constants$
PRINT "Examine file ENWATBAL.PRN. Press any key to end program ...."
SLEEP
END
'=============================================================================
MkDirErr:
IF ERR = 75 OR ERR = 53 THEN RESUME NEXT
PRINT "Error no."; ERR; "while making directory??"
SLEEP: END
'=============================================================================
OpenFileErr:
'PRINT "Error no."; ERR; "opening file."
RESUME NEXT
'==============================================================================
SUB AFGENInit
SHARED ClvsWP(), ClvsGR(), TevsKO(), SoilAL()
SHARED TvsP1(), TvsP2(), TvsP3(), TvsP4(), TvsP5(), TvsP6(), TvsP7(), TvsP8()
SHARED TvsP9()
SHARED TvsC1(), TvsC2(), TvsC3(), TvsC4(), TvsC5(), TvsC6(), TvsC7(), TvsC8()
SHARED TvsC9()
SHARED AfGenFile$, dummy(), Porsty(), SatCon
'Open file:
File% = FREEFILE
OPEN "i", File%, AfGenFile$
'Input lines and find code for table to input:
DO
LINE INPUT #File%, in$
PRINT in$
id$ = LTRIM$(RTRIM$(in$))
GOSUB SelectTable
LOOP WHILE NOT EOF(File%)
CLOSE File%
EXIT SUB
SelectTable:
SELECT CASE id$
CASE "CLVSWP"
'Leaf water potential [m] vs. epidermal conductance [m/s]:
IF Restart$ = "" THEN PRINT #2, "Data for array ClvsWP(), leaf water potential vs. epidermal conductance:"
INPUT #File%, np%
REDIM ClvsWP(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, ClvsWP(i%, j%)
IF Restart$ = "" THEN PRINT #2, ClvsWP(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "CLVSGR"
'Incident solar radiation [W m^-2] vs. epidermal conductance [m/s]:
IF Restart$ = "" THEN PRINT #2, "Data for array ClvsGr(), solar radiation vs. epidermal conductance:"
INPUT #File%, np%
REDIM ClvsGR(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, ClvsGR(i%, j%)
IF Restart$ = "" THEN PRINT #2, ClvsGR(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSP1"
'Volume fraction of water vs. soil water potential [m]:
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP1(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP1(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP1(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP1(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP1(i%, 2) 'Rearrange so THETA is a function of
dummy(i%, 2) = TvsP1(i%, 1) 'potential in AFGEN using dummy().
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(1) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #1:"; Porsty(1)
END IF
CASE "TVSP2"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP2(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP2(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP2(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP2(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP2(i%, 2)
dummy(i%, 2) = TvsP2(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(2) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #2:"; Porsty(2)
END IF
CASE "TVSP3"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP3(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP3(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP3(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP3(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP3(i%, 2)
dummy(i%, 2) = TvsP3(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(3) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #3:"; Porsty(3)
END IF
CASE "TVSP4"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP4(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP4(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP4(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP4(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP4(i%, 2)
dummy(i%, 2) = TvsP4(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(4) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #4:"; Porsty(4)
END IF
CASE "TVSP5"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP5(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP5(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP5(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP5(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP5(i%, 2)
dummy(i%, 2) = TvsP5(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(5) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #5:"; Porsty(5)
END IF
CASE "TVSP6"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP6(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP6(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP6(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP6(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP6(i%, 2)
dummy(i%, 2) = TvsP6(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(6) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #6:"; Porsty(6)
END IF
CASE "TVSP7"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP7(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP7(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP7(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP7(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP7(i%, 2)
dummy(i%, 2) = TvsP7(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(7) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #7:"; Porsty(7)
END IF
CASE "TVSP8"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP8(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP8(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP8(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP8(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP8(i%, 2)
dummy(i%, 2) = TvsP8(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(8) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #8:"; Porsty(8)
END IF
CASE "TVSP9"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsP9(), volumetric water content vs. ";
PRINT #2, "soil water potential [m]:"
END IF
INPUT #File%, np%
REDIM TvsP9(np%, 2)
REDIM dummy(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsP9(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsP9(i%, j%);
NEXT j%
dummy(i%, 1) = TvsP9(i%, 2)
dummy(i%, 2) = TvsP9(i%, 1)
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Find theta for potential of 0.0 m and call this soil porosity:
Porsty(9) = AFGEN(dummy(), 0!)
REDIM dummy(0, 0)
IF Restart$ = "" THEN
PRINT #2, "Porosity for horizon #9:"; Porsty(9)
END IF
CASE "TVSC1"
'Volume fraction of water vs. soil hydraulic conductivity [m/s]:
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC1(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC1(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC1(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC1(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
'Saturated conductivity for surface soil layer, SATCON [m/s]:
SatCon = AFGEN(TvsC1(), (Porsty(1)))
IF Restart$ = "" THEN
PRINT #2, "Saturated conductivity of surface soil layer (SatCon):"; SatCon; " m/s."
END IF
CASE "TVSC2"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC2(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC2(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC2(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC2(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSC3"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC3(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC3(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC3(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC3(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSC4"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC4(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC4(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC4(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC4(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSC5"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC5(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC5(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC5(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC5(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSC6"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC6(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC6(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC6(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC6(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSC7"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC7(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC7(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC7(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC7(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSC8"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC8(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC8(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC8(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC8(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TVSC9"
IF Restart$ = "" THEN
PRINT #2, "Data for array TvsC9(), volumetric water content vs. ";
PRINT #2, "hydraulic conductivity [m]:"
END IF
INPUT #File%, np%
REDIM TvsC9(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TvsC9(i%, j%)
IF Restart$ = "" THEN PRINT #2, TvsC9(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "TEVSKO"
'Soil temperature [Deg.C] vs. heat conductivity by vapor [W m^-1 C^-1]:
IF Restart$ = "" THEN PRINT #2, "Data for array TevsKO(), soil temp. vs. heat conductivity by vapor:"
INPUT #File%, np%
REDIM TevsKO(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, TevsKO(i%, j%)
IF Restart$ = "" THEN PRINT #2, TevsKO(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE "SOILAL"
'Soil water content [m^3/m^3] in first layer vs. soil albedo:
IF Restart$ = "" THEN PRINT #2, "Data for array SoilAL(), soil water content vs. soil albedo."
INPUT #File%, np%
REDIM SoilAL(np%, 2)
FOR i% = 1 TO np%
FOR j% = 1 TO 2
INPUT #File%, SoilAL(i%, j%)
IF Restart$ = "" THEN PRINT #2, SoilAL(i%, j%);
NEXT j%
IF Restart$ = "" THEN PRINT #2,
NEXT i%
CASE ELSE
END SELECT
RETURN
END SUB
'==============================================================================
'FUNCTION ARCOS (BYVAL xdum)
FUNCTION ARCOS (xdum)
'Returns inverse cosine.
IF ABS(xdum) > 1! THEN PRINT "Fatal error in ARCOS.": SLEEP: END
IF xdum = 0! THEN
ARCOS = HalfPi
ELSE
IF xdum = -1! THEN
ARCOS = Pi
ELSE
IF xdum = 1 THEN
ARCOS = 0!
ELSE
ARCOS = 1.570796 - ATN(xdum / SQR(1! - xdum * xdum))
END IF
END IF
END IF
END FUNCTION
'==============================================================================
'FUNCTION ARSIN (BYVAL xdum)
FUNCTION ARSIN (xdum)
'Returns inverse sine.
IF ABS(xdum) > 1! THEN PRINT "Error in ARSIN.": SLEEP: END
IF xdum = -1! THEN
ARSIN = -HalfPi
ELSE
IF xdum = 1! THEN
ARSIN = HalfPi
ELSE
ARSIN = ATN(xdum / SQR(1! - xdum * xdum))
END IF
END IF
END FUNCTION
'=============================================================================
SUB FinGraphFile
SHARED path$, hTime, EndDay%, sDay%
PRINT "Finishing graph files."
ON ERROR GOTO OpenFileErr
CLOSE 'Close all files.
IF HourlyOutputFlag > 0 THEN
'Finish hourly output files:
OPEN "o", #8, path$ + "Profile1\data1.tem"
PRINT #8, "cdnum%; hTime; water contents & temperatures:"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 5, hTime, 0, 0, 0
di = 5
DataFile$ = path$ + "Profile1\data1"
GOSUB AddData
OPEN "o", #8, path$ + "temp\data1.tem"
PRINT #8, "cdnum%; hTime; Ta; DPTc; Tl; Ts; Temp(1)"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 5, hTime, 0, 0, 0
di = 5
DataFile$ = path$ + "temp\data1"
GOSUB AddData
OPEN "o", #8, path$ + "cond\data1.tem"
PRINT #8, "cdnum%; hTime; Cl; Cl1; Cl2"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 3, hTime, 0, 0, 0
di = 3
DataFile$ = path$ + "cond\data1"
GOSUB AddData
' OPEN "o", #8, path$ + "resist\data1.tem"
' PRINT #8, "cdnum%; hTime; Rl; CRH; CRV"
' WRITE #8, "data1.tem"
' WRITE #8, ""
' PRINT #8, 3, hTime, 0, 0, 0
' di = 3
' DataFile$ = path$ + "resist\data1"
' GOSUB AddData
OPEN "o", #8, path$ + "hum\data1.tem"
PRINT #8, "cdnum%; hTime; Hl; Ha; Ho; Hs"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 4, hTime, 0, 0, 0
di = 4
DataFile$ = path$ + "hum\data1"
GOSUB AddData
OPEN "o", #8, path$ + "flux1\data1.tem"
PRINT #8, "cdnum%; hTime; GR; SkL; NRBC; NRBS; LwRc; Albedo"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 6, hTime, 0, 0, 0
di = 6
DataFile$ = path$ + "flux1\data1"
GOSUB AddData
OPEN "o", #8, path$ + "flux2\data1.tem"
PRINT #8, "cdnum%; hTime; SHCA; LWRS; LEvS; a; S; LTr; RCNeg; RCPos; RCSum" 'FLUX2
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 5, hTime, 0, 0, 0
di = 5
DataFile$ = path$ + "flux2\data1"
GOSUB AddData
OPEN "o", #8, path$ + "pot\data1.tem"
PRINT #8, "cdnum%; hTime; WPSeff; WPotCr; ppot(1)"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 3, hTime, 0, 0, 0
di = 3
DataFile$ = path$ + "pot\data1"
GOSUB AddData
OPEN "o", #8, path$ + "non\data1.tem"
PRINT #8, "cdnum%; hTime; LAI; FTSR; ABSC; ABSSa; CRH / Ra; Rs / Ra"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 4, hTime, 0, 0, 0
di = 4
DataFile$ = path$ + "non\data1"
GOSUB AddData
END IF
OPEN "o", #8, path$ + "et\data1.tem"
PRINT #8, "cdnum%; dEvap; dTrans; dET; dG; dInf; dPrec; dDrain; dRunoff; WBalance; dRs"
WRITE #8, "data1.tem"
WRITE #8, ""
PRINT #8, 9, EndDay% - sDay% + 1, 0, 0, 0
di = 9
DataFile$ = path$ + "et\data1"
GOSUB AddData
OPEN "o", #8, path$ + "profile\data1.tem"
DataFile$ = path$ + "profile\data1"
GOSUB AddData
ON ERROR GOTO 0
EXIT SUB
'=============================================================================
AddData: 'Add data lines to graph file.
OPEN "i", #2, DataFile$
WHILE NOT EOF(2)
LINE INPUT #2, in$
PRINT #8, in$
WEND
'FOR i = 1 TO di
' PRINT #2, 0, 0
'NEXT i
CLOSE #2
KILL DataFile$
CLOSE #8
RETURN
END SUB
'==============================================================================
SUB GetCommandLine
'Get name of file containing data file names from command line:
SHARED InfoFile$, Mode2$, Restart$, FErr%, path$
InfoFile$ = RTRIM$(COMMAND$)
Mode2$ = "o" 'set mode to open files for output.
ON ERROR GOTO FileOpenErr.2
IF INSTR(InfoFile$, " ") > 0 THEN
'there is more than one file name in command line string.
'get rest of string.
Restart$ = LTRIM$(MID$(InfoFile$, INSTR(InfoFile$, " ")))
InfoFile$ = MID$(InfoFile$, 1, INSTR(InfoFile$, " ") - 1) 'get file.
FErr% = 6
OPEN "i", #1, Restart$
INPUT #1, path$ 'get path for output files.
CLOSE #1
Mode2$ = "a" 'set mode to open files for append.
END IF
ON ERROR GOTO 0
END SUB
'==============================================================================
SUB GetConstants (Constants$)
SHARED Zo, Z, WPCrMx, SRCr, LowBoundGrad, ZeroCdNum%
SHARED DetCap, Lat, AvBarP, FErr%, TStepL, TStepH, Header$()
i% = 0
PRINT #2, : PRINT #2, DATE$, TIME$
PRINT #2, "Constants that may have changed for this run:"
ON ERROR GOTO FileOpenErr.2
FErr% = 5
OPEN "i", #7, Constants$ 'Constants for this run are in this file.
ON ERROR GOTO 0
ON ERROR GOTO ConstantInputErr
PRINT "Header for file "; Constants$
LINE INPUT #7, Header$(1): PRINT Header$(1)
INPUT #7, Zo, Zo$ 'Surface roughness length [m].
INPUT #7, Z, Z$ 'Reference elevation [m] for measurement of wind
'speed, air temperature & dew point temperature.
INPUT #7, WPCrMx, WPCrMx$ 'Maximum crop water potential [m].
INPUT #7, SRCr, SRCr$ 'Specific hydraulic resistance of the crop [s].
INPUT #7, DetCap, DetCap$ 'Ponded water detention capacity [m].
INPUT #7, Lat, Lat$ 'Latitude [Deg.].
INPUT #7, AvBarP, AvBarP$ 'Average barometric pressure [mbar] at Bushland.
INPUT #7, TStepL, TStepL$ 'Lower limit of time step in s.
INPUT #7, TStepH, TStepH$ 'Upper limit of time step in s.
'Gradient to use for lower soil boundary water flux (m/m):
INPUT #7, LowBoundGrad, LowBoundGrad$
INPUT #7, ZeroCdNum%, ZeroCdNum$ 'day of year on which to invoke impeeding layer.
i% = 1
DO
i% = i% + 1
IF NOT EOF(7) THEN LINE INPUT #7, Header$(i%) ELSE EXIT DO
LOOP
EndConstantInput:
ON ERROR GOTO 0
CLOSE #7
'Print user defined header:
FOR j% = 2 TO i% - 1
PRINT #2, Header$(j%)
PRINT #6, Header$(j%)
NEXT j%
'Print constants:
PRINT #2, Header$(1)
PRINT #6, Header$(1)
'Surface roughness length [m].
PRINT #2, Zo, Zo$
PRINT #6, Zo, Zo$
'Reference elevation [m].
PRINT #2, Z, Z$
PRINT #6, Z, Z$
'Maximum crop water potential [m].
PRINT #2, WPCrMx, WPCrMx$
PRINT #6, WPCrMx, WPCrMx$
'Specific hydraulic resistance of the crop [s].
PRINT #2, SRCr, SRCr$
PRINT #6, SRCr, SRCr$
'Ponded water detention capacity [m].
PRINT #2, DetCap, DetCap$
PRINT #6, DetCap, DetCap$
'Latitude [Deg.].
PRINT #2, Lat, Lat$
PRINT #6, Lat, Lat$
'Average barometric pressure [mbar] at Bushland.
PRINT #2, AvBarP, AvBarP$
PRINT #6, AvBarP, AvBarP$
'Lower limit of time step in s.
PRINT #2, TStepL, TStepL$
PRINT #6, TStepL, TStepL$
'Upper limit of time step in s.
PRINT #2, TStepH, TStepH$
PRINT #6, TStepH, TStepH$
'Gradient for water flux at lower soil boundary (m/m):
PRINT #2, LowBoundGrad, LowBoundGrad$
PRINT #6, LowBoundGrad, LowBoundGrad$
'Day of which to invoke impeeding layer:
PRINT #2, ZeroCdNum%, ZeroCdNum$
PRINT #6, ZeroCdNum%, ZeroCdNum$
REDIM Header$(0)
EXIT SUB
END SUB
'==============================================================================
SUB GetDayYear
SHARED sDay%, EndDay%, InitDayFile$, sYear%, Plant$, Restart$, EndYear%
'Find starting day:
sDay% = VAL(MID$(InitDayFile$, INSTR(InitDayFile$, ".") + 1, 3))
IF sDay% < 1 OR sDay% > 366 THEN
PRINT "Error in naming file containing initial conditions."
PRINT "File name was "; InitDayFile$; "."
PRINT "See documentation. Program will end now. Press any key."
SLEEP
END
END IF
sYear% = VAL(MID$(Plant$, INSTR(Plant$, ".") + 1, 3))
IF sYear% < 1 THEN
PRINT "Error in naming file containing weather data for each day."
PRINT "See documentation. Program will end now. Press any key."
SLEEP
END
END IF
IF Restart$ = "" THEN
PRINT "The simulation will start on day"; sDay%; " of"; sYear%
ELSE
PRINT "The simulation will re-start at 0 hours on day";
PRINT 1 + VAL(MID$(Restart$, INSTR(Restart$, ".") + 1, 3));
PRINT " of"; sYear%
'sleep
END IF
IF EndDay% < sDay% AND EndYear% <= sYear% THEN
PRINT "Ending day is before starting day. Program will end."
PRINT "Start Day: "; sDay%
PRINT "EndDay: "; EndDay%
PRINT "Start year:"; sYear%
PRINT "End year: "; EndYear%
PRINT "Press any key now...."
SLEEP
END
ELSE
PRINT "Simulation will stop on day"; EndDay%; "of"; EndYear%
END IF
END SUB
'==============================================================================
SUB GetFileNames
'Get names of files needed by ENWATBAL:
SHARED InfoFile$, InitDayFile$, IrrPrecip$, Plant$, Constants$, AfGenFile$
SHARED DripFile$, path$, Y$, EndDay%, FErr%, Meteo$, WMode%, HourlyOutputFlag
SHARED EndYear%
f% = FREEFILE
ON ERROR GOTO FileOpenErr.2
FErr% = 1
OPEN "i", #f%, InfoFile$