'; } ?> No Radar Images Are Currently Available From Here!'; exit; } else if ($errorMessage=='Too Many Images Requested') { echo 'Too Many Images Requested from here. Try Requesting '.$goodImages.' Images.'; exit; } ?>
'; // Debug Code $i=0; foreach($matches[2] as $match) { echo 'File No '.$i.': '.$match . '
'; $i++; } /* End Debug Code */ if ($imageNumber<$numbImages) { // echo 'https://radar.weather.gov/ridge/RadarImg/'.$radar.'/'.strtoupper($radarLoc).'/'; if ( $imageNumber==0) { return 'Radar Images Currently Unavailable!'; } else if ($imageNumber<$numbImages) { $goodImages = $imageNumber; return 'Too Many Images Requested'; } } else if ($listFiles) { $imageFile = array(); for ($i=($imageNumber-1),$j=$numbImages; $i>=($imageNumber-$numbImages); $i--,$j--) { $imageFile[$j] = $matches[2][$i]; } for ($i=1; $i<$numbImages; $i++) { $image = 'https://radar.weather.gov/ridge/RadarImg/'.$radar.'/'.strtoupper($radarLoc).'/'.$imageFile[$i]; // $image = getUniqueImageURL($image); echo $image; // echo $i<11?'& ':''; echo '& '; $radInfo[$i] = $imageFile[$i]; } echo ' '.'https://radar.weather.gov/ridge/RadarImg/'.$radar.'/'.strtoupper($radarLoc).'_'.$radar.'_0.gif'; } } /* end get_overlay_fnames */ // ------------------------------------------------------------------ /* begin get_overlay_warnings */ function get_overlay_warnings($radarLoc) { global $numbImages; $matches = array(); $theData = get_data('https://radar.weather.gov/ridge/Warnings/Short/'.strtoupper($radarLoc).'/'); preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", $theData, $matches); $imageNumber = count($matches[2]); $imageFile = array(); for ($i=($imageNumber-2),$j=$numbImages; $i>($imageNumber-(($numbImages*2)+3)); $i-=2,$j--) { $imageFile[$j] = $matches[2][$i]; } /* Debug Code */ $i=0; foreach($matches[2] as $match) { echo 'File No '.$i.': '.$match . '
'; $i++; } /* End Debug Code */ for ($i=1; $i<$numbImages; $i++) { $image = 'https://radar.weather.gov/ridge/Warnings/Short/'.strtoupper($radarLoc).'/'.$imageFile[$i]; // $image = getUniqueImageURL($image); echo $image; # echo $i<11?'& ':''; echo '& '; } echo ' '.'https://radar.weather.gov/ridge/Warnings/Short/'.strtoupper($radarLoc).'_'.'Warnings_0.gif'; } /* end get_overlay_warnings */ // ------------------------------------------------------------------ /* begin get_legends */ function get_legends($radarLoc,$radar) { global $numbImages; $matches = array(); $theData = get_data('https://radar.weather.gov/ridge/Legend/'.strtoupper($radar).'/'.strtoupper($radarLoc).'/'); preg_match_all("/(a href\=\")([^\?\"]*)(\")/i", $theData, $matches); $imageNumber = count($matches[2]); $imageFile = array(); for ($i=($imageNumber-1),$j=$numbImages; $i>=($imageNumber-$numbImages); $i--,$j--) { $imageFile[$j] = $matches[2][$i]; } /* Debug Code * $i=0; for($i=1; $i<$numbImages; $i++) { echo 'File No '.$i.': '.$imageFile[$i] . '
'; // $i++; } /* End Debug Code */ for ($i=1; $i<$numbImages; $i++) { $image = 'https://radar.weather.gov/ridge/Legend/'.strtoupper($radar).'/'.strtoupper($radarLoc).'/'.$imageFile[$i]; echo $image; # echo $i<11?'& ':''; echo '& '; } echo ' '.'https://radar.weather.gov/ridge/Legend/'.strtoupper($radar).'/'.strtoupper($radarLoc).'_'.strtoupper($radar).'_Legend_0.gif'; } /* end get_legends */ // ------------------------------------------------------------------ /* Begin getUniqueImageURL */ function getUniqueImageURL($image_url){ $timestamp = time(); if(strpos($image_url, '?')){ $image_url = str_replace('?', "?$timestamp&", $image_url); } else{ $image_url .= "?$timestamp"; } return $image_url; } /* end getUniqueImageURL */ // ------------------------------------------------------------------ /* Begin Function get_data */ function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // don't verify peer certificate curl_setopt($ch, CURLOPT_TIMEOUT, 8); // data timeout curl_setopt($ch, CURLOPT_NOBODY, false); // set nobody curl_setopt($ch, CURLOPT_HEADER, true); // include header information curl_setopt($ch, CURLOPT_USERAGENT,'US Ridge Radars/1.1 (Web Application, www.gwwilkins.org)'); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } /* End Function get_data */ // ------------------------------------------------------------------ /* Begin Function QJ_fetchUrlWithoutHanging */ function QJgetURL_Without_Hanging($url,$useFopen=false) { // Currently not used! Retained for possible switch by NWS to HTTP 1.1 // Borrowed from Ken True's 'quake-json.php' // thanks to Tom at Carterlake.org for this script fragment global $Debug, $needCookie,$timeStamp,$TOTALtime; $overall_start = time(); if (! $useFopen) { // Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed $numberOfSeconds=5; // Suppress error reporting so Web site visitors are unaware if the feed fails error_reporting(1); // Extract resource path and domain from URL ready for fsockopen $FullUrl = $url; $urlParts = parse_url($url); $domain = $urlParts['host']; if(isset($urlParts['port'])) { $port = $urlParts['port']; } else { $port = 80; } $resourcePath = $urlParts['path']; $resourcePath = preg_replace('|nocache|','?'.$timeStamp,$resourcePath); if(isset($urlParts['query'])) {$resourcePath .= "?" . $urlParts['query']; } if(isset($urlParts['fragment'])) {$resourcePath .= "#" . $urlParts['fragment']; } $T_start = QJ_microtime_float(); $hostIP = gethostbyname($domain); $T_dns = QJ_microtime_float(); $ms_dns = sprintf("%01.3f",round($T_dns - $T_start,3)); // $Debug .= "\n"; // print "GET $resourcePath HTTP/1.1 \n Host: $domain Port: $port IP=$hostIP\n"; // Establish a connection $socketConnection = fsockopen($hostIP, $port, $errno, $errstr, $numberOfSeconds); $T_connect = QJ_microtime_float(); $T_puts = 0; $T_gets = 0; $T_close = 0; if (!$socketConnection) { // You may wish to remove the following debugging line on a live Web site // $Debug .= "\n"; // print "Network error: $errstr ($errno)\n"; } // end if else { $xml = ''; $getString = "GET $resourcePath HTTPS/1.1\r\nHost: $domain\r\nCache-Control: no-cache, must-revalidate\r\nCache-control: max-age=0\r\nConnection: close\r\nUser-agent: Ridge Radars (wxusradars-hanis3.php gwwilkins.org)\r\nAccept: */*,text/html\r\n\r\n"; if (isset($needCookie[$domain])) { $getString .= $needCookie[$domain] . "\r\n"; // $Debug .= "\n"; } $getString .= "Accept: text/plain,text/html\r\n"; $getString .= "\r\n"; // print "Sending:\n$getString\n\n"; fputs($socketConnection, $getString); $T_puts = QJ_microtime_float(); // Loop until end of file $TGETstats = array(); $TGETcount = 0; while (!feof($socketConnection)) { $T_getstart = QJ_microtime_float(); $xml .= fgets($socketConnection, 16384); $T_getend = QJ_microtime_float(); $TGETcount++; $TGETstats[$TGETcount] = sprintf("%01.3f",round($T_getend - $T_getstart,3)); } // end while $T_gets = QJ_microtime_float(); fclose ($socketConnection); $T_close = QJ_microtime_float(); } // end else $ms_connect = sprintf("%01.3f",round($T_connect - $T_dns,3)); if($T_close > 0) { $ms_puts = sprintf("%01.3f",round($T_puts - $T_connect,3)); $ms_gets = sprintf("%01.3f",round($T_gets - $T_puts,3)); $ms_close = sprintf("%01.3f",round($T_close - $T_gets,3)); $ms_total = sprintf("%01.3f",round($T_close - $T_start,3)); } else { $ms_puts = 'n/a'; $ms_gets = 'n/a'; $ms_close = 'n/a'; $ms_total = sprintf("%01.3f",round($T_connect - $T_start,3)); } // $Debug .= "\n"; // print "HTTP stats: dns=$ms_dns conn=$ms_connect put=$ms_puts get($TGETcount blocks)=$ms_gets close=$ms_close total=$ms_total secs \n"; // foreach ($TGETstats as $block => $mstimes) { // print "HTTP Block $block took $mstimes\n"; // } $TOTALtime+= ($T_close - $T_start); $overall_end = time(); $overall_elapsed = $overall_end - $overall_start; // $Debug .= "\n"; // print "fetch function elapsed= $overall_elapsed secs.\n"; return($xml); } else { // print "\n"; $T_start = QJ_microtime_float(); $xml = implode('',file($url)); $T_close = QJ_microtime_float(); $ms_total = sprintf("%01.3f",round($T_close - $T_start,3)); // $Debug .= "\n"; // print " file() stats: total=$ms_total secs.\n"; $TOTALtime+= ($T_close - $T_start); $overall_end = time(); $overall_elapsed = $overall_end - $overall_start; // $Debug .= "\n"; // print "fetch function elapsed= $overall_elapsed secs.\n"; return($xml); } } // end QJ_fetchUrlWithoutHanging // ------------------------------------------------------------------ function QJ_microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } //------------------------------------------------------------------------------------------ ############ end functions ############ ?>