Barotrend and Enbarotrend
Moderator: Mattk
Barotrend and Enbarotrend
I have included barotrend and enbarotrend in my realtime template as follows:
[thb0seapress-delta12h=barotrend.2:--]
[thb0seapress-delta12h=enbarotrend.2:--]
This results in a number or a two-letter message (currently 2 and RF). Does anyone have a php script that converts the letter code into comprehensible text so that I can display it on my site?
I'm a "php beginner" , I've tried for 2 hours but it doesn't work.
Thanks,
Bart
[thb0seapress-delta12h=barotrend.2:--]
[thb0seapress-delta12h=enbarotrend.2:--]
This results in a number or a two-letter message (currently 2 and RF). Does anyone have a php script that converts the letter code into comprehensible text so that I can display it on my site?
I'm a "php beginner" , I've tried for 2 hours but it doesn't work.
Thanks,
Bart
Re: Barotrend and Enbarotrend
Attached two scripts.Bart wrote: ↑Tue May 17, 2022 11:10 am I have included barotrend and enbarotrend in my realtime template as follows:
[thb0seapress-delta12h=barotrend.2:--]
[thb0seapress-delta12h=enbarotrend.2:--]
This results in a number or a two-letter message (currently 2 and RF). Does anyone have a php script that converts the letter code into comprehensible text so that I can display it on my site?
I'm a "php beginner" , I've tried for 2 hours but it doesn't work.
Thanks,
Bart
_test.php is to test other scripts.
It switches error-reporting on and includes the PHP-script to test.
If you are working on multiple scripts you can run it in the browser as . . ./_test.php?test=xyz.php
This test-scripts makes sure you are not getting a blank screen after you made a typing error.
Also attached the xyz.php to convert the returned Meteobridge values FF, FS, ST, RS, RF to human readable texts.
Code: Select all
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL); # error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
#
$test = 'RF'; // enbarotrend reports trend as strings FF, FS, ST, RS, RF
#
$arr_vals = array();
$arr_vals['FF'] = 'Rapidly Falling';
$arr_vals['FS'] = 'Falling';
$arr_vals['ST'] = 'Steady';
$arr_vals['RS'] = 'Rising';
$arr_vals['RF'] = 'Rapidly Rising';
#
if (array_key_exists( $test, $arr_vals) )
{ $result = $arr_vals[$test];}
else { $result = 'Steady';} // 'unknown' ?
echo $result;
Wim
P.S. There is also a dutch forum to ask these things https://www.hetweeractueel.nl/forum/
- Attachments
-
- voorbeeld.zip
- (1.8 KiB) Downloaded 158 times
Re: Barotrend and Enbarotrend
Thanks Wim,
the xyz script works fine of course. But not if I read my realtime file and turn off the test ($test = 'RF';) line and replace it with the read-in result of the MB.
I read the results of the operation in the MB in a php file as follows:
$test = file($myFile);
When I read it (print_r) I see (at this moment) this:
Array[0].....[117] => -2 [118] => FF.... (btw, [117]=barotrend)
If I then insert the script on the relevant site, the outcome always is 'Steady'. While that at this point should be Rapidly Faling.
Of course I disabled the test_line "...$test = 'RF'; ....".
In my realtime file I manually replaced the Mb variable with the different letter (RF, FF etc). combinations...result remains 'Steady
'.
I also tried inserting only 1 line by inserting " ....$test = test[118]...". But the outcome remains steady.
What am I doing wrong.
Bart
the xyz script works fine of course. But not if I read my realtime file and turn off the test ($test = 'RF';) line and replace it with the read-in result of the MB.
I read the results of the operation in the MB in a php file as follows:
$test = file($myFile);
When I read it (print_r) I see (at this moment) this:
Array[0].....[117] => -2 [118] => FF.... (btw, [117]=barotrend)
If I then insert the script on the relevant site, the outcome always is 'Steady'. While that at this point should be Rapidly Faling.
Of course I disabled the test_line "...$test = 'RF'; ....".
In my realtime file I manually replaced the Mb variable with the different letter (RF, FF etc). combinations...result remains 'Steady
'.
I also tried inserting only 1 line by inserting " ....$test = test[118]...". But the outcome remains steady.
What am I doing wrong.
Bart
Re: Barotrend and Enbarotrend
IMHO: Better use another forum, this forum is about Meteobridge not about PHP-basics.Bart wrote: ↑Thu May 19, 2022 9:22 am Thanks Wim,
the xyz script works fine of course. But not if I read my realtime file and turn off the test ($test = 'RF';) line and replace it with the read-in result of the MB.
I read the results of the operation in the MB in a php file as follows:
$test = file($myFile);
When I read it (print_r) I see (at this moment) this:
Array[0].....[117] => -2 [118] => FF.... (btw, [117]=barotrend)
If I then insert the script on the relevant site, the outcome always is 'Steady'. While that at this point should be Rapidly Faling.
Of course I disabled the test_line "...$test = 'RF'; ....".
In my realtime file I manually replaced the Mb variable with the different letter (RF, FF etc). combinations...result remains 'Steady
'.
I also tried inserting only 1 line by inserting " ....$test = test[118]...". But the outcome remains steady.
What am I doing wrong.
Bart
With print_r() there is an arrray name between the brackets. https://www.php.net/manual/en/function.print-r.phpWhen I read it (print_r) I see (at this moment) this:
Array[0].....[117] => -2 [118] => FF.... (btw, [117]=barotrend)
F.i. print_r($my_data).
To access the 118-th item in that array you should code $my_data[118];
The example script needs that value to be assigned to the variable $test.
The line should not read "$test = test[118]" as you posted
=> test is not a variable and also not an array with at leas 118 items.
=> $test therefor wil get a false value (= -1).
So you should code that line as
$test=$my_data[118]; // replace my_data with the correct name of the realtime data array, whicch you used with your print_r($whatever_name)
I stop answering here, please use the HWA forum for other questions.
There are dozens PHP script writers on the HWA forum.
Wim
Advice 1: G et a PHP book and start learning the basic PHP code.
Advice 2: Always use a test program as the one I supplied.
That will display all typing errors and had warned you that your $test = test[118] was invalid as test is not a variable.
Re: Barotrend and Enbarotrend
I was just asking in this post if anyone here has a script...
"...Does anyone have a php script that converts the letter code into comprehensible text so that I can display it on my site?
I'm a "php beginner" , I've tried for 2 hours but it doesn't work...."
A logical question in this place I think, everyone knows what I mean and I am definitely not asking a PHP question.
Very kindly I got a script from your Wim. The 'xyz-file' includes a test line to make errors visible.
But I don't get that to work if I replace the line "....$test = 'RF'; ...." with
$test=$test[118]; of course after I first added:
$myFile = "//...txt";
$test = file($myFile);
There I always got (and get) the result under the "else" statement, which is 'Steady', even though the content (!) of that line changed during the day.
That's why I wrote a follow-up question where I made one big mistake I forgot the $ in $test in the text. That's all. In the xyz file I did write that $ Wim, exactly as mentioned above.
Everything else was as I wrote and as you indicated, in the first and second instance.
This reply / question was meant to test if I might have done something wrong. But apparently that was not the case. So...
So I honestly don't know why I deserve this scolding. A patronizing mention of a book? I can always use that (or another) book because I already mentioned that I have little knowledge of PHP, I am a PHP beginner I wrote.
I am and did not intend to have a whole discussion about PHP here, I just asked if one of the experts here uses it on his/her website. Neither implicitly nor explicitly with the intent to start a PHP discussion.
Asking the question in this forum is very obvious as it is about Meteobridge processing, indeed not PHP.
Incidentally, I never got a single error message when running the 'xyz script'.
Bart
"...Does anyone have a php script that converts the letter code into comprehensible text so that I can display it on my site?
I'm a "php beginner" , I've tried for 2 hours but it doesn't work...."
A logical question in this place I think, everyone knows what I mean and I am definitely not asking a PHP question.
Very kindly I got a script from your Wim. The 'xyz-file' includes a test line to make errors visible.
But I don't get that to work if I replace the line "....$test = 'RF'; ...." with
$test=$test[118]; of course after I first added:
$myFile = "//...txt";
$test = file($myFile);
There I always got (and get) the result under the "else" statement, which is 'Steady', even though the content (!) of that line changed during the day.
That's why I wrote a follow-up question where I made one big mistake I forgot the $ in $test in the text. That's all. In the xyz file I did write that $ Wim, exactly as mentioned above.
Everything else was as I wrote and as you indicated, in the first and second instance.
This reply / question was meant to test if I might have done something wrong. But apparently that was not the case. So...
So I honestly don't know why I deserve this scolding. A patronizing mention of a book? I can always use that (or another) book because I already mentioned that I have little knowledge of PHP, I am a PHP beginner I wrote.
I am and did not intend to have a whole discussion about PHP here, I just asked if one of the experts here uses it on his/her website. Neither implicitly nor explicitly with the intent to start a PHP discussion.
Asking the question in this forum is very obvious as it is about Meteobridge processing, indeed not PHP.
Incidentally, I never got a single error message when running the 'xyz script'.
Bart
Re: Barotrend and Enbarotrend
Another xyz.php attached as zip and inserted as code
Please change only the line with the file-name.
I can not test the script myslef without a link to that file.
Succes, Wim
P.S. I am of the grid from tonight for 8 days.
Let just hurry then.
Please change only the line with the file-name.
I can not test the script myslef without a link to that file.
Succes, Wim
P.S. I am of the grid from tonight for 8 days.
Let just hurry then.
Code: Select all
<?php ini_set('display_errors', 'On'); error_reporting(E_ALL); # error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
echo '<pre>'.PHP_EOL; // makes the text readable
$myFile = "//...txt"; //
echo $myFile.PHP_EOL;
$mydata = file($myFile);// read data into array
print_r($mydata); // prints the array
$key = $mydata[118]; // select tyhe correct field
#
$arr_vals = array();
$arr_vals['FF'] = 'Rapidly Falling';
$arr_vals['FS'] = 'Falling';
$arr_vals['ST'] = 'Steady';
$arr_vals['RS'] = 'Rising';
$arr_vals['RF'] = 'Rapidly Rising';
#
if (array_key_exists( $key, $arr_vals) )
{ $result = $arr_vals[$test];} // the contents of field 118 is known
else { $result = $key.' is not a valid trend';} // 'unknown' ?
#
echo 'Trend data >'.$key.'< translated to '.$result;
- Attachments
-
- xyz.php.zip
- (988 Bytes) Downloaded 156 times
Re: Barotrend and Enbarotrend
The compleet list is displayed.
:
[118] RF
:
:
[169] => --
[170] => 1020.67
[171] => 1015.93
At the end of the list it shows:
)
Trend data >RF
< translated to RF
is not a valid trend
:
[118] RF
:
:
[169] => --
[170] => 1020.67
[171] => 1015.93
At the end of the list it shows:
)
Trend data >RF
< translated to RF
is not a valid trend
Re: Barotrend and Enbarotrend
All data items seem to have an extra linefeed?
So the contents of the item is not
RF
but it seems to be
RF
With an extra "cr/lf" type of character.
Again i have no access to the file, but the examples you gave should have been without the extra line feeds.
I added a line
So the contents of the item is not
RF
but it seems to be
RF
With an extra "cr/lf" type of character.
Again i have no access to the file, but the examples you gave should have been without the extra line feeds.
I added a line
Code: Select all
$key = trim($key); // to get rid of linefeeds
- Attachments
-
- xyz.php.zip
- (1.02 KiB) Downloaded 166 times
Re: Barotrend and Enbarotrend
Now there are some other remarks..see attachment.
- Attachments
-
- Schermafbeelding 2022-05-20 om 10.57.33.png (492.82 KiB) Viewed 3887 times
Last edited by Bart on Fri May 20, 2022 11:00 am, edited 1 time in total.
Re: Barotrend and Enbarotrend
No attachement to check?
===
Sorry for the wasted time for both of us.
https://www.php.net/manual/en/function.file.php read part Parameters => Flags
Just change your file() in your script from
Code: Select all
$test = file($myFile);
Code: Select all
$test = file($myFile,FILE_IGNORE_NEW_LINES);
I overlooked when you posted all data on one single line
Array[0].....[117] => -2 [118] => FF.... (btw, [117]=barotrend)
and having no access to the file itself
and with a dozen or so different realtimeMB.txt file formats
better next time also post a link (URL) to the file itself.
Then one can access that file. There is really no dangerous information in the file
Wim
Re: Barotrend and Enbarotrend
Typo, line 20 should read
Code: Select all
{ $result = $arr_vals[$key];} // the contents of field 118 is known
Re: Barotrend and Enbarotrend
It is reading correct now:
)
23 Trend data >RF< translated to >Rapidly Rising<
I get what you mean it's more convenient to see the information yourself. Logically. Apologies on my part.
But what I don't understand are those extra lines that are there. I see them when I open the page of the xyz.php but not in the file I get from the meteobridge.
For the things I use it for on the site I use, the line numbers are correct, there are no extra lines
RF
88.3
88.1
81.7
80.6
77.7
etc...
Made it with BBEdit
I am curious about the cause of that line phenomenon. That cost us a lot of time.
It seems to work Wim, thanks for the persistence. It is not always easy to communicate via a typewriter in the form of the internet.
Bart
)
23 Trend data >RF< translated to >Rapidly Rising<
I get what you mean it's more convenient to see the information yourself. Logically. Apologies on my part.
But what I don't understand are those extra lines that are there. I see them when I open the page of the xyz.php but not in the file I get from the meteobridge.
For the things I use it for on the site I use, the line numbers are correct, there are no extra lines
RF
88.3
88.1
81.7
80.6
77.7
etc...
Made it with BBEdit
I am curious about the cause of that line phenomenon. That cost us a lot of time.
It seems to work Wim, thanks for the persistence. It is not always easy to communicate via a typewriter in the form of the internet.
Bart
Re: Barotrend and Enbarotrend
You said
Otherwise BBEDIT would have displayed your file as one long line.
The data on disc is one long string of characters all on one long line often also as you view it in your browser.
Every different weather-value is separated from the next by that "EOL character"
BBEDIT knows what to do with "EOL characters" as it is a program editor. Browsers do not use them normally.
The "problem" is that according to the HTML definitions, the browsers do not display "EOL characters" they are ignored.
They are present in the page-source but not visible on the screen so you not easily detect them if they are there but they can play havoc with correctly formatting your pages.
The file() instruction makes an array with the values by splitting the separate weather-values at the position of the "EOL character" and leaves the "EOL character" attached to the weather-value.
Adding FILE_IGNORE_NEW_LINES removes those "EOL characters"
By not removing those characters, you encounter problems when calculating with weather-values because 1027.1 is a valid floating point value but 1027.1
is not.
Wim
There is no extra line there is a "EOL (=EndOfLine) character" after each field.I am curious about the cause of that line phenomenon. That cost us a lot of time.
Otherwise BBEDIT would have displayed your file as one long line.
The data on disc is one long string of characters all on one long line often also as you view it in your browser.
Every different weather-value is separated from the next by that "EOL character"
BBEDIT knows what to do with "EOL characters" as it is a program editor. Browsers do not use them normally.
The "problem" is that according to the HTML definitions, the browsers do not display "EOL characters" they are ignored.
They are present in the page-source but not visible on the screen so you not easily detect them if they are there but they can play havoc with correctly formatting your pages.
The file() instruction makes an array with the values by splitting the separate weather-values at the position of the "EOL character" and leaves the "EOL character" attached to the weather-value.
Adding FILE_IGNORE_NEW_LINES removes those "EOL characters"
By not removing those characters, you encounter problems when calculating with weather-values because 1027.1 is a valid floating point value but 1027.1
is not.
Wim
Re: Barotrend and Enbarotrend
Thanks for the clear explanation. good to know and to take into account in future.
Bart
Bart