APPENDIX A: THE CODE 


The code is ANSI-C compatible, so it should be possible to use it on any plate form.
 

NOTE: Only the code to the command line version of 5-Scale is available, not the MS Visual C++ code for the Windows interface.
 

All subroutines/functions created for this program are in CAPITAL letters in the code. The code for these functions can be found in the file with the same name as the function, (i.e., SUBROUTINE() would be in subroutine.c) the only exceptions are the main function FOUR_SCALE that is found in 4-scaleX.c, GetParameters in parameters.c, Q1 for the multiple scattering scheme is found in q1_ms.c, and Initialise in Initialise.c

X = Version of the 4-Scale part of 5-Scale. Latest version: X =  3
 


Code files:
5-scale.c
Main file that calls the models (both LIBERTY and 4-SCALE)
This is the file you will modify for your needs.

4-scaleX.c-> FOUR_SCALE()
This is the main model files, called from 5-scale.c in the UNIX/DOS version or from the main document in the Windows  version.
The latest version is 4-scale3.c which is called from 5-scale.c

cone_gs.c --> void CONE_GS()
cone_ta.c --> void CONE_TA()
cone_ti.c  --> void CONE_TI()
Subroutines for the geometry computations associated with the cone-cylinder crown shape.
cone_gs.c computes Sg (shadow projection on the ground Eq. 10 [1]) or Vg ("view ground area blocked") projection on the ground Eq. 11 [1]).
cone_ta.c and cone_ti.c computes the crowns surface (imaginary surface) seen by the viewer and the proportion illuminated (Pti Eq. 15 [1]). 

equation1.c --> double EQUATION1()
This is a part of a solution for an integral used in the model (mostly in cone_ti.c see appendix A of [1]

fo.c --> void FO()
This function simulates the natural repulsion effect between trees. At nadir, the overlapping of tree crown should be very small. (Was Eq. 31 [2], has now been changed

Initialise.c --> void Initialise()
This subroutine initialise the input parameters 

ls.c --> void LS()
Prepares the parameters needed for Q1tot and Q2tot : LAI accumulated horizontaly in one crown (LH), Cs and Cv.

liberty.c--> void LIBERTY()
contains T. Dawson's code for the forward mode of LIBERTY.

multiple_scattering.c --> void MULTIPLE_SCATTERING()
Contains multiple scattering scheme and most of the hyperspectral part of the model. (4-Scale 3.0 and higher and 5-Scale)

nadir.c --> void NADIR() 
Function that takes into account the non randomness of shadow distribution on the background

neyman.c --> void NEYMAN()
This subroutine computes the Neyman distribution probability up to imax (imax = 350 in this version) trees in a quadrat. (Eq. 3 [1]

overlap.c -->double OVERLAP()
This subroutine computes the gap fraction of the canopy (equ. 20 in the paper.) This form of the equation assumes that you can have overlapping of trees at nadir, because of the repulsion effect due to the fight for sunlight, the overlapping is often absent at nadir, it is now compensated by FO (in fo.c)

This is explained in  Leblanc et al. 1999 [2]


parameters.c   -> GetParameters(struct PARAMETER *local_in_p)
Subroutine that reads the input parameter file. 

p_gap_ax_b.c --> double P_GAP_AX_B() (Eq. 22 [1])
p_gap_branch.c --> double P_GAP_BRANCH() (Eq. 17 [2])
Subroutines for computing the gap in one tree.
p_gap_ax_b.c with G(q) = A*q + C
p_gap_branch.c with branch architecture.
alphaB =0 means horizontal branches
alphaL =0 means horizontal leaves (or shoots)
Ll is the branch leaf area index (often around unity) 

poisson.c --> void POISSON() (Eq. 1 [1])
Computes the Poisson distribution probability 

pq_sub.c --> void PQ_SUB()
Sunlit crown height dependency subroutine for conifers

ptg_sub.c--> void PTG_SUB()


Computes the probability of seeing the sunlit ground PG (Eq. 49 in [1]) or sunlit tree crown PT (Eq. 69 in [1])

This subroutine contains the hotspot kernel calculation. 


ps.c --> void PS()
Computes parameters needed in the ground hotspot (Ft (Eq 51 [1]) lambda_m, Wt, etc.) 

q.c --> void Q()
Subroutine for computing the proportion of tree crown illuminated on the sunlit side (Qtot1 was Eq. 58 in [1], now uses same reasoning as Qtot2) and on the shaded side (Qtot2 Eq. 62 in [1]

q1_ms.c --> double Q1()
Used for calculating an equivalent of Q1, but for the view factors in the multiple scattering scheme. (version 3.1 and higher)


spheroid_ta.c --> void SPHEROID_TA() ____\ Eq. 22 [2]
spheroid_ti.c --> void SPHEROID_TI()           /
spheroid_svg.c">spheroid_vg.c --> void SPHEROID_SVG() (Eq. 19 [2])
Subroutines for the geometry computations associated with the spheroid form. spheroid_ta.c and spheroid_ti.c compute the proportion of the outline crown sunlit. spheroid_vg.c computes the projection of the crown on the ground (shadow (Sg) or "view shadow" (Vg)) 

tree_size.c ---> TREE_SIZE()
This function diminishes the crown when more trees than the average can be found in a quadrat so that clusters of trees will have smaller trees. This is based on similar arguments as eq. (21) in [1]

triangle.c ---> TRIANGLE()
Used in cone_ti.c for the sunlit proportion of the cone(see appendix of Chen and Leblanc, 1997 [1]); it computes the area of any triangles. 

xi.c -->double XI(sza,vza,phi)
Returns the angular difference between the sun and the viewer.

Include files:
data.h
Contains the structures used in the model and the default reflectivities and transmittance.

liberty.h
Contains the default setting of LIBERTY (Jack Pine Needles)