-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradn.f90
executable file
·2296 lines (1946 loc) · 76.7 KB
/
radn.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
!**********************************************************************
! RADN.FOR
! This file contains all the canopy structure and radiation interception
! routines. The major routines are:
! POINTS - sets up the grid points
! SUN - calculates the daylength
! ZENAZ - calculates zenith and azimuth angles
! SLOPES - calculates corrections for slope of plot (to soil reflectance)
! EXDIFF, EXBEAM - calculate the extinction coefficients for diffuse and
! beam radiation, respectively
! TRANSD, TRANSB - calculate the transmittances of diffuse and beam radiation
! EHC - sets up the equivalent horizontal canopy (used in scattering calculations)
! SCATTER - calculates scattered radiation
! ABSRAD - calculates absorbed radiation
! CATEGO - used to set up PAR histogram
! These subroutines call the following additional routines:
! POINTS
! SEGMT, CUMUL, BETA, SURFACE
! SUN
! ALUNAR, ANOM, ECCENT, EPSIL, OMEGA, DAYJUL
! EXBEAM, EXDIFF
! COSDEL
! TRANSB, TRANSD
! TREDST, DISTIN, DIST, CDIST, WPATH, SHADED, TESTD, POSSIBLE
! EHC
! ASSIGN, CHART, TDUMIN
! SCATTER
! ABSTHERM
!**********************************************************************
!**********************************************************************
SUBROUTINE POINTSNEW( &
NOLAY,PPLAY,JLEAF,JSHAPE,SHAPE,RXNTR,RYNTR,RZNTR, &
ZBCNTR,DXTNTR,DYTNTR,DZTNTR,FOLNTR,PROPC,PROPP, &
BPT,NOAGEC,NOAGEP, &
XL,YL,ZL,VL,DLT,DLI,LGP,FOLLAY &
)
! This subroutine is used to set up to 120 grid points through
! the crown. There are 12 grid points per layer and a minimum of
! 3 layers (36 points) is recommended. It is also recommended that
! the number of grid points used is a multiple of 36.
! The inputs required are:
! NUMPNT: the number of gridpoints
! JLEAF: 0 - no leaf area dist; 1 - vertical only; 2 - horiz. & vert.
! JSHAPE,SHAPE: indicate crown shape
! RX,RY,RZ: radius & green crown length of target crown
! ZBC: height to base of crown in target crown
! DXT,DYT,DZT: x,y,z co-ordinates of target crown
! FOL: leaf area of target crown
! BPT: coefficients of beta distributions of leaf area
! NOAGEC: no of age classes for which beta distributions are specified
! NOAGEP: no of age classes for which physiological params specified
! PROP: proportion of leaf area in each age class
! NOLAY: no of layers of crown
! Routine outputs are:
! XL,YL,ZL: the co-ordinates of each grid point
! VL: the volume of crown associated with each grid point
! DLT, DLI: the amount of leaf area associated with each grid point
! LGP: the physiological layer corresponding to each grid point
! FOLLAY: the amount of foliage in each layer
! CANOPYDIMS: canopy dimensions when these gridpoints were calculated
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER LGP(MAXP),PPLAY, PPQ
INTEGER NUMPNT,NOLAY,NOSPOKES,JSHAPE,MUMPNT,LAYER
INTEGER IPQ,I,IPQ1,IPQ2,IPQ3,IPQ4,JLEAF,IPT,IAGE,NOAGEP
INTEGER NOAGEC,J,IJ,ILAY
REAL BPT(8,MAXC),PROPC(MAXC),PROPP(MAXC)
REAL DLT(MAXP),DLI(MAXC,MAXP)
REAL XL(MAXP),YL(MAXP),ZL(MAXP),VL(MAXP),AX(MAXP/4),CZ(MAXP/4)
REAL FOLLAY(MAXLAY),AXPOINTS(MAXP/4),HORIZ(MAXP/4), ARG1, ARG2
REAL HTINT,RX2,RXNTR,RY2,RYNTR,RXY
REAL CORR,HDN,VLM,HUP,FOLNTR,SHAPE, CORR2
REAL RZNTR,DXTNTR,DYTNTR,ZBCNTR,DZTNTR,AVGSD
REAL CORFL,DOWN,UP,VERT
REAL COSALFA, SENALFA
REAL, EXTERNAL :: SURFACE
REAL, EXTERNAL :: SEGMT
REAL, EXTERNAL :: CUMUL
! Constants for use later in the subroutine
NUMPNT = PPLAY * NOLAY
NOSPOKES = 4 ! will be a parameter, once figured out.
! Number of grid points within quarter of a layer (PPQ).
! was hardwired to 3.
PPQ = PPLAY/NOSPOKES
! Relative height of each height interval (HTINT).
HTINT = 1.0/REAL(NOLAY)
! Radius of crown at 45 degrees to axis.
! Hard to use NOSPOKES here...
RX2 = RXNTR**2
RY2 = RYNTR**2
IF (JSHAPE.EQ.JBOX) THEN
RXY = SQRT(RX2+RY2)
ELSE
RXY = SQRT(2.0*(RX2*RY2)/(RX2+RY2))
ENDIF
! Number of grid points in each quadrant.
MUMPNT = NUMPNT/NOSPOKES
! 1. Calculate co-ordinates (XL,YL,ZL) and volume (VL) for each grid point.
! (a) for one quadrant of the crown, set relative heights (CZ), radial
! distances (AX) and volume (VL) of each grid point.
DO 10 LAYER = 1, NOLAY ! for each layer
IPQ = (LAYER-1)*REAL(PPQ) + 1 ! grid point number
! calculate relative height - same for each grid point in the layer
DO I = 1,PPQ
CZ(IPQ + (I-1)) = (LAYER-0.5)*HTINT
ENDDO
! calculate relative radial distance - differs in odd & even layers
! The function 'surface' finds relative radial distance to crown surface as function of relative height
IF(MOD(LAYER,2).EQ.1) THEN
CORR = SURFACE(CZ(IPQ),JSHAPE)
ELSE
! Modified by A. Morales on March 2012
! Multiply by cos 45 or Rx/Rxy (i.e. cos angle between Rx and Rxy) for boxes
IF(JSHAPE.EQ.JBOX) THEN
CORR = RXNTR/RXY*SURFACE(CZ(IPQ),JSHAPE)
! Modified by A. Morales on March 2012
! Y coordinates != X coordinates in even layers
CORR2 = RYNTR/RXNTR
ELSE
CORR = 0.5*SQRT(2.0)*SURFACE(CZ(IPQ),JSHAPE)
! Modified by A. Morales on March 2012
! Y coordinates = X coordinates in even layers
CORR2 = 1
ENDIF
ENDIF
! Factors come from assuming volume of each gridpoint is equal
CALL AXVOL(PPQ, AXPOINTS)
DO I=1,PPQ
AX(IPQ + (I-1)) = AXPOINTS(I) * CORR
ENDDO
! Calculate volume for each grid point.
HUP = LAYER*HTINT*RZNTR
HDN = (LAYER-1)*HTINT*RZNTR
VLM = SEGMT(JSHAPE,HUP,HDN,RXNTR,RYNTR,RZNTR)
DO I = 1,PPQ
VL(IPQ + (I-1)) = VLM/PPLAY
ENDDO
10 CONTINUE
! (b) Now set x,y,z co-ordinates of each grid point, using AX & CZ from above.
DO 20 IPQ1 = 1,MUMPNT ! loop over gridpoints in 1st quadrant
IPQ2 = IPQ1+MUMPNT ! gridpoints in 2nd quadrant
IPQ3 = IPQ1+MUMPNT*2 ! ditto 3rd quadrant
IPQ4 = IPQ1+MUMPNT*3 ! ditto 4th quadrant
! Odd layers
IF ((MOD(IPQ1,INT(2*PPQ)).LE.PPQ).AND. &
(MOD(IPQ1,INT(2*PPQ)).NE.0)) THEN
XL(IPQ1)= AX(IPQ1)*RXNTR+DXTNTR
XL(IPQ2)= 0.0 +DXTNTR
XL(IPQ3)=-AX(IPQ1)*RXNTR+DXTNTR
XL(IPQ4)= 0.0 +DXTNTR
YL(IPQ1)= 0.0 +DYTNTR
YL(IPQ2)= AX(IPQ1)*RYNTR+DYTNTR
YL(IPQ3)= 0.0 +DYTNTR
YL(IPQ4)=-AX(IPQ1)*RYNTR+DYTNTR
ELSE ! Even layers
XL(IPQ1)= AX(IPQ1)*RXY+DXTNTR
XL(IPQ2)=-AX(IPQ1)*RXY+DXTNTR
XL(IPQ3)= XL(IPQ2)
XL(IPQ4)= XL(IPQ1)
YL(IPQ1)= AX(IPQ1)*RXY*CORR2+DYTNTR
YL(IPQ2)= YL(IPQ1)
YL(IPQ3)=-AX(IPQ1)*RXY*CORR2+DYTNTR
YL(IPQ4)= YL(IPQ3)
ENDIF
ZL(IPQ1)=CZ(IPQ1)*RZNTR+ZBCNTR+DZTNTR
! Height & volume is the same for every grid point in the one layer.
ZL(IPQ2)=ZL(IPQ1)
ZL(IPQ3)=ZL(IPQ1)
ZL(IPQ4)=ZL(IPQ1)
VL(IPQ2)=VL(IPQ1)
VL(IPQ3)=VL(IPQ1)
VL(IPQ4)=VL(IPQ1)
20 CONTINUE
! 2. Calculate the leaf area density associated with each grid point.
! (a) for uniform leaf area density, this is easy.
IF (JLEAF.EQ.0) THEN
AVGSD = FOLNTR/(PI*RXNTR*RYNTR*RZNTR*SHAPE)
DO 30 IPT=1,NUMPNT
DLT(IPT)=AVGSD
DO 30 IAGE=1,NOAGEP
DLI(IAGE,IPT)=DLT(IPT)*PROPP(IAGE)
30 CONTINUE
! (b) less easy when LAD is specified with beta-distributions
ELSE
DO 40 IAGE = 1,NOAGEC ! for each age class
IF (JLEAF.EQ.2) THEN ! calc. horizontal factors
! RAD, FEB '09
DO I = 1,PPQ
HORIZ(I) = CUMUL(SQRT((I-1)/REAL(PPQ)),SQRT(I/REAL(PPQ)), &
2,BPT,IAGE)
ENDDO
CORFL = TWOPI*FOLNTR/4.0
ELSE
HORIZ = 1.0
CORFL = FOLNTR/REAL(PPLAY)
END IF
! set DLI for gridpoints in 1st quadrant
DO 50 LAYER = 1,NOLAY ! for each layer
IPQ = (LAYER-1)*PPQ + 1 ! grid point number - 1st quadrant
DOWN = (LAYER-1)*HTINT ! calc. vertical factors
UP = LAYER*HTINT
VERT = CUMUL(DOWN,UP,1,BPT,IAGE)
! RAD, FEB '09
DO I = 1,PPQ
DLI(IAGE,IPQ + (I-1)) = VERT*HORIZ(I) / &
VL(IPQ)*PROPC(IAGE)
ENDDO
50 CONTINUE
! now set for gridpoints in other quadrants
DO 40 IPQ1 = 1,MUMPNT ! loop over gridpoints in 1st quadrant
IPQ2 = IPQ1+MUMPNT ! gridpoints in 2nd quadrant
IPQ3 = IPQ1+MUMPNT*2 ! ditto 3rd quadrant
IPQ4 = IPQ1+MUMPNT*3 ! ditto 4th quadrant
DLI(IAGE,IPQ2) = DLI(IAGE,IPQ1)
DLI(IAGE,IPQ3) = DLI(IAGE,IPQ1)
DLI(IAGE,IPQ4) = DLI(IAGE,IPQ1)
40 CONTINUE !Finish looping over age classes as well as gridpoints
! Calculate total leaf area density for each grid point
! BM 7/03: Moved this within loop to correct error with JLEAF = 0, NOAGEC > 1, NOAGEP > 1
DO 100 IPT = 1,NUMPNT
DLT(IPT) = 0.0
DO 60 IAGE = 1,NOAGEC
DLT(IPT) = DLT(IPT) + DLI(IAGE,IPT)
60 CONTINUE
DLT(IPT)=DLT(IPT)*CORFL
100 CONTINUE
END IF ! If JLEAF = 0
! Normalize the subvolume and foliage of each grid point.
! BM 11/99 Following is unnecessary.
! TOTVL=0.0
! DO 70 IPT=1,NUMPNT
! TOTVL=VL(IPT)+TOTVL
!70 CONTINUE
! CORVL=PI*RXntr*RYntr*RZntr*SHAPE/TOTVL
! DO 80 IPT=1, NUMPNT
! VL(IPT)=VL(IPT)*CORVL
!80 CONTINUE
! BM 12/99 Calculate CORFL directly - provides check on function
! TOTFL=0.0
! DO 90 IPT=1, NUMPNT
! TOTFL=DLT(IPT)*VL(IPT)+TOTFL
!90 CONTINUE
! IF (TOTFL.EQ.0.0) THEN
! CORFL = 0.0
! ELSE
! CORFL=FOLntr/TOTFL
! END IF
! DO 100 IPT=1,NUMPNT
! DO 100 IAGE = 1,NOAGEC
! DLI(IAGE,IPT)=DLI(IAGE,IPT)*CORFL
!100 CONTINUE
! Re-calculate DLI: it must correspond to NOAGEP
! BM 11/99 Moved this part to after correction for total leaf area
IF (NOAGEP.EQ.1) THEN
DO 65 IPT = 1,NUMPNT
DLI(1,IPT) = DLT(IPT)
65 CONTINUE
ELSE
DO 66 IPT = 1,NUMPNT
DO 66 IAGE = 1,NOAGEP
DLI(IAGE,IPT) = PROPP(IAGE)*DLT(IPT)
66 CONTINUE
END IF
! Set the layer of each grid point (LGP)
DO 110 IPT = 1,MUMPNT
LGP(IPT) = NOLAY - INT(CZ(IPT)*REAL(NOLAY))
IF (LGP(IPT).EQ.0) LGP(IPT)=1
110 CONTINUE
DO 120 J=1,MUMPNT
DO 120 IJ=1,3
IPT=J+IJ*MUMPNT
LGP(IPT)=LGP(J)
120 CONTINUE
! Calculate leaf area in each layer of the tree
DO 130 ILAY = 1,MAXLAY
FOLLAY(ILAY) = 0.0
130 CONTINUE
DO 140 IPT = 1,NUMPNT
FOLLAY(LGP(IPT)) = FOLLAY(LGP(IPT)) + DLT(IPT)*VL(IPT)
140 CONTINUE
RETURN
END !PointsNew
!**********************************************************************
SUBROUTINE AXVOL(PPQ,RMID)
! RAD, Feb. 2009.
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER PPQ,I
REAL R(MAXP/4),RMID(MAXP/4)
! First get radii of intersections between equi-areas:
DO I = 1,PPQ
R(I) = SQRT(I/REAL(PPQ))
ENDDO
! Then place points in the middle of these equi-areas.
RMID(1) = 0.5*R(1)
DO I = 2,PPQ
RMID(I) = R(I) - 0.5*(R(I) - R(I-1))
ENDDO
RETURN
END
!**********************************************************************
REAL FUNCTION SEGMT(JSHAPE,HUP,HDN,RX1,RY1,RZ1)
! This subroutine calculates the volume of a segment of the crown
! between relative crown heights HUP and HDN.
! Inputs: JSHAPE = shape of crown; RX1,RY1,RZ1 = dimensions of crown.
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER JSHAPE
REAL V1,V2,HUP,HDN,RX1,RY1,RZ1
IF (JSHAPE.EQ.JHELIP) THEN
V1 = PI*RX1*RY1* (HUP- (HUP**3)/ (3.0*RZ1*RZ1))
V2 = PI*RX1*RY1* (HDN- (HDN**3)/ (3.0*RZ1*RZ1))
SEGMT = V1 - V2
ELSE IF (JSHAPE.EQ.JFELIP) THEN
V1 = PI*RX1*RY1* (HUP-((HUP-RZ1/2.)**3)/(3.0*(RZ1/2.)**2))
V2 = PI*RX1*RY1* (HDN-((HDN-RZ1/2.)**3)/(3.0*(RZ1/2.)**2))
SEGMT = V1 - V2
ELSE IF (JSHAPE.EQ.JCONE) THEN
V1 = PI*RX1*RY1*(HUP-(HUP**2/RZ1)+(HUP**3)/(3*RZ1**2))
V2 = PI*RX1*RY1*(HDN-(HDN**2/RZ1)+(HDN**3)/(3*RZ1**2))
SEGMT = V1 - V2
ELSE IF (JSHAPE.EQ.JPARA) THEN
V1 = PI*RX1*RY1*(HUP-(HUP**2)/(2*RZ1))
V2 = PI*RX1*RY1*(HDN-(HDN**2)/(2*RZ1))
SEGMT = V1 - V2
ELSE IF (JSHAPE.EQ.JCYL) THEN
SEGMT = PI*RX1*RY1*(HUP-HDN)
ELSE IF (JSHAPE.EQ.JBOX) THEN
SEGMT = 4.*RX1*RY1*(HUP-HDN)
END IF
RETURN
END !Segmt
!**********************************************************************
REAL FUNCTION CUMUL(DOWN,UP,JFUN,BPT,IAGE)
! Use the Gaussian numerical integration method to integrate beta function over gridpoint volume
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER JFUN,IAGE,I
REAL DOWN,UP,B1,B2,B3,B4
REAL GI,GS1,GS2,S11,S12
REAL BPT(8,MAXC)
REAL, EXTERNAL :: BETA
! WRITE (*,*) 'CALLING CUMUL'
IF (JFUN.EQ.1) THEN
B1 = BPT(1,IAGE)
B2 = BPT(2,IAGE)
B3 = BPT(3,IAGE)
B4 = BPT(4,IAGE)
ELSE
B1 = BPT(5,IAGE)
B2 = BPT(6,IAGE) + 1 ! Because of r term in integral
B3 = BPT(7,IAGE)
B4 = BPT(8,IAGE)
END IF
GI = (UP-DOWN)/20.0
GS1 = DOWN + GI*0.42265
GS2 = DOWN + GI*1.5774
CUMUL = 0.0
DO 100 I = 1,10
S11 = BETA(B1,B2,B3,B4,GS1)
S12 = BETA(B1,B2,B3,B4,GS2)
CUMUL = CUMUL + S11 + S12
GS1 = GS1 + 2.0*GI
GS2 = GS2 + 2.0*GI
100 CONTINUE
CUMUL = CUMUL*GI
RETURN
END !Cumul
!**********************************************************************
REAL FUNCTION SURFACE(H,JSHAPE)
! Find the relative radial distance to the surface of the tree crown
! as a function of relative tree height.
! H is the relative height in the crown.
! JSHAPE is the crown shape.
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER JSHAPE
REAL H
IF (JSHAPE.EQ.JCONE) THEN
SURFACE = (1.- H)
ELSE IF (JSHAPE.EQ.JHELIP) THEN
SURFACE = SQRT(1. - H**2)
ELSE IF (JSHAPE.EQ.JPARA) THEN
SURFACE = SQRT(1. - H)
ELSE IF (JSHAPE.EQ.JFELIP) THEN
SURFACE = SQRT(1. - ((H-1./2.)**2)/((1./2.)**2))
ELSE IF (JSHAPE.EQ.JCYL) THEN
SURFACE = 1.
ELSE IF (JSHAPE.EQ.JBOX) THEN
SURFACE = 1.
END IF
RETURN
END !Surface
!**********************************************************************
SUBROUTINE EXDIFF(NALPHA,ALPHA,FALPHA,NZEN,DIFZEN,RANDOM,DEXT)
! calculate the extinction coefficients for the diffuse radiation
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER IZEN, NZEN, NALPHA, IALP
REAL DIFZEN(MAXANG),ALPHA(MAXANG),FALPHA(MAXANG),DEXT(MAXANG)
REAL RANDOM,ASUM,RSUM
REAL, EXTERNAL :: COSDEL
DO 10 IZEN = 1,NZEN
DEXT(IZEN) = 0.0
RSUM = 0.0
DO 5 IALP = 1,NALPHA
RSUM = RSUM + COSDEL(RANDOM,DIFZEN(IZEN),ALPHA(IALP))*FALPHA(IALP)
5 CONTINUE
DEXT(IZEN) = RSUM
10 CONTINUE
RETURN !Exdiff
END
!**********************************************************************
REAL FUNCTION COSDEL(RANDOM,THETA,ALPHA)
! FUNCTION TO calculate COSINE DELTA WHERE THETA IS SOLAR ZENITH
! ANGLE AND ALPHA IS INCLINATION ANGLE OF DLEAF.
!**********************************************************************
USE maestcom
IMPLICIT NONE
REAL RANDOM,THETA,ALPHA,BP0
IF ((THETA+ALPHA-PID2).LE.0.00000) THEN
COSDEL = COS(ALPHA)*COS(THETA)
ELSE
BP0 = ACOS(1./ (TAN(ALPHA)*TAN(THETA)))
COSDEL = ((PID2-BP0)*COS(ALPHA)*COS(THETA) + &
SIN(ALPHA)*SIN(THETA)*SIN(BP0))/PID2
END IF
COSDEL = COSDEL*RANDOM
RETURN
END !COSDEL
!**********************************************************************
SUBROUTINE TRANSD( &
IDAY,IOTUTD,NEWCANOPY,IPROG,NT,XSLOPE,YSLOPE, &
NZEN,DIFZEN,NAZ,NUMPNT,DEXTT,DIFSKY, &
XL,YL,ZL,RX,RY,RZ,DXT,DYT,DZT, &
XMAX,YMAX,SHADEHT, &
FOLT,ZBC,JLEAFT,BPTT,NOAGECT,PROPCT,JSHAPET,SHAPET, &
NEWTUTD,TU,TD,RELDF,DEXT & ! dext now output.
)
! This subroutine calculates the diffuse transmittances, if required.
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER IRAD,I,NT,NZEN,NEWTUTD,IOTUTD,IDAY
INTEGER J,NUMPNT,NEWCANOPY, FLOAT,K
INTEGER JSHAPET(MAXT),JLEAFT(MAXT),NOAGECT(MAXT)
INTEGER NAZ,IPT,IPROG,IFLAG
REAL DXT(MAXT),DYT(MAXT),DZT(MAXT),RX(MAXT),RY(MAXT), &
RZ(MAXT),ZBC(MAXT),FOLT(MAXT)
REAL PROPCT(MAXC,MAXT)
REAL DIFZEN(MAXANG),DEXT(MAXANG),DEXTT(MAXT,MAXANG)
REAL XL(MAXP),YL(MAXP),ZL(MAXP)
REAL TU(MAXP),TD(MAXP),RELDF(MAXP)
REAL SHAPET(MAXT),EXTC(MAXT),BPTT(8,MAXC,MAXT)
REAL DA,WNS,WDS,WNS1,WDS1,WNG,WDG,DZUP,DZDN,SINUP
REAL COSUP,SINDN,COSDN,ADDUP,ADDDN,DAZ,SLOPE,XSLOPE,YSLOPE
REAL XMAX,YMAX,SHADEHT,SU,SU1,SL,SL1,TMPVAR,DIFSKY,PTHUP
LOGICAL SHADEDYN
LOGICAL, EXTERNAL :: SHADED
! Flag passed to TREDST, for debugging (IRAD=0 for diffuse, 1 for beam).
IRAD = 0
! Set default DEXT (output!) to average across trees (for each angle band),
! otherwise SCATTER and ABSRAD crash. This (naive) average will not actually
! affect results, because if pathlength>0, it is recalculated.
DO I = 1,NZEN
DEXT(I) = SUM(DEXTT(1:NT,I)) / REAL(NT)
ENDDO
! If IOTUTD = 0, then the diffuse transmittances are read in from file.
! This only needs to be done on the first day of the simulation.
! After reading in the transmittances, the subroutine ends.
NEWTUTD = 0
IF (IOTUTD.EQ.0) THEN
IF (IDAY.EQ.0) THEN
REWIND (UTUTD)
READ (UTUTD,*) (J,TU(I),TD(I),RELDF(I),I =1,NUMPNT)
NEWTUTD = 1
END IF
RETURN
! The transmittances are only calculated every IOTUTD'th day.
! If the canopy has changed significantly they will also need recalculation.
! Check to see whether this needs to be done, otherwise return.
ELSE IF ((MOD(IDAY,IOTUTD).NE.0).AND.(NEWCANOPY.NE.1))THEN
RETURN
END IF
! Calculate transmittances (this is the old function TRANSD).
NEWTUTD = 1
DA = TWOPI/FLOAT(NAZ)
!$OMP PARALLEL DEFAULT(SHARED), PRIVATE(IPT)
!$OMP DO
DO 900 IPT = 1,NUMPNT
WNS = 0.
WDS = 0.
WNS1= 0.
WDS1= 0.
WNG = 0.
WDG = 0.
DO 500 J = 1,NZEN
DZUP = DIFZEN(J)
DZDN = PI - DZUP
SINUP = SIN(DZUP)
COSUP = COS(DZUP)
SINDN = SIN(DZDN)
COSDN = COS(DZDN)
ADDUP = 0.00
ADDDN = 0.00
DO 400 K = 1,NAZ
DAZ = DA * (K-0.5)
SLOPE = ATAN(COS(DAZ)*TAN(XSLOPE)+SIN(DAZ)*TAN(YSLOPE))
IF ((PID2-DZUP).LT.SLOPE) GO TO 300
SHADEDYN = SHADED(XL(IPT),YL(IPT),ZL(IPT),DZUP,DAZ,XMAX,YMAX,SHADEHT)
IF (SHADEDYN) GO TO 300
IFLAG = 1
CALL TREDST(IFLAG,IPROG,ipt,DZUP,DAZ, &
XL(IPT),YL(IPT),ZL(IPT),RX,RY,RZ,DXT,DYT,DZT, &
FOLT,ZBC,JLEAFT,BPTT,NOAGECT,PROPCT,JSHAPET,SHAPET, &
DEXTT(1:MAXT,J),NT,SU,SU1,DEXT(J))!! DEXT is output!!
ADDUP = ADDUP + EXP(-DEXT(J)*(SU+SU1))
300 IFLAG = 2
CALL TREDST(IFLAG,IPROG,ipt,DZDN,DAZ, &
XL(IPT),YL(IPT),ZL(IPT),RX,RY,RZ,DXT,DYT,DZT, &
FOLT,ZBC,JLEAFT,BPTT,NOAGECT,PROPCT,JSHAPET,SHAPET, &
DEXTT(1:MAXT,J),NT,SL,SL1,DEXT(J)) !! DEXT is output!!
ADDDN = ADDDN + EXP(-DEXT(J)*(SL+SL1))
400 CONTINUE
! TMPVAR=(1.0+DIFSKY*COSUP)/(1.0+2.0*DIFSKY/PI)
TMPVAR=(1.0+DIFSKY*COSUP)/(1.0+DIFSKY)
PTHUP = ADDUP*SINUP*TMPVAR/FLOAT(NAZ)
WNS = WNS + COSUP*PTHUP
WNS1 = WNS1 + DEXT(J)*PTHUP
WDS = WDS + SINUP*COSUP*TMPVAR
WNG = WNG + ADDDN*SINDN*COSDN/FLOAT(NAZ)
WDG = WDG + SINDN*COSDN
500 CONTINUE
! DIFFUSE TRANSMITTANCES FOR UPPER AND LOWER HEMISPHERES
TD(IPT) = WNS/WDS
TU(IPT) = WNG/WDG
RELDF(IPT)= WNS1/WDS
900 CONTINUE
!$OMP END DO
!$OMP END PARALLEL
RETURN
END !Transd
!**********************************************************************
SUBROUTINE TREDST(IFLAG,IPROG,IPT,DZ,DAZ, &
XPT,YPT,ZPT,RX,RY,RZ,DXT,DYT,DZT, &
FOLT,ZBC,JLEAFT,BPTT,NOAGECT,PROPCT,JSHAPET,SHAPET, &
EXTC,NT,S,S1,EFFK)
! This subroutine is used to calculate the weighted pathlength,
! which is also kernel function of radiation penetration.
!
! EXTC is an array with tree extinction coefficients. (new, Feb. 2009).
! DEXT is now output; it is the extinction coefficient weighted by
! pathlengths. This is the effective K for the whole path.
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER JSHAPET(MAXT),JLEAFT(MAXT),NOAGECT(MAXT)
INTEGER M,NT,IPROG,IRAD,IFLAG,IPT
REAL DXT(MAXT),DYT(MAXT),DZT(MAXT),OLDEFFK
REAL RX(MAXT),RY(MAXT),RZ(MAXT),ZBC(MAXT),FOLT(MAXT)
REAL BPT(8,MAXC),PROPCT(MAXC,MAXT)
REAL SHAPET(MAXT),EXTC(MAXT),BPTT(8,MAXC,MAXT)
REAL TANAZ,SINAZ,S,S1,SW,S1W,DAZ
REAL PATH, XTPOS, YTPOS, XPT,YPT,DZ,ZPT,X1,Y1,Z1
REAL X2,Y2,Z2,AVGDL,SS,SSW,EFFK
LOGICAL, EXTERNAL :: POSSIBLE
TANAZ = TAN(DAZ)
SINAZ = SIN(DAZ)
! Remember old value of 'EFFK' (effective extinction coefficient). This is the average across trees,
! when TREDST is called from TRANSD (as it exclusively is).
OLDEFFK = EFFK
! Zero the pathlengths.
! S1 is distance in target tree, S is distance in other trees.
! Note: in normal program, gridpoints are all in target tree. In
! test program, gridpoints may be outside. Flag IPROG indicates this.
S = 0.0
S1 = 0.0
SW = 0.0
S1W = 0.0
! Loop over each tree to see if it affects the ray passing through the point.
DO 200 M = 1,NT
! choose the largest of the x and y radii for use in a quick test to
! see if the tree could possibly be in the way.
PATH = 0.00
XTPOS = DXT(M) - XPT
YTPOS = DYT(M) - YPT
IF ((M.EQ.1).AND.(IPROG.NE.ITEST)) THEN
CALL DISTIN(IRAD,JSHAPET(M),IFLAG,DZ,DAZ,XPT,YPT,ZPT, &
RX(M),RY(M),RZ(M),ZBC(M),DXT(M),DYT(M),DZT(M), &
PATH,X1,Y1,Z1,X2,Y2,Z2)
ELSE IF (POSSIBLE(XTPOS,YTPOS,RX(M),RY(M),SINAZ,TANAZ,DAZ)) THEN
CALL DIST(JSHAPET(M),IFLAG,DZ,DAZ,XPT,YPT,ZPT, &
RX(M),RY(M),RZ(M),ZBC(M),DXT(M),DYT(M),DZT(M), &
PATH,X1,Y1,Z1,X2,Y2,Z2)
END IF
IF (PATH.EQ.0.00) GO TO 200
IF (JLEAFT(M).EQ.0) THEN
AVGDL = FOLT(M)/ (RX(M)*RY(M)*RZ(M)*SHAPET(M)*PI)
SS = PATH*AVGDL
! Path length multiplied by K for current tree.
SSW = SS*EXTC(M)
ELSE
CALL WPATH(ipt,JSHAPET(M),SHAPET(M),JLEAFT(M), &
BPTT(1:8,1:MAXC,M), &
NOAGECT(M),PROPCT(1:MAXC,M),X1,Y1,Z1,X2,Y2,Z2,PATH, &
RX(M),RY(M),RZ(M),ZBC(M),DXT(M),DYT(M),DZT(M),FOLT(M),SS)
! Path length multiplied by K for current tree.
SSW = SS*EXTC(M)
END IF
IF ((M.GT.1).OR.(IPROG.EQ.ITEST)) THEN
S = S + SS
SW = SW + SSW
ELSE
S1 = S1 + SS
S1W = S1W + SSW
END IF
200 CONTINUE
! Calculate weighted effective extinction coefficient.
IF((S+S1).GT.0.0)THEN
EFFK = (S1W + SW) / (S + S1)
ELSE
EFFK = OLDEFFK ! A value here is important if IPROG = ITEST (otherwise EHC will crash!).
ENDIF
RETURN
END !Tredst
!**********************************************************************
SUBROUTINE WPATH(ipt,JSHAPE,SHAPE,JLEAF,BPT,NOAGEC,PROP, &
X1,Y1,Z1,X2,Y2,Z2, &
PATH,RXQ,RYQ,RZQ,ZBCQ,DXTQ,DYTQ,DZTQ,FOLTQ,SS)
! This subroutine weighs the pathlength: SS is the weighted path.
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER JSHAPE,JLEAF,NOAGEC,I,J,IPT
REAL BPT(8,MAXC),PROP(MAXC)
REAL SHAPE,X1,Y1,Z1,X2,Y2,Z2
REAL PATH,RXQ,RYQ,RZQ,ZBCQ,DXTQ,DYTQ,DZTQ,FOLTQ,SS
REAL ZZ,RCH,TRD,BETA1,DFT,XX,YY,TEMPRD
REAL RR,ANG,TRDE,BETA2
REAL, EXTERNAL :: SURFACE
REAL, EXTERNAL :: BETA
SS = 0.000
! Sample path at 20 points
DO 100 I = 1,20
! Calculate co-ordinates of the 20 sample points
ZZ = Z1 + (I-0.5)* (Z2-Z1)/20.0000 - ZBCQ - DZTQ ! Height of sample point
RCH = ZZ/RZQ ! relative height of sample point
IF ((RCH.LT.1.01) .AND. (RCH.GT.1.0)) RCH = 1.00 ! numerical tidying
TRD = SURFACE(RCH,JSHAPE)*SQRT(RXQ*RYQ) ! TRD is mean distance to crown surface
! Find beta in vertical direction
BETA1 = 0.0
DO 10 J = 1,NOAGEC ! normalized leaf area density
BETA1 = BETA1 + &
BETA(BPT(1,J),BPT(2,J),BPT(3,J),BPT(4,J),RCH) * PROP(J)
10 CONTINUE
!tester = BETA(BPT(1,1),BPT(2,1),BPT(3,1),BPT(4,1),RCH)
DFT = BETA1*FOLTQ/(TRD*TRD*RZQ)
IF (JLEAF.EQ.1) THEN
DFT = DFT/PI
! Find beta in horizontal direction
ELSE IF (JLEAF.EQ.2) THEN
XX = X1 + (I-0.5)* (X2-X1)/20.000 - DXTQ
YY = Y1 + (I-0.5)* (Y2-Y1)/20.000 - DYTQ
TEMPRD = SQRT((XX)**2+ (YY)**2)
IF (RXQ.EQ.RYQ) THEN
RR = TEMPRD/TRD
ELSE
IF (XX.EQ.0.0.AND.YY.GE.0.0) THEN
ANG = PID2
ELSE IF (XX.EQ.0.0.AND.YY.LT.0.0) THEN
ANG = -PID2
ELSE
ANG=ATAN(YY/XX)
END IF
TRDE = SURFACE(RCH,JSHAPE)* &
SQRT((RXQ*COS(ANG))**2+(RYQ*SIN(ANG))**2)
RR = TEMPRD/TRDE
END IF
IF (RR.GT.1.00 .AND. (RR.LE.1.10)) RR = 1.00
BETA2 = 0.0
DO 20 J = 1,NOAGEC
BETA2 = BETA2 + &
BETA(BPT(5,J),BPT(6,J),BPT(7,J),BPT(8,J),RR)*PROP(J)
20 CONTINUE
DFT = DFT*BETA2
ENDIF
SS = SS + DFT*PATH/20.00
100 CONTINUE
RETURN
END !Wpath
!**********************************************************************
SUBROUTINE DIST(JSHAPE,IFLAG,DZZ,DAZ, &
XPP,YPP,ZPP,RXQ,RYQ,RZQ,ZBCQ,DXTQ,DYTQ,DZTQ, &
PATH,X1,Y1,Z1,X2,Y2,Z2)
! this subroutine is used to calculate the pathlength inside all
! trees around the tree we do all these calculations for
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER JSHAPE,IFLAG,ISITU
REAL DZZ,DAZ,XPP,YPP,ZPP,RXQ,RYQ,RZQ,ZBCQ,DXTQ,DYTQ,DZTQ
REAL PATH,X1,Y1,Z1,X2,Y2,Z2,POL,POM,PON,XX,YY,ZZ
REAL DISTRADIAL,DELTA,R1,R2,X3,Y3,Z3,TEMP
! The default path length is zero.
PATH = 0.00
! Calculate multipliers for converting from polar to rectangular co-ords.
POL = SIN(DZZ)*COS(DAZ)
POM = SIN(DZZ)*SIN(DAZ)
PON = COS(DZZ)
! Check the path does not lie completely above or below the tree of interest.
IF (IFLAG.EQ.2 .AND. ZPP.LE. (ZBCQ+DZTQ)) GO TO 100
IF (IFLAG.NE.2 .AND. ZPP.GT. (ZBCQ+RZQ+DZTQ)) GO TO 100
! Find co-ords of the point of intersection between the ray and the bottom
! plane of the tree crown.
XX = XPP + POL* (ZBCQ+DZTQ-ZPP)/PON
YY = YPP + POM* (ZBCQ+DZTQ-ZPP)/PON
ZZ = ZBCQ + DZTQ
! Two situations:
! 1. The point on the bottom plane lies within the tree crown
! 2. The point on the bottom plane lies outwith the tree crown
! For full ellipsoid, case 2. always holds.
ISITU = 2
IF (JSHAPE.NE.JFELIP) THEN
DISTRADIAL = ((XX-DXTQ)/RXQ)**2 + ((YY-DYTQ)/RYQ)**2
IF (DISTRADIAL.LT.1.00001) ISITU = 1
END IF
! Find co-efficients of quadratic for distance between points on crown
! surface and grid point, then solve quadratic.
call CDIST(JSHAPE,XPP,YPP,ZPP,RXQ,RYQ,RZQ,ZBCQ, &
DXTQ,DYTQ,DZTQ,POL,POM,PON,DELTA,R1,R2)
IF (DELTA.LE.0.00) GO TO 100 ! No intersection of path with crown
! Handle situation where point on bottom plane (XX,YY,ZZ) is within crown
! Points of interest are (XX,YY,ZZ) and one of two other points.
! BM Mar07 If the shape is a cylinder, you want the upper point of intersection
! Otherwise, you want the point that is neither above nor below the tree crown.
IF (ISITU.EQ.1) THEN
X1 = XX
Y1 = YY
Z1 = ZZ
X2 = XPP + POL*R1
Y2 = YPP + POM*R1
Z2 = ZPP + PON*R1
X3 = XPP + POL*R2
Y3 = YPP + POM*R2
Z3 = ZPP + PON*R2
IF (JSHAPE.EQ.JCYL) THEN
IF (Z2.LT.Z1) THEN
X2 = X3
Y2 = Y3
Z2 = Z3
END IF
ELSE IF (Z2.GT. (Z1+RZQ) .OR. (Z2.LT.Z1)) THEN
X2 = X3
Y2 = Y3
Z2 = Z3
END IF
! Handle situation where point on bottom plane (XX,YY,ZZ) is without crown
! Two points of interest given by solns to quadratic.
ELSE
X1 = XPP + POL*R1
Y1 = YPP + POM*R1
Z1 = ZPP + PON*R1
X2 = XPP + POL*R2
Y2 = YPP + POM*R2
Z2 = ZPP + PON*R2
END IF
! Swap point1(x1,y1,z1) with point2(x2,y2,z2) if necessary to ensure
! that point2 is always above the point1
IF (Z1.GT.Z2) THEN
TEMP = Z2
Z2 = Z1
Z1 = TEMP
TEMP = Y2
Y2 = Y1
Y1 = TEMP
TEMP = X2
X2 = X1
X1 = TEMP
END IF
! If the grid point is between the two intersection points, two possibilities:
! 1. The crowns overlap, in which case take the grid point as one point
! 2. The path is completely outwith the crown, in which case pathlength = 0
IF ((Z1.LT.ZPP).AND.(ZPP.LT.Z2)) THEN
IF ((Z1.LT.ZZ).AND.(Z2.GT.ZZ+RZQ)) GOTO 100 !Case 2
IF (IFLAG.NE.2) THEN
X1 = XPP
Y1 = YPP
Z1 = ZPP
ELSE
Z2 = ZPP
Y2 = YPP
X2 = XPP
END IF
END IF
! Check the path is not completely below the grid point
IF (IFLAG.EQ.2 .AND. (Z1.GE.ZPP)) GOTO 100
IF (IFLAG.NE.2 .AND. (Z2.LE.ZPP)) GOTO 100
! Check the points of intersection are not completely above
! or below the tree crown
IF ((Z2-0.0001).LE.ZZ .OR. (Z1+0.0001).GE.(RZQ+ZZ)) GOTO 100
! BM ADDED 27/3/07
! If the upper point is above the top of the crown, take the
! point of intersection with the top plane as the upper point.
! This can only happen if you're using the cylinder shape.
IF (Z2.GT. (ZBCQ+DZTQ+RZQ).AND.JSHAPE.EQ.JCYL) THEN
Z2 = ZBCQ + DZTQ + RZQ
Y2 = YPP + POM* (ZBCQ+DZTQ+RZQ-ZPP)/PON
X2 = XPP + POL* (ZBCQ+DZTQ+RZQ-ZPP)/PON
END IF
! CONE Bug. Intersection can be with top cone (the inverted cone),
! that is also specified by the quadratic surface. July 13 2009 (RAD).
IF (Z2.GT. (ZBCQ+DZTQ+RZQ).AND.JSHAPE.EQ.JCONE)THEN
DELTA = 0.0
GOTO 100
ENDIF
! Calculate path length!
PATH = SQRT((X1-X2)**2+ (Y1-Y2)**2+ (Z1-Z2)**2)
100 RETURN
END !Dist
!**********************************************************************
SUBROUTINE DISTIN(IRAD,JSHAPE,IFLAG,DZZ,DAZ,XPP,YPP,ZPP, &
RXQ,RYQ,RZQ,ZBCQ,DXTQ,DYTQ,DZTQ, &
PATH,X1,Y1,Z1,X2,Y2,Z2)
! this subroutine is used to calculate the pathlength inside the
! the crown of the tree we are concerned with.
!**********************************************************************
USE maestcom
IMPLICIT NONE
INTEGER IRAD,JSHAPE,IFLAG
REAL DZZ,DAZ,XPP,YPP,ZPP
REAL RXQ,RYQ,RZQ,ZBCQ,DXTQ,DYTQ,DZTQ
REAL PATH,X1,Y1,Z1,X2,Y2,Z2,POL,POM,PON,DELTA
REAL R1,R2,TEMP
! The default path length is zero.
PATH = 0.00
! Calculate multipliers for converting from polar to rectangular co-ords.
POL = SIN(DZZ)*COS(DAZ)
POM = SIN(DZZ)*SIN(DAZ)