Page 1 of 2

Now available - metar-display.php for non-Saratoga templates

Posted: Thu 10 Jan 2013 3:59 am
by saratogaWX
I've taken a couple of the support scripts from the Saratoga AJAX/PHP template set that are used to provide the template wxmetar.php display, and packaged them with the needed images and a new metar-display.php script so folks can have METAR conditions displays on their websites too.

All the customization needed is in the metar-display.php sample page, so it should be relatively simple for you to port the active content to your existing website template (or just run the metar-display.php page as-is on your site).

Docs/download from http://saratoga-weather.org/scripts-metar.php#metar

Enjoy!

Ken

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Thu 10 Jan 2013 7:45 am
by William Grimsley
Hi Ken,

That's a great thing to do! Hopefully many people will enjoy this as not all want the pain of modifying PHP! :lol:

Will

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Thu 10 Jan 2013 9:04 am
by water01
What's painful about modding php, install your own apache server and php and you have a free testbed and then its a doddle to test it and it's much more powerful than html?

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 9:09 am
by laulau
Hi,
I've tested the script on my own server (EasyPHP) and works fine.
Then i upload the script to my free account site but it doen't work!

http://ialsacem4.chez.com/metar/metar-display.php

Any suggestions?

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 1:23 pm
by beteljuice
Fatal error: Call to undefined function langtransstr() in xxxxxxxxxxxxxx/metar/include-metar-display.php on line 74
Is langtransstr (and langtrans) function(s) defined in your base page ?

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 2:05 pm
by laulau
No!
I've no base page based on Ken's Saratoga template.
But why is it working on EasyPHP home server and not on chez.com server ?
Does EasyPHP ignore this fatal error ?
Is there a way to look at what happen in EasyPHP (debug) ?

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 3:09 pm
by saratogaWX
The active part of the sample metar-display.php page includes definitions for the two functions langtrans() and langtransstr()

Code: Select all

<?php
$SITE = array();  // required for non-Saratoga template use
global $SITE;

// Customize this list with your nearby METARs by
// using http://saratoga-weather.org/wxtemplates/find-metar.php to create the list below

$MetarList = array( // set this list to your local METARs 
// Metar(ICAO) | Name of station | dist-mi | dist-km | direction |
  'KNUQ|Moffett Nas/Mtn, California, USA|9|14|N|', // lat=37.4000,long=-122.0500, elev=12, dated=28-FEB-12
  'KSJC|San Jose, California, USA|9|14|NE|', // lat=37.3667,long=-121.9167, elev=24, dated=28-FEB-12
  'KRHV|San Jose/Reid, California, USA|12|19|ENE|', // lat=37.3167,long=-121.8167, elev=41, dated=28-FEB-12
  'KPAO|Palo Alto, California, USA|14|23|NNW|', // lat=37.4667,long=-122.1167, elev=2, dated=28-FEB-12
  'KSQL|San Carlos Airpo, California, USA|21|34|NW|', // lat=37.5167,long=-122.2500, elev=1, dated=28-FEB-12
  'KWVI|Watsonville, California, USA|27|44|SSE|', // lat=36.9333,long=-121.7833, elev=43, dated=28-FEB-12
  'KHWD|Hayward, California, USA|28|44|N|', // lat=37.6667,long=-122.1167, elev=21, dated=28-FEB-12
  'KSFO|San Francisco, California, USA|30|49|NW|', // lat=37.6167,long=-122.3667, elev=3, dated=28-FEB-12
  'KHAF|Half Moon Bay, California, USA|31|50|WNW|', // lat=37.5167,long=-122.5000, elev=21, dated=28-FEB-12
  'KOAK|Oakland, California, USA|31|50|NNW|', // lat=37.7000,long=-122.2167, elev=26, dated=28-FEB-12
  'KLVK|Livermore, California, USA|31|51|NNE|', // lat=37.7000,long=-121.8167, elev=117, dated=28-FEB-12
  'KCVH|Hollister Muni, California, USA|42|68|SE|', // lat=36.9000,long=-121.4167, elev=70, dated=28-FEB-12
  'KSNS|Salinas, California, USA|48|77|SSE|', // lat=36.6667,long=-121.6000, elev=30, dated=28-FEB-12
  'KMRY|Monterey, California, USA|49|78|SSE|', // lat=36.5833,long=-121.8500, elev=66, dated=28-FEB-12
  'KCCR|Concord, California, USA|50|81|N|', // lat=38.0000,long=-122.0500, elev=11, dated=28-FEB-12
// list generated Wed, 09-Jan-2013 4:39pm PST at http://saratoga-weather.org/wxtemplates/find-metar.php
);
$maxAge = 75*60; // max age for metar in seconds = 75 minutes
#
$SITE['cacheFileDir']   =  './cache/';   // directory to use for scripts cache files .. use './' for doc.root.dir
$SITE['tz'] 			= 'America/Los_Angeles'; //NOTE: this *MUST* be set correctly to
// translate UTC times to your LOCAL time for the displays.
//  http://us.php.net/manual/en/timezones.php  has the list of timezone names
//  pick the one that is closest to your location and put in $SITE['tz'] like:
//    $SITE['tz'] = 'America/Los_Angeles';  // or
//    $SITE['tz'] = 'Europe/Brussels';
$SITE['timeFormat'] = 'D, d-M-Y g:ia T';  // Day, 31-Mar-2006 6:35pm Tz  (USA Style)
$SITE['latitude']		= '37.27153397';    //North=positive, South=negative decimal degrees
$SITE['longitude']		= '-122.02274323';  //East=positive, West=negative decimal degrees

