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

Documentation generated on Mon, 11 Mar 2019 13:56:23 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.