Services_Weather
[ class tree: Services_Weather ] [ index: Services_Weather ] [ all elements ]

Source for file metar-extensive.php

Documentation is available at metar-extensive.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  3.  
  4. /**
  5.  * Elaborate example for the METAR/TAF-service
  6.  *
  7.  * Well, this is a more elaborate example how to create a neat little page
  8.  * with fetching METAR/TAF data from NOAA and putting it into a design.
  9.  * I'm not too proud of my design-skills, most of the stuff here is taken
  10.  * from the metar-block which can be found within the Horde Framework,
  11.  * courtesy of Rick Emery - creative pixelshoving isn't my domain :-P
  12.  * I've used a Firefox for checking the design, so don't be too
  13.  * disappointed, if the page looks shabby with the IE, not that I care
  14.  * very much anyway ;-)
  15.  * Have fun!
  16.  * 
  17.  * PHP versions 4 and 5
  18.  *
  19.  * <LICENSE>
  20.  * Copyright (c) 2005, Alexander Wirtz
  21.  * All rights reserved.
  22.  * 
  23.  * Redistribution and use in source and binary forms, with or without
  24.  * modification, are permitted provided that the following conditions
  25.  * are met:
  26.  * o Redistributions of source code must retain the above copyright notice,
  27.  *   this list of conditions and the following disclaimer.
  28.  * o Redistributions in binary form must reproduce the above copyright notice,
  29.  *   this list of conditions and the following disclaimer in the documentation
  30.  *   and/or other materials provided with the distribution.
  31.  * o Neither the name of the software nor the names of its contributors
  32.  *   may be used to endorse or promote products derived from this software
  33.  *   without specific prior written permission.
  34.  * 
  35.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  38.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  39.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  40.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  41.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  42.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  43.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  44.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  45.  * POSSIBILITY OF SUCH DAMAGE.
  46.  * </LICENSE>
  47.  * 
  48.  * @category    Web Services
  49.  * @package     Services_Weather
  50.  * @author      Alexander Wirtz <alex@pc4p.net>
  51.  * @copyright   2005 Alexander Wirtz
  52.  * @license     http://www.opensource.org/licenses/bsd-license.php  BSD License
  53.  * @version     CVS: $Id: metar-extensive.php,v 1.17 2005/11/13 22:45:21 eru Exp $
  54.  * @link        http://pear.php.net/package/Services_Weather
  55.  * @filesource
  56.  */
  57.  
  58. //-------------------------------------------------------------------------
  59. // This is the area, where you can customize the script
  60. //-------------------------------------------------------------------------
  61. $location        = "Bonn, Germany"; // The city we want to fetch the data for.
  62.                                     // Where the search function will look for
  63.                                     // the ICAO database (generated with the
  64.                                     // buildMetarDB.php script)
  65. $dsn             = "sqlite://localhost//usr/local/lib/php/data/Services_Weather/servicesWeatherDB"; 
  66. $sourceMetar     = "http";          // This script will pull the METAR data via http
  67. $sourceTaf       = "http";          //                           TAF
  68. $sourcePathMetar = "";              // Only needed when non-standard access is used
  69. $sourcePathTaf   = "";              //
  70. $cacheType       = "";              // Set a type (file, db, mdb, ...) to
  71.                                     // enable caching.
  72. $cacheOpt        = array();         // Cache needs various options, depending
  73.                                     // on the container-type - please consult
  74.                                     // the Cache manual / sourcecode!
  75. $unitsFormat     = "metric";        // The format the units are displayed in -
  76.                                     // metric, standard or some customization.
  77. $dateFormat      = "j. M Y";        // Set the format the date is displayed in
  78. $timeFormat      = "H:i";           //                    time
  79. //-------------------------------------------------------------------------
  80.  
  81. // Load the Weather class
  82. require_once "Services/Weather.php";
  83.  
  84. // Object initialization - error checking is important, because of
  85. // handling exceptions such as missing PEAR modules
  86. $metar = &Services_Weather::service("Metar");
  87. if (Services_Weather::isError($metar)) {
  88.     die("Error: ".$metar->getMessage()."\n");
  89. }
  90.  
  91. // Set parameters for DB access, needed for location searches
  92. $metar->setMetarDB($dsn);
  93. if (Services_Weather::isError($metar)) {
  94.     echo "Error: ".$metar->getMessage()."\n";
  95. }
  96.  
  97. // Initialize caching
  98. if (strlen($cacheType)) {
  99.     $status = $metar->setCache($cacheType, $cacheOpt);
  100.     if (Services_Weather::isError($status)) {
  101.         echo "Error: ".$status->getMessage()."\n";
  102.     }
  103. }
  104.  
  105. // Define the units format, bring the retrieved format into
  106. // something more common...
  107. $metar->setUnitsFormat($unitsFormat);
  108. $units = $metar->getUnitsFormat();
  109. $units["temp"]   = "&deg;".strtoupper($units["temp"]);
  110. $units["wind"]   = "&nbsp;".str_replace("kmh", "km/h", $units["wind"]);
  111. $units["vis"]    = "&nbsp;".$units["vis"];
  112. $units["height"] = "&nbsp;".$units["height"];
  113. $units["pres"]   = "&nbsp;".$units["pres"];
  114. $units["rain"]   = "&nbsp;".$units["rain"];
  115.  
  116. $metar->setMetarSource($sourceMetar, $sourcePathMetar, $sourceTaf, $sourcePathTaf);
  117.  
  118. // Set date-/time-format
  119. $metar->setDateTimeFormat($dateFormat, $timeFormat);
  120.  
  121. // Search for defined location and fetch the first item found.
  122. // Bail out if something bad happens...
  123. $search = $metar->searchLocation($location, true);
  124. if (Services_Weather::isError($search)) {
  125.     die("Error: ".$search->getMessage()."\n");
  126. }
  127.  
  128. // Retrieve data, store in variables, bail out on error
  129. $fetch = array(
  130.     "location" => "getLocation",
  131.     "weather"  => "getWeather",
  132.     "forecast" => "getForecast"
  133. );
  134. foreach ($fetch as $variable => $function) {
  135.     $$variable = $metar->$function($search);
  136.     if (Services_Weather::isError($$variable)) {
  137.         echo "Error: ".$$variable->getMessage()."\n";
  138.         continue;
  139.     }
  140. }
  141.  
  142. // Now we output all the data, please don't expect extensive comments here, this is basic
  143. // HTML/CSS stuff. Also this isn't a very fancy design, it's just to show you, what
  144. // the script is able to do (and more ;-))...
  145. ?>
  146. <html>
  147. <head>
  148.     <title>Services_Weather::METAR/TAF</title>
  149.     <style type="text/css">
  150.         .normal     { font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-weight: normal; font-style: normal }
  151.         .italic     { font-weight: normal; font-style: italic }
  152.         .bold       { font-weight: bold; font-style: normal }
  153.         .bolditalic { font-weight: bold; font-style: italic }
  154.         .redbold    { font-weight: bold; font-style: normal; color: #ff0000 }
  155.         .bluebold   { font-weight: bold; font-style: normal; color: #0000ff }
  156.         .bggrey     { background-color: #e9e9e9 }
  157.         .bgkhaki    { background-color: #d8d8c0 }
  158.         .reg        { font-size: 7pt; vertical-align: super }
  159.         img         { vertical-align: middle; border-style: none; border-width: 0px }
  160.         a           { font-weight: bold; font-style: italic; color: #993300; text-decoration: none }
  161.         a:visited   { font-weight: bold; font-style: italic; color: #993300; text-decoration: none }
  162.         a:hover     { font-weight: bold; font-style: italic; color: #cc3300; text-decoration: underline }
  163.         table       { border: 0px none black; border-spacing: 0px }
  164.         td          { font-family: Arial, Helvetica, sans-serif; font-size: 11pt; font-weight: normal; font-style: normal }
  165.     </style>
  166. </head>
  167. <body class="normal">
  168. <?php
  169. // Debug outputs the raw data fetched by the foreach-loop above, just for checking...
  170. if (isset($_GET["debug"])) {
  171.     echo "<pre>\n";
  172.     var_dump($location, $weather, $forecast);
  173.     echo "</pre>\n";
  174. } 
  175. ?>
  176. <span class="bluebold" style="font-size: 13pt">Weather Forecast</span> created with <a style="font-size: 13pt" href="http://pear.php.net/">PEARs</a> <a style="font-size: 13pt" href="http://pear.php.net/package/Services_Weather/">Services_Weather</a><br>
  177. <table style="width: 100%">
  178. <tr>
  179.     <td>
  180.         <table border="0" style="border-top: 2px solid #524b98; border-bottom: 2px solid #e0e3ce; border-left: 2px solid #b8b6c1; border-right: 2px solid #8b87a0; width: 100%">
  181.         <tr class="bgkhaki">
  182.             <td colspan="4" style="border-bottom: 2px solid #abada2"><span class="bold"><?=$location["name"]?> (<?=$search?>)</span></td>
  183.         </tr>
  184.         <tr>
  185.             <td><span class="bold">Sunrise:</span> <img style="width: 28px; height: 13px; vertical-align: baseline" alt="Sunrise" src="images/sunrise.gif"> <?=$location["sunrise"]?></td>
  186.             <td><span class="bold">Sunset:</span> <img style="width: 30px; height: 15px; vertical-align: baseline" alt="Sunset" src="images/sunset.gif"> <?=$location["sunset"]?></td>
  187.             <td style="width: 190px">&nbsp;</td>
  188.             <td style="width: auto">&nbsp;</td>
  189.         </tr>
  190.         <tr style="height: 15px">
  191.             <td nowrap><span class="bold">Temperature:</span> <?=round($weather["temperature"], 1).$units["temp"]?></td>
  192.             <td nowrap><span class="bold">Dew point:</span> <?=round($weather["dewPoint"], 1).$units["temp"]?></td>
  193.             <td nowrap><span class="bold">Felt temperature:</span> <?=round($weather["feltTemperature"], 1).$units["temp"]?></td>
  194.             <td rowspan="4" valign="top">
  195.                 <span class="bold">Trend:</span><br>
  196. <?php
  197. if (isset($weather["trend"]) && sizeof($weather["trend"])) {
  198.     // Output the trends, loop through the arrays,
  199.     // convert the stuff to nice looking design, jadda, jadda...
  200.     foreach ($weather["trend"] as $trend) {
  201.         foreach ($trend as $key => $val) {
  202.             switch ($key) {
  203.                 case "type":
  204.                     switch ($val) {
  205.                         case "NOSIG":
  206.                             $string = "No Significant Weather";
  207.                             break;
  208.                         case "TEMPO":
  209.                             $string = "Temporary Weather";
  210.                             break;
  211.                         case "BECMG":
  212.                             $string = "Weather Becoming";
  213.                             break;
  214.                     }
  215.                     $value  = "";
  216.                     foreach (array("from", "to", "at") as $time) {
  217.                         if (isset($trend[$time])) {
  218.                             $value .= " ".$time." ".$trend[$time];
  219.                         }
  220.                     }
  221.                     ($value != "") ? $value  = trim($value).":":"";
  222.                     $string = '<span class="italic">'.$string.'</span>';
  223.                     $value  = '<span class="italic">'.$value.'</span>';
  224.                     break;
  225.                 case "wind":
  226.                     $string = "Wind:";
  227.                     $value  = (strtolower($trend["windDirection"]) == "calm") ? "Calm" : "From the ".$trend["windDirection"]." (".$trend["windDegrees"]."&deg;) at ".round($trend["wind"], 1).$units["wind"];
  228.                     if (isset($trend["windVariability"])) {
  229.                         $value .= ", variable from ".$trend["windVariability"]["from"]."&deg; to ".$trend["windVariability"]["to"]."&deg;";
  230.                     }
  231.                     if (isset($trend["windGust"])) {
  232.                         $value .= ", with gusts up to ".round($trend["windGust"], 1).$units["wind"];
  233.                     }
  234.                     break;
  235.                 case "visibility":
  236.                     $string = "Visibility:";
  237.                     $value  = strtolower($trend["visQualifier"])." ".round($trend["visibility"], 1).$units["vis"];
  238.                     break;
  239.                 case "clouds":
  240.                     $string = "Clouds:";
  241.                     $value  = "";
  242.                     for ($i = 0; $i < sizeof($val); $i++) {
  243.                         $cloud = ucwords($val[$i]["amount"]);
  244.                         if (isset($val[$i]["type"])) {
  245.                             $cloud .= " ".$val[$i]["type"];
  246.                         }
  247.                         if (isset($val[$i]["height"])) {
  248.                             $cloud .= " at ".$val[$i]["height"].$units["height"];
  249.                         }
  250.                         $value .= $cloud." ";
  251.                     }
  252.                     break;
  253.                 case "condition":
  254.                     $string = "Condition:";
  255.                     $value  = ucwords($val);
  256.                     break;
  257.                 case "pressure":
  258.                     $string = "Pressure:";
  259.                     $value  = round($val, 1).$units["pres"];
  260.                     break;
  261.                 case "from":
  262.                 case "to":
  263.                 case "at":
  264.                 case "windDirection":
  265.                 case "windDegrees":
  266.                 case "windVariability":
  267.                 case "windGust":
  268.                 case "visQualifier":
  269.                     continue 2;
  270.                 default:
  271.                     $string = ""; $value = "";
  272.                     var_dump($key, $val);
  273.                     break;
  274.             }
  275. ?>
  276.                 <?=$string?> <?=$value?><br>
  277. <?php
  278.         }
  279.  
  280.     }
  281. } else {
  282. ?>
  283.                 none<br>
  284. <?php
  285. }
  286. ?>
  287.                 <span class="bold">Remarks:</span><br>
  288. <?php
  289. if (isset($weather["remark"]) && sizeof($weather["remark"])) {
  290.     // Same for the remarks, even less spectacular...
  291.     foreach($weather["remark"] as $key => $val) {
  292.         switch ($key) {
  293.             case "autostation":
  294.             case "presschg":
  295.             case "nospeci":
  296.             case "sunduration":
  297.             case "maintain":
  298.                 $string = "";
  299.                 $value  = $val;
  300.                 break;
  301.             case "seapressure":
  302.                 $string = "Pressure at sealevel:";
  303.                 $value  = round($val, 1).$units["pres"];
  304.                 break;
  305.             case "1htemp":
  306.                 $string = "Temperature for last hour:";
  307.                 $value  = round($val, 1).$units["temp"];
  308.                 break;
  309.             case "1hdew":
  310.                 $string = "Dew Point for last hour:";
  311.                 $value  = round($val, 1).$units["temp"];
  312.                 break;
  313.             case "6hmaxtemp":
  314.             case "6hmintemp":
  315.                 if (!isset($weather["remark"]["6hmaxtemp"]) && !isset($weather["remark"]["6hmintemp"])) {
  316.                     continue(2);
  317.                 }
  318.                 $string = "Max/Min Temp for last 6 hours:";
  319.                 $value  = (isset($weather["remark"]["6hmaxtemp"])) ? round($weather["remark"]["6hmaxtemp"], 1).$units["temp"] : "-";
  320.                 $value .= "/";
  321.                 $value .= (isset($weather["remark"]["6hmintemp"])) ? round($weather["remark"]["6hmintemp"], 1).$units["temp"] : "-";
  322.                 unset($weather["remark"]["6hmaxtemp"]); unset($weather["remark"]["6hmintemp"]);
  323.                 break;
  324.             case "24hmaxtemp":
  325.             case "24hmintemp":
  326.                 if (!isset($weather["remark"]["24hmaxtemp"]) && !isset($weather["remark"]["24hmintemp"])) {
  327.                     continue(2);
  328.                 }
  329.                 $string = "Max/Min Temp for last 24 hours:";
  330.                 $value  = (isset($weather["remark"]["24hmaxtemp"])) ? round($weather["remark"]["24hmaxtemp"], 1).$units["temp"] : "-";
  331.                 $value .= "/";
  332.                 $value .= (isset($weather["remark"]["24hmintemp"])) ? round($weather["remark"]["24hmintemp"], 1).$units["temp"] : "-";
  333.                 unset($weather["remark"]["24hmaxtemp"]); unset($weather["remark"]["24hmintemp"]);
  334.                 break;
  335.             case "snowdepth":
  336.                 $string = "Snow depth:";
  337.                 $value  = $val.$units["rain"];
  338.                 break;
  339.             case "snowequiv":
  340.                 $string = "Water equivalent of snow:";
  341.                 $value  = $val.$units["rain"];
  342.                 break;
  343.             case "sensors":
  344.                 $string = "";
  345.                 $value  = implode("<br>", $val);
  346.                 break;
  347.             default:
  348.                 $string = ""; $value = "";
  349.                 var_dump($key, $val);
  350.                 break;
  351.         }
  352. ?>
  353.                 <?=$string?> <?=$value?><br>
  354. <?php
  355.     }
  356. } else {
  357. ?>
  358.                 none<br>
  359. <?php
  360. }
  361. ?>
  362.             </td>
  363.         </tr>
  364.         <tr style="height: 15px">
  365.             <td colspan="2" style="width: 310px" nowrap><span class="bold">Pressure:</span> <?=round($weather["pressure"], 1).$units["pres"]?></td>
  366.             <td nowrap><span class="bold">Humidity:</span> <?=$weather["humidity"]?>%</td>
  367.         </tr>
  368.         <tr style="height: 15px">
  369.             <td colspan="2" nowrap>
  370.                 <span class="bold">Wind:</span> <?=strtolower($weather["windDirection"]) == "calm" ? "Calm" : "From the ".$weather["windDirection"]." (".$weather["windDegrees"]."&deg;) at ".round($weather["wind"], 1).$units["wind"]?> 
  371.                 <?=isset($weather["windVariability"]) ? "<br>variable from ".$weather["windVariability"]["from"]."&deg; to ".$weather["windVariability"]["to"]."&deg;" : ""?> 
  372.                 <?=isset($weather["windGust"]) ? "<br>with gusts up to ".round($weather["windGust"], 1).$units["wind"] : ""?> 
  373.             </td>
  374.             <td valign="top" nowrap><span class="bold">Visibility:</span> <?=strtolower($weather["visQualifier"])?> <?=round($weather["visibility"], 1).$units["vis"]?></td>
  375.         </tr>
  376.         <tr>
  377.             <td><span class="bold">Current condition:</span><br><?=isset($weather["condition"]) ? ucwords($weather["condition"]) : "No Significant Weather"?></td>
  378.             <td><img style="height: 32px; width: 32px" alt="<?=isset($weather["condition"]) ? ucwords($weather["condition"]) : "No Significant Weather"?>" src="images/32x32/<?=$weather["conditionIcon"]?>.png"></td>
  379. <?php
  380. if (isset($weather["precipitation"]) && sizeof($weather["precipitation"])) {
  381.     // Output a line for each type of precipitation,
  382.     // distinguish between string and numeric values
  383. ?>
  384.                 <br><span class="bold">Precipitation:</span><br>
  385. <?php
  386.     for ($i = 0; $i < sizeof($weather["precipitation"]); $i++) {
  387.         $precip = "last ".$weather["precipitation"][$i]["hours"]."h: ".$weather["precipitation"][$i]["amount"];
  388.         $precip .= (ctype_alpha($weather["precipitation"][$i]["amount"])) ? "" : $units["rain"];
  389. ?>
  390.                 <?=$precip?><br>
  391. <?php
  392.     }
  393. }
  394. ?>
  395.             </td>
  396.             <td valign="top">
  397.                 <span class="bold">Clouds:</span><br>
  398. <?php
  399. if (isset($weather["clouds"]) && sizeof($weather["clouds"])) {
  400.     // Yeah, clouds... same as in the trend handling...
  401.     for ($i = 0; $i < sizeof($weather["clouds"]); $i++) {
  402.         $cloud = ucwords($weather["clouds"][$i]["amount"]);
  403.         if (isset($weather["clouds"][$i]["type"])) {
  404.             $cloud .= " ".$weather["clouds"][$i]["type"];
  405.         }
  406.         if (isset($weather["clouds"][$i]["height"])) {
  407.             $cloud .= " at ".$weather["clouds"][$i]["height"].$units["height"];
  408.         }
  409. ?>
  410.                 <?=$cloud?><br>
  411. <?php
  412.     }
  413. } else {
  414. ?>
  415.                 Clear Below <?=$metar->convertDistance(12000, "ft", $units["height"]).$units["height"]?> 
  416. <?php
  417. }
  418. ?>
  419.             </td>
  420.         </tr>
  421.         </table>
  422.     </td>
  423. </tr>
  424. <tr>
  425.     <td>
  426.         <table style="border-top: 2px solid #524b98; border-bottom: 2px solid #e0e3ce; border-left: 2px solid #b8b6c1; border-right: 2px solid #8b87a0; width: 100%">
  427.         <tr class="bgkhaki">
  428.             <td colspan="3" align="center" style="border-bottom: 2px solid #abada2"><span class="bold">Forecast (TAF)</span><br>valid from <span class="bold"><?=$forecast["validFrom"]?></span> to <span class="bold"><?=$forecast["validTo"]?></span></td>
  429.         </tr>
  430.         <tr valign="top">
  431.             <td colspan="3">
  432.                 <table style="width: 100%">
  433.                 <tr>
  434.                     <td align="center" class="bgkhaki" style="height: 15px; border-top: 2px solid #d8d8c0; border-right: 2px solid #8b87a0; border-left: 2px solid #d8d8c0">&nbsp;</td>
  435.                     <td align="center" style="width: 18%"><span class="bold">Meteorological Conditions</span></td>
  436.                     <td align="center" style="width: 18%" class="bggrey"><span class="bold">Wind</span></td>
  437.                     <td align="center" style="width: 18%"><span class="bold">Visibility</span></td>
  438.                     <td align="center" style="width: 18%" class="bggrey"><span class="bold">Clouds</span></td>
  439.                     <td align="center" style="width: 18%"><span class="bold">Condition</span></td>
  440.                 </tr>
  441. <?php
  442. $times = array_keys($forecast["time"]);
  443. $pre   = array("wind" => 0, "vis" => 0, "clouds" => 0, "cond" => 0);
  444. // Ok, the forecast is a bit more interesting, as I'm taking a few
  445. // precautions here so that the table isn't filled up to the max.
  446. // o If a value is repeated in the next major timeslot (not when
  447. //   significant weather changes are processed), it's not printed
  448. // o Significant weather gets its own rows, with times printed normal
  449. //   as in opposition to bold print for major timeslots
  450. // o The while($row)-construct below is for handling the significant
  451. //   weather, as I point $row to $row["fmc"] afterwards, where the
  452. //   smaller changes are mentioned
  453. for ($i = 0; $i < sizeof($forecast["time"]); $i++) {
  454.     $row = $forecast["time"][$times[$i]];
  455.  
  456.     // Create timestamp
  457.     $start = $times[$i];
  458.     if ($i + 1 < sizeof($forecast["time"])) {
  459.         $end = $times[$i + 1];
  460.     } else {
  461.         $end = substr($forecast["validRaw"], -2).":00";
  462.         $end = ($end == "24:00") ? "00:00" : $end;
  463.     }
  464.     $time    = $start." - ".$end;
  465.     $class   = ' class="bold"';
  466.     // This is for outputting "Becoming", "Temporary" and such
  467.     $fmc     = isset($row["fmc"]) ? $row["fmc"] : false; 
  468.     $fmctype = "";
  469.     $fmccnt  = 0;
  470.  
  471.     while ($row) {
  472. ?>
  473.                 <tr class="bgkhaki">
  474.                     <td style="height: 1px; empty-cells: show; border-right: 2px solid #8b87a0; border-left: 2px solid #d8d8c0"></td>
  475.                     <td style="height: 1px" colspan="5"></td>
  476.                 </tr>
  477.                 <tr>
  478.                     <td align="center" class="bgkhaki" style="border-right: 2px solid #8b87a0; border-left: 2px solid #d8d8c0" nowrap><span<?=$class?>><?=$time?></span></td>
  479.                     <td align="center"><?=$fmctype?></td>
  480. <?php
  481.         // This loops through the available data and processes it
  482.         // for output, the different methods were already used above
  483.         // (Only difference is the checking for the pre-values.)
  484.         foreach(array("wind", "vis", "clouds", "cond") as $val) {
  485.             switch ($val) {
  486.                 case "wind":
  487.                     if (!isset($row["windDirection"])) {
  488.                         $string = "&nbsp;";
  489.                     } else {
  490.                         $string = strtolower($row["windDirection"]) == "calm" ? "Calm" : "From the ".$row["windDirection"]." (".$row["windDegrees"]."&deg;)<br>at ".round($row["wind"], 1).$units["wind"];
  491.                         if (isset($row["windProb"])) {
  492.                             $string .= " (".$row["windProb"]."%&nbsp;Prob.)";
  493.                         }
  494.                         if ($string === $pre["wind"]) {
  495.                             $string = "&nbsp;";
  496.                         } else {
  497.                             $pre["wind"] = $string;
  498.                         }
  499.                     }
  500.                     $class = ' class="bggrey"';
  501.                     break;
  502.                 case "vis":
  503.                     if (!isset($row["visibility"])) {
  504.                         $string = "&nbsp;";
  505.                     } else {
  506.                         $string = strtolower($row["visQualifier"])." ".round($row["visibility"], 1).$units["vis"];
  507.                         if (isset($row["visProb"])) {
  508.                             $string .= " (".$row["visProb"]."%&nbsp;Prob.)";
  509.                         }
  510.                         if ($string === $pre["vis"]) {
  511.                             $string = "&nbsp;";
  512.                         } else {
  513.                             $pre["vis"] = $string;
  514.                         }
  515.                     }
  516.                     $class = '';
  517.                     break;
  518.                 case "clouds":
  519.                     if (!isset($row["clouds"])) {
  520.                         $string = "&nbsp;";
  521.                     } else { 
  522.                         $clouds  = "";
  523.                         for ($j = 0; $j < sizeof($row["clouds"]); $j++) {
  524.                             $cloud = ucwords($row["clouds"][$j]["amount"]);
  525.                             if (isset($row["clouds"][$j]["type"])) {
  526.                                 $cloud .= " ".$row["clouds"][$j]["type"];
  527.                             }
  528.                             if (isset($row["clouds"][$j]["height"])) {
  529.                                 $cloud .= " at ".$row["clouds"][$j]["height"].$units["height"];
  530.                             }
  531.                             if (isset($row["clouds"][$j]["prob"])) {
  532.                                 $cloud .= " (".$row["clouds"][$j]["prob"]."%&nbsp;Prob.)";
  533.                             }
  534.                             $clouds .= $cloud."<br>";
  535.                         }
  536.                         if ($clouds === $pre["clouds"]) {
  537.                             $string = "&nbsp;";
  538.                         } else {
  539.                             $string        = $clouds;
  540.                             $pre["clouds"] = $clouds;
  541.                         }
  542.                     }
  543.                     $class = ' class="bggrey"';
  544.                     break;
  545.                 case "cond":
  546.                     if (!isset($row["condition"]) || (isset($prerow) && $prerow["condition"] == $row["condition"])) {
  547.                         $string = "&nbsp;";
  548.                     } else {
  549.                         $string = ucwords($row["condition"]);
  550.                     }
  551.                     $class = '';
  552.             }
  553. ?>
  554.                     <td valign="top"<?=$class?>><?=$string?></td>
  555. <?php
  556.         }
  557. ?>                    
  558.                 </tr>
  559. <?php
  560.         // Now check for significant weather changes and move
  561.         // the row accordingly... maybe ugly coding, but this
  562.         // is for showing design, not for fany programming ;-)
  563.         if ($fmc && $fmccnt < sizeof($fmc)) {
  564.             $row     = $fmc[$fmccnt];
  565.             $fmccnt++;
  566.             $fmctype = $row["type"];
  567.             // Check if we have a timestamp, don't output if it's
  568.             // the same as the major-timeslot
  569.             if (!isset($row["from"]) || $row["from"]." - ".$row["to"] == $time) {
  570.                 $time = "&nbsp;";
  571.             } else {
  572.                 $time    = $row["from"]." - ".$row["to"];
  573.             }
  574.             switch ($row["type"]) {
  575.                 case "PROB":
  576.                     $fmctype = "";
  577.                     break;
  578.                 case "TEMPO":
  579.                     $fmctype = "Temporary";
  580.                     break;
  581.                 case "BECMG":
  582.                     $fmctype = "Becoming";
  583.                     break;
  584.             }
  585.             if (isset($row["probability"])) {
  586.                 $fmctype .= " (".$row["probability"]."%&nbsp;Prob.)";
  587.             }
  588.         } else {
  589.             $row = false;
  590.         }
  591.     }
  592. }
  593. ?>                
  594.                 <tr>
  595.                     <td class="bgkhaki" style="height: 1px; empty-cells: show; border-bottom: 2px solid #d8d8c0; border-left: 2px solid #d8d8c0; border-right: 2px solid #8b87a0"></td>
  596.                     <td style="height: 1px" colspan="5"></td>
  597.                 </tr>
  598.                 </table>
  599.             </td>
  600.         </tr>
  601.         <tr class="bgkhaki">
  602.             <td style="width: 93px; border-top: 2px solid #abada2">&nbsp;</td>
  603.             <td style="border-top: 2px solid #abada2">Updated: (<?=substr($weather["update"], -5)?>&nbsp;/&nbsp;<?=substr($forecast["update"], -5)?>)</td>
  604.             <td style="border-top: 2px solid #abada2" align="right">All times UTC</td>
  605.         </tr>
  606.         </table>
  607.     </td>
  608. </tr>
  609. </table>
  610. <a href="javascript:history.back()">back</a>
  611. </body>
  612. </html>

Documentation generated on Mon, 11 Mar 2019 14:37:51 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.