$condIconDir = './metar-images/';  // directory for metar-images with trailing slash
$SITE['fcsticonstype'] = '.jpg'; // default type='.jpg' 
#                                // use '.gif' for animated icons from # http://www.meteotreviglio.com/
$SITE['uomTemp'] = '&deg;F';  // ='&deg;C', ='&deg;F'
$SITE['uomBaro'] = ' inHg';   // =' hPa', =' inHg'
$SITE['uomWind'] = ' mph';    // =' km/h', =' mph'
$SITE['uomRain'] = ' in';     // =' mm', =' in'
$SITE['uomDistance'] = ' mi'; // =' mi' or =' km'
// end of customizations
#
# utility functions .. you don't need to change these
// Wind Rose graphic in ajaxwindiconwr as wrName . winddir . wrType
$wrName   = 'wr-';       // first part of the graphic filename (followed by winddir to complete it)
$wrType   = '.png';      // extension of the graphic filename
$wrHeight = '58';        // windrose graphic height=
$wrWidth  = '58';        // windrose graphic width=
$wrCalm   = 'wr-calm.png';  // set to full name of graphic for calm display ('wr-calm.gif')
$Lang = 'en'; // default language used (for Windrose display)
$SITE['lang'] = $Lang;
if (!function_exists('date_default_timezone_set')) {
   putenv("TZ=" . $SITE['tz']);
  } else {
   date_default_timezone_set($SITE['tz']);
 }
function langtrans ( $str ) { echo $str; return; }
function langtransstr ($str) { return($str); }
$time = date('H:i');
$sun_info = date_sun_info(time(),$SITE['latitude'], $SITE['longitude']);
$sunrise = date('H:i',$sun_info['sunrise']);
$sunset  = date('H:i',$sun_info['sunset']);
print "<!-- time='$time' sunrise='$sunrise' sunset='$sunset' latitude='".$SITE['latitude']."' longitude='".$SITE['longitude']."' -->\n";
# end of utility functions
?>
be sure to copy all the PHP code to your sample page.

There may be another issue with your other site. If you run http://ialsacem4.chez.com/metar/metar-d ... hp?debug=y then do a view-source on the page you'll see:
<!-- get-metar-conditions-inc.php - Version 1.13 - 31-Aug-2012 -->
<!-- mtr_conditions using METAR ICAO='LFSB' -->
<!-- GET /pub/data/observations/metar/stations/LFSB.TXT HTTP/1.1
Host: weather.noaa.gov Port: 80 IP=193.159.160.40-->
<!-- Network error: () -->
it appears that the chez.com website is disallowing fconnect() PHP functions as it returns an unspecified network error. Their hosting setup may forbid scripts from trying to access external websites for data, in which case, the script will not work with that hoster.

Best regards,
Ken

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 3:31 pm
by laulau
Thank's

