-
Notifications
You must be signed in to change notification settings - Fork 0
/
getmet.f90
1910 lines (1660 loc) · 67 KB
/
getmet.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!**********************************************************************
! GETMET.FOR
!
! This file contains all the subroutines required to read the met data
! file. The main routines (called externally to this file) are:
! OPENMETF - opens the met file & reads the format information
! RESTARTMETF - finds the start of the actual met data in the met file
! GETMET - calls the appropriate subroutine to read the met data, based
! on the flag MFLAG describing the format
! SKIPMET - skips any unwanted met data
! ALTERMETOTC - alters met data to account for effects of OTC
! ALTERMETCC - alters met data in accordance with climate change scenario
! GETWIND - calculates wind speed through the canopy using exponential formula
!
! Subsidiary routines are:
! 1. Subroutines to read in data
! GETMETDAY - reads the standard daily met data format
! GETMETHR - reads the standard hourly met data format
! READENVIRON - reads in constant met data values
! READLAT - reads latitude and longitude
! READDELTAT - reads in information needed to calculate incident radiation, if needed
! 2. Subroutines to process temperatures & rainfall
! CALCTHRLY - calculates hourly air temps from Tmax & Tmin
! CALCTSOIL - sets hourly soil temp equal to average daily air temp
! ASSIGNRAIN - assigns daily rainfall to hours in the day
! 3. Subroutines to process VPD/RH
! CALCRH - calculates hourly RH from hourly air temp & the minimum temp
! RHTOVPD - converts RH to VPD
! VPDTORH - converts VPD to RH
! TDEWTORH - calculates RH from air temperature & dewpoint temperature
! MFDTORH - converts from water vapour mole fraction to RH
! VPDTOMFD - converts from VPD to water vapour mole fraction
! CALCAH - converts relative humidity to absolute humidity (called by ALTERMETCC)
! AHTORH - converts absolute humidity to relative humidity (called by ALTERMETCC)
! 4. Subroutines to process radiation
! ESTPARIN - estimates daily incident radiation from temperature
! CALPARHHRLY - calculates hourly incident PAR from daily totals of beam & diffuse
! CALCFBMD - calculates diffuse fraction of daily incident radiation
! CALCFBMH - calculates diffuse fraction of hourly incident radiation
! CALCFSUN - calculate sunlit fraction of hour (presently unused)
! CALCNIR - calculates incident NIR from incident PAR
! THERMAL - calculates incident thermal radiation from air temperature
! CALCFBMWN - an alternative method to calculate the diffuse fraction (currently unused)
! 5. Additionally, the following functions are provided:
! SATUR - calculate water vapour saturation pressure at given T MOVED TO UTILS
! TK - calculate T in Kelvin given T in Celsius MOVED TO UTILS
! ETRAD - calculate radiation incident on the atmosphere
!**********************************************************************
!**********************************************************************
SUBROUTINE OPENMETF(ISTART,IEND,CAK,PRESSK,SWMIN,SWMAX,USEMEASET,DIFSKY,ALAT,TTIMD,&
DELTAT,MFLAG,METCOLS,NOMETCOLS,MTITLE,MSTART,in_path)
! This subroutine opens the meteorological data file and reads the
! data describing it. It checks that it covers the dates of the simulation
! and returns the format of the met file.
! INPUTS:
! ISTART, IEND - Desired start and end of simulation (in days-since-1950) - from confile. If not defined,
! program uses all met data.
! OUTPUTS:
! CAK - Constant CO2 concentration (umol mol-1), if specified; 0 otherwise
! PRESSK - Constant air pressure (Pa), if specified; PATM otherwise
! SWMIN - Minimum soil water content
! SWMAX - Maximum soil water content - in same units as soil water content in met data
! DIFSKY - Parameter indicating light distribution over cloudy sky, if specified; default 0
! ALAT - latitude, in radians (-ve for S hemisphere)
! TTIMD - time difference between longitude of plot & longitude of time zone, in hours
! MFLAG - indicates whether daily (0) or hourly (1) met data
! METCOLS - array containing the number of the column corresponding to each met data element used by program
! NOMETCOLS - number of columns of met data
! MTITLE - title of met data file
! MSTART - start date of met data (in days-since-1950 format)
! DELTAT - monthly mean daily temperature amplitude
!**********************************************************************
USE maestcom
USE metcom
IMPLICIT NONE
CHARACTER*8 COLUMNS(MAXMET)
CHARACTER*256 STARTDATE,ENDDATE
CHARACTER(LEN=*), INTENT(INOUT) :: MTITLE
CHARACTER(LEN=*), INTENT(IN) :: in_path
REAL DELTAT(12)
INTEGER METCOLS(MAXMET),KHRSPERDAY,NOCOLUMNS,IOERROR
INTEGER, INTENT(IN) :: USEMEASET
INTEGER, EXTERNAL :: IDATE50
INTEGER DAYORHR,MSTART,MEND,ISTART,IEND,ICOL,MFLAG,I,NOMETCOLS
NAMELIST /METFORMAT/ DAYORHR, KHRSPERDAY, NOCOLUMNS, COLUMNS, STARTDATE, ENDDATE
REAL CAK,PRESSK,DIFSKY,SWMIN,SWMAX,ALAT,TTIMD
!print *, "OPENMETF"
990 FORMAT (A60) ! For reading titles in input files.
991 FORMAT (A12,A60) ! For writing comments to output files.
! Open input file with met data
OPEN (UMET, FILE =trim(in_path)//'met.dat', STATUS='OLD', IOSTAT=IOERROR)
IF (IOERROR.NE.0) THEN
CALL SUBERROR('ERROR OPENING MET FILE',IFATAL,IOERROR)
END IF
READ (UMET, 990, IOSTAT=IOERROR) MTITLE
IF (IOERROR.NE.0) THEN
CALL SUBERROR('ERROR READING MET FILE',IFATAL,IOERROR)
END IF
! Read in unchanging met data
CALL READENVIRON(UMET, CAK, PRESSK, DIFSKY, SWMIN, SWMAX)
! Read in latitude & longitude
CALL READLAT(UMET, ALAT, TTIMD)
! Read format
KHRSPERDAY = 0 ! Init.
REWIND(UMET)
READ (UMET,METFORMAT,IOSTAT = IOERROR)
IF (IOERROR.NE.0) CALL SUBERROR('ERROR IN MET FILE: MISSING FORMAT INFORMATION', IFATAL,IOERROR)
! Check dates of simulation are covered
MSTART = IDATE50(STARTDATE)
MEND = IDATE50(ENDDATE)
IF ((ISTART.EQ.0).AND.(IEND.EQ.0)) THEN
ISTART = MSTART
IEND = MEND
ELSE
IF ((ISTART.LT.MSTART).OR.(IEND.GT.MEND))CALL SUBERROR('ERROR: MET FILE DOES NOT COVER DATES',IFATAL,IOERROR)
END IF
! Process number of hours per day - the old KHRS
IF (KHRSPERDAY.EQ.0) CALL SUBERROR('ERROR: ADD KHRSPERDAY TO MET.DAT FORMAT',IFATAL,KHRSPERDAY)
IF (KHRSPERDAY.GT.MAXHRS) CALL SUBERROR('ERROR: KHRSPERDAY MUST NOT EXCEED MAXHRS',IFATAL,KHRSPERDAY)
KHRS = KHRSPERDAY
HHRS = (KHRS) / 2.0
SPERHR = 3600 * 24.0 / KHRS
! Process columns - assign column numbers to METCOLS array
IF (NOCOLUMNS.GT.MAXMET) THEN
CALL SUBERROR('ERROR: TOO MANY MET DATA COLUMNS: DATA LOST',IWARN,IOERROR)
NOCOLUMNS = MAXMET
END IF
! Initialise array of met columns
DO ICOL = 1,MAXMET
METCOLS(ICOL) = MISSING
END DO
MFLAG = DAYORHR
! If MFLAG = 0, look for daily values; if MFLAG = 1, hourly values
IF (MFLAG.EQ.0) THEN ! Daily values
DO I = 1,NOCOLUMNS
ICOL = MISSING
IF (COLUMNS(I).EQ.'DATE'.OR.COLUMNS(I).EQ.'DOY')THEN
ICOL = MDDATE
ELSEIF (COLUMNS(I).EQ.'WIND') THEN
ICOL = MDWIND
ELSEIF (COLUMNS(I).EQ.'TMIN') THEN
ICOL = MDTMIN
ELSEIF (COLUMNS(I).EQ.'TMAX') THEN
ICOL = MDTMAX
ELSEIF (COLUMNS(I).EQ.'PAR') THEN
ICOL = MDPAR
ELSEIF (COLUMNS(I).EQ.'SI') THEN
ICOL = MDSI
ELSEIF (COLUMNS(I).EQ.'FBEAM') THEN
ICOL = MDFBEAM
ELSEIF (COLUMNS(I).EQ.'CA') THEN
ICOL = MDCA
ELSEIF (COLUMNS(I).EQ.'PRESS') THEN
ICOL = MDPRESS
ELSEIF (COLUMNS(I).EQ.'PPT') THEN
ICOL = MDPPT
ELSEIF (COLUMNS(I).EQ.'SMD') THEN
ICOL = MDSMD
ELSEIF (COLUMNS(I).EQ.'SWP') THEN
ICOL = MDSWP
ELSEIF (COLUMNS(I).EQ.'SWC') THEN
ICOL = MDSWC
ELSEIF (COLUMNS(I).EQ.'SW') THEN
ICOL = MDSWC
ELSEIF (COLUMNS(I).EQ.'ET') THEN
ICOL = MDET
!ELSEIF (COLUMNS(I).EQ.'RAD') THEN
! ICOL = MDRad
ELSE
CALL SUBERROR('ERROR: Header incorrectly specified in Met file',&
IFATAL,0)
ENDIF
IF (ICOL.NE.MISSING) METCOLS(ICOL) = I
END DO
! Check to see if any of the essential information is missing.
IF (METCOLS(MDTMIN).EQ.MISSING) CALL SUBERROR('ERROR: NEED VALUES OF TMIN IN MET FILE',IFATAL,0)
IF (METCOLS(MDTMAX).EQ.MISSING) CALL SUBERROR('ERROR: NEED VALUES OF TMAX IN MET FILE',IFATAL,0)
IF ((METCOLS(MDPAR).EQ.MISSING).AND.(METCOLS(MDSI).EQ.MISSING)) CALL READDELTAT(UMET,DELTAT,IOERROR)
IF ((CAK.EQ.0).AND.(METCOLS(MDCA).EQ.MISSING)) CALL SUBERROR('ERROR: NO VALUE FOR CA IN MET FILE',IFATAL,0)
IF (USEMEASET.EQ.1.AND.(METCOLS(MDET).EQ.MISSING)) &
CALL SUBERROR('ERROR: NEED MEASURED ET WHEN USEMEASET=1',IFATAL,0) ! RAD
ELSE ! Hourly values
DO I = 1,NOCOLUMNS
ICOL = MISSING
IF (COLUMNS(I).EQ.'DATE'.OR.COLUMNS(I).EQ.'DOY') THEN
ICOL = MHDATE
ELSEIF (COLUMNS(I).EQ.'WIND') THEN
ICOL = MHWIND
ELSEIF (COLUMNS(I).EQ.'TAIR') THEN
ICOL = MHTAIR
ELSEIF (COLUMNS(I).EQ.'TSOIL') THEN
ICOL = MHTSOIL
ELSEIF (COLUMNS(I).EQ.'RH') THEN
ICOL = MHRH
ELSEIF (COLUMNS(I).EQ.'RH%') THEN
ICOL = MHRHP
ELSEIF (COLUMNS(I).EQ.'VPD') THEN
ICOL = MHVPD
ELSEIF (COLUMNS(I).EQ.'PAR') THEN
ICOL = MHPAR
ELSEIF (COLUMNS(I).EQ.'RAD') THEN
ICOL = MHRAD
ELSEIF (COLUMNS(I).EQ.'FBEAM') THEN
ICOL = MHFBEAM
ELSEIF (COLUMNS(I).EQ.'CA') THEN
ICOL = MHCA
ELSEIF (COLUMNS(I).EQ.'MFD') THEN
ICOL = MHMFD
ELSEIF (COLUMNS(I).EQ.'PRESS') THEN
ICOL = MHPRESS
ELSEIF (COLUMNS(I).EQ.'TDEW') THEN
ICOL = MHTDEW
ELSEIF (COLUMNS(I).EQ.'PPT') THEN
ICOL = MHPPT
ELSEIF (COLUMNS(I).EQ.'ET') THEN
ICOL = MHET
ELSEIF (COLUMNS(I).EQ.'SMD') THEN
ICOL = MHSMD
ELSEIF (COLUMNS(I).EQ.'SWC') THEN
ICOL = MHSWC
ELSEIF (COLUMNS(I).EQ.'SW') THEN
ICOL = MHSWC
ELSEIF (COLUMNS(I).EQ.'SWP') THEN
ICOL = MHSWP
ELSEIF (COLUMNS(I).EQ.'TIME') THEN
ICOL = MHTIME
ELSEIF (COLUMNS(I).EQ.'VMFD') THEN
ICOL = MHMFD
ELSE
CALL SUBERROR('WARNING: Header includes unknown variable - ignored',&
IWARN,0)
ENDIF
IF (ICOL.NE.MISSING) METCOLS(ICOL) = I
END DO
! Check to see if any of the essential information is missing.
IF (METCOLS(MHTAIR).EQ.MISSING) CALL SUBERROR('ERROR: NEED VALUES OF TAIR IN MET FILE',IFATAL,0)
IF ((METCOLS(MHPAR).EQ.MISSING).AND.(METCOLS(MHRAD).EQ.MISSING))CALL READDELTAT(UMET,DELTAT,IOERROR)
IF ((CAK.EQ.0).AND.(METCOLS(MHCA).EQ.MISSING))CALL SUBERROR('ERROR: NO VALUE FOR CA IN MET FILE',IFATAL,0)
END IF
NOMETCOLS = NOCOLUMNS
RETURN
END SUBROUTINE OPENMETF
!**********************************************************************
SUBROUTINE RESTARTMETF(ISTART,MSTART,MFLAG)
! Position met file at start of met data
! BM Changed 10/00: Start of data must be directly specified
! INPUTS:
! ISTART - Date for which met data is wanted
! MSTART - Date on which met data starts
! MFLAG - indicates whether daily or hourly data
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER IOERROR,MFLAG,LINESTOSKIP,ISTART,MSTART,I
CHARACTER*60 TMPTXT, DATASTART
!print *, "RESTARTMETF"
DATASTART = 'DATA STARTS'
REWIND(UMET)
! Read through format information to find start of data
990 FORMAT (A60)
30 READ (UMET,990,IOSTAT = IOERROR) TMPTXT
IF (IOERROR.NE.0) CALL SUBERROR('ERROR: COULD NOT FIND START OF MET DATA',IFATAL,IOERROR)
IF (TMPTXT.NE.DATASTART) GOTO 30
! Read data until the start date
IF (MFLAG.EQ.0) THEN
LINESTOSKIP = ISTART-MSTART
ELSE
LINESTOSKIP = KHRS*(ISTART-MSTART)
END IF
DO I = 1,LINESTOSKIP
READ (UMET,990,IOSTAT = IOERROR) TMPTXT
IF (IOERROR.NE.0) CALL SUBERROR('READ PAST EOF IN RESTARTMETF', IFATAL,IOERROR)
END DO
RETURN
END SUBROUTINE RESTARTMETF
!**********************************************************************
SUBROUTINE READENVIRON(UFILE,CAK,PRESSK,DIFSKYI,SWMINI,SWMAXI)
! Read in environmental conditions which do not change with time.
! These must be at the start of the met.dat file.
! INPUT:
! UFILE - file number of met data file
! OUTPUTS:
! CAK - Constant CO2 concentration (umol mol-1), if specified; 0 otherwise
! PRESSK - Constant air pressure (Pa), if specified; PATM otherwise
! DIFSKYI - Parameter indicating light distribution over cloudy sky, if specified; default 0
! SWMINI - Minimum soil water content
! SWMAXI - Maximum soil water content - in same units as soil water content in met data
!**********************************************************************
USE maestcom
IMPLICIT NONE
NAMELIST /ENVIRON/ CA,PRESS,DIFSKY, SWMIN, SWMAX
INTEGER UFILE,IOERROR
REAL CA,PRESS,DIFSKY, SWMIN, SWMAX
REAL CAK,PRESSK,DIFSKYI, SWMINI, SWMAXI
!print *, "READENVIRON"
! Default values
PRESS = PATM
CA = 0
DIFSKY = 0.0
SWMIN = 0.0
SWMAX = 1.0
! Read namelist
READ (UFILE, ENVIRON, IOSTAT = IOERROR)
IF (IOERROR.NE.0) THEN
CALL SUBERROR('WARNING: DEFAULT VALUES: PRESS = 101.25 kPa, DIFSKY = 0', IWARN,IOERROR)
END IF
CAK = CA
PRESSK = PRESS
DIFSKYI = DIFSKY
SWMINI = SWMIN
SWMAXI = SWMAX
RETURN
END SUBROUTINE READENVIRON
!**********************************************************************
SUBROUTINE READDELTAT(UFILE,DELTATI,IOERROR)
! Read in mean monthly daily temperature amplitudes
! Needed to calculate incident PAR (if not specified) using routine of Bristow & Campbell 1984
! If not present, program will stop (only called if PAR not specified).
!**********************************************************************
USE maestcom
IMPLICIT NONE
NAMELIST /BRISTO/ DELTAT
REAL DELTAT(12),DELTATI(12)
INTEGER UFILE,IOERROR,I
!print *, "READDELTAT"
! Read namelist
REWIND(UFILE)
READ (UFILE, BRISTO, IOSTAT = IOERROR)
IF (IOERROR.NE.0) THEN
CALL SUBERROR('ERROR: NEED VALUES OF PAR IN MET FILE OR DELTAT', IFATAL,0)
END IF
DO I = 1,12
DELTATI(I) = DELTAT(I)
END DO
RETURN
END SUBROUTINE READDELTAT
!**********************************************************************
SUBROUTINE GETMET(IDATE,MFLAG,ZEN,METCOLS,NOMETCOLS,CAK,PRESSK,SWMIN,SWMAX,DELTAT,ALAT,DEC,DAYL,WINDAH,&
TSOIL,TAIR,RADABV,FBEAM,RH,VPD,VMFD,CA,PRESS,PPT,SOILMOIST,SOILDATA,TSOILDATA,ETMEAS, solarRad, iDay)
! According to the value of MFLAG, this subroutine calls the appropriate
! subroutine to read in the meteorological data for use in MAESTRO.
! It is important that all handling of meteorological data occurs within
! this function. In particular, the flag MFLAG should not be referred to
! within the main body of the program. This maintains modularity & makes it
! easier to add new met data formats.
! The values passed to this function are:
! IDATE - date of simulation, in days-since-1950 format
! MFLAG - flag indicating the format of the input file
! ZEN - the zenith angle of the sun
! NOMETCOLS - the number of columns in the met file
! METCOLS - the format of the columns in the met file
! CAK - Constant CO2 concentration (umol mol-1), if specified; 0 otherwise
! PRESSK - Constant air pressure (Pa), if specified; PATM otherwise
! SWMINI - Minimum soil water content
! SWMAXI - Maximum soil water content - in same units as soil water content in met data
! The values which must be returned are:
! arrays of KHRSly values of the following met variables:
! WINDAH - wind speed in m s-1
! TSOIL - soil surface temperature (degrees !)
! TAIR - air temperature (degrees !)
! RADABV(3) - incident radiation in three wavelengths (J m-2 s-1)
! FBEAM(3) - beam fractions of radiation in 3 wavelengths (fraction)
! RH - relative humidity of air (fraction)
! VPD - vapour pressure deficit of air (Pa)
! VMFD - mole fraction deficit (mmol mol-1)
! CA - the atmospheric CO2 concentration (umol mol-1)
! PRESS - the atmospheric pressure (Pa)
! PPT - rainfall over the time period (mmol H2O m-2)
! SOILMOIST - soil moisture data - either potential (MPa) or deficit (dimnless)
! SOILDATA - type of soil moisture data
! ET - measured evapotranspiration (mm t-1)
!**********************************************************************
USE maestcom
IMPLICIT NONE
REAL ZEN(MAXHRS)
REAL WINDAH(MAXHRS),TSOIL(MAXHRS),TAIR(MAXHRS)
REAL RADABV(MAXHRS,3),FBEAM(MAXHRS,3)
REAL solarRad(MAXHRS,3)
integer iDay
REAL RH(MAXHRS),VPD(MAXHRS),CA(MAXHRS),VMFD(MAXHRS),PRESS(MAXHRS)
REAL PPT(MAXHRS), SOILMOIST(MAXHRS), ETMEAS(MAXHRS)
REAL DELTAT(12)
INTEGER METCOLS(MAXMET),SOILDATA,TSOILDATA,MFLAG,IDATE,NOMETCOLS
REAL CAK,PRESSK,SWMIN,SWMAX,ALAT,DEC,DAYL
!print *, "GETMET"
! Call appropriate function to read met file.
IF (MFLAG.EQ.0) THEN
CALL GETMETDAY(IDATE,ZEN,NOMETCOLS,METCOLS,CAK,PRESSK,SWMIN,SWMAX,DELTAT,ALAT,DEC, &
DAYL,WINDAH,TSOIL,TAIR,RADABV,FBEAM,RH,VPD,VMFD,CA,PRESS,PPT, &
SOILMOIST,SOILDATA,TSOILDATA)
ELSE IF (MFLAG.EQ.1) THEN
CALL GETMETHR(IDATE,ZEN,NOMETCOLS,METCOLS,CAK,PRESSK,SWMIN,SWMAX,DELTAT,ALAT,DEC, &
DAYL,WINDAH,TSOIL,TAIR,RADABV,FBEAM,RH,VPD,VMFD,CA,PRESS,PPT, &
SOILMOIST,SOILDATA,TSOILDATA,ETMEAS,solarRad,iDay)
! ELSE
! insert other formats if required
END IF
RETURN
END SUBROUTINE GETMET
!**********************************************************************
SUBROUTINE GETMETDAY(IDATE,ZEN,NOMETCOLS,METCOLS,CAK,PRESSK,SWMIN,SWMAX,DELTAT,ALAT,DEC,DAYL, &
WINDAH,TSOIL,TAIR,RADABV,FBEAM,RH,VPD,VMFD,CA,PRESS,PPT,SOILMOIST, &
SOILDATA,TSOILDATA)
! Read daily met data: see function GETMET for parameter definitions
!**********************************************************************
USE maestcom
USE metcom
IMPLICIT NONE
INTEGER METCOLS(MAXMET),SOILDATA,TSOILDATA,IOERROR,I,NOMETCOLS
INTEGER IHR,IDATE
REAL ZEN(MAXHRS)
REAL DATAIN(MAXMET)
REAL windah(MAXHRS),tsoil(MAXHRS),TAIR(MAXHRS),PPT(MAXHRS)
REAL SOILMOIST(MAXHRS)
REAL RADABV(MAXHRS,3),FBEAM(MAXHRS,3),FSUN(MAXHRS)
REAL RH(MAXHRS),VPD(MAXHRS),VMFD(MAXHRS),CA(MAXHRS),PRESS(MAXHRS)
REAL DELTAT(12)
REAL WIND,PRESSK,TMAX,TMIN,DAYL,PRECIP,ALAT,DEC,PAR,FBM
REAL RADBM,RADDF,SMD,CAK,SWMIN,SWMAX
!print *, "GETMETDAY"
! Read in day's data
READ (UMET,*,IOSTAT = IOERROR) (DATAIN(I), I = 1,NOMETCOLS)
IF (IOERROR.NE.0) CALL SUBERROR('ERROR READING MET DATA',IFATAL,IOERROR)
! Set up wind speed array
IF (METCOLS(MDWIND).EQ.MISSING) THEN
WIND = DEFWIND ! Very default value - CHECK!!
ELSE IF (DATAIN(METCOLS(MDWIND)).LE.0) THEN
WIND = DEFWIND
ELSE
WIND = DATAIN(METCOLS(MDWIND))
END IF
DO I = 1,KHRS
WINDAH(I) = WIND
END DO
! Set up pressure array
IF (METCOLS(MDPRESS).NE.MISSING) THEN
DO IHR = 1,KHRS
PRESS(IHR) = DATAIN(METCOLS(MDPRESS))
END DO
ELSE
DO IHR = 1,KHRS
PRESS(IHR) = PRESSK
END DO
END IF
! Calculate hourly temperatures
TMAX = DATAIN(METCOLS(MDTMAX))
TMIN = DATAIN(METCOLS(MDTMIN))
CALL CALCTHRLY(TMAX,TMIN,DAYL,TAIR)
! Calculate soil temperatures
! CALL CALCTSOIL(TAIR,TSOIL)
TSOILDATA = 0 ! Can't read in daily values.
! Calculate relative humidities
CALL CALCRH(TMIN,TAIR,RH)
! Calculate VPDs
CALL RHTOVPD(RH,TAIR,VPD)
! Calculate VMFDs
CALL VPDTOMFD(VPD,PRESS,VMFD)
! Calculate incident PAR
IF (METCOLS(MDSI).EQ.MISSING) THEN
IF (METCOLS(MDPAR).EQ.MISSING) THEN
PRECIP = 0.0
IF (METCOLS(MDPPT).NE.MISSING) PRECIP = DATAIN(METCOLS(MDPPT))
CALL BRISTO(IDATE,TMAX,TMIN,PRECIP,DELTAT,ALAT,DEC,DAYL,PAR)
ELSE
PAR = DATAIN(METCOLS(MDPAR))
END IF
END IF
! Calculate diffuse fraction
IF (METCOLS(MDFBEAM).EQ.MISSING) THEN
IF (METCOLS(MDSI).EQ.MISSING) THEN
CALL CALCFBMD(IDATE,ZEN,PAR,FBM)
ELSE
CALL CALCFBMD(IDATE,ZEN,DATAIN(METCOLS(MDSI))*FPAR,FBM)
END IF
ELSE
FBM = DATAIN(METCOLS(MDFBEAM))
END IF
! Calculate PAR
IF (METCOLS(MDSI).EQ.MISSING) THEN
RADBM = PAR*FBM
RADDF = PAR*(1.-FBM)
ELSE
RADBM = DATAIN(METCOLS(MDSI))*FBM*FPAR
RADDF = DATAIN(METCOLS(MDSI))*(1.-FBM)*FPAR
END IF
CALL CALCPARHRLY(RADBM,RADDF,ZEN,RADABV,FBEAM)
! Calculate NIR
CALL CALCNIR(RADABV,FBEAM)
! Calculate FSUN
CALL CALCFSUN(FBEAM,FSUN)
! Calculate thermal radiation
CALL THERMAL(TAIR,VPD,FSUN,RADABV)
! Read in value of CA if present - NB could add daily variation if wished?
IF (METCOLS(MDCA).NE.MISSING) THEN
DO IHR = 1,KHRS
CA(IHR) = DATAIN(METCOLS(MDCA))
END DO
ELSE
DO IHR = 1,KHRS
CA(IHR) = CAK
END DO
END IF
! Read in rainfall data
DO IHR = 1,KHRS
PPT(IHR) = 0.0 ! Initially set all values to zero
END DO
IF (METCOLS(MDPPT).NE.MISSING) THEN
CALL ASSIGNRAIN(DATAIN(METCOLS(MDPPT)),PPT)
END IF
! Three options for soil water content: SMD, SWC, SWP
! For SWP, data is soil water potential (MPa)
! For SMD, data is soil moisture deficit (0-1)
! For SWC, data is soil water content (m3 m-3)
IF (METCOLS(MDSWP).NE.MISSING) THEN
SOILDATA = POTENTIAL
SMD = DATAIN(METCOLS(MDSWP))
! Data given is soil water deficit;
! Changed from Belinda's version: no conversion done here.
ELSE IF (METCOLS(MDSMD).NE.MISSING) THEN
SOILDATA = DEFICIT
SMD = DATAIN(METCOLS(MDSMD))
! IF (SMD.GT.SWMAX) THEN
! CALL SUBERROR('SW CONTENT EXCEEDS MAX',IWARN,IERROR)
! SMD = 0.0
! ELSE IF (SMD.LT.SWMIN) THEN
! CALL SUBERROR('SW CONTENT IS LESS THAN MIN',IWARN,IERROR)
! SMD = 1.0
! ELSE
! SMD = (SWMAX - DATAIN(METCOLS(MDSW)))/(SWMAX - SWMIN)
! END IF
ELSE IF (METCOLS(MDSWC).NE.MISSING) THEN
SOILDATA = CONTENT
SMD = DATAIN(METCOLS(MDSWC))
! Not 'sw', not 'swp', not 'swc'
ELSE
SOILDATA = NONE
SMD = 0.0
END IF
DO IHR = 1,KHRS
SOILMOIST(IHR) = SMD
END DO
RETURN
END SUBROUTINE GETMETDAY
!**********************************************************************
SUBROUTINE GETMETHR(IDATE,ZEN,NOMETCOLS,METCOLS,CAK,PRESSK,SWMIN,SWMAX,DELTAT,ALAT,DEC,DAYL,WINDAH, &
TSOIL,TAIR,RADABV,FBEAM,RH,VPD,VMFD,CA,PRESS,PPT,SOILMOIST,SOILDATA, &
TSOILDATA,ETMEAS,solarRad,iDay)
! Read hourly met data: see function GETMET for parameter definitions
!**********************************************************************
USE maestcom
USE metcom
use switches
IMPLICIT NONE
INTEGER IHR,IOERROR,I,NOMETCOLS
INTEGER METCOLS(MAXMET),SOILDATA, TSOILDATA
INTEGER IDATES(MAXHRS),IDATE
REAL DATAIN(MAXHRS,MAXMET)
REAL WINDAH(MAXHRS),TSOIL(MAXHRS),TAIR(MAXHRS)
REAL RADABV(MAXHRS,3),FBEAM(MAXHRS,3),FSUN(MAXHRS)
REAL solarRad(MAXHRS,3)
INTEGER iDay
REAL RH(MAXHRS),VPD(MAXHRS),VMFD(MAXHRS),TDEW(MAXHRS)
REAL ETMEAS(MAXHRS)
REAL CA(MAXHRS),PRESS(MAXHRS),ZEN(MAXHRS),PPT(MAXHRS)
REAL SOILMOIST(MAXHRS)
REAL DELTAT(12),PRESSK,TMIN,TMAX,DAYPPT,ALAT,DEC,DAYL
REAL PAR,FBM,RADBM,RADDF,CALCFBMH,CAK,SWMIN,SWMAX
REAL, EXTERNAL :: SATUR
!print *, "GETMETHR"
! Read in one day's worth of data at a time.
DO IHR = 1,KHRS
READ (UMET,*,IOSTAT = IOERROR) (DATAIN(IHR,I), I = 1,NOMETCOLS)
IF (IOERROR.NE.0) CALL SUBERROR('ERROR READING MET DATA',IFATAL,IOERROR)
END DO
! Read date array, for checking (RAD).
IF(METCOLS(MHDATE).NE.MISSING) THEN
DO IHR = 1,KHRS
IDATES(IHR) = DATAIN(IHR, METCOLS(MHDATE))
END DO
DO IHR = 2,KHRS
IF(IDATES(IHR).NE.IDATES(IHR-1))THEN
CALL SUBERROR('ERROR: NUMBER OF MET LINES NOT EQUAL',IFATAL,-1)
ENDIF
END DO
ENDIF
! Set up pressure array
IF (METCOLS(MHPRESS).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in atmospheric pressures..."
DO IHR = 1,KHRS
PRESS(IHR) = DATAIN(IHR,METCOLS(MHPRESS))
if (PRESS(IHR).eq.-9999) THEN
if(verbose.ge.2)print *, " Error. A pressure datum is missing. Hour:",iHR-1
if(verbose.ge.2)print *, " Setting pressure to: ", PRESSK
PRESS(ihr)=DEFWIND
else if (PRESS(IHR).LE.0) THEN
if(verbose.ge.2)print *, " Error. A pressure datum is less than 0. Hour:",iHR-1
if(verbose.ge.2)print *, " Setting pressure to: ", PRESSK
PRESS(ihr)=PRESSK
end if
END DO
ELSE
if(verbose.ge.2)print *, " Atmospheric pressure is missing. Setting values to: ", PRESSK
DO IHR = 1,KHRS
PRESS(IHR) = PRESSK
END DO
END IF
! Set up wind speed array
IF (METCOLS(MHWIND).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in wind speeds..."
DO IHR = 1,KHRS
WINDAH(IHR) = DATAIN(IHR,METCOLS(MHWIND))
if (WINDAH(IHR).eq.-9999) THEN
if(verbose.ge.2)print *, " Error. A wind speed datum is missing. Hour:",iHR-1
if(verbose.ge.2)print *, " Setting wind speed to: ", DEFWIND
windah(ihr)=DEFWIND
else if (WINDAH(IHR).LE.0) THEN
if(verbose.ge.2)print *, " Error. A wind speed datum is less than 0. Hour:",iHR-1
if(verbose.ge.2)print *, " Setting wind speed to: ", DEFWIND
windah(ihr)=DEFWIND
end if
end do
else
if(verbose.ge.2)print *, " Setting wind speeds to: ", DEFWIND
DO IHR = 1,KHRS
WINDAH(IHR) = DEFWIND
end do
end if
! Set hourly air temperatures
if(verbose.ge.2)print *, " Determining max and min air temperatures..."
TMIN = DATAIN(1,METCOLS(MHTAIR))
TMAX = DATAIN(1,METCOLS(MHTAIR))
DO IHR = 1,KHRS
TAIR(IHR) = DATAIN(IHR,METCOLS(MHTAIR))
IF (TAIR(IHR).LT.TMIN) TMIN = TAIR(IHR)
IF (TAIR(IHR).GT.TMAX) TMAX = TAIR(IHR)
END DO
! Set hourly soil temperatures
IF (METCOLS(MHTSOIL).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in soil temperatures..."
DO IHR = 1,KHRS
TSOIL(IHR) = DATAIN(IHR,METCOLS(MHTSOIL))
if (tSoil(iHR).eq.-9999) THEN
if(verbose.ge.2)print *, " Error. A soil temperature datum is missing. Hour:",iHR-1
if(verbose.ge.2)print *, " Calculating soil temperature from air temperature"
! Like the CALCTSOIL Routine. Set equal to average daily air temperature.
! Does it for a single timepoint and not a day's worth of data
tSoil(iHr)=sum(tAir)/khrs
!windah(ihr)=DEFWIND
end if
TSOILDATA = 1
END DO
ELSE
if(verbose.ge.2)print *, " Calculating soil temperature from air temperature...."
TSOILDATA = 0
CALL CALCTSOIL(TAIR,TSOIL)
END IF
! Read in RH, VPD, VMFD, Tdew
IF (METCOLS(MHRH).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in relative humidity..."
DO IHR = 1,KHRS
RH(IHR) = DATAIN(IHR,METCOLS(MHRH))
END DO
ELSE IF (METCOLS(MHRHP).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in relative humidity percent..."
DO IHR = 1,KHRS
RH(IHR) = DATAIN(IHR,METCOLS(MHRHP))/100.0
END DO
END IF
IF (METCOLS(MHVPD).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in vapour pressure differential..."
DO IHR = 1,KHRS
VPD(IHR) = DATAIN(IHR,METCOLS(MHVPD))
END DO
END IF
IF (METCOLS(MHTDEW).NE.MISSING) THEN
!Not smart enough to deal with missing or bad values yet
if(verbose.ge.2)print *, " Reading in dew point temperature..."
DO IHR = 1,KHRS
TDEW(IHR) = DATAIN(IHR,METCOLS(MHTDEW))
END DO
else
if(verbose.ge.2)print *, " Calculating dew point temperature from air temp and RH..."
DO IHR = 1,KHRS
!print *, RH(ihr)
!print *, tAir(iHr)
tDew(iHr) = (237.7*(((17.271*tAir(iHr))/(237.7+tAir(iHr)))+(log(RH(iHr)))))/(17.271-(((17.271*tAir(iHr))/(237.7+tAir(iHr)))+(log(RH(iHr)))))
!tDew(iHr) = tAir(iHr) - ((1 - RH(iHr))/5.)
!print *,tDew(iHr)
END DO
END IF
IF (METCOLS(MHMFD).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in vapour pressure mole fraction deficit..."
DO IHR = 1,KHRS
VMFD(IHR) = DATAIN(IHR,METCOLS(MHMFD))
END DO
END IF
IF (METCOLS(MHRH).NE.MISSING) THEN
do iHr = 1, khrs
if ((RH(iHR).eq.-9999).AND.(METCOLS(MHRHP).NE.MISSING)) THEN
if(verbose.ge.2)print *, " ***Error. A relative humidity datum is missing."
IF ((METCOLS(MHVPD).NE.MISSING).AND.(vpd(iHr).NE.-9999)) then
!try to supply value from VPD
if(verbose.ge.2)print *, " ***Using vapour pressure differential to supply relative humidity."
RH(iHr) = 1.0 - VPD(iHr)/SATUR(TAIR(iHr))
elseIF ((METCOLS(MHtDew).NE.MISSING).AND.(tDew(iHr).NE.-9999)) then
!try to supply value from tDew
if(verbose.ge.2)print *, " ***Using dew point temperature to supply relative humidity."
RH(iHr) = SATUR(TDEW(iHr))/SATUR(TAIR(iHr))
elseIF ((METCOLS(MHMFD).NE.MISSING).AND.(VMFD(iHr).NE.-9999)) then
!try to supply value from VMFD
if(verbose.ge.2)print *, " ***Using vapour pressure mole fraction deficit to supply relative humidity."
RH(iHr) = 1 - VMFD(iHr)*PRESS(iHr)*1E-3/SATUR(TAIR(iHr))
else
!use air temp as last resort
if(verbose.ge.2)print *, " ***Using air temp to supply relative humidity"
RH(iHr)=SATUR(tMin)/SATUR(tAir(iHr))
end if
if(verbose.ge.2)print *, " Setting relative humidity to:", RH(iHr)
end if
end do
end if
! Calculate RH column if not in file
IF ((METCOLS(MHRH).EQ.MISSING).AND.(METCOLS(MHRHP).EQ.MISSING)) THEN
if(verbose.ge.2)print *, " Relative humidity values are missing. Hour:",iHR-1
IF (METCOLS(MHVPD).NE.MISSING) THEN
if(verbose.ge.2)print *, " Calculating relative humidity from vapour pressure differential..."
CALL VPDTORH(VPD,TAIR,RH)
ELSEIF (METCOLS(MHTDEW).NE.MISSING) THEN
if(verbose.ge.2)print *, " Calculating relative humidity from dew point temperature..."
CALL TDEWTORH(TDEW,TAIR,RH)
ELSEIF (METCOLS(MHMFD).NE.MISSING) THEN
if(verbose.ge.2)print *, " Calculating relative humidity from vapour pressure mole fraction deficit..."
CALL MFDTORH(VMFD,PRESS,TAIR,RH)
ELSE
if(verbose.ge.2)print *, " Calculating relative humidity from air temp and min air temp..."
CALL CALCRH(TMIN,TAIR,RH)
END IF
END IF
! Calculate VPD column if not in file
IF (METCOLS(MHVPD).EQ.MISSING) THEN
if(verbose.ge.2)print *, " Calculating vapour pressure differential from relative humidity..."
CALL RHTOVPD(RH,TAIR,VPD)
END IF
! Calculate VMFD column if not in file
IF (METCOLS(MHMFD).EQ.MISSING) THEN
if(verbose.ge.2)print *, " Calculating vapour pressure mole fraction deficit from vapour pressure differential..."
CALL VPDTOMFD(VPD,PRESS,VMFD)
END IF
! Read in rainfall if present.
! Don't convert to mmol m-2 as before (RAD)
DAYPPT = 0.0
IF (METCOLS(MHPPT).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in rainfall data..."
DO IHR = 1,KHRS
PPT(IHR) = DATAIN(IHR,METCOLS(MHPPT)) !*1E6/18.
if (PPT(IHR).eq.-9999) THEN
if(verbose.ge.2)print *, " Error. A rainfall datum is missing. Hour:",iHR-1
if(verbose.ge.2)print *, " Setting rainfall to:", 0.0
PPT(IHR)=0.0
else if (PPT(IHR).LE.0) THEN
if(verbose.ge.2)print *, " Error. A rainfall datum is less than 0. Hour:",iHR-1
if(verbose.ge.2)print *, " Setting rainfall to:", 0.0
PPT(IHR)=0.0
end if
DAYPPT = DAYPPT+PPT(IHR)
END DO
ELSE
if(verbose.ge.2)print *, " Setting rainfall data to zero"
DO IHR = 1,KHRS
PPT(IHR) = 0.0
END DO
END IF
! Read in measured ET, if present.
IF(METCOLS(MHET).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in crown evapotranspiration..."
DO IHR = 1,KHRS
ETMEAS(IHR) = DATAIN(IHR,METCOLS(MHET))
END DO
ENDIF
!---STH 2015-0528: Read in the recorded global radiation ( W m-2 )
IF (METCOLS(MHRad).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in incident total short-wave radiation (RAD)..."
DO IHR = 1,KHRS
solarRad(IHR,1) = DATAIN(IHR,METCOLS(MHRad)) !in W m-2
if ((solarRad(IHR,1).eq.-9999).OR.(solarRad(IHR,1).LE.-100)) then
if(verbose.ge.2)print *, " Terminal error. Hour:",iHR-1
end if
END DO
ELSE IF (METCOLS(MHPAR).NE.MISSING) THEN
if(verbose.ge.2)print *, " Calculating incident total short-wave radiation (RAD) using incident photosynthetically active radiation(PAR)..."
DO IHR = 1,KHRS
!Convert PAR umol m-2 s -2 to PAR to W m-2 s-1. Convert W PAR to W RAD
solarRad(IHR,1) = DATAIN(IHR,METCOLS(MHPAR)) / UMOLPERJ / FPAR
if ((solarRad(IHR,1).eq.-9999).OR.(solarRad(IHR,1).LE.-100)) then
if(verbose.ge.2)print *, " Terminal error. Hour:",iHR-1
end if
END DO
END IF
!---STH 2015-0528
! Must have either PAR (umol m-2 s-1) or global radiation (W m-2)
!RADABV(1) is PAR in W/m2
IF (METCOLS(MHPAR).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in incident photosynthetically active radiation(PAR)..."
DO IHR = 1,KHRS
RADABV(IHR,1) = DATAIN(IHR,METCOLS(MHPAR)) / UMOLPERJ !convert umol m-2 s-1 to W m-2
if ((RADABV(IHR,1).eq.-9999).OR.(RADABV(IHR,1).LE.-100)) then
if(verbose.ge.2)print *, " Terminal error. Hour:",iHR-1
end if
END DO
ELSE IF(METCOLS(MHRAD).NE.MISSING) THEN
if(verbose.ge.2)print *, " Calculating incident photosynthetically active radiation(PAR) from incident total short-wave radiation (RAD)..."
DO IHR = 1,KHRS
!RADABV(IHR,1) = DATAIN(IHR,METCOLS(MHRAD)) * FPAR
!Need to convert the RAD W m-2 to PAR W m-2
RADABV(IHR,1) = solarRad(IHR, 1) * FPAR
if ((RADABV(IHR,1).eq.-9999).OR.(RADABV(IHR,1).LE.-100)) then
if(verbose.ge.2)print *, " Terminal error. Hour:",iHR-1
end if
END DO
ELSE
if(verbose.ge.2)print *, " Calculating incident photosynthetically active radiation(PAR) from latitude and day"
!This needs to be modified so it can give individual hourly values. STH 2015-1007
CALL BRISTO(IDATE,TMAX,TMIN,DAYPPT,DELTAT,ALAT,DEC,DAYL,PAR)
CALL CALCFBMD(IDATE,ZEN,PAR,FBM)
RADBM = PAR*FBM
RADDF = PAR*(1.-FBM)
CALL CALCPARHRLY(RADBM,RADDF,ZEN,RADABV,FBEAM)
END IF
! Calculate beam fractions
IF (METCOLS(MHFBEAM).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in fraction of incident PAR which is direct-beam..."
DO IHR = 1,KHRS
FBEAM(IHR,1) = DATAIN(IHR,METCOLS(MHFBEAM))
END DO
ELSE
if(verbose.ge.2)print *, " Calculating fraction of incident PAR which is direct-beam..."
DO IHR = 1,KHRS
FBEAM(IHR,1) = CALCFBMH(IDATE,ZEN(IHR),RADABV(IHR,1))
! 29/3 FBEAM(IHR,1) = CALCFBMH(IDATE,IHR,ALAT,DEC,RADABV(IHR,1))
! FBEAM(IHR,1) = CALCFBMWN(IDATE,IHR,ZEN(IHR),RADABV(IHR,1))
END DO
END IF
if(verbose.ge.2)print *, " Calculating NIR..."
! Calculate NIR
CALL CALCNIR(RADABV,FBEAM)
if(verbose.ge.2)print *, " Calculating FSUN..."
! Calculate FSUN
CALL CALCFSUN(FBEAM,FSUN)
if(verbose.ge.2)print *, " Calculating thermal radiation..."
! Calculate thermal radiation
CALL THERMAL(TAIR,VPD,FSUN,RADABV)
! Read in values of CA if present
IF (METCOLS(MHCA).NE.MISSING) THEN
if(verbose.ge.2)print *, " Reading in atmospheric CO2 concentration..."
DO IHR = 1,KHRS
CA(IHR) = DATAIN(IHR,METCOLS(MHCA))
if (CA(IHR).eq.-9999) THEN
if(verbose.ge.2)print *, " Error. A atmospheric CO2 concentration datum is missing. Hour:",iHR-1
if(verbose.ge.2)print *, " Setting [CO2] to ", CAK
CA(IHR)=CAK
end if
END DO
ELSE
if(verbose.ge.2)print *, " Atmospheric CO2 concentration is missing. Setting values to ", CAK
DO IHR = 1,KHRS
CA(IHR) = CAK
END DO
END IF
! Get soil moisture - either soil water potential or soil moisture deficit
! Initialize
SOILMOIST = 0.0
SOILDATA = NONE
IF (METCOLS(MHSWP).NE.MISSING) THEN
if(verbose.ge.2)print *, " Read in soil water potential..."
SOILDATA = POTENTIAL
DO IHR = 1,KHRS
SOILMOIST(IHR) = DATAIN(IHR,METCOLS(MHSWP))
END DO
ELSE IF (METCOLS(MHSMD).NE.MISSING) THEN
if(verbose.ge.2)print *, " Read in soil water deficit..."
SOILDATA = DEFICIT
DO IHR = 1,KHRS
SOILMOIST(IHR) = DATAIN(IHR,METCOLS(MHSMD))
! No conversion as was done before: assume that data is already deficit.
! SOILMOIST(IHR) = (SWMAX - DATAIN(IHR,METCOLS(MHSW)))
! & /(SWMAX - SWMIN)
END DO
ELSE IF (METCOLS(MHSWC).NE.MISSING) THEN
if(verbose.ge.2)print *, " Read in soil water content..."
SOILDATA = CONTENT
DO IHR = 1,KHRS
SOILMOIST(IHR) = DATAIN(IHR,METCOLS(MHSWC))
END DO
END IF
!print *, solarRad
DO IHR = 1,KHRS
write (umetout,*) int(iDay)+1, int(IHR), WINDAH(IHR), TAIR(IHR), TSOIL(IHR), RH(IHR), VPD(IHR), VMFD(IHR), CA(IHR), RADABV(IHR,1), SOLARRAD(IHR,1), FBEAM(IHR,1), PRESS(IHR), TDEW(IHR), SOILMOIST(ihr), PPT(IHR), tMin, tMax
END DO
RETURN
END SUBROUTINE GETMETHR
!**********************************************************************
SUBROUTINE CALCTHRLY(TMAX,TMIN,DAYL,TAIR)
! Calculate a daily variation in temperature from max & min temperatures.
! Temp varies linearly between sunset & sunrise, and sinusoidally during the day.