CDL - EVAL: Difference between revisions

m
 
(16 intermediate revisions by the same user not shown)
== Introduction ==
{|align=right
The EVAL functions gives the possibility to modfy a measurement and plot the result as a separate line. So theoretically one could plot the Dewpoint as a calculated derivative of the Temperature. Also the Growth Degree Days can be simply calculated. The effect of EVAL is that it is not required to transfer data if it can be derived from measurement. Only the measurement needs to be transferred.
|__TOC__
|}
'''The Equations are kind of in continuous BETA, by the nature of all possible combinations and the recursive parsing not all possible equations have been tested (haha)'''
 
The EVAL functions gives the possibility to modfymodify a measurement and plot the result as a separate line. So theoretically one could plot the Dewpoint as a calculated derivative of the Temperature. Also the Growth Degree Days can be simply calculated. The effect of EVAL is that it is not required to transfer data if it can be derived from measurement. Only the measurement needs to be transferred.
To be able to accomplish the calculations, on e needs certain additional functions such as SUM, LN and EXP. The functions which are available to the user are described below. The list will grow as the functions become available.
 
To be able to accomplish the calculations, on eone needs certain additional functions such as SUM, LN and EXP. The functions which are available to the user are described below. The list will grow as the functions become available.
 
== Equation ==
 
Term := '(' Equation ')' | Function '(' Equation ')' | Plotvariable | Number
 
Function := 'SUM' | 'LN' | 'EXP'
 
Number := <Integer>[.[<Integer>]]
 
NOTE: The plotvariable MUST be from the range as defined for the PLOT i.e. ALL | DAILY | RECENT.
 
== Functions ==
The SUM function produces the sum of the Plotvariable from the first of january to the 31 of december after which it resets to zero. So it is a cyclic function!
When applied to the temperature this leads to the Growing Degree Days, when applied to rain it leads to the yearly rainfall until the current day. For other variables it may have meaning or it may have not.
 
At the moment there can be only one sum function per chart.
 
The following example shows the daily average temperature modified to the Growing Degree Days with an offset of 5 °C:
PLOT ALL AverageTemp EVAL [ SUM(AverageTemp-5) ] colour green Axis DegreeDays
EndChart
 
=== LN ===
The LN function provides the [https://en.wikipedia.org/wiki/Natural_logarithm Natural Logarithm] (the logarithm on the basis of the Euler number e).
It is implemented as the JavaScript function ''Math.log''.
 
=== EXP ===
The EXP function provides the power function for the base of the Euler number e.
It is implemented as the JavaScript function ''Math.exp''.
 
== Trouble in Paradise ==
Equations may seem like functions, and there is a resemblance, but they are not. If you are using an equation in another you must be aware that the plotparameters in the first equation remain the same during substitution. I will explain this through an example of the ''Wet Bulb Temperature calculation'' (WBT).
 
The WBT is calculated in CMX as:
<pre>
public static double CalculateWetBulbC(double tempC, double dewPointC, double pressureMb)
{
double svpDP = SaturationVapourPressure1980(dewPointC);
return (((0.00066 * pressureMb) * tempC) + ((4098 * svpDP) / (Sqr(dewPointC + 237.7)) * dewPointC)) / ((0.00066 * pressureMb) + (4098 * svpDP) / (Sqr(dewPointC + 237.7)));
}
 
(Sqr(a) being a*a)
</pre>
To put this in CDL the first attempt was:
<pre>
Psat1980 EVAL [ 6.112 * EXP(17.67*Temperature/(243.5+Temperature)) ]
WetBulbTemp Eval [ (0.00066 * Pressure * Temperature + 4098 * Psat1980 / Pow( (Dewpoint + 237.7), 2) * Dewpoint) /
(0.00066 * Pressure + 4098 * Psat1980 / Pow((Dewpoint + 237.7),2)) ]
</pre>
''Psat1980'' will be substituted into the ''WetBulbTemp'' equation when needed so it will calculate with Temperature but it required to be the ''Dewpoint'' calculation as you can see from ''CMX svpDP'' function. To account for this issue a Psat1980 equation specifically for the dewPoint needs to be created. So, to calculate the WetBulbTemp correctly, we have to do:
 
<pre>
; Specifically for the Wet Bulb Calculation: Psat at Dewpoint
dewpointPsat1980 EVAL [ 6.112 * EXP(17.67*Dewpoint/(243.5+Dewpoint)) ]
WetBulbTemp Eval [ (0.00066 * Pressure * Temperature + 4098 * dewpointPsat1980 / Pow( (Dewpoint + 237.7), 2) * Dewpoint) /
(0.00066 * Pressure + 4098 * dewpointPsat1980 / Pow((Dewpoint + 237.7),2)) ]
</pre>
 
The CUtils compiler then takes the rest and creates the correct javascript function required for Highcharts.
 
This took 5 years before the problem was discovered and when it finally showed it took some considerable time before it was understood. See [https://cumulus.hosiene.co.uk/viewtopic.php?t=24257 this topic on the forum].
 
[[Category:CumulusUtils]]