So I have to change the hoster :(

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 5:48 pm
by nking
laulau wrote:Thank's

So I have to change the hoster :(

You may be able to get them to allow this action, it's worth asking.

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 5:59 pm
by avoorpool
Thanks to Ken's great efforts, not only the mentioned 'METAR' script runs flawlessly, other modified scripts (like 'Astronomy' and WU forecast) are a great contribution to non Saratoga template related websites (templates).

I'm running Weather Blues Template and all previous mentioned scripts run great and are easily modified to match template lay-out and backgrnd colours!!!!

Thanks again, Ken,

Cheers,

Arthur

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 6:25 pm
by KevinF
I see what you mean Arthur....the reports do look good on that page - neat and tidy

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 6:39 pm
by William Grimsley
water01 wrote:What's painful about modding php, install your own apache server and php and you have a free testbed and then its a doddle to test it and it's much more powerful than html?
Well, I wouldn't say it's painful modding PHP but it's much harder to work with that HTML, surely? :D

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 6:46 pm
by saratogaWX
avoorpool wrote:Thanks to Ken's great efforts, not only the mentioned 'METAR' script runs flawlessly, other modified scripts (like 'Astronomy' and WU forecast) are a great contribution to non Saratoga template related websites (templates).

I'm running Weather Blues Template and all previous mentioned scripts run great and are easily modified to match template lay-out and backgrnd colours!!!!

Thanks again, Ken,

Cheers,

Arthur
Thanks for the kind words, Arthur! :oops:

When I started doing PHP scripts back in 2004, the scripts were all designed for 'standalone' use so they could be incorporated into any website as needed. Since I'm a big fan of 'code reuse', I tend to borrow from myself when creating new scripts. In 2006, I decided to augment the HTML website template designed by Tom at carterlake.org for Weather-Display and allow the scripts to be used both in the new template and as standalone scripts. With Kevin's (of tnetweather.com) architecture for an included-site layout using a common Settings.php file for website configuration, the first Saratoga templates were released. The standalone scripts were made 'template aware' and would do needed configuration from the entries in Settings.php. That was later expanded to allow translations (using the langlookup entries) and multiple weather software support.

So, while the majority of my development is still in the Saratoga template area, I do keep in mind that not everyone uses the the template set, so useful functions are also made available as standalone packages wherever possible, and I'll continue to do that.
Each script tends to have a local settings area near the top, and an override of those settings if the appropriate $SITE[] variables are available. This allows the script to be generally replaced with a new version without further customization since under the Saratoga template, the configuration is done in $SITE[] variables inside the Settings.php/Settings-weather.php files .. makes for easy maintenance of the website using the Saratoga template :)

Adapting standalone scripts to Jacque's templates can be a bit of a challenge as his internal architecture is quite different. The easy way around the issue is what I'd done with the metar-display package: provide just enough configuration via $SITE[] variables that my template uses to configure the script(s) to run without further configuration. The longer-term issue is the big difference in handling multilingual ability. Jacques does it with a loadable PHP file with $variables containing the strings for the fixed text display. My template uses lookups to replace fixed English text with the corresponding language words/phrase. There's not an easy 'shim' to fix that incompatibility of methods for translation, sadly. So the output of the metar-display.php page will remain in English for the forseeable future.

Best regards,
Ken

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Fri 11 Jan 2013 7:05 pm
by avoorpool
Hi Ken,

Thanks for your thorough explanation!!

Since English is the well adapted #1 language in the World, I don't bother too much about changing my website into multiple languages..........
Nice feature for 'English illiterates'..., however I assume most visitors do understand the weather displays in degrees C anyhow :D. If not, I've just implemented some 'mini-icons' to my 'Site-Map' page, so hopefully that will explain page content, even if you can't read English.. :lol:

Please keep the spirit going in future (re)-development of exisitng Saratoga Templates.. ;) ..!!
Thanks,

Cheers,

Arthur

Re: Now available - metar-display.php for non-Saratoga templ

Posted: Sat 19 Jan 2013 9:46 am
by nking
I wonder if someone might be able to point me in the right direction. I have installed the script and, I think, made the right variable changes but as you will see it's not working correctly. http://www.pc-king.co.uk/weather/metar-display.php

1. The icons are not being diplayed
2. The distance from station are way off e.g. Gatwick 40 miles, actual is 15 miles.
3. Cloud details reported in metres and not feet.

The trouble is I don't know php and...... I'm proably not to bright :roll: