cloudy

Author Topic: Configure get-metar-conditions-inc  (Read 2254 times)

0 Members and 1 Guest are viewing this topic.

Offline g-force

  • Posts: 21
  • Cap de Fibló
    • El tiempo en Ibiza
Configure get-metar-conditions-inc
« on: November 15, 2011, 09:22:34 AM »
Hello I can not run get-metar-inc-conditions where do I put the code icao = LEIB?

http://www.meteoibiza.com/get-metar-conditions-inc.php

Thanks.
Modelo local para Sant Antoni de Portmany: Versión gráfica - Versión texto

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: Configure get-metar-conditions-inc
« Reply #1 on: November 15, 2011, 03:23:38 PM »
The script is really a package for a subroutine to decode the metar.

Use it like
Code: [Select]
include_once("get-metar-conditions-inc.php");
list($Currentsolardescription,$iconnumber,$icongraphic,$icontext,$mtrstuff) = mtr_conditions('LEIB', $time, $sunrise, $sunset,true);

$time is local time, $sunrise is local sunrise time, $sunset is local sunset time.

The $Currentsolardescription will contain the text of the METAR weather and sky conditions,
$iconnumber is the WD Icon to use (0 to 34).

More info is in comments in the code itself..

Hope this helps.

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline g-force

  • Posts: 21
  • Cap de Fibló
    • El tiempo en Ibiza
Re: Configure get-metar-conditions-inc
« Reply #2 on: November 15, 2011, 04:24:16 PM »
Hello ¿need to change some of this code?

that it does not work, nothing appears

http://www.meteoibiza.com/Metar-LEIB.php




*/
global $Debug;

$Version = 'get-metar-conditions-inc.php - Version 1.04 - 09-Oct-2011';

if (isset($_REQUEST['sce']) && ( strtolower($_REQUEST['sce']) == 'view' or
    strtolower($_REQUEST['sce']) == 'show') ) {
   //--self downloader --
   $filenameReal = __FILE__;
   $download_size = filesize($filenameReal);
   header('Pragma: public');
   header('Cache-Control: private');
   header('Cache-Control: no-cache, must-revalidate');
   header("Content-type: text/plain");
   header("Accept-Ranges: bytes");
   header("Content-Length: $download_size");
   header('Connection: close');
   
   readfile($filenameReal);
   exit;
}
// local settings
$cacheFileDir = './';   // default cache file directory

global $cacheFileDir;
//------------ override from Settings.php --------------------
global $SITE;
if(isset($SITE['cacheFileDir']))     {$cacheFileDir = $SITE['cacheFileDir']; }
//------------ end override from Settings.php ----------------
# ------------------------------------------------------------------------------
# main function mtr_conditions
#-------------------------------------------------------------------------------

