-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradn.f90
2876 lines (2460 loc) · 94.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 POINTS( &
! NUMPNT,JLEAF,JSHAPE,SHAPE,RXNTR,RYNTR,RZNTR, &
! ZBCNTR,DXTNTR,DYTNTR,DZTNTR,FOLNTR,PROPC,PROPP, &
! BPT,NOAGEC,NOAGEP,NOLAY, &
! 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
!
! 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)
! INTEGER LGP(MAXP), PPQ
! REAL FOLLAY(MAXLAY)
!
!! Constants for use later in the subroutine
!! Number of grid points within quarter of a layer (PPQ).
! PPLAY = 12 ! Was in MAESTCOM
! PPQ = PPLAY/4
!
!! Relative height of each height interval (HTINT).
! HTINT = 1.0/REAL(NOLAY)
!! Radius of crown at 45 degrees to axis.
! 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/4
!
!! 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)*PPQ + 1 ! grid point number
!! calculate relative height - same for each grid point in the layer
! CZ(IPQ) = (LAYER-0.5)*HTINT ! 3 grid points in each quadrant
! CZ(IPQ+1) = CZ(IPQ)
! CZ(IPQ+2) = CZ(IPQ)
!!!! Could be like; CZ(1:PPQ) = (LAYER-0.5)*HTINT
!
!! 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
! ! Multiply by cos 45°
! CORR = 0.5*SQRT(2.0)*SURFACE(CZ(IPQ),JSHAPE)
! ENDIF
! ! Factors come from assuming volume of each gridpoint is equal
! AX(IPQ) = 0.288675*CORR ! 0.5*sqrt(1/3)
! AX(IPQ+1) = 0.696923*CORR ! sqrt(2/3) - 0.5*(sqrt(2/3) - sqr
! AX(IPQ+2) = 0.908248*CORR !
! !!! Will be something like do i=1,noqp AX(I) = somefun(I) * CORR
!
!! Calculate volume for each grid point.
! HUP= LAYER*HTINT*RZNTR
! HDN= (LAYER-1)*HTINT*RZNTR
!! DH = HUP-HDN // BM 11/99 not used
! VLM = SEGMT(JSHAPE,HUP,HDN,RXNTR,RYNTR,RZNTR)
! VL(IPQ) = VLM/PPLAY
! VL(IPQ+1)= VL(IPQ)
! VL(IPQ+2)= VL(IPQ)
! TMP = 0.
!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
! IF ((MOD(IPQ1,6).LE.3).AND.(MOD(IPQ1,6).NE.0)) THEN ! Odd layer
! 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+DYTntr
! YL(IPQ2)= YL(IPQ1)
! YL(IPQ3)=-AX(IPQ1)*RXY+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
! HORIZ1 = CUMUL(0.000000,0.577350,2,BPT,IAGE)
! HORIZ2 = CUMUL(0.577350,0.816497,2,BPT,IAGE)
! HORIZ3 = CUMUL(0.816497,1.000000,2,BPT,IAGE)
! CORFL = TWOPI*FOLntr/4.0
! ELSE
! HORIZ1 = 1.0
! HORIZ2 = 1.0
! HORIZ3 = 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)
! DLI(IAGE,IPQ) = VERT*HORIZ1/VL(IPQ)*PROPC(IAGE)
! DLI(IAGE,IPQ+1)= VERT*HORIZ2/VL(IPQ+1)*PROPC(IAGE)
! DLI(IAGE,IPQ+2)= VERT*HORIZ3/VL(IPQ+2)*PROPC(IAGE)
!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 gridpoint
!! 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 !Points
!**********************************************************************
SUBROUTINE POINTSNEW2( &
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
REAL RZNTR,DXTNTR,DYTNTR,ZBCNTR,DZTNTR,AVGSD
REAL CORFL,DOWN,UP,VERT
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
! Multiply by cos 45°
CORR = 0.5*SQRT(2.0)*SURFACE(CZ(IPQ),JSHAPE)
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+DYTNTR
YL(IPQ2)= YL(IPQ1)
YL(IPQ3)=-AX(IPQ1)*RXY+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
ARG1 = REAL((I-1)/PPQ)
ARG2 = REAL(I/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 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, 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, really.
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 LAYER = 1, NOLAY ! for each layer
IPQ = (LAYER-1)*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
END DO
! 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
END DO
! 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
END DO
END DO
! (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
ARG1 = REAL((I-1)/PPQ)
ARG2 = REAL(I/PPQ)
! HORIZ(I) = CUMUL(SQRT(ARG1),SQRT(ARG2),2,BPT,IAGE) modification mars 2013
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(REAL(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))
!V1 = PI*RX1*RY1*(HUP-(HUP**2/RZ1)+(HUP**3)/(3*RZ1**2))
! Thats my duplicate line to avoid bizarre bug #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
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 FUNCTION CUMUL !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
REAL, EXTERNAL :: COSDEL
DO IZEN = 1,NZEN
DEXT(IZEN) = 0.0