-
Notifications
You must be signed in to change notification settings - Fork 1
/
TIME.FOR
1544 lines (1310 loc) · 56.3 KB
/
TIME.FOR
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
* Source file TIME.FOR |||||||||||||||||||||||||||||||||||||||||||||||||
subroutine TmCont(dt,dtMaxW,dtOpt,dMul,dMul2,dtMin,Iter,tPrint,
! tAtm,t,tMax,dtMaxC,ItMin,ItMax,lMinStep,dtInit)
logical lMinStep
double precision t,tPrint,tAtm,tMax,tFix
if(lMinStep) then
dtMax=amin1(dtMaxW,dtMaxC,dtInit,dtOpt)
dtOpt=dtMax
lMinStep=.false.
else
dtMax=amin1(dtMaxW,dtMaxC)
end if
tFix=dmin1(tPrint,tAtm,tMax)
if(Iter.le.ItMin.and.(tFix-t).ge.dMul*dtOpt)
! dtOpt=amin1(dtMax,dMul*dtOpt)
if(Iter.ge.ItMax)
! dtOpt=amax1(dtMin,dMul2*dtOpt)
dt=amin1(dtOpt,sngl(tFix-t))
iStep=1
if(dt.gt.0.) iStep=anint(sngl(tFix-t)/dt)
if(iStep.ge.1.and.iStep.le.10)
! dt=amin1(sngl(tFix-t)/iStep,dtMax)
if(iStep.eq.1) then
dt=sngl(tFix-t)
if(dt-dtMax.gt.dtMin) dt=dt/2.
end if
if(dt.le.0.0) dt=dtMin/3.
return
end
************************************************************************
double precision function RTime(iMonth,iDay,iHours,iMins,iSecs,
! i100th)
integer*2 iMonth,iDay,iHours,iMins,iSecs,i100th
if(iMonth.eq.1.or.iMonth.eq.3.or.iMonth.eq.5.or.iMonth.eq.7.or.
! iMonth.eq.8.or.iMonth.eq.10.or.iMonth.eq.12) then
NoDay=31
else if(iMonth.eq.4.or.iMonth.eq.6.or.iMonth.eq.9.or.iMonth.eq.11)
! then
NoDay=30
else if(iMonth.eq.2) then
NoDay=28
end if
nMonth=NoDay*24.*60.*60.
RTime=nMonth+iDay*24.*60.*60.+iHours*60.*60.+iMins*60.+iSecs+
! i100th/100.
return
end
************************************************************************
subroutine SetBC(tMax,tAtm,rTop,rRoot,rBot,hCritA,hBot,hTop,GWL0L,
! TopInF,BotInF,cT,cBot,NS,tTop,tBot,Ampl,lTemp,
! lChem,KodTop,lVarBC,ierr,lMinStep,lMeteo,Prec,
! rSoil,lLAI,rExtinct,lCentrif,CosAlf,xConv,
! tConv,iModel,hTopN,iRootIn,xRoot,WLayer,lLinear,
! lActRSU,SPot)
logical TopInF,BotInF,lTemp,lChem,lMinStep,lVarBC,lMeteo,lCentrif,
! WLayer,lLAI,lVarGr,lLinear(NS),lActRSU
dimension cBot(NS),cT(NS),cB(11)
character*3 TheEnd
double precision tAtm,tMax
KodTOld=KodTop
read(31,101) TheEnd
if(TheEnd.eq.'end') then
tMax=tAtm
return
else
backspace 31
if(iRootIn.ne.0) then
if(.not.lChem.and..not.lTemp) then
read(31,*,err=901) tAtm,Prec,rSoil,rR,hCA,rB,hB,hT
else if(lTemp.and..not.lChem) then
read(31,*,err=901) tAtm,Prec,rSoil,rR,hCA,rB,hB,hT,tTop,
! tBot,Ampl
else
read(31,*,err=901) tAtm,Prec,rSoil,rR,hCA,rB,hB,hT,tTop,
! tBot,Ampl,(cT(jj),cB(jj),jj=1,NS)
end if
else
if(.not.lChem.and..not.lTemp) then
read(31,*,err=901) tAtm,Prec,rSoil,rR,hCA,rB,hB,hT,xRoot
else if(lTemp.and..not.lChem) then
read(31,*,err=901) tAtm,Prec,rSoil,rR,hCA,rB,hB,hT,tTop,
! tBot,Ampl,xRoot
else
read(31,*,err=901) tAtm,Prec,rSoil,rR,hCA,rB,hB,hT,tTop,
! tBot,Ampl,(cT(jj),cB(jj),jj=1,NS),xRoot
end if
end if
if(lLAI) then
rLAI=rR
rPET=rSoil
SC=1.
rR=0.
if(rLAI.gt.0.)
! rR=rPET*amax1(0.,1.-exp(-amax1(rExtinct,0.1)*rLAI))*SC
rSoil=rPET-rR
end if
end if
* Top of the profile
if(TopInF) then
lVarGr=.false. ! Variable gravity field - for Scott Jones
if(lVarGr) then
if(CosAlf.ne.Prec) lMinStep=.true.
CosAlf=Prec
Prec=0.
end if
rTopOld=rTop
hCritA=-abs(hCA)
if(lVarBC) then
rTop=Prec
if(abs(rTopOld-rTop).gt.abs(rTop)*0.2.and.rTop.lt.0.)
! lMinStep=.true.
KodTop=int(rSoil)
rSoil=0.
if(KodTop.eq.-1.and.KodTOld.eq.+1.and.Prec.gt.0.
! .and.hNewT.gt.0) hNewT=-0.01*xConv
else
if(.not.lMeteo) rTop=abs(rSoil)-abs(Prec)
if(lMeteo) rTop= -abs(Prec)
if(abs(rTopOld-rTop).gt.abs(rTop)*0.2.and.rTop.lt.0.)
! lMinStep=.true.
if(rTop.gt.0..and.rTopOld.lt.0..and..not.WLayer) then
xLimit=0.0
if(iModel.eq.3) xLimit=-0.03*xConv
if(KodTop.eq.4.or.hTopN.gt.xLimit) then
if(iModel.ne.3) xLimit=-0.01*xConv
hTopN=xLimit
KodTop=-4
end if
end if
end if
if(KodTop.eq.3.or.lVarBC) then
hTop=hT
if(abs(hTop-hT).gt.abs(hTop)*0.2) lMinStep=.true.
end if
rRoot=abs(rR)
end if
* Bottom of the profile
if(BotInF) then
if(lCentrif) then
g=9.80665*xConv/tConv/tConv
CosAlf=hB*hB/g
hB=0.
lMinStep=.true.
end if
if(abs(rBot-rB).gt.abs(rBot)*0.2) lMinStep=.true.
rBot=rB
if(abs(hBot-hB-GWL0L).gt.abs(hBot)*0.2) lMinStep=.true.
hBot=hB+GWL0L
end if
if(lChem) then
do 11 jj=1,NS
if(.not.lLinear(JJ).and.cT(jj).gt.0.) lMinStep=.true.
cBot(jj)=cB(jj)
if(lActRSU.and.NS.eq.1) then
cBot(jj)=0.
SPot=cB(jj)
end if
11 continue
end if
return
* Error when reading from an input file
901 ierr=1
return
101 format(a3)
end
************************************************************************
subroutine SetChemBC(Prec,rSoil,NS,cTop,cT,WLayer,
! hNewT,KodTop,kTopCh)
logical WLayer
dimension cTop(NS),cT(NS)
do 11 jj=1,NS
if(WLayer.and.hNewT.gt.0.) then
cTop(jj)=cTop(jj) ! this is handled in the main program
else
cTop(jj)=cT(jj)
if(abs(KodTop).eq.4.and.kTopCh.le.0) then
if(Prec-rSoil.gt.0.) then
cTop(jj)=cT(jj)*Prec/(Prec-rSoil)
else if(rSoil.gt.0.) then
cTop(jj)=0.
end if
end if
end if
11 continue
return
end
************************************************************************
subroutine DailyVar(tConv,t,rRoot,rRootD)
* Temperature, max at 1. p.m.
* Radiation, max at noon, hourly values between 0-6 a.m. and 18-24 p.m.
* represent 1% of daily value, sinusoid in between
double precision t
PI=3.141592654
tPeriod=1. ! one day !24.*60.*60.*tConv
tDay=sngl(t)/tConv/86400 ! time in day units
c if(tPeriod.gt.0.) tTopA=tTop+Ampl*sin(2.*PI*sngl(t)/tPeriod-7.*PI/12.)
tRemainder=amod(tDay,tPeriod)
if(tRemainder.le.0.264.or.tRemainder.ge.0.736) then
rRoot=0.24*rRootD
else
rRoot=2.75*rRootD*sin(2.*PI*tDay/tPeriod-6.*PI/12.)
end if
return
end
************************************************************************
subroutine SinPrec(t,t1,t2,rPrec,rPrecD)
* Cosinusoidal distribution of precipitation
double precision t,t1,t2
PI=3.141592654
dt=sngl(t2-t1)
if(rPrecD.gt.0.) then
rPrec=rPrecD*(1.+1.*cos(2.*PI*sngl(t-t1)/dt-PI))
else
rPrec=0.
end if
return
end
************************************************************************
subroutine Snow(Prec,dt,Temp,SnowMF,SnowLayer,rEvap,xConv,
! lMinStep,cTop,cT,NS)
logical lMinStep
dimension cTop(NS),cT(NS)
PrecOld=Prec
rEvapOld=rEvap
Q=1.
if(SnowLayer.lt.0.001*xConv) then
if(Temp.lt.-2.0) then
Q=1.
else if(Temp.lt.2.0) then
Q=1.-((Temp+2.)/4.)
else
Q=0.
end if
end if
rTop=Prec*(1.-Q)
SnowF=Prec*Q
if(Temp.gt.0..and.SnowLayer.gt.0.) then
SnowMelt=Temp*SnowMF*dt
else
SnowMelt=0.
end if
SnowLayer=SnowLayer+SnowF*dt-SnowMelt
if(SnowLayer.lt.0.) then
SnowMelt=SnowMelt+SnowLayer
SnowLayer=0.
else if(SnowLayer.gt.0..and.rEvap.gt.0.) then
SnowLayerO=SnowLayer
if(rEvap*dt.lt.SnowLayer) then
SnowLayer=SnowLayer-rEvap*dt
rEvap=0.
else
rEvap=(rEvap*dt-SnowLayer)/max(dt,1e-8)
SnowLayer=0.
end if
end if
Prec=rTop+SnowMelt/max(dt,1e-8)
if(abs(PrecOld-Prec).gt.abs(Prec)*0.2.and.Prec.gt.0.)
! lMinStep=.true.
if(SnowLayer.gt.0.001*xConv) then
do 11 jj=1,NS
if((SnowLayer+dt*(PrecOld-rEvapOld)).gt.0.)
! cTop(jj)=(SnowLayer*cTop(jj)+dt*PrecOld*cT(jj))/
! (SnowLayer+dt*(PrecOld-rEvapOld))
11 continue
end if
return
end
************************************************************************
subroutine Meteo(iKod,lMetDaily,lDayVar,t,dt,tInit,tMax,tAtm2,
! tAtmN,tAtm2O,dtMax,rLat,rAlt,ShWRadA,ShWRadB,
! rLWRadA,rLWRadB,rLWRadA1,rLWRadB1,WindHeight,
! TempHeight,iCrop,iLAI,rRoot,xConv,tConv,rGrowth,
! nGrowth,iInterc,rInterc,aInterc,ExcesInt,lEnBal,
! rExtinct,lPrint,lHargr,iRadiation,iSunSh,iRelHum,
! iMetHour,CloudF_Ac,CloudF_Bc,Prec,Precc,rSoil,
! EvapP,TransP,Rns,Rnl,RadTerm,AeroTerm,Rst,ETcomb,
! Rad,RadN,RadO,Wind,WindN,WindO,Albedo,AlbedoN,
! xLAI,xLAIN,xRoot,xRootN,CropHeight,CropHeightN,
! Ampl,tTop,TMaxAN,TMinAN,TMax1,TMaxN,TMaxO,TMin1,
! TMinN,TMinO,TempA,TMaxA,TMaxAO,TMinA,TMinAO,
! SunHours,SunHoursN,SunHoursO,RHMean,RHMeanN,
! RHMeanO,RHMax,RHMaxN,RHMaxO,RHMin,RHMinN,RHMinO,
! RH_A,EaMean,EaMeanN,rTop,ierr)
implicit real(A-H,L-Z)
logical lMetDaily,lDayVar,lEnBal,lPrint,lHargr
dimension rGrowth(1000,5)
integer nGrowth,iCrop,iRelHum
double precision t,tInit,tMax,tAtm2,tAtm2O,tAtmN
ierr=0
if(iKod.eq.1) then
if(lMetDaily) then
dtMax=min(3600.*tConv,dtMax) ! Maximum time step is less than 1 hour
lDayVar=.false.
call DailyMet(1,t,dt,tInit,tMax,tAtm2,tAtmN,TMax1,TMaxN,TMaxO,
! TMin1,TMinN,TMinO,TempA,RHMax,RHMaxN,RHMaxO,
! RHMin,RHMinN,RHMinO,RH_A,iRelHum,EaMean,EaMeanN,
! Rad,RadN,Wind,WindN,SunHours,SunHoursN,
! CropHeight,CropHeightN,Albedo,AlbedoN,xLAI,
! xLAIN,xRoot,xRootN,iCrop,xConv,ierr)
if(ierr.ne.0) goto 901
call SetDayMet(rLat,rAlt,ShWRadA,ShWRadB,rLWRadA,rLWRadB,
! rLWRadA1,rLWRadB1,WindHeight,TempHeight,iCrop,
! iLAI,CropHeight,Albedo,xLAI,xRoot,tAtm2,rRoot,
! xConv,tConv,iInterc,aInterc,nGrowth,rGrowth,
! ExcesInt,rExtinct,Prec,rSoil,iRadiation,Wind,
! Rad,SunHours,iSunSh,CloudF_Ac,CloudF_Bc,TempA,
! RH_A,t,lEnBal,Rst,ETcomb,EvapP,TransP,Rns,Rnl,
! RadTerm,AeroTerm,rInterc,Precc,ierr)
if(ierr.eq.3) goto 903
else
call SetMeteo(rLat,rAlt,ShWRadA,ShWRadB,rLWRadA,rLWRadB,
! rLWRadA1,rLWRadB1,WindHeight,TempHeight,iCrop,
! iLAI,CropHeight,Albedo,xLAI,xRoot,tAtm2,rRoot,
! xConv,tConv,iInterc,aInterc,nGrowth,rGrowth,
! ExcesInt,rExtinct,lEnBal,Prec,rSoil,iRadiation,
! TMaxAN,TMinAN,WindN,RHMeanN,RadN,SunHoursN,
! lPrint,iSunSh,iRelHum,tTop,Ampl,CloudF_Ac,
! CloudF_Bc,lHargr,tInit,1,iMetHour,ierr)
if(ierr.ne.0) goto (901,903) ierr
call MeteoInt(1,tInit,tAtm2O,tAtm2,Rad,RadO,RadN,TMaxA,TMaxAO,
! TMaxAN,TMinA,TMinAO,TMinAN,Wind,WindO,WindN,
! RHMean,RHMeanO,RHMeanN,SunHours,SunHoursO,
! SunHoursN,lEnBal)
if(ierr.ne.0) goto (902,903) ierr
end if
else if(iKod.eq.2) then
if(lMetDaily) then
call DailyMet(2,t,dt,tInit,tMax,tAtm2,tAtmN,TMax1,TMaxN,TMaxO,
! TMin1,TMinN,TMinO,TempA,RHMax,RHMaxN,RHMaxO,
! RHMin,RHMinN,RHMinO,RH_A,iRelHum,EaMean,EaMeanN,
! Rad,RadN,Wind,WindN,SunHours,SunHoursN,
! CropHeight,CropHeightN,Albedo,AlbedoN,xLAI,
! xLAIN,xRoot,xRootN,iCrop,xConv,ierr)
if(ierr.ne.0) goto 901
else
call MeteoInt(2,t,tAtm2O,tAtm2,Rad,RadO,RadN,TMaxA,TMaxAO,
! TMaxAN,TMinA,TMinAO,TMinAN,Wind,WindO,WindN,
! RHMean,RHMeanO,RHMeanN,SunHours,SunHoursO,
! SunHoursN,lEnBal)
call SetMeteo(rLat,rAlt,ShWRadA,ShWRadB,rLWRadA,rLWRadB,
! rLWRadA1,rLWRadB1,WindHeight,TempHeight,iCrop,
! iLAI,CropHeight,Albedo,xLAI,xRoot,tAtm2,rRoot,
! xConv,tConv,iInterc,aInterc,nGrowth,rGrowth,
! ExcesInt,rExtinct,lEnBal,Prec,rSoil,iRadiation,
! TMaxAN,TMinAN,WindN,RHMeanN,RadN,SunHoursN,
! lPrint,iSunSh,iRelHum,tTop,Ampl,CloudF_Ac,
! CloudF_Bc,lHargr,tInit,2,iMetHour,ierr)
if(ierr.ne.0) goto (901,903) ierr
end if
else if(iKod.eq.3) then
if(lMetDaily) then
call DailyMet(4,t,dt,tInit,tMax,tAtm2,tAtmN,TMax1,TMaxN,TMaxO,
! TMin1,TMinN,TMInO,TempA,RHMax,RHMaxN,RHMaxO,
! RHMin,RHMinN,RHMinO,RH_A,iRelHum,EaMean,EaMeanN,
! Rad,RadN,Wind,WindN,SunHours,SunHoursN,
! CropHeight,CropHeightN,Albedo,AlbedoN,xLAI,
! xLAIN,xRoot,xRootN,iCrop,xConv,ierr)
if(ierr.ne.0) goto 901
call SetDayMet(rLat,rAlt,ShWRadA,ShWRadB,rLWRadA,rLWRadB,
! rLWRadA1,rLWRadB1,WindHeight,TempHeight,iCrop,
! iLAI,CropHeight,Albedo,xLAI,xRoot,tAtm2,rRoot,
! xConv,tConv,iInterc,aInterc,nGrowth,rGrowth,
! ExcesInt,rExtinct,Prec,rSoil,iRadiation,Wind,
! Rad,SunHours,iSunSh,CloudF_Ac,CloudF_Bc,TempA,
! RH_A,t,lEnBal,Rst,ETcomb,EvapP,TransP,Rns,Rnl,
! RadTerm,AeroTerm,rInterc,Precc,ierr)
if(ierr.eq.3) goto 903
rTop=abs(rSoil)-abs(Prec)
end if
if(lEnBal.and..not.lMetDaily)
! call MeteoInt(3,t,tAtm2O,tAtm2,Rad,RadO,RadN,TMaxA,TMaxAO,
! TMaxAN,TMinA,TMinAO,TMinAN,Wind,WindO,WindN,
! RHMean,RHMeanO,RHMeanN,SunHours,SunHoursO,
! SunHoursN,lEnBal)
end if
return
901 ierr=1 !932
return
902 ierr=2 !913
return
903 ierr=3 !933
return
return
end
************************************************************************
* Subroutine reading meteorological input data and calculating potential
* evapotranspiration using either Penman-Montheith or Hargreaves equations.
subroutine SetMeteo(Latitude,Altitude,ShortWaveRadA,ShortWaveRadB,
! LongWaveRadA,LongWaveRadB,LongWaveRadA1,
! LongWaveRadB1,WindHeight,TempHeight,iCrop,
! iLAI,CropHeight,Albedo,LAI,xRoot,tAtm,rRoot,
! xConv,tConv,iInterc,aInterc,nGrowth,rGrowth,
! ExcesInt,rExtinct,lEnBal,Prec,rSoil,
! iRadiation,TMax,TMin,Wind_ms,RHMean,Rad,
! SunHours,lPrint,iSunSh,iRelHum,TAver,Ampl,
! CloudF_Ac,CloudF_Bc,lHargr,tInit,iInit,
! iMetHour,ierr)
* DayNo - Day number
* Rad - Net radiation flux at the surface [MJ/m2/d]
* TMax - Maximum temperature [C]
* TMin - Minimum temperature [C]
* RHMean - Relative humidity [%]
* Wind_kmd- Average daily wind speed [km/d]
* Albedo - Albedo [-]
* xRoot - Rooting depth [L]
* iRadiation - = 0: potential radiation, = 1: solar radiation, = 2: net radiation
* iInterc - interception
* =1: uses LAI and Soil Cover (SC)
* =2; uses only SC
implicit real(A-H,L-Z)
logical lEnBal,lPrint,lHargr
dimension rGrowth(1000,5)
integer nGrowth
double precision tInit,tAtm,tAtmOld
character*3 TheEnd
PI=3.141592654
raa=0.
rc=60.
SCF=0.
* Conversion to mm/d from L/T
rConv=0.001*xConv
TTConv=24.*60.*60.*tConv
tAtmOld=tAtm
read(33,101) TheEnd
if(TheEnd.eq.'end') then
c tMax=tAtm
return
else
backspace 33
if(iCrop.eq.3) then
read(33,*,err=901) tAtm,Rad,TMax,TMin,RHMean,Wind_kmd,
! SunHours,CropHeight,Albedo,LAI,xRoot
CropHeight=CropHeight*100./xConv ! conversion to cm
else
read(33,*,err=901) tAtm,Rad,TMax,TMin,RHMean,Wind_kmd,SunHours
end if
end if
DayNo=sngl(tAtm)/TTConv ! Conversion to [d]
if(iInit.eq.1) then ! Check time interval of meteo data
if((tAtm-tInit).le.0.9999*TTConv) then ! short interval
iMetHour=1
else
iMetHour=0 ! daily data
end if
end if
if(iCrop.eq.2) then
i=1000
j=5
call Table(nGrowth,rGrowth,i,j,tAtm,CropHeight,Albedo,LAI,
! xRoot)
end if
Wind_ms=Wind_kmd/86.4 ! Conversion, [m/s]
if(lEnBal) return
call CropRes(rc,iLAI,LAI,rExtinct,iCrop,CropHeight,SCF)
TAver=(TMax+TMin)/2.
if(.not.lHargr) then
Ampl=(TMax-TMin)/2.
Ea_TMax=0.6108*exp((17.27*TMax)/(TMax+237.3)) ! Equation 10
Ea_TMin=0.6108*exp((17.27*TMin)/(TMin+237.3)) ! Equation 10
if(iRelHum.eq.0) then
* When average relative humidity is the input
EaDew=RHMean/(50./Ea_TMin+50./Ea_TMax) ! Equation 14
else if(iRelHum.eq.1) then
* When average daily vapor pressure is the input
EaDew=RHMean
RHMean=EaDew*(50./Ea_TMin+50./Ea_TMax) ! Equation 13
end if
end if
* Net shortwave radiation
DayNo=mod(DayNo,365.)
if(iRadiation.ne.2.or.lHargr) then
call RadGlobal(Ra,Latitude,DayNo,Omega,xx,yy,SC)
if(lHargr) goto 11
call Cloudiness(CloudF,iSunSh,SunHours,Omega,LongWaveRadB,
! LongWaveRadA,n_N,Cover,Tt)
if(iRadiation.eq.0.or.iSunSh.eq.3) then
if(iRadiation.eq.0) Rad=Ra*(ShortWaveRadA+ShortWaveRadB*n_N) ! Equation 52
if(iSunSh.eq.3) then
Tt=Rad/Ra
Cover=max(0.1,min(1.,2.330-3.330*Tt))
n_N=1.-Cover
end if
if(iRadiation.eq.1.and.iSunSh.eq.3) then
Rad_cs=Ra*(ShortWaveRadA+ShortWaveRadB*1.0) ! solar radiation of clear-sky
if(iMetHour) then ! Short term interval, calculate daily variation of Rad_cs
Sum=0.
do 10 k=1,24
sine1=xx+yy*cos(2.*PI/24.*(k-12.))
Sum=Sum+max(sine1,0.)/24.
10 continue
HourNo=24.*mod(DayNo,1.)
sine=xx+yy*cos(2.*PI/24.*(HourNo-12.)) ! Hourly variations eq.12.8 (Basic)
Rad_csH=max(sine*Rad_cs/Sum,0.)
if (Rad_csH.le.0.0001) then
CloudF=CloudF_Ac*0.6+CloudF_Bc ! average Rad/Rad_csH=0.6 in night time
else if(Rad.ge.Rad_csH) then
CloudF=CloudF_Ac*1.+CloudF_Bc ! Equation 57
else
CloudF=max(CloudF_Ac*Rad/Rad_csH+CloudF_Bc,0.01) ! Equation 57
end if
else ! Daily interval
CloudF=CloudF_Ac*Rad/Rad_cs+CloudF_Bc ! Equation 57
end if
end if
end if
Rns=(1.-Albedo)*Rad ! Equation 51
* Calculate net longwave radiation
call RadLongNet(Rnl,TMax,TMin,LongWaveRadA1,LongWaveRadB1,
! EaDew,CloudF)
* Net radiation
Rn=Rns-Rnl ! Equation 50
else
Rn=Rad
end if
* Calculate aerodynamic and radiation terms of the Penman-Montheith equation
call Aero(AeroTerm,RadTerm,Rn,CropHeight,WindHeight,TempHeight,
! Wind_ms,Altitude,TAver,TMax,TMin,rc,raa,Ea_TMax,Ea_TMin,
! EaDew,ierr)
if(ierr.eq.3) return
* Evapotranspiration
ETcomb=amax1(0.,RadTerm+AeroTerm) ! Equation 69, 31
row=1000. !(ms) water density [kg/m3]
row=(1.-7.37e-6*(TAver-4.)**2+3.79e-8*(TAver-4.)**3)*1000.
ETcomb=ETcomb/row*1000. ! conversion from [kg/m2/d] to [mm/d]
11 if(lHargr) then ! Hargreaves Formula
ETcomb=0.0023*0.408*Ra*(TAver+17.8)*sqrt(TMax-Tmin) ![mm/d], 0.408 - conversin from MJ/m2/d to mm/d
end if
* Potential Evaporation and Transpirations [mm/d]
EvapP=ETcomb*(1.-SCF)
TransP=ETcomb*SCF
* Calculate interception
Prec=Prec/rConv*TTConv ! to mm/d
Precc=Prec
call Intercept(rInterc,iInterc,LAI,aInterc,SCF,Prec,ExcesInt,
! TransP)
* conversion from mm/d to L/T
rRoot=(amax1(TransP-rInterc,0.))*rConv/TTConv
rSoil=EvapP*rConv/TTConv
Prec=Prec*rConv/TTConv
if(DayNo.eq.0) DayNo=365
if(lPrint) write(43,120) DayNo,ETcomb,EvapP,TransP,Rns,Rnl,
! RadTerm,AeroTerm,Precc,rInterc,ExcesInt
return
* Error when reading from an input file
901 ierr=1
return
101 format(a3)
120 format(f8.2,10f10.3)
end
************************************************************************
* Calculate aerodynamic and radiation terms of the Penman-Montheith equation
subroutine Aero(AeroTerm,RadTerm,Rn,CropHeight,WindHeight,
! TempHeight,Wind_ms,Altitude,TAver,TMax,TMin,rc,
! raa,Ea_TMax,Ea_TMin,EaDew,ierr)
real lambda
dl0=0.667*CropHeight
if(dl0.ge.WindHeight.or.dl0.ge.TempHeight) goto 901
AerDynRes=alog((WindHeight-dl0)/(0.123*CropHeight))*
! alog((TempHeight-dl0)/(0.0123*CropHeight))/
! 0.41**2 ! Equation 36,37,38,39
if(Wind_ms.gt.0.) raa=AerDynRes/Wind_ms ! Equation 36
AeroTCff=0.622*3.486*86400./AerDynRes/1.01 ! Equation 47b
PAtm=101.3*((293.-0.0065*Altitude)/293.)**5.253 ! Equation 6
lambda=2.501-0.002361*TAver ! Equation 1
gamma=0.0016286*PAtm/lambda ! Equation 4
gamma1=gamma
if(raa.gt.0.) gamma1=gamma*(1+rc/raa) ! Equation 41
Dlt=2049.*Ea_TMax/(TMax+237.3)**2+
! 2049.*Ea_TMin/(TMin+237.3)**2 ! Equation 3
dl_dl=Dlt/(Dlt+gamma1) ! Equation 49a
gm_dl=gamma/(Dlt+gamma1) ! Equation 47a
EaMean=(Ea_TMax+Ea_TMin)/2. ! Equation 11
AeroTerm=gm_dl*AeroTCff/(TAver+273.)*Wind_ms*(EaMean-EaDew)! Equation 45, 47
* Radiation term
RadTerm=0.
if(lambda.gt.0.) RadTerm=dl_dl*Rn/lambda ! Equation 49
return
901 ierr=3
return
end
************************************************************************
* Calculate global radiation
subroutine RadGlobal(Ra,Latitude,DayNo,Omega,xx,yy,SC)
real Lat1,Lat2,Latitude
PI=3.141592654
SC=118.08 ! Solar Constant MJ/m2/d
Lat1=(Latitude-aint(Latitude))*(5./3.)+aint(Latitude)
Lat2=Lat1*PI/180.
SolDeclin=sin(2.*PI/365.*DayNo-1.39)*0.4093 ! Equation 22
Omega=acos(-tan(SolDeclin)*tan(Lat2)) ! Equation 20
xx=sin(SolDeclin)*sin(Lat2) ! Equation 18a
yy=cos(SolDeclin)*cos(Lat2) ! Equation 18a
dr=(1.+0.033*cos((2.*Pi/365.)*DayNo)) ! Equation 21
Ra=SC/PI*dr*(Omega*xx+sin(Omega)*yy) ! Equation 18
return
end
************************************************************************
* Calculate cloudiness factor
* CloudF - Cloudiness factor [-]
* Cover - Cloud cover fraction
subroutine Cloudiness(CloudF,iSunSh,SunHours,Omega,LongWaveRadB,
! LongWaveRadA,n_N,Cover,Tt)
implicit real(A-H,L-Z)
PI=3.141592654
if(iSunSh.eq.0) then ! sunshine hours
NN=24./PI*Omega ! Equation 25
n_N=min(SunHours/NN,1.) ! Equation 52a
CloudF=LongWaveRadB+LongWaveRadA*n_N ! Equation 59
Cover=1.-n_N
else if(iSunSh.eq.1) then ! cloudiness
CloudF=SunHours
n_N=(CloudF-LongWaveRadB)/LongWaveRadA
Cover=1.-n_N
else if(iSunSh.eq.2) then ! transmission coeff
Tt=SunHours
Cover=max(0.0001,min(1.,2.330-3.330*Tt))
n_N=1.-Cover
CloudF=LongWaveRadB+LongWaveRadA*n_N ! Equation 59
end if
return
end
************************************************************************
* Calculate crop canopy resistance, rc
* SunHours- Bright sunshine hours per day [hr]
* alternatively, it can be Tt instead of SunHours
* iLAI - LAI is calculated from crop height for grass (1), for alfalfa (2), and soil cover (3)
* CropHeight - Crop Height [cm]
* LAI - Leaf Area Index [-]
subroutine CropRes(rc,iLAI,LAI,rExtinct,iCrop,CropHeight,SCF)
real LAI
logical lCrop
if(iCrop.eq.0.or.CropHeight.le.0) then
CropHeight=0.1 ! cm
lCrop=.false.
else
lCrop=.true.
end if
rc=0.
if(lCrop) then
if(iLAI.eq.1) then ! only clipped grass
LAI=0.24*CropHeight ! Equation 35
else if(iLAI.eq.2) then ! alfalfa
LAI=1.5*alog(CropHeight)+5.5 ! Equation 34
else if(iLAI.eq.3) then ! SCF
if(LAI.lt.1.) then
LAI=-alog(1.-LAI)/amax1(rExtinct,0.1)
else
LAI=10.
end if
end if
if(LAI.gt.0) rc=200./LAI ! Equation 32
if(LAI.gt.0) SCF=amax1(0.,1.-exp(-amax1(rExtinct,0.1)*LAI))
else
rc=0.
end if
return
end
************************************************************************
* Calculate net longwave radiation
subroutine RadLongNet(Rnl,TMax,TMin,LongWaveRadA1,LongWaveRadB1,
! Ea,CloudF)
real LongWaveRadA1,LongWaveRadB1
sigma=0.00000000245*((TMax+273.16)**4+(TMin+273.16)**4) ! Equation 63a
Emissivity=LongWaveRadA1+LongWaveRadB1*sqrt(Ea) ! Equation 60
Rnl=sigma*CloudF*Emissivity ! Equation 63
return
end
************************************************************************
* Calculate interception [mm]
subroutine Intercept(rInterc,iInterc,LAI,aInterc,SCF,Prec,
! ExcesInt,TransP)
real LAI
rInterc=0.
if(iInterc.gt.0) then
if(iInterc.eq.1.and.LAI.gt.0.) then
rInterc=amin1(aInterc*LAI*(1.-1./(1+SCF*Prec/aInterc/LAI)),
! Prec) ! Newly intercepted
if(rInterc+ExcesInt.gt.aInterc*LAI) ! can not be more than max interception
! rInterc=aInterc*LAI-ExcesInt
end if
Prec=amax1(Prec-rInterc,0.)
rInterc=ExcesInt+rInterc ! Old interception + new interception
ExcesInt=0.
if(TransP-rInterc.lt.0.) ExcesInt=-TransP+rInterc
end if
return
end
************************************************************************
* Interpolate meteo variables in time
* i = 1 (initialize), i = 2 (move new into old), i = 3 (interpolate)
subroutine MeteoInt(i,t,tAtm2O,tAtm2,Rad,RadO,RadN,TMaxA,TMaxAO,
! TMaxAN,TMinA,TMinAO,TMinAN,Wind,WindO,WindN,
! RHMean,RHMeanO,RHMeanN,SunHours,SunHoursO,
! SunHoursN,lEnBal)
double precision t,tAtm2O,tAtm2
logical lEnBal ! for lEnBal, there is no need to interpolate Rad and SunHours
if(i.eq.1) then
tAtm2O=t
RadO=RadN
Rad =RadN
TMaxAO=TMaxAN
TMaxA =TMaxAN
TMinAO=TMinAN
TMinA =TMinAN
WindO =WindN
Wind =WindN
RHMeanO=RHMeanN
RHMean =RHMeanN
SunHoursO=SunHoursN
SunHours =SunHoursN
else if(i.eq.2) then
tAtm2O=tAtm2
RadO=RadN
TMaxAO=TMaxAN
TMinAO=TMinAN
WindO =WindN
RHMeanO=RHMeanN
SunHoursO=SunHoursN
else if(i.eq.3) then
Rad =RadO +(RadN -RadO) *(sngl(t)-tAtm2O)/(tAtm2-tAtm2O)
if(lEnBal) Rad=RadN
TMaxA=TMaxAO+(TMaxAN-TMaxAO)*(sngl(t)-tAtm2O)/(tAtm2-tAtm2O)
TMinA=TMinAO+(TMinAN-TMinAO)*(sngl(t)-tAtm2O)/(tAtm2-tAtm2O)
Wind =WindO +(WindN -WindO) *(sngl(t)-tAtm2O)/(tAtm2-tAtm2O)
RHMean=RHMeanO+(RHMeanN-RHMeanO)*(sngl(t)-tAtm2O)/(tAtm2-tAtm2O)
SunHours=SunHoursO+(SunHoursN-SunHoursO)*(sngl(t)-tAtm2O)/
! (tAtm2 -tAtm2O)
if(lEnBal) SunHours=SunHoursN
end if
return
end
************************************************************************
* Evaluate surface energy balance
subroutine Evapor(t,TempS,TMaxA,TMinA,Rad,hTop,TempHeight,
! WindHeight,Wind,RHMean,HeatFlux,rTop,Prec,
! tPeriod,Latitude,Albedo,SunHours,ThetaT,xConv,
! tConv,iRadiation,Rns,Rnl,Rn,SensFlux,Evap,Lat,
! Const,iSunSh,r_H,lMetDaily,Rst,TempA,RH_A,
! ShortWaveRadA,ShortWaveRadB,LongWaveRadA,
! LongWaveRadB,iMetHour)
implicit real(A-H,L-Z)
real Lat,Latitude,n_N
double precision t
logical lMetDaily
* Rn - Net radiation [MJ/m2/d]
* Ra - Potential radiation [MJ/m2/d]
* Rad - Solar radiation flux at the surface [MJ/m2/d]
* Rns - Net short wave radiation [MJ/m2/d]
* Rst - Daily variated net short wave radiation [MJ/m2/d]
* Rnl - Net long wave radiation [MJ/m2/d]
* Rnlu - Outgoing long wave radiation [MJ/m2/d]
* Rnld - Incoming long wave radiation [MJ/m2/d]
* SC - Solar Constant [MJ/m2/d] (=118.08)
* g - gravitational acceleration [m/s2] (9.81)
* xMol - molecular weight of water [kg/mol] (0.018015)
* R - universal gas constant [J/mol/K] (8.314)
* row - density of soil water [kg/m3]
* Lat - mass latent heat of vaporization of water [J/kg, m2/s2]
* xLatent - volumetric latent heat of vaporization of water [J/m3,kg/m/s2]
* TempS - soil temperature
* TempA - atmosphere temperature
* rovs - saturated vapor density [kg/m3]
* rov - vapor density [kg/m3]
* Hr - relative humidity [-]
* uu - friction velocity
* Wind - wind speed [m/s]
* SensFlux - sensible flux [W/m2]
* HeatFlux - heat flux fo soil [W/m2]
* Evap - evaporation flux [kg/s/m2]
* sigma - Stephan-Boltzmann constant [5.6697e-8 J/s/m2/K4], [4.899e-9 MJ/d/m2/K4]
* Tt - Transmission coefficient (either given or calculated from potential and
* measured solar radiation)
* r_v - Aerodynamic resistance to vapor flow [s/m]
* r_h - Aerodynamic resistance to heat flow [s/m] (=r_v)
* r_s - Soil surface resistance [s/m]
* CloudF - Cloudiness factor [-]
* Cover - Cloud cover fraction
Pi=3.141592654
g=9.81
xMol=0.018015
R=8.314
Ca=1200.0
* Hourly variations of atmospheric temperature
if(.not.lMetDaily) then
TMean=(TMaxA+TMinA)/2.
TempA=TMean
if(tPeriod.gt.0.) TempA=TMean+(TMaxA-TMinA)/2.*
! sin(2.*PI*sngl(t)/tPeriod-7.*PI/12.)
end if
TKelvS=TempS+273.15
TKelvA=TempA+273.15
rovsA=0.001*exp(31.3716-6014.79/TKelvA-0.00792495*TkelvA)/TKelvA
if(lMetDaily) RHMean=RH_A
roa=RHMean/100.*rovsA
* Net shortwave radiation (Cloud cover fraction to calculate Rnl)
if(iRadiation.ne.2) then
DayNo=mod(sngl(t),365.)
call RadGlobal(Ra,Latitude,DayNo,Omega,xx,yy,SC)
call Cloudiness(CloudF,iSunSh,SunHours,Omega,LongWaveRadB,
! LongWaveRadA,n_N,Cover,Tt)
if(iRadiation.eq.0.or.iSunSh.eq.3) then
if(iRadiation.eq.0) Rad=Ra*(ShortWaveRadA+ShortWaveRadB*n_N) ! Equation 52
if(iSunSh.eq.3) then
if(iMetHour.eq.1) then ! short term interval radiation data
HourNo=24.*mod(DayNo,1.)
sine=xx+yy*cos(2.*PI/24.*(HourNo-12.))
RaH=max(SC*sine,0.) ! Hourly variations of extraterrestorial radiation, eq.12.8 (Basic)
if(RaH.le.0.0001) then ! night time
Cover=0.6 ! average value calculated from Rad/Rad_csH=0.6
else
Tt=min(Rad/RaH,1.)
Cover=max(0.1,min(1.,2.330-3.330*Tt))
end if
else ! daily interval radiation data
Tt=Rad/Ra
Cover=max(0.1,min(1.,2.330-3.330*Tt))
end if
end if
end if
if(iRadiation.eq.0.or.iMethour.eq.0)then
if(iSunSh.ne.2)Tt=Rad/Ra
HourNo=24.*mod(DayNo,1.)
sine=xx+yy*cos(2.*Pi/24.*(HourNo-12.)) ! Hourly variations eq.12.8 (Basic)
RadH=max(SC*Tt*sine,0.) ! Equation 12.7
else
RadH=Rad
end if
* Surface Albedo van Bavel and Hillel (1976)
Albedo=0.25
if(ThetaT.gt.0.25) Albedo=0.1
if(ThetaT.gt.0.1.and.ThetaT.le.0.25) Albedo=0.35-ThetaT
if(lMetDaily) RadH=Rst
Rns=(1.-Albedo)*RadH ! Equation 51
* Net longwave radiation
call RadLongNet1(Rnl,TempA,RHMean,Cover,ThetaT,TkelvA,TkelvS)
Rn=Rns+Rnl ! Equation 50
else
Rn=Rad
end if
* Calculate aerodynamic resistance to vapor flow
call AeroRes(r_v,TempHeight,WindHeight,Wind,TKelvS,TKelvA,Ca,g)
* Soil surface resistance (van de Griend and Owe, 1994)
r_s=10.0
if(ThetaT.lt.0.15) r_s=10.0*exp(35.63*(0.15-ThetaT))
* Aerodynamic resistances to heat transfer
r_h=r_v
SensFlux=Ca*(TempS-TempA)/r_h
h=hTop/xConv ! conversions to m
Hr=exp(h*xMol*g/R/TkelvS)
c if(hTop.lt.0.999*hCritA.and.TempS.gt.TempS1) Hr=0.0001
rovsS=0.001*exp(31.3716-6014.79/TKelvS-0.00792495*TkelvS)/TKelvS
rov=rovsS*Hr
Evap=max(0.,(rov-roa)/(r_v+r_s))
row=(1.-7.37e-6*(TempS-4.)**2+3.79e-8*(TempS-4.)**3)*1000.
Lat=xLatent(TempA)/row
* Conversion from [MJ/m2/d] to [J/m2/s,W/m2]
rConv=1000000./86400.