function mtr_conditions ($icao,$curtime='',$sunrise='',$sunset='',$useJpgIcon=false) {
  global $lang, $Debug, $mtrInfo, $metarPtr, $group, $Version;
  global $Icons, $IconsLarge, $IconsText, $cacheFileDir;
  $metarCacheName = $cacheFileDir."metarcache-$icao.txt";
  $metarRefetchSeconds = 600;  // fetch every 10 minutes

  if(isset($_REQUEST['cache']) and strtolower($_REQUEST['cache']) == 'refresh') {
      $metarRefetchSeconds = 0;
  }

  $mtrInfo = array();
  $Debug .= "<!-- $Version -->\n";
  if(isset($icao) and strlen($icao) == 4) {

   $Debug .= "<!-- mtr_conditions using METAR ICAO='$icao' -->\n";
   $host = 'weather.noaa.gov';
   $path = '/pub/data/observations/metar/stations/';
   $metarURL = 'http://' . $host . $path . $icao . '.TXT';

    $html = '';
    $raw = '';
// get the metar data from the cache or from the URL if the cache is 'stale'
  if (file_exists($metarCacheName) and filemtime($metarCacheName) + $metarRefetchSeconds > time()) {
      $WhereLoaded = "from cache $metarCacheName";
      $html = implode('', file($metarCacheName));
    } else {
      $WhereLoaded = "from URL $metarURL";
      $rawhtml = mtr_fetchUrlWithoutHanging($metarURL);
     $i = strpos($rawhtml,"\r\n\r\n");
     $headers = substr($rawhtml,0,$i-1);
     $content = substr($rawhtml,$i+2);
     if(preg_match('|Content-Encoding: gzip|Ui',$headers)) {
        $Debug .= "<!-- Webserver returned gzipped data, dang 'em -- unzipping response -->\n";
        // $Debug .= "<!-- content='".$content."' -->\n";
        $err = 'None';
        $html = trim(mtr_gzdecode($content,$err));
        $Debug .= "<!-- mtr_gzdecode err='$err' -->\n";
        if($err <> 'None') {
          $Debug .= "<!-- contentX='".bin2hex($content).". -->\n";
        }
     } else {
         $html = $content;
     }
    $fp = fopen($metarCacheName, "w");
Modelo local para Sant Antoni de Portmany: Versión gráfica - Versión texto

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: Configure get-metar-conditions-inc
« Reply #3 on: November 15, 2011, 06:49:55 PM »
No, you do not have to change any code in get-metar-conditions-inc.php ..
Since you are running the script inside a V2 WD/AJAX/PHP template set, you only need to make a copy of wxnewpage.php, and put the following in the <div id="main-copy"> ... </div> section of the page
 
Code: [Select]
<?php
  
include_once("get-metar-conditions-inc.php");
  
  list(
$condwords,$iconnum,$condicon,$condicondesc,$mtr) =
        
mtr_conditions('LEIB'$time$sunrise$sunsettrue);
// now $mtr array contains the decoded values

print "<p>\n";

foreach (
$mtr as $k => $val) {

   print 
"$k : $val<br/>\n";
}
print 
"</p>\n";

?>



My sample with this code is at http://saratoga-weather.org/wxtemplates/Test/wxmetar.php
Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline g-force

  • Posts: 21
  • Cap de Fibló
    • El tiempo en Ibiza
Re: Configure get-metar-conditions-inc
« Reply #4 on: November 15, 2011, 07:29:30 PM »
Now one does work! thanks   :D :D :D :D

another question:
Why not the icon of these variables?
$ iconnumber, $ icongraphic, $ icontext, $ mtrstuff
And the hour of sunrise and metar the sun?
$ time, $ sunrise, $ sunset, true

text only appears metar ...

STATION : LEIB
WIND : varies at 1 mph (2 km/h)
VISIBILITY : greater than 7 miles
CONDITIONS : Clear
TEMP : 59F (15C)
DEWPT : 55F (13C)
HUMIDITY : 88%
BAROMETER : 1013 hPa (29.91 inHg)
Modelo local para Sant Antoni de Portmany: Versión gráfica - Versión texto

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: Configure get-metar-conditions-inc
« Reply #5 on: November 15, 2011, 08:19:08 PM »
Only the text appeared because that was all that was printed in the example above :)

Try
Code: [Select]
<?php
$condIconDir 
'./ajax-images/';  // directory for ajax-images with trailing slash
$condIconType '.jpg'// default type='.jpg' -- use '.gif' for animated icons from http://www.meteotreviglio.com/
if (isset($SITE['fcsticonstype']))  {$condIconType $SITE['fcsticonstype'];}

  include_once(
"get-metar-conditions-inc.php");
  
  list(
$condwords,$iconnum,$condicon,$condicondesc,$mtr) =
        
mtr_conditions('LEIB'$time$sunrise$sunsettrue);
// now $mtr array contains the decoded values
?>

<table style="border: none" width="250">
<tr>
<td align="center" valign="top" class="data1" style="text-align: center;border: none">
      <img src="<?php echo $condIconDir newIcon($iconnum?>
        alt="<?php $t1 fixupCondition($condwords);
              echo 
$t1?>
"
        title="<?php echo $t1?>" height="58" width="55" />
</td>
<td class="data1" style="text-align: left;border: none">
<?php echo $t1?>
</td>
</tr>
<tr>
<td colspan="2" class="data1" style="text-align: left;border: none">
<?

foreach ($mtr as $k => $val) {

   print "$k : $val<br/>\n";
}
?>
</td>
</tr>
</table>

<?php

// supporting functions
//=========================================================================
// pick the NOAA style condition icon based on iconnumber 
function newIcon($numb) {
  global 
$condIconDir,$condIconType;
  
  
$iconList = array(
"skc.jpg",          //  0 imagesunny.visible
"nskc.jpg",         //  1 imageclearnight.visible
"bkn.jpg",          //  2 imagecloudy.visible
"sct.jpg",          //  3 imagecloudy2.visible
"nbkn.jpg",         //  4 imagecloudynight.visible
"sct.jpg",          //  5 imagedry.visible
"fg.jpg",           //  6 imagefog.visible
"hazy.jpg",         //  7 imagehaze.visible
"ra.jpg",           //  8 imageheavyrain.visible
"few.jpg",          //  9 imagemainlyfine.visible
"mist.jpg",         // 10 imagemist.visible
"nfg.jpg",          // 11 imagenightfog.visible
"nra.jpg",          // 12 imagenightheavyrain.visible
"novc.jpg",         // 13 imagenightovercast.visible
"nra.jpg",          // 14 imagenightrain.visible
"nshra.jpg",        // 15 imagenightshowers.visible
"nsn.jpg",          // 16 imagenightsnow.visible
"ntsra.jpg",        // 17 imagenightthunder.visible
"ovc.jpg",          // 18 imageovercast.visible
"sct.jpg",          // 19 imagepartlycloudy.visible
"ra.jpg",           // 20 imagerain.visible
"ra.jpg",           // 21 imagerain2.visible
"shra.jpg",         // 22 imageshowers2.visible
"ip.jpg",           // 23 imagesleet.visible
"ip.jpg",           // 24 imagesleetshowers.visible
"sn.jpg",           // 25 imagesnow.visible
"sn.jpg",           // 26 imagesnowmelt.visible
"sn.jpg",           // 27 imagesnowshowers2.visible
"skc.jpg",          // 28 imagesunny.visible
"scttsra.jpg",      // 29 imagethundershowers.visible
"hi_tsra.jpg",      // 30 imagethundershowers2.visible
"tsra.jpg",         // 31 imagethunderstorms.visible
"nsvrtsra.jpg",     // 32 imagetornado.visible
"wind.jpg",         // 33 imagewindy.visible
"ra1.jpg",          // 34 stopped rainning
"windyrain.jpg"     // 35 windy/rain 
);
$tempicon $iconList[$numb];
if($condIconType <> '.jpg') {
  $tempicon preg_replace('|\.jpg|',$condIconType,$tempicon);
}
return($tempicon);
  }

// Function to process %Currentsolarcondition% string and 
// remove duplicate stuff, then fix capitalization, and translate from English if needed
//  
  
function fixupCondition$inCond ) {
    global 
$DebugMode;

    
$Cond str_replace('_',' ',trim($inCond));
$Cond strtolower($Cond);

$vals explode("/",$Cond);
if(strpos('/',$Cond) === false and strpos(',',$Cond) !==false) {
$vals explode(', ',$Cond);
}
$ocnt count($vals);
foreach ($vals as $k => $v) { 
  $v ucfirst(strtolower(trim($v)));
  $vals[$k] = langtransstr($v); 
}

if($vals[0] == '') {$junk array_shift($vals);}
if(isset($vals[2]) and $vals[0] == $vals[2]) {$junk array_pop($vals);}
reset($vals);
$t join(', ',$vals);

// return($Cond . "' orig=$ocnt n=" . count($vals) ." t='$t'");
    
if($DebugMode) {
      
$t "<!-- fixupCondition in='$inCond' out='$t' ocnt='$ocnt' -->" $t;
}
    return(
$t);
  
  }
?>

to show the icon and the conditions text.

Weather-Display provides the $time, $sunrise, $sunset times from testtags.php.
$mtr contains the array of values printed.  To print just one value (say the Barometer), you just have to use
Code: [Select]
<?php echo $mtr['BAROMETER']; ?> and the value for the barometer will be printed.

I've included in the above sample two functions (newIcon and fixupConds) from the ajax-dashboard.php to help with the formatting.

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline g-force

  • Posts: 21
  • Cap de Fibló
    • El tiempo en Ibiza
Re: Configure get-metar-conditions-inc
« Reply #6 on: November 15, 2011, 08:57:39 PM »
that well! :D :D :D

one last question, is to show when we have taken the METAR?
Modelo local para Sant Antoni de Portmany: Versión gráfica - Versión texto

Offline g-force

  • Posts: 21
  • Cap de Fibló
    • El tiempo en Ibiza
Re: Configure get-metar-conditions-inc
« Reply #7 on: November 16, 2011, 08:31:33 PM »
Hello Ken ,

tell me the code would be possible to set the time of collection of METAR?

Modelo local para Sant Antoni de Portmany: Versión gráfica - Versión texto

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: Configure get-metar-conditions-inc
« Reply #8 on: November 16, 2011, 08:33:56 PM »
I'm working on a generalized wxmetar.php page (along with an update to get-metar-conditions-inc.php) that will allow the display of multiple metars (with the update date).   Hold on a bit.. should be released later today (Pacific Time).

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: Configure get-metar-conditions-inc
« Reply #9 on: November 17, 2011, 09:58:40 PM »
Ok.. generalized multi-metar display page now included in all the AJAX/PHP V3 template sets

See it in action at http://saratoga-weather.org/wxtemplates/Test/wxmetar.php

Updates from http://saratoga-weather.org/wxtemplates/updates.php (for 17-Nov-2011)

Update includes:
get-metar-conditions-inc.php  V1.05
wxmetar.php V1.00
include-metar-display.php V1.00

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline g-force

  • Posts: 21
  • Cap de Fibló
    • El tiempo en Ibiza
Re: Configure get-metar-conditions-inc
« Reply #10 on: November 18, 2011, 10:24:01 PM »
Great, thank you very much for everything, here the result. :hello1: :hello1:


http://www.meteoibiza.com/wxmetar.php
Modelo local para Sant Antoni de Portmany: Versión gráfica - Versión texto

Offline i_fiorentino

  • Alessandro Bardi
  • Posts: 1,439
  • 160 mls Carmignano (Po), Tuscany, Italy
    • Meteocarmignano.it
Re: Configure get-metar-conditions-inc
« Reply #11 on: November 19, 2011, 12:53:05 PM »
Hi Ken,
i've installed metar script but there're some translation minor bugs.
The term of "at" in ajax dashboard is translated to "alle" (f.e. Wind from NNO at 3.00pm)
But the term of "at" referred to kmh should be translate to "a" in italian language not "alle".
Is it possible to separate the two terms with another function?

Code: [Select]
  if(isset($t[1])) $t[1] = langtransstr($t[1]); // translate 'at'

There are also two terms without any translation.
WIND: greater than x miles -> superiore a x kmh ..... where can i put that?
WIND DIRECTION: varies alle x km/h -> variabile a x km/h .....where can i put that?

Metar page here: http://www.meteocarmignano.it/wxmetar.php

Many thanks,

Alessandro
« Last Edit: November 19, 2011, 12:55:37 PM by i_fiorentino »

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: Configure get-metar-conditions-inc
« Reply #12 on: November 19, 2011, 04:06:40 PM »
Hi Alessandro,

I've done an update to include-metar-display.php V1.02 to fix a malformed PHP tag (a <? instead of a <?php ), and to remove the translation for 'at' in the Wind: display .. the current translation tables do not have the appropriate word for the English there.. just makes a better display of 'Wind: SSE 15 km/h' instead of 'Wind: SSE at 15 km/h'.

Missing translation items can be added to the language-LL.txt file

langlookup|Wind Chill|Wind Chill|
langlookup|Heat Index|Heat Index|
langlookup|Clouds|Clouds|
langlookup|Visibility|Visibility|
langlookup|Few clouds|Few clouds|
langlookup|calm|calm|
langlookup|varies|varies|
langlookup|greater than|greater than|

Best regards,
Ken
« Last Edit: November 19, 2011, 04:09:59 PM by saratogaWX »
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline Axelvold

  • Posts: 980
  • Axelvold / Sweden
  • Axelvold, Sverige
    • Axelvold's weather and photo
Re: Configure get-metar-conditions-inc
« Reply #13 on: November 19, 2011, 07:21:52 PM »
Hi Ken

Did find a minor bug in your script.

This,
Code: [Select]
$mtrInfo['WIND CHILL'] = "$chillC&deg;C)";Should most probably be like this,
Code: [Select]
$mtrInfo['WIND CHILL'] = "$chillC&deg;C";



Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: Configure get-metar-conditions-inc
« Reply #14 on: November 19, 2011, 07:42:32 PM »
Lars, I see... the trailing parenthesis is the issue, yes?
Looking at http://www.axelvold.net/wd/wxmetar.php seems to show correctly.

Best regards,
Ken
« Last Edit: November 19, 2011, 07:44:43 PM by saratogaWX »
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

 

cumulus