-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPlot.h
More file actions
460 lines (391 loc) · 14.1 KB
/
Plot.h
File metadata and controls
460 lines (391 loc) · 14.1 KB
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
//---------------------------------------------------------------------------
#ifndef PlotH
#define PlotH
#include "WorkerBase.h"
#include <math.h>
/**
* PLOT CLASS
* This class represents the underlying plot. It controls for torus topology
* and manages the grid coordinates. It also contains geographic and climate
* information about the plot, for those behaviors that require it.
*
* There are some changes in the coordinate structure. The origin is in the
* southwest corner of the plot (unwrapped). The Y axis is NS and values
* increase to the north. The X axis is EW and values increase to the east.
* There are no negative values. The azimuth is north zero, east positive.
*
* The truly underlying grid cell structure is no longer in the hands of the
* users. The base coordinates will be structured as 8 X 8 grid cells, which
* is what the trees will be organized into.
*
* This class inherits from clWorkerBase to take advantage of the XML parsing
* functions in that class.
*
* Copyright Charles D. Canham.
* @author Lora E. Murphy
*
* <br>Edit history:
* <br>-----------------
* <br>October 20, 2011 - Wiped the slate clean for SORTIE 7.0 (LEM)
* <br>June 27, 2013 - Added N deposition value (LEM)
* <br>October 31, 2013 - Added water deficit and seasonal precipitation
* <br>August 5, 2023 - Added long-term means (LEM)
*/
class clPlot : virtual public clWorkerBase {
public:
/**
* Destructor.
*/
~clPlot();
/**
* Constructor.
* @param p_oSimManager Sim Manager object.
*/
clPlot(clSimManager *p_oSimManager);
//clPlot(const clPlot &oldPlot); //copy constructor
/**
* Gets the latitude.
* @return Latitude, in decimal degrees.
*/
double GetLatitude() {return m_fLatitude;};
/**
* Gets the plot X length.
* @return Length of plot in X direction in meters.
*/
double GetXPlotLength() {return m_fPlotLenX;};
/**
* Gets the plot Y length.
* @return Length of plot in Y direction in meters.
*/
double GetYPlotLength() {return m_fPlotLenY;};
/**
* Gets the length of cells in the X direction.
* @return Length of cells in the X direction, in m.
*/
float GetXCellLength() {return m_iCellSize;};
/**
* Gets the length of cells in the Y direction.
* @return Length of cells in the Y direction, in m.
*/
float GetYCellLength() {return m_iCellSize;};
/**
* Gets the plot area.
* @return Plot area, in hectares.
*/
float GetPlotArea() {return m_fPlotArea;};
/**
* Gets the mean annual precipitation.
* @return Mean annual precipitation, in mm.
*/
double GetMeanAnnualPrecip() {return m_fMeanAnnualPrecipMm;};
/**
* Sets the mean annual precipitation.
* @param fMeanAnnualPrecip Mean annual precipitation, in mm.
*/
void SetMeanAnnualPrecip(double fMeanAnnualPrecip)
{m_fMeanAnnualPrecipMm = fMeanAnnualPrecip;};
/**
* Gets the long-term mean annual precipitation.
* @return Long-term mean annual precipitation, in mm.
*/
double GetLTMAnnualPrecip() {return m_fLTMPrecipMm;};
/**
* Sets the long-term mean annual precipitation.
* @param fLTMPrecip Long-term mean annual precipitation, in mm.
*/
void SetLTMAnnualPrecip(double fLTMPrecip)
{m_fLTMPrecipMm = fLTMPrecip;};
/**
* Gets the mean annual temperature.
* @return Mean annual precipitation, in degrees C.
*/
double GetMeanAnnualTemp() {return m_fMeanTempC;};
/**
* Sets the mean annual temperature.
* @param fMeanTemp Mean annual precipitation, in degrees C.
*/
void SetMeanAnnualTemp(double fMeanTemp)
{m_fMeanTempC = fMeanTemp;};
/**
* Gets the long-term mean annual temperature.
* @return Long-term mean annual precipitation, in degrees C.
*/
double GetLTMAnnualTemp() {return m_fLTMTempC;};
/**
* Sets the long-term mean annual temperature.
* @param fLTMTemp Mean annual precipitation, in degrees C.
*/
void SetLTMAnnualTemp(double fLTMTemp)
{m_fLTMTempC = fLTMTemp;};
/**
* Gets the annual seasonal precipitation.
* @return The annual seasonal precipitation.
*/
double GetSeasonalPrecipitation() {
return m_fSeasonalPrecipitation;
}
/**
* Sets the annual seasonal precipitation.
* @param fSeasonalPrecipitation The annual seasonal precipitation.
*/
void SetSeasonalPrecipitation(double fSeasonalPrecipitation) {
m_fSeasonalPrecipitation = fSeasonalPrecipitation;
}
/**
* Gets the long-term mean seasonal precipitation.
* @return The long-term mean seasonal precipitation.
*/
double GetLTMSeasonalPrecipitation() {
return m_fLTMSeasonalPrecipitation;
}
/**
* Sets the long-term mean seasonal precipitation.
* @param fLTMSeasonalPrecipitation Long-term mean seasonal precipitation.
*/
void SetLTMSeasonalPrecipitation(double fLTMSeasonalPrecipitation) {
m_fLTMSeasonalPrecipitation = fLTMSeasonalPrecipitation;
}
/**
* Gets the annual water deficit.
* @return The annual water deficit.
*/
double GetWaterDeficit() {
return m_fWaterDeficit;
}
/**
* Sets the annual water deficit.
* @param fWaterDeficit The annual water deficit.
*/
void SetWaterDeficit(double fWaterDeficit) {
m_fWaterDeficit = fWaterDeficit;
}
/**
* Gets the long-term mean annual water deficit.
* @return The long-term mean annual water deficit.
*/
double GetLTMWaterDeficit() {
return m_fLTMWaterDeficit;
}
/**
* Sets the long-term mean annual water deficit.
* @param fLTMWaterDeficit The long-term mean annual water deficit.
*/
void SetLTMWaterDeficit(double fLTMWaterDeficit) {
m_fLTMWaterDeficit = fLTMWaterDeficit;
}
/**
* Gets the annual N deposition.
* @return Annual N deposition.
*/
double GetNDeposition() {return m_fNDep;};
/**
* Sets the annual N deposition.
* @param fNDep Annual N deposition.
*/
void SetNDeposition(double fNDep)
{m_fNDep = fNDep;};
/**
* Gets the plot title.
* @return Plot title.
*/
std::string GetPlotTitle() {return m_sPlotTitle;};
/**
* Gets number of X grid cells.
* @return Number of grid cells in the X direction.
*/
int GetNumXGrids() {return m_iNumXGrids;};
/**
* Gets number of Y grid cells.
* @return Number of grid cells in the Y direction.
*/
int GetNumYGrids() {return m_iNumYGrids;};
/**
* Gets the area of a grid cell.
* @return The area of a grid cell in square meters.
*/
float GetGridCellArea() {return m_iCellSize * m_iCellSize;};
/**
* Gets the length of a grid cell side (cells are square).
* @return Grid cell side length, in meters.
*/
int GetGridCellSize() {return m_iCellSize;};
/**
* Translates an X coordinate to a position guaranteed to be valid.
* If the number passed is already within the plot, it is left alone. If the
* number is outside of the plot, it is "wrapped" by adding or subtracting the
* appropriate plot length until it is inside the plot. Because of the torus
* shape of the plot, a number corrected in this way will have the same
* geometric relationships as the original number. This function is
* recursive - it will call itself until the number is correct. The edge of
* the plot is actually considered to be m_fMaxX; this catches numbers so close
* to the edge of the plot that they are likely to be rounded up and then be
* out of the plot.
*
* @param fX Coordinate to correct.
* @return Corrected version of the coordinate.
*/
float CorrectX(float fX);
/**
* Translates a Y coordinate to a position guaranteed to be valid.
* If the number passed is already within the plot, it is left alone. If the
* number is outside of the plot, it is "wrapped" by adding or subtracting the
* appropriate plot length until it is inside the plot. Because of the torus
* shape of the plot, a number corrected in this way will have the same
* geometric relationships as the original number. This function is
* recursive - it will call itself until the number is correct. The edge of
* the plot is actually considered to be m_fMaxY; this catches numbers so close
* to the edge of the plot that they are likely to be rounded up and then be
* out of the plot.
*
* @param fY Coordinate to correct.
* @return Corrected version of the coordinate.
*/
float CorrectY(float fY);
/**
* Calculates the effective distance between two points, correcting for the
* torus. Note that because of the torus, there are always two possible
* distances to any two points. This will return the shorter.
*
* @param fFromX X coordinate of the "from" point.
* @param fFromY Y coordinate of the "from" point.
* @param fToX X coordinate of the "to" point.
* @param fToY Y coordinate of the "to" point.
* @return Distance between the two points in meters.
* @throw BAD_DATA error if either of the points is not in the plot.
*/
float GetDistance(float fFromX, float fFromY, float fToX, float fToY);
/**
* Calculates the azimuth angle between two points on the plot.
* @param fFromX X coordinate of the "from" point.
* @param fFromY Y coordinate of the "from" point.
* @param fToX X coordinate of the "to" point.
* @param fToY Y coordinate of the "to" point.
* @return Azimuth, in RADIANS, north = 0.
*/
float GetAzimuthAngle(float fFromX, float fFromY, float fToX, float fToY);
/**
* Speedy way to do an azimuth calculation.
* @param fFromX X coordinate of the "from" point.
* @param fFromY Y coordinate of the "from" point.
* @param fToX X coordinate of the "to" point.
* @param fToY Y coordinate of the "to" point.
* @return Azimuth in number of DEGREES (whole number).
*/
int GetFastAzimuthAngle(float fFromX, float fFromY, float fToX, float fToY);
/**
* Gets the X coordinate of a point defined in polar coordinates relative to
* another point, uncorrected for torus topology. If you want a torus-corrected
* point, use CorrectX() on the result of this function.
* @param fFromX X coordinate of point that the desired point is defined
* relative to.
* @param fAzimuth Azimuth angle from fFromX to the unknown point, in radians,
* north 0.
* @param fDistance Distance from fFromX to the unknown point, in meters.
* @return The uncorrected X value of the point (meaning that it could be
* negative or greater than the plot length).
* @throws modelErr if the distance is negative, the azimuth is negative, or the
* azimuth is greater than 2PI.
*/
float GetUncorrectedX(float fFromX, float fAzimuth, float fDistance);
/**
* Gets the Y coordinate of a point defined in polar coordinates relative to
* another point, uncorrected for torus topology. If you want a torus-corrected
* point, use CorrectY() on the result of this function.
* @param fFromY Y coordinate of point that the desired point is defined
* relative to.
* @param fAzimuth Azimuth angle from fFromX to the unknown point, in radians,
* north 0.
* @param fDistance Distance from fFromX to the unknown point, in meters.
* @return The uncorrected Y value of the point (meaning that it could be
* negative or greater than the plot length).
* @throws modelErr if the distance is negative, the azimuth is negative, or the
* azimuth is greater than 2PI.
*/
float GetUncorrectedY(float fFromY, float fAzimuth, float fDistance);
/**
* Gets the distance between two points in the X plane, corrected for torus
* wrapping. If the "to" point is lower than the "from", the answer will be
* negative.
*
* @param fFromX X coordinate of the "from" point.
* @param fToX X coordinate of the "to" point.
* @return X distance in meters.
*/
inline float GetXDistance(float fFromX, float fToX) {
float fTemp2, fTemp1 = fToX - fFromX;
if (fTemp1 < 0) fTemp2 = (fToX + m_fPlotLenX) - fFromX;
else fTemp2 = fToX - (fFromX + m_fPlotLenX);
if (fabs(fTemp1) < fabs(fTemp2)) return fTemp1;
else return fTemp2;
};
/**
* Gets the distance between two points in the Y plane, corrected for torus
* wrapping. If the "to" point is lower than the "from", the answer will be
* negative.
*
* @param fFromY Y coordinate of the "from" point.
* @param fToY Y coordinate of the "to" point.
* @return Y distance in meters.
*/
inline float GetYDistance(float fFromY, float fToY) {
float fTemp2, fTemp1 = fToY - fFromY;
if (fTemp1 < 0) fTemp2 = (fToY + m_fPlotLenY) - fFromY;
else fTemp2 = fToY - (fFromY + m_fPlotLenY);
if (fabs(fTemp1) < fabs(fTemp2)) return fTemp1;
else return fTemp2;
}
protected:
/**
* Reads data from the parameter file.
* @param p_oDoc DOM tree of parsed input file.
*/
void GetData(xercesc::DOMDocument *p_oDoc);
/**
* Declares and populates the tangents of the azimuth angles.
*/
void PopulateAziTans();
/**Name for this plot. Optional.*/
std::string m_sPlotTitle;
/**Number of grid divisions along the X axis.*/
int m_iNumXGrids;
/**Number of grid divisions along the Y axis.*/
int m_iNumYGrids;
/**Length of one side of a grid cell, in meters. Cells are square. Make this
* always a power of 2! The const means the compiler can optimize divisions
* and multiplications into bit shifts.*/
int m_iCellSize;
/**Plot area, in hectares.*/
float m_fPlotArea;
/**Plot length along the X axis, in m.*/
double m_fPlotLenX;
/**Plot length along the Y axis, in m.*/
double m_fPlotLenY;
/**Max allowed X value - m_fPlotLenX minus a small value.*/
float m_fMaxX;
/**Max allowed Y value - m_fPlotLenY minus a small value.*/
float m_fMaxY;
/**Plot latitude, in decimal degrees - from the par file.*/
double m_fLatitude;
/**Mean annual precipitation, mm.*/
double m_fMeanAnnualPrecipMm;
/**Long-term mean annual precipitation, mm*/
double m_fLTMPrecipMm;
/**Water deficit*/
double m_fWaterDeficit;
/**Long-term mean water deficit, mm*/
double m_fLTMWaterDeficit;
/** Seasonal precipitation */
double m_fSeasonalPrecipitation;
/**Long-term mean seasonal precip, mm*/
double m_fLTMSeasonalPrecipitation;
/**Mean annual temperature, degrees Celsius.*/
double m_fMeanTempC;
/**Long-term mean annual temperature, C*/
double m_fLTMTempC;
/**Annual N deposition.*/
double m_fNDep;
/**Tangent of each azimuth angle. Array size is 360 (degrees).*/
float *mp_fAziTans;
} ;
//---------------------------------------------------------------------------
#endif