Page 1 of 2
PressTrendVal and PHP question
Posted: Sat 01 Feb 2014 5:17 pm
by RayProudfoot
In recent times there have been huge pressure changes in the UK but although my Cumulus pages showed "Falling Very Rapidly" on several occasions my PHP banner never did. It just showed "Falling Rapidly".
Here is the code that was in place...
$weather_trend = ret_value("presstrend") * 3;
if ($weather_trend >= 6.0)
$pressure_trend_text = "Rising Rapidly";
elseif ($weather_trend > 3.5)
$pressure_trend_text = "Rising Quickly";
elseif ($weather_trend > 1.5)
$pressure_trend_text = "Rising";
else if ($weather_trend > 0.1)
$pressure_trend_text = "Rising Slowly";
elseif ($weather_trend > -0.1)
$pressure_trend_text = "Steady";
elseif ($weather_trend > -1.5)
$pressure_trend_text = "Falling Slowly";
elseif ($weather_trend > -3.5)
$pressure_trend_text = "Falling";
elseif ($weather_trend > -6.0)
$pressure_trend_text = "Falling Quickly";
else
$pressure_trend_text = "Falling Rapidly";
As you can see it's incorrect when pressure is falling at a great rate.
So this afternoon I changed it to what follows and although I think it will resolve the "Falling Very Rapidly" problem I'm not sure about the logic for Steady which is why I've put it in the Else part but I'm uncomfortable doing that as it doesn't look right.
$weather_trend = ret_value("presstrend") * 3;
if ($weather_trend >= 6.0)
$pressure_trend_text = "Rising Very Rapidly";
elseif ($weather_trend > 3.5)
$pressure_trend_text = "Rising Quickly";
elseif ($weather_trend > 1.5)
$pressure_trend_text = "Rising";
else if ($weather_trend > 0.1)
$pressure_trend_text = "Rising Slowly";
elseif ($weather_trend > -0.1)
$pressure_trend_text = "Falling Slowly";
elseif ($weather_trend > -1.5)
$pressure_trend_text = "Falling";
elseif ($weather_trend > -3.5)
$pressure_trend_text = "Falling Quickly";
elseif ($weather_trend > -6.0)
$pressure_trend_text = "Falling Very Rapidly";
else
$pressure_trend_text="Steady";
I did try adding an AND condition but the PHP webpage just went blank so I guessed it couldn't resolve the argument...
else if ($weather_trend > -0.1) AND ($weather_trend < 0.1)
$pressure_trend_text ="Steady"
Appreciate any help to correct the syntax and logic.
Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 10:26 pm
by RayProudfoot
I appear to have resolved the problem by changing the code as follows:-
$weather_trend = ret_value("presstrend") * 3;
if ($weather_trend >= 6.0)
$pressure_trend_text = "Rising Very Rapidly";
elseif ($weather_trend > 3.5)
$pressure_trend_text = "Rising Quickly";
elseif ($weather_trend > 1.5)
$pressure_trend_text = "Rising";
else if ($weather_trend > 0.1)
$pressure_trend_text = "Rising Slowly";
elseif ($weather_trend >= -0.1 && $weather_trend <= 0.1)
$pressure_trend_text="Steady";
elseif ($weather_trend < -0.1)
$pressure_trend_text = "Falling Slowly";
elseif ($weather_trend < -1.5)
$pressure_trend_text = "Falling";
elseif ($weather_trend < -3.5)
$pressure_trend_text = "Falling Quickly";
elseif ($weather_trend < -6.0)
$pressure_trend_text = "Falling Very Rapidly";
Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 10:49 pm
by mcrossley
No that will not work for negative trends.
Try it with -8.0 say - you will get "Falling Slowly"
All your comparisons must be > (or >=), so if you want 'Steady' to be +0.1 to -0.1 then...
$weather_trend = ret_value("presstrend") * 3;
if ($weather_trend >= 6.0)
$pressure_trend_text = "Rising Very Rapidly";
elseif ($weather_trend > 3.5)
$pressure_trend_text = "Rising Quickly";
elseif ($weather_trend > 1.5)
$pressure_trend_text = "Rising";
elseif ($weather_trend > 0.1)
$pressure_trend_text = "Rising Slowly";
elseif ($weather_trend >= -0.1)
$pressure_trend_text="Steady";
elseif ($weather_trend > -1.5)
$pressure_trend_text = "Falling Slowly";
elseif ($weather_trend > -3.5)
$pressure_trend_text = "Falling";
elseif ($weather_trend > -6.0)
$pressure_trend_text = "Falling Quickly";
else
$pressure_trend_text = "Falling Very Rapidly";
Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 10:50 pm
by steve
I don't think that's right, Ray. If the value is -7, say, then elseif ($weather_trend < -0.1) will be true and it will return "Falling slowly".
Edit: OK, Mark, you win this time

Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 10:53 pm
by mcrossley
Odd, the forum has always warned me in the past about posts before mine - we must have synchronised 'submit' buttons tonight!
Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 11:00 pm
by steve
Often it does, but sometimes if they are very close it seems not to. Sometimes I have completely missed the fact that someone has posted again, possibly with further information to a question, just before my reply.
Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 11:16 pm
by RayProudfoot
Thanks Mark and Steve. I follow your logic with the -8 example but I'm still struggling to understand negative comparisons must be> or >= rather than < or <=.
I will of course change it as you have suggested Mark. Oh to be able to step through the code with VB. PHP is not very user-friendly.

Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 11:30 pm
by RayProudfoot
Mark,
Looking at your provided code why is there a Rising Very Rapidly but no Falling Very Rapidly?
Re: PressTrendVal and PHP question
Posted: Mon 03 Feb 2014 11:48 pm
by BCJKiwi
Ray,
did you try;
else if ($weather_trend > -0.1 && $weather_trend < 0.1)
Re: PressTrendVal and PHP question
Posted: Tue 04 Feb 2014 7:40 am
by mcrossley
RayProudfoot wrote:Mark,
Looking at your provided code why is there a Rising Very Rapidly but no Falling Very Rapidly?
A cut'n'paste error from the original code you posted, now fixed.
You have to compare greater than throughout because if you switch from > to < halfway, any large negative value will satisfy the first compare and the code will not then check the other compares.
You could code the whole thing in reverse and do all the compares < , but then you could not have some of the compares >
Re: PressTrendVal and PHP question
Posted: Tue 04 Feb 2014 8:28 am
by steve
This is the code in Cumulus (Pascal, but hopefully understandable). And I think it's effectively the same as Mark's PHP, with perhaps some slight differences over ">" and ">=".
Code: Select all
if ThreeHourlyPressureChangeMB > 6 then
presstrendstr := Risingveryrapidly
else if ThreeHourlyPressureChangeMB > 3.5 then
presstrendstr := Risingquickly
else if ThreeHourlyPressureChangeMB > 1.5 then
presstrendstr := Rising
else if ThreeHourlyPressureChangeMB > 0.1 then
presstrendstr := Risingslowly
else if ThreeHourlyPressureChangeMB > -0.1 then
presstrendstr := Steady
else if ThreeHourlyPressureChangeMB > -1.5 then
presstrendstr := Fallingslowly
else if ThreeHourlyPressureChangeMB > -3.5 then
presstrendstr := Falling
else if ThreeHourlyPressureChangeMB > -6 then
presstrendstr := Fallingquickly
else
presstrendstr := Fallingveryrapidly;
Your original code looks correct to me. Isn't the only problem that you have the string "Falling rapidly" rather than "Falling very rapidly" (and the same for rising)?
Re: PressTrendVal and PHP question
Posted: Tue 04 Feb 2014 9:21 am
by RayProudfoot
BCJKiwi wrote:Ray,
did you try;
else if ($weather_trend > -0.1 && $weather_trend < 0.1)
Hi,
No but I did use:-
elseif ($weather_trend >= -0.1 && $weather_trend <= 0.1)
But the Steady condition is catered for in Mark's code. It was my change to the falling pressure part that would result in the wrong condition being satisfied.
Re: PressTrendVal and PHP question
Posted: Tue 04 Feb 2014 9:33 am
by RayProudfoot
mcrossley wrote:A cut'n'paste error from the original code you posted, now fixed.
Thanks.
You have to compare greater than throughout because if you switch from > to < halfway, any large negative value will satisfy the first compare and the code will not then check the other compares.
You could code the whole thing in reverse and do all the compares < , but then you could not have some of the compares >
It did occur to me I could change the falling pressure section by starting with the greatest fall and ending with the smallest. Almost a mirror copy of the rising section. But I'll stick with your amended code, thanks.
Steve,
In the original code I pasted Falling Slowly, Falling and Falling Quickly all have different criteria to Rising Slowly, Rising and Rising Quickly. Unless I'm missing something very obvious.
One final point. >6 equates to Rising Very Rapidly but >-6 only equates to Falling Rapidly. What would trigger Falling Very Rapidly?
Re: PressTrendVal and PHP question
Posted: Tue 04 Feb 2014 10:03 am
by steve
RayProudfoot wrote:In the original code I pasted Falling Slowly, Falling and Falling Quickly all have different criteria to Rising Slowly, Rising and Rising Quickly. Unless I'm missing something very obvious.
Your original post said that for large drops in pressure, Cumulus was showing "Falling very rapidly", but the PHP was showing "Falling rapidly". This is because the PHP you quoted has no "Falling very rapidly". It uses the phrase "Falling rapidly" instead. So it was showing "Falling rapidly" for the same conditions where Cumulus was showing "Falling very rapidly", simply because the text is different, not because the logic is different.
One final point. >6 equates to Rising Very Rapidly but >-6 only equates to Falling Rapidly. What would trigger Falling Very Rapidly?
A fall of more than 6 mb, i.e. a negative number which isn't greater than -6, e.g. -7.
Re: PressTrendVal and PHP question
Posted: Tue 04 Feb 2014 11:13 am
by RayProudfoot
Hi Steve,
I've copied that code into a module in Visual Basic in Access just so I can step through various values and see how they're dealt with. The fact the language is different shouldn't make any difference and because I can step through the code I can better see how it deals with negative values.
So -5.7 is greater than -6. I think I had it in my head that it was less.

So now I see the sense in how it's coded. Thanks to you and Mark for your help.