\n"; // Establish timezone offset for time display putenv("TZ=$ourTZ"); // set our timezone for 'as of' date on file // ---------------------main program ----------------------------------- // open and read links file global $Debug,$doDebug,$cacheName,$refetchSeconds,$Icons,$windArrowDir,$wxInfo, $metarPtr, $group; $updatedOn = filemtime($LinksFile); // for our 'as of' date $updatedOnG = filemtime($Graphic); // for graphic file $Stations = array(); // storage area for the station info $StationData = array(); // storage area for current conditions $StationStats = array(); // storage for fetch stats for station $wxInfo = array(); $timeStamp = time(); $currentTime = date($timeFormat,$timeStamp); load_config($LinksFile); // load up the $Stations from the config file // show jpg image of map with hotspots outlined if (isset($_REQUEST['show']) and strtolower($_REQUEST['show']) == 'map' ) { $ShowMap = '&show=map'; $genJPEG = 1; } else { $ShowMap = ''; // no outlines for map $genJPEG = 0; } // show image of map with hotspots outlined if (isset($_REQUEST['show']) and strtolower($_REQUEST['show']) == 'hotspots' ) { $ourGraphic = $SCRIPT_URI . "?show=map"; $toggleState = "Now showing Hotspots -- click to show normal graphic.\n"; } else { $ourGraphic = $Graphic; // no outlines for map $toggleState = "Now showing normal graphic -- click to show hotspots outlined.\n"; } if ($genJPEG) { // just produce the map with hotspots outlined outline_hotspots($ourGraphic); exit; } load_strings(); // Load up the CSS and boilerplates $Units = load_units('E'); gen_CSS(); // generate the CSS first if ($CSSonly) { // just print the CSS and exit print $CSS; return; } load_iconDefs(); // create definitions for condition icons load_weather_data(); // this is the time consumer :-) reset($Stations); // and reset the list from the config file $lastState = ''; // to handle the sublists // generate the links list sorted by State, Station name while (list($key, $val) = each($Stations)) { list($State,$Name) = explode("\t",$key); list($URL,$Coords,$Features,$DataPage) = explode("\t",$Stations["$key"]); if ($lastState <> $State) { if ($lastState) { // not first state $html .= " \n"; $html .= " \n"; } $html .= "
  • $State\n"; $html .= '
      ' . "\n"; $lastState = $State; } // different state $t = ''; if ($TARGET) {$t = " $TARGET";} $html .= "
    1. $Name [ " . $Features . " ]
    2. \n"; } // end while $html .= "
    \n"; $html .= "
  • \n"; $html .= "\n"; // generate the MAP list sorted by State, Station name $html .= '' . "\n"; prt_tablehead(); // initialize the $table area with col heads reset($Stations); // and reset the list so we can start at begining $lastState = ''; // to handle the sublists while (list($key, $val) = each($Stations)) { list($State,$Name) = explode("\t",$key); list($URL,$Coords,$Features,$DataPage) = explode("\t",$Stations["$key"]); prt_tabledata($key); if ($lastState <> $State) { $html .= "\n"; $lastState = $State; } $t = ''; if ($TARGET) {$t = "\n $TARGET";} $html .= " \""\n"; } // end while // --------------- customize HTML if you like ----------------------- $table .= "\n\n

     

    \n"; // finish up the CSS/HTML assembly strings $html .= "
    \n"; $scroller .= " \n"; $table .= "\n"; // text is done now in $html if ($PrintMode and ! $includeOnly and ! $genJPEG) { // print headers only if inc parm omitted ?> Generate RMWN mesomap code - <?php echo $Version ?>

    Link generation utility for Rocky Mountain Weather Network mesomap -

    Detailed instructions on how to implement/maintain on your website are available here.

    New PHP users: You can download a starter .zip file, unpack it and upload to your website. It includes all files required by the script and the proper subdirectory structure (for ./RMWN-images/). Then you can use the links below to refresh the components.

    PHP users: Download graphic file updated on " . date($timeFormat,$updatedOnG) . "
        (Right click on link above and save to $Graphic on your offline copy of your website,
         then upload it to your website).
    PHP users: Download data file updated on " . date($timeFormat,$updatedOn) . "
        (Right click on link above and save to $LinksFile on your website)
    PHP users: If needed, download PHP source for $scriptName $Version.
        (Note: only needed if your copy of the script is older than this one)
        (Right click on link above, then save page as RMWN-mesomap.php on your website).

    HTML users: Please use the IFRAME method to include the mesomap in your HTML-only website.

    Top of page | Preview of code

    "; print "

    Preview of RMWN meso-map

    \n

    $toggleState

    \n"; print $htmlstart . $ourGraphic . $htmlnext . $scroller . $html; print prt_jscript(); print $table; if ($doDebug) { print $Debug; } print '

    Generating '; if ($TARGET <> '') { print "HTML 4.01"; $toggleGenState = "XHTML 1.0-Strict"; } else { print "XHTML 1.0-Strict"; $toggleGenState = "HTML 4.01"; } print ' code (change to '. $toggleGenState . ')

    '; $scriptName = substr($PHP_SELF,1); print "

    Top of page | Preview of code

    Generated by $scriptName - $Version
    Author: Ken True - webmaster@saratoga-weather.org

    "; } else if ($PrintMode) { // if including .. just print it print $htmlstart . $ourGraphic . $htmlnext . $scroller . $html; print prt_jscript(); print $table; if ($doDebug) {print $Debug; } } else { // end of if not includeOnly $RMWN_MAP = $htmlstart . $ourGraphic . $htmlnext . $scroller . $html . prt_jscript(); $RMWN_TABLE = $table; $RMWN_CSS = $CSS; if ($doDebug) {$RMWN_TABLE .= $Debug; } } return; //-------------------end of main program ------------------- //----------------------------functions ----------------------------------- // Generate CSS for positioning rollover conditions display function gen_CSS () { global $CSS, $Stations, $LegendX, $LegendY; $Top = 35; // default location for values legend on map $Left = 350; if ($LegendX) {$Left = $LegendX;} if ($LegendY) {$Top = $LegendY;} //------------customize this CSS entry for font/color/background for legend $CSS .= "#mesolegend { top: ${Top}px; left: ${Left}px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14pt; font-weight: bold; color: #FFFFFF; padding: 6px 6px; border: 1px solid white; } "; while (list($key, $val) = each($Stations)) { list($State,$Name,$Seqno) = explode("\t",$key); list($URL,$Coords,$Features,$DataPage,$RawDataType,$RawDataURL,$Offsets) = explode("\t",$Stations["$key"]); $URLparts = parse_url($URL); $host = $URLparts['host']; $hostalias = preg_replace('/www\.|\.\w{3}|\W/s','',$host); $hostalias = preg_replace('/weather/','wx',$hostalias); $hostalias .= "S$Seqno"; // generate the CSS to place the rotating display over the map $Coords = preg_replace("|\s|is","",$Coords); list($Left,$Top,$Right,$Bottom) = explode(",",$Coords . ',,,,'); list($OLeft,$OTop) = explode(",",$Offsets . ',,'); if (! $Offsets) { // use default positioning $Top = $Top - 2; $Left = $Right + 2; } else { // use relative positioning from bottom/left $Top = $Bottom + $OTop; $Left = $Right + $OLeft; } $CSS .= "#$hostalias { top: ${Top}px; left: ${Left}px; } "; } // end while $Stations $CSS .= "\n\n"; reset($Stations); // and reset the list return; } // end gen_CSS // ------------------------------------------------------------------ // produce the table heading row function prt_tablehead ( ){ global $Units, $table, $scroller, $CSS, $LegendX, $LegendY; // --------------- customize HTML if you like ----------------------- $table .= "

    Note: Click on table column heading below to sort table by that column's values.

    "; $scroller .= "

     Temperature   Humidity   Wind from direction @ Speed   Rain today   Barometer & Trend   Current Conditions   Fire Danger based on 
     Chandler Burning Index 

    \n"; $scroller .= '



    '; return; } // end function prt_tablehead // ------------------------------------------------------------------ // produce one row of current conditions data function prt_tabledata($key) { global $StationData,$Stations,$Units,$table,$scroller,$CSS,$skipNoData,$windArrowDir,$showNoData,$TARGET, $windArrowSize,$StationStats,$Icons,$condIconsDir, $IconsText, $showBaroTrendArrow, $showMapCondIcons, $NAtext; ; if ($skipNoData && ! isset($StationData["$key"])) { return; } list($State,$Name,$Seqno) = explode("\t",$key); list($URL,$Coords,$Features,$DataPage,$RawDataType,$RawDataURL) = explode("\t",$Stations["$key"]); $URLparts = parse_url($URL); $host = $URLparts['host']; $hostalias = preg_replace('/www\.|\.\w{3}|\W/s','',$host); $hostalias = preg_replace('/weather/','wx',$hostalias); $hostalias .= "S$Seqno"; if ($windArrowSize == 'S') { $windGIF = '-sm.gif'; $windSIZE = 'height="9" width="9"'; } else { $windGIF = '.gif'; $windSIZE = 'height="14" width="14"'; } if (! isset($StationData["$key"])) { if ($showNoData) { $table .= " "; } // end showNoData //---------------------------- $scroller .= "

    $NAtext $NAtext $NAtext $NAtext $NAtext $NAtext $NAtext

    \n"; //---------------------------- return; } // got data for one of our stations.. format the table entry list($TEMP,$HUMID,$WDIR,$WSPD,$RAIN,$BARO,$BTRND,$COND,$CTXT,$FTIME) = preg_split("/\,/",$StationData["$key"]); // --------------- customize HTML if you like ----------------------- $t = ''; if ($TARGET) {$t = " $TARGET";} $table .= " \n"; // generate the data for the changing conditions display // NOTE: changes here may break the rotating conditions display.. $scroller .= "

    $TEMP " . $Units['temp'] . " $HUMID " . $Units['humid'] . " "; $wda = ''; if ($WDIR <> 'n/a') { $wda = $WDIR; if ($windArrowDir) { $scroller .= "\"Wind"; } $scroller .= $WDIR . " " . $WSPD . " " . $Units['wind'] ; } else { $scroller .= $WDIR; } $scroller .= " $RAIN ". $Units['rain'] . " "; if ($BARO <> '') { $scroller .= "$BARO ". $Units['baro']; if ($showBaroTrendArrow) { $scroller .= getBaroTrendArrow($BTRND); } else { list($t,$q) = explode(" ",$BTRND); $scroller .= " $BTRND"; } } $scroller .= " "; if ($showMapCondIcons and preg_match('|.gif$|',$COND) && $condIconsDir) { $scroller .= "\"$CTXT\" "; } list($mt,$t) = explode(":",$CTXT . '::'); if ($t <> '') { $scroller .= trim($t); } else { $scroller .= trim($mt); } $scroller .= " "; $scroller .= getFireDanger($TEMP,$HUMID) ; // Fire danger word+CBI $scroller .= "

    \n"; return; } // end prt_tabledata // ------------------------------------------------------------------ // load JPG image for hotspot work function loadJPEG ($imgname) { $im = @imagecreatefromjpeg ($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreate (150, 30); /* Create a blank image */ $bgc = imagecolorallocate ($im, 255, 255, 255); $tc = imagecolorallocate ($im, 0, 0, 0); imagefilledrectangle ($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc); } return $im; } // ------------------------------------------------------------------ // load the configuration file and set up $Stations function load_config($LinksFile) { global $Stations; $rawlinks = file($LinksFile); // read file into array // strip comment records, build $Stations indexed array $nrec = 0; $Seqno = 0; foreach ($rawlinks as $rec) { $Seqno++; $rec = preg_replace("|[\n\r]*|","",$rec); $len = strlen($rec); if($rec and substr($rec,0,1) <> "#") { //only take non-comments // echo "Rec $nrec ($len): $rec\n"; list($State,$URL,$Name,$Coords,$Features,$DataPage,$RawDataType,$RawDataURL,$Offsets,$METAR) = explode("|",trim($rec) . '|||||||||||'); $Stations["$State\t$Name\t$Seqno"] = "$URL\t$Coords\t$Features\t$DataPage\t$RawDataType\t$RawDataURL\t$Offsets\t$METAR"; // prepare for sort // echo "$Name $State, coord=\"$Coords\"\n"; } elseif (strlen($rec) > 0) { // echo "comment $nrec ($len): $rec\n"; } else { // echo "blank record ignored\n"; } $nrec++; } ksort($Stations); // now sort the keys (state, station name) } // ------------------------------------------------------------------ // fetch the weather data from stations and place in $StationData function load_weather_data() { global $Stations,$StationData,$StationRawData,$Debug,$maxAge, $cacheName,$refetchSeconds,$masterCacheURL,$onMasterHost,$StationStats,$timeFormat; // use cache if current and available if ($cacheName and file_exists($cacheName) and filemtime($cacheName) + $refetchSeconds > time()) { $Debug .= "\n"; $rawcache = file($cacheName); foreach ($rawcache as $rec) { list($key,$val) = explode('|',trim($rec)); $StationData["$key"] = $val; } return; } // Fetch master cache data if available if ($masterCacheURL <> '' and ! $onMasterHost) { $Debug .= "\n"; $rawcache = fetchURLWithoutHanging($masterCacheURL,false); list($headers,$content) = explode("\r\n\r\n",$rawcache); $cache = explode("\n",$content); $html = ''; if ($cache) { foreach ($cache as $rec) { $html .= trim($rec) . "\n"; list($key,$val) = explode('|',trim($rec)); $StationData["$key"] = $val; } $fp = fopen($cacheName, "w"); if (! $fp ) { $Debug .= "\n"; } else { $write = fputs($fp, $html); fclose($fp); $Debug .= "\n"; } return; } else { // failed to get master cache so have to load the hard way $Debug .= "\n"; } } $total_time = 0; while (list($key, $val) = each($Stations)) { list($State,$Name) = explode("\t",$key); list($URL,$Coords,$Features,$DataPage,$RawDataType,$RawDataURL,$Offsets,$METAR) = explode("\t",$Stations["$key"]); if (! $RawDataURL && $DataPage) { // fetch datapage instead $RawDataType = 'SWN'; $RawDataURL = "$DataPage"; } if(preg_match('|^http|i',$RawDataURL)) { // do nothing.. url fully formed } else { $URLparts = parse_url($URL); $RawDataURL = 'http://' . $URLparts['host'] . '/' . $RawDataURL; } if($RawDataURL && $RawDataType ) { $Debug .= "\n\n"; $useFopen = false; if ($RawDataType == 'STF' || $RawDataType == 'CRF') { $useFopen = true; } $time_start = microtime_float(); $rawhtml = fetchUrlWithoutHanging($RawDataURL,$useFopen); $time_stop = microtime_float(); $total_time += ($time_stop - $time_start); $time_fetch = sprintf("%01.3f",round($time_stop - $time_start,3)); $RC = ''; if (preg_match("|^HTTP\/\S+ (.*)\r\n|",$rawhtml,$matches)) { $RC = trim($matches[1]); } $Debug .= "\n"; // list($headers,$content) = explode("\r\n\r\n",$rawhtml); // split headers from html $i = strpos($rawhtml,"\r\n\r\n"); $headers = substr($rawhtml,0,$i-1); $content = substr($rawhtml,$i+2); $html = explode("\n",$content); // put HTML area as separate lines $age = 0; if(preg_match('|\nLast-Modified: (.*)\n|Ui',$headers,$match)) { $udate = trim($match[1]); $age = abs(time() - strtotime($udate)); // age in seconds $Debug .= "\n"; } $metric = implode('',$html); // now put as one long string $metric = preg_replace('|<[^>]+>|is','',$metric); // clean out any HTML markup $metric = preg_replace('|\s+,|is',',',$metric); // clean out unwanted spaces $metric = trim($metric); // stickertag metric should be ok $Debug .= "\n"; if (! preg_match('|^\d|',$metric)) { $Debug .= "\n"; } else { if ($age <= $maxAge) { $StationData["$key"] = parse_data($metric,$RawDataType,$METAR) . ",$time_fetch"; // save away the raw values $Debug .= "\n\n"; } else { $Debug .= "\n\n"; } } } // if $RawDataURL $localUdate = date($timeFormat,strtotime($udate)); // $StationStats["$key"] = "$RawDataType\t$time_fetch\t$age\t$localUdate"; } // end while $Debug .= "\n"; if ($cacheName <> '') { // create cache of values $html = ''; while (list($key, $val) = each($StationData)) { $html .= $key . "|" . $val . "\n"; } $fp = fopen($cacheName, "w"); if (! $fp ) { $Debug .= "\n"; } else { $write = fputs($fp, $html); fclose($fp); $Debug .= "\n"; } } } // ------------------------------------------------------------------ function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } // ------------------------------------------------------------------ // ------------------------------------------------------------------ function parse_data($metric,$RawDataType,$METAR) { global $Debug,$Icons,$IconsText; // from the returned data, select the variables we'll use if ($RawDataType == 'ST' || $RawDataType == 'STF') { // a stickertag format // 0: , // 1: , // 2: , // 3: , // 4: , // 5: , // 6: , // 7: , // 8: , // 9: , //10: , //11: //'12:44pm,7/3/06,99,101,97,31,63,29.90,Falling,2,SE,0.00,3' $v = explode(",",$metric); $TEMP = round(trim($v[2]),0); $HUMID= trim($v[5]); $WDIR = split(" ",trim($v[10])); $WDIR = $WDIR[0]; // handle spaces in wind-dir from edhweather if (preg_match('|\d+|',$WDIR)) { $Debug .= "\n"; $host = 'weather.noaa.gov'; $path = '/pub/data/observations/metar/stations/'; $MetarURL = 'http://' . $host . $path . $icao . '.TXT'; $time_start = microtime_float(); $rawhtml = fetchUrlWithoutHanging($MetarURL,false); list($headers,$html) = explode("\r\n\r\n",$rawhtml); $time_stop = microtime_float(); $total_time += ($time_stop - $time_start); $time_fetch = sprintf("%01.3f",round($time_stop - $time_start,3)); $Debug .= "\n"; $raw_metar = ereg_replace("[\n\r ]+", ' ', trim(implode(' ', (array)$html))); $Debug .= "\n"; $metar = trim($raw_metar); $metarDate = preg_replace('|/|','-',substr($metar,0,16)) . ':00 GMT'; $age = abs(time() - strtotime($metarDate)); // age in seconds $Debug .= "\n"; if ($age >= $maxAgeMetar) { $Debug .= "\n"; return('' . '|' . ''); } error_reporting(E_ALL); process_metar($metar,$icao); error_reporting(0); $Debug .= "\n"; $Sky = trim($wxInfo['CLOUDS']); $Weather = trim($wxInfo['CONDITIONS']); if ($Sky && $Weather) { $Sky = $Weather; } if ($Sky && ! $Weather) { $Weather = $Sky; } return($Sky . '|' . $Weather); } // end getMetar functions // ------------------------------------------------------------ // get contents from one URL and return as string function fetchUrlWithoutHanging($url,$useFopen) { // thanks to Tom at Carterlake.org for this script fragment global $Debug; if (! $useFopen) { // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed $numberOfSeconds=4; // Suppress error reporting so Web site visitors are unaware if the feed fails error_reporting(0); // Extract resource path and domain from URL ready for fsockopen $FullUrl = $url; $url = str_replace("http://","",$url); $urlComponents = explode("/",$url); $domain = $urlComponents[0]; $resourcePath = str_replace($domain,"",$url); $Debug .= "\n"; // Establish a connection $socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds); if (!$socketConnection) { // You may wish to remove the following debugging line on a live Web site // print(""); } // end if else { $xml = ''; fputs($socketConnection, "GET $resourcePath HTTP/1.0\r\nHost: $domain\r\nConnection: close\r\nUser-agent: RMWN-mesomap V2.0\r\n\r\n"); // Loop until end of file while (!feof($socketConnection)) { $xml .= fgets($socketConnection, 4096); } // end while fclose ($socketConnection); } // end else return($xml); } else { // print "\n"; $xml = implode('',file($url)); return($xml); } } // end fetchUrlWithoutHanging // ------------------------------------------------------------------ // load the image and draw hotspots on it function outline_hotspots($Graphic) { global $Stations; $image = loadJPEG($Graphic); // fetch our map image $color = imagecolorallocate($image, 0, 255, 0); $MaxX = imagesx($image); $MaxY = imagesy($image); while (list($key, $val) = each($Stations)) { //write each hotspot list($State,$Name) = explode("\t",$key); list($URL,$Coords,$Features) = explode("\t",$Stations["$key"]); list($X1,$Y1,$X2,$Y2) = explode(",",$Coords); // make sure images in top-left, bottom-right order if($X1 > $X2) { $tmp = $X2; $X2 = $X1; $X1 = $tmp; } if($Y1 > $Y2) { $tmp = $Y2; $Y2 = $Y1; $Y1 = $tmp; } imagerectangle($image, $X1, $Y1, $X2, $Y2, $color); } $msg = "Green rectangles outline the hotspots on the image map. DON'T SAVE THIS IMAGE."; imagestring($image, 3, 45, 2, $msg, $color); header("Content-type: image/jpeg"); // now send to browser imagejpeg($image); imagedestroy($image); } // ------------------------------------------------------------------ function getFireDanger( $ftemp, $rh) { // from SLOWeather.com = calculate fire danger based on temperature and relative humidity // Convert F temp to C temp $ctemp = ($ftemp - 32) * 0.5556; // Start Index Calcs // Chandler Index $cbi = (((110 - 1.373 * $rh) - 0.54 * (10.20 - $ctemp)) * (124 * pow(10,(-0.0142*"$rh"))))/60; // CBI = (((110 - 1.373*RH) - 0.54 * (10.20 - T)) * (124 * 10**(-0.0142*RH)))/60 //Sort out the Chandler Index $cbitextcolor = "white"; if ($cbi > "97.5") { $cbitxt = "Extreme"; $cbicolor = "red"; $cbiimg= "fdl_extreme.gif"; } elseif ($cbi >="90") { $cbitxt = "Very High"; $cbicolor = "orange"; $cbitextcolor = "black"; $cbiimg= "fdl_vhigh.gif"; } elseif ($cbi >= "75") { $cbitxt = "High"; $cbicolor = "yellow"; $cbitextcolor = "black"; $cbiimg= "fdl_high.gif"; } elseif ($cbi >= "50") { $cbitxt = "Moderate"; $cbicolor = "blue"; $cbiimg= "fdl_moderate.gif"; } else { $cbitxt="Low"; $cbicolor = "green"; $cbiimg= "fdl_low.gif"; } $val = ' ' . $cbitxt . ' '; return("$val"); // (CBI " . round($cbi,0) . ")"); } // ------------------------------------------------------------------ // convert degrees into wind direction abbreviation function getWindDir ($degrees) { // figure out a text value for compass direction $winddir = $degrees; if ($winddir == "n/a") { return($winddir); } switch (TRUE) { case (($winddir >= 349) and ($winddir <= 360)): $winddir = 'N'; break; case (($winddir >= 0) and ($winddir <= 11)): $winddir = 'N'; break; case (($winddir > 11) and ($winddir <= 34)): $winddir = 'NNE'; break; case (($winddir > 34) and ($winddir <= 56)): $winddir = 'NE'; break; case (($winddir > 56) and ($winddir <= 78)): $winddir = 'ENE'; break; case (($winddir > 78) and ($winddir <= 101)): $winddir = 'E'; break; case (($winddir > 101) and ($winddir <= 124)): $winddir = 'ESE'; break; case (($winddir > 124) and ($winddir <= 146)): $winddir = 'SE'; break; case (($winddir > 146) and ($winddir <= 169)): $winddir = 'SSE'; break; case (($winddir > 169) and ($winddir <= 191)): $winddir = 'S'; break; case (($winddir > 191) and ($winddir <= 214)): $winddir = 'SSW'; break; case (($winddir > 214) and ($winddir <= 236)): $winddir = 'SW'; break; case (($winddir > 236) and ($winddir <= 259)): $winddir = 'WSW'; break; case (($winddir > 259) and ($winddir <= 281)): $winddir = 'W'; break; case (($winddir > 281) and ($winddir <= 304)): $winddir = 'WNW'; break; case (($winddir > 304) and ($winddir <= 326)): $winddir = 'NW'; break; case (($winddir > 326) and ($winddir <= 349)): $winddir = 'NNW'; break; } // end switch // return("$winddir ($degrees° true)"); return("$winddir"); } // end function getWindDir // ------------------------------------------------------------------ function set_barotrend($baromtrend) { // routine from Anole's wxsticker PHP (adapted) // Barometric Trend(3 hour) // Change Rates // Rapidly: =.06" H; 1.5 mm Hg; 2 hPa; 2 mb // Slowly: =.02" H; 0.5 mm Hg; 0.7 hPa; 0.7 mb // 5 Arrow Positions: // Rising Rapidly // Rising Slowly // Steady // Falling Slowly // Falling Rapidly // Page 52 of the PDF Manual // http://www.davisnet.com/product_documents/weather/manuals/07395.234-VP2_Manual.pdf // figure out a text value for barometric pressure trend settype($baromtrend, "float"); switch (TRUE) { case (($baromtrend >= -.6) and ($baromtrend <= .6)): $baromtrendwords = "Steady"; break; case (($baromtrend > .6) and ($baromtrend < 2)): $baromtrendwords = "Rising Slowly"; break; case ($baromtrend >= 2): $baromtrendwords = "Rising Rapidly"; break; case (($baromtrend < -.6) and ($baromtrend > -2)): $baromtrendwords = "Falling Slowly"; break; case ($baromtrend <= -2): $baromtrendwords = "Falling Rapidly"; break; } // end switch return($baromtrendwords); } // generate the alt=/title= text for area statement tooltip popups function gen_tag($ID) { global $StationData,$Stations,$Units; list($State,$Name) = preg_split("/\t/","$ID"); list($URL,$Coords,$Features,$DataPage,$RawDataType,$RawDataURL) = preg_split("/\t/",$Stations["$ID"]); if (! isset($StationData["$ID"]) ) { return "$Name - no current conditions report"; } list($TEMP,$HUMID,$WDIR,$WSPD,$RAIN,$BARO,$BTRND,$COND,$CTXT) = preg_split("/\,/",$StationData["$ID"]); // --------------- customize HTML if you like ----------------------- // note: only IE supports using new-line and tabs in tooltip displays // Firefox, Netscape and Opera all ignore these formatting characters, // or display a funky character instead. $wind = convertWind($WSPD); //$gust = convertWind($GST); $tag = "$Name: " . "$TEMP". $Units['temp'] . ", " . "$HUMID" . $Units['humid'] . ", " . "$WDIR $WSPD" . $Units['wind'] . ", " . "Rain: $RAIN". $Units['rain'] . ", " . "Baro: $BARO". $Units['baro'] . " " . $BTRND . ", $CTXT"; return $tag; } // end gen_tag // ------------------------------------------------------------------ // change wind units if necessary function convertWind($wind) { global $myUOM,$doWindConvert; if (! $doWindConvert) { return $wind; } if ($wind == 'n/a') { return $wind; } if ($myUOM == 'E') { return round($wind*1.150779,0); // knots rounded to integer MPH } else { return round($wind*3.6,0); // m/s rounded to integer kph } } // end convertWind // ------------------------------------------------------------------ // select units to display based on units of measure (UOM) function load_units($UOM) { $Units = array(); if ($UOM == 'M') { $Units = array( // metric with native wind units 'wind' => 'kph', 'temp' => '°C', 'baro' => 'hPa', 'humid' => '%', 'rain' => 'mm', 'dist' => 'km'); } else { $Units = array( // english with native wind units 'wind' => 'mph', 'temp' => '°F', 'baro' => 'in', 'humid' => '%', 'rain' => 'in', 'dist' => 'nm'); } $Units['time'] = ''; return $Units; } // end load_units // ------------------------------------------------------------------ // generate the rotation JavaScript to browser page function prt_jscript () { // NOTE: the following is not PHP, it's JavaScript // no changes should be required here. $t = ' '; $t .= ' '; return($t); } // end prt_jscript // ------------------------------------------------------------------ // initalize the assembly string for CSS function load_strings () { global $CSS,$Graphic,$Version,$Program,$ControlsX, $ControlsY; // top of CSS for mesomap display $CSS ='

    State

    Station
    Curr
    Cond
    Temp
    " . $Units['temp'] . "
    Hum
    " . $Units['humid'] . "
    Wind
    " . $Units['wind'] . "
    Rain
    " . $Units['rain'] . "
    Baro
    " . $Units['baro'] . "
    Baro
    Trend
    $State $Name No current conditions report.
    $State $Name "; if (preg_match('|.gif$|',$COND) && $condIconsDir) { $table .= "\"$CTXT\""; } else { $table .= "$COND"; } $table .= " $TEMP $HUMID "; if ($WDIR == 'n/a') { $table .= $WDIR; } else { $wda = $WDIR; $table .= $wda; if ($windArrowDir) { $table .= " \"Wind"; } $table .= " " . $WSPD; } $table .= " $RAIN
    $BARO"; if($showBaroTrendArrow) { $table .= getBaroTrendArrow($BTRND); } $table .="
    $BTRND