-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-scale3.c
478 lines (319 loc) · 10.9 KB
/
4-scale3.c
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
/*************************************************************************/
/* 4-scale (version 3.3 for 5-Scale 5.2) void FOUR_SCALE() */
/*************************************************************************/
/* Jing M. Chen, @CCRS [email protected] */
/* Sylvain G. Leblanc @CCRS [email protected] */
/* (C) 2000 Canada Centre for Remote Sensing */
/* 588 Booth Street, 4th Floor, Ottawa, Ontario, Canada, K1A 0Y7 */
/*************************************************************************/
/*********************** usual C librairies ******************************/
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include <string.h>
/*********************** 4-Scale header file *****************************/
# include "data.h"
void FOUR_SCALE( in_p, out_p)
struct PARAMETER in_p;
struct RESULT *out_p;
{
/* Standard C function declaration */
double exp();
double pow();
double log();
double cos();
double sqrt();
double asin();
/* declaration of functions used by FOUR_SCALE() */
double XI(); /* phase or scattering angle */
void DISTANCE();
void FO();
void LS();
void MULTIPLE_SCATTERING();
void OVERLAP();
void P_GAP_AX_B();
void P_GAP_BRANCH();
void PTG_SUB();
void PQ_SUB();
void PS();
void POISSON(); /* random (Poisson) distribution */
void Q();
void NADIR();
void NEYMAN(); /* clumped distribution using Neyman */
void CONE_TA();
void CONE_TI();
void CONE_GS();
void SPHEROID_TA();
void SPHEROID_TI();
void SPHEROID_SVG();
void TREE_SIZE();
/********************* variables declaration *************************/
/********************* integer *************************/
int k=0; /* index of arrays */
int distribution =2; /* 1 = Poisson , 2 = neyman */
int Gchoice=1; /* 1--> G()=a+c(), 2-> branches */
int shape=1; /* 1--> cone+Cylinder 2--> spheroid */
/********************* double ************************/
double temp_Pig=0;
double temp_Px[NN];
double num=0,dem=0;
double Intensity=0;
double TT1=0,TT2=0,TT3=0,TT4=0;
out_p->OmegaE_stand = in_p.OMEGA_E;
/********* calculating the height of the cone part for conifers ******/
if(tan(in_p.ALPHA)!=0)out_p->Hc=in_p.R/tan(in_p.ALPHA);
else out_p->Hc =0;
if (!strcmp(in_p.SHAPE,"SPHEROID"))
{
out_p->Hc =0; /* no cone for the spheroid */
shape=2;
}
else shape=1;
if (!strcmp(in_p.GE_CHOICE,"BRANCH")) Gchoice=2;
else Gchoice=1;
/**** Neyman grouping m2=0 forces a Poisson distribution ****/
if(in_p.m2==0) distribution =1; /* Poisson tree distribution */
if(in_p.m2 >0) distribution =2; /* Neyman tree distribution */
/********* call to subroutine of trees distribution *************/
out_p->Error[4]=0; /* error initialisation, NT/95 only */
out_p->Error[1]=0; /* error initialisation, NT/95 only */
/* should change the next lines so that out_p.Error[] can be use with
Command line version (UNIX/DOS) */
if(PI*in_p.R*in_p.R*in_p.D > in_p.B)
{
if(in_p.Fr >0.5 && out_p->DIST==1)
{
printf("\n Maybe you should reduce the repulsion factor \n");
printf("\n because the total surface of the crowns is larger than the domain surface");
out_p->Error[4]=1;
}
/* Need to introduce something
to take care automatically of
this repulsion problem
(done in Windows 95/NT version) */
}
/* calculation of scattering angle */
out_p->xi = XI(in_p.SZA,out_p->vza,out_p->phi);
/********************************************************************/
/********* call to subroutines for shaded and sunlit areas **********/
/********************************************************************/
switch (shape)
{
case 1: CONE_TA(in_p,out_p);
CONE_GS(in_p,out_p,"VZA");
if(out_p->SZA_TMP!=in_p.SZA || (out_p->DIST==1))
{
CONE_GS(in_p,out_p,"LAI");
CONE_GS(in_p,out_p,"SZA");
}
break;
case 2: SPHEROID_TA(in_p,out_p);
SPHEROID_SVG(in_p,out_p,"VZA");
out_p->Vgc=0;
if(out_p->SZA_TMP!=in_p.SZA || (out_p->DIST==1))
{
SPHEROID_SVG(in_p,out_p,"LAI");
SPHEROID_SVG(in_p,out_p,"SZA");
out_p->tic=0;
out_p->Sgc=0;
}
out_p->tac=0.;
break;
default: printf("\n error, bad tree shape requested");
exit(1);
}
if (out_p->xi <= 0.000001 && out_p->xi >=0.0)
{
out_p->tic = out_p->tac;
out_p->tib = out_p->tab;
}
else
{
switch (shape)
{
case 1: CONE_TI(in_p,out_p);
break;
case 2: SPHEROID_TI(in_p,out_p);
break;
default: printf("\n error, bad tree shape requested");
exit(1);
}
}
out_p->Sv = out_p->V/(out_p->Vg_0*cos(out_p->vza));
out_p->Ss = out_p->V/(out_p->Sg_0*cos(in_p.SZA));
/****************************************************************/
/* out_p->DIST=1; <--USE ONLY INSIDE A LOOP THAT CHANGES */
/* EITHER THE TREE DENSITY,QUADRAT SIZE, OR NEYMAN GROUPING */
/* For Plane plots, the program only compute Px once */
/****************************************************************/
if(out_p->DIST==1)
{
for (k=0;k<NN;k++) out_p->Px[k] =0.;
switch(distribution)
{
case 1: POISSON(in_p,out_p);
break;
case 2: NEYMAN(in_p,out_p);
break;
default: printf("\n error, bad tree distribution requested");
exit(1);
}
}
TREE_SIZE(in_p,out_p,"VZA") ;
if(out_p->Pvg< 0) out_p->Pvg =0;
switch (Gchoice)
{
case 1: P_GAP_AX_B(in_p,out_p,"VZA");
out_p->PSG0_VIEW = 1- out_p->Vg*in_p.D/in_p.B*(1-out_p->PgapV);
if(out_p->SZA_TMP!=in_p.SZA)
{
P_GAP_AX_B(in_p,out_p,"LAI");
P_GAP_AX_B(in_p,out_p,"SZA");
TREE_SIZE(in_p,out_p,"SZA") ;
out_p->PSG0_SUN = 1- out_p->Sg*in_p.D/in_p.B*(1-out_p->PgapS);
P_GAP_AX_B(in_p,out_p,"0");
}
break;
case 2:
P_GAP_BRANCH(in_p,out_p,"VZA");
out_p->PSG0_VIEW = 1- out_p->Vg*in_p.D/in_p.B*(1-out_p->PgapV);
if(out_p->SZA_TMP!=in_p.SZA)
{
P_GAP_BRANCH(in_p,out_p,"LAI");
P_GAP_BRANCH(in_p,out_p,"SZA");
TREE_SIZE(in_p,out_p,"SZA") ;
out_p->PSG0_SUN = 1- out_p->Sg*in_p.D/in_p.B*(1-out_p->PgapS);
P_GAP_AX_B(in_p,out_p,"0");
}
break;
}
out_p->PSG_HOT0= 1- PI*in_p.R*in_p.R*in_p.D/in_p.B*(1-out_p->Pgap0);
if (out_p->PSG0_SUN <0)
{
/* when this condition is met, it means that the projection*number of trees is larger than the domain */
out_p->PSG0_SUN =0;
}
if (out_p->PSG0_VIEW <0)
{
/* when this condition is met, it means that the projection*number of trees is larger than the domain */
out_p->PSG0_VIEW =0;
}
if (out_p->SZA_TMP != in_p.SZA || (out_p->DIST==1) )
{
for (k=0;k<NN;k++)
{
temp_Px[k] = out_p->Px[k] ;
out_p->Px[k] =0;
}
POISSON(in_p,out_p); /* call POISSON for computation of Omega_T ... */
temp_Pig = out_p->Pig;
out_p->Pig=0;
OVERLAP(in_p,out_p,"SZA"); /* Pig (Poisson) Eq. 43 [1] */
out_p->Pig_poisson = out_p->Pig;
if(out_p->Pig_poisson >1 || out_p->Pig_poisson<0) out_p->Pig_poisson=0;
out_p->Pig = temp_Pig;
for (k=0;k<NN;k++)
{
out_p->Px[k] =temp_Px[k] ;
}
}
/***************************** Pig ********************************/
/********* probability of having an illuminated bacground ***********/
/********************************************************************/
if (out_p->SZA_TMP != in_p.SZA || (out_p->DIST==1))
{
OVERLAP(in_p,out_p,"LAI");
out_p->Pig=0;
OVERLAP(in_p,out_p,"SZA");
OVERLAP(in_p,out_p,"NADIR");
FO(in_p,out_p,"SZA");
/*****************************************************************/
/******************* Calculation of OmegaT *********************/
/*****************************************************************/
out_p->OmegaT = log(out_p->Pig)/log(out_p->Pig_poisson);
}
/******************************* Pvg ***************************/
/************** probability of viewing the background ************/
/*****************************************************************/
out_p->Pvg=0;
OVERLAP(in_p,out_p,"VZA");
out_p->Error[13] =0;
FO(in_p,out_p,"VZA");
if(out_p->Pvg < 0 )
{
out_p->Pvg =0;
out_p->Error[13] =1;
}
if(out_p->DIST==1)
{
DISTANCE(in_p,out_p);
}
PS(in_p,out_p); /* computes PS and parameters for PG */
/************************* overlapping subroutine *******************/
PQ_SUB(in_p,out_p,shape);
out_p->Error[17] =0;
if(out_p->Pti>1)
{
out_p->Pti=1;
out_p->Error[17] =1;
}
else if(out_p->Pti<0)
{
out_p->Pti=0;
out_p->Error[17] =1;
}
/**********************************************************************/
/* calculation of PG --- Prob seen sunlit background */
/**********************************************************************/
if(out_p->DIST==1)NADIR(in_p,out_p);
PTG_SUB(in_p,out_p,"NADIR",120000,0.10);
PTG_SUB(in_p,out_p,"GROUND",20000,0.01) ;
/**************************************************************************/
/* calculation of PT --- Prob seen sunlit foliage */
/**************************************************************************/
num = log(out_p->Pvg_mean);
dem = log(exp(-0.5*in_p.LAI/(0.537+0.025*in_p.LAI))); /* based on Chen et al, 1999 */
out_p->OmegaTotal= num/dem;
LS(in_p,out_p,shape);
Q(in_p,out_p,in_p.Cp,shape);
/****************************** PT *********************************/
out_p->PT_Cold = out_p->QQ1*out_p->Pti +(1-out_p->Pti)*out_p->QQ2 ;
PTG_SUB(in_p,out_p,"CANOPY",40000,0.001) ;
/***************** reflectance computation ****************************/
out_p->Error[2] =0;
out_p->ZG = out_p->Pvg - out_p->PG;
if(out_p->PT<0)
{
out_p->PT =0;
}
if (out_p->ZG <0)
{
out_p->ZG =0;
out_p->PG = out_p->Pvg;
if (out_p->xi > 0.0001) /* it doesn't matter if this is not calculated properly at the hotspot */
{
/* printf("\n BRDF may not be calculated correctly");
printf("(PG at vza = %5.1f deg.)\n",out_p->vza*180./PI);*/
out_p->Error[2] =1;
}
}
out_p->ZT = (1-out_p->Pvg) - out_p->PT;
out_p->Error[3] =0;
if (out_p->ZT <0)
{
out_p->ZT =0;
out_p->PT = 1-out_p->Pvg;
if(out_p->xi >0.0001)
{
/*printf("\n BRDF may not be calculated correctly");
printf("(PT at vza =%5.1f deg.)\n",out_p->vza*180./PI);*/
out_p->Error[3] =1;
}
}
/******************** MULTIPLE SCATTERING ****************/
MULTIPLE_SCATTERING(in_p,out_p);
out_p->SZA_TMP = -10000;
out_p->DIST=0;
/* out_p->DIST=0; means that if DIST is not changed elsewhere, the tree distribution */
/* and other parameters won't be re-calculated for the next data point */
}