CDL - EVAL: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
m
It is implemented as the JavaScript function ''Math.exp''.
 
== ExampleTrouble &in pitfallsParadise ==
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 but it required to be the ''Dewpoint'' 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)) ]
 
; WetbulbTemperature in degr Celsius then becomes
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.
 
[[Category:CumulusUtils]]

Navigation menu