Environmental Observations

Tropical Storms

\n"; print "
  • Summary
  • \n"; print "
  • Advisory
  • \n"; print "
  • Discussion
  • \n"; //print "
  • Probabilities
  • \n"; print "
  • Forecast
  • \n"; print "
  • Google Map
  • \n"; print " \n"; $panes = sprintf("panesd%d", $i); print "
    \n"; stormPrinter($TS_DIR, $TS_GRAPHICS, $stormArr[$i], $i); print "
    \n"; } print "\n"; print "\n"; } print "

    \n"; print "\"Atlantic  \n"; print "\"Pacific\n"; print "

    \n"; function stormNames($tsdir) { $dirs = array(); if ($dirFH = opendir($tsdir)) { while (($d = readdir($dirFH)) !== false) { $dir = $tsdir . "/$d"; if (is_dir($dir) && !preg_match("/^\./", $dir) && file_exists($dir . "/name")) { $dirs[] = $d; } } closedir($dirFH); sort($dirs); return($dirs); } else {return("");} } function stormPrinter($tsdir, $ts_graphics, $storm, $which) { print "
    \n"; TSsummary($tsdir, $ts_graphics, $storm, $which); print "
    \n"; print "
    \n"; TSadvisory($tsdir, $storm); print "
    \n"; print "
    \n"; TSdiscussion($tsdir, $storm); print "
    \n"; print "
    \n"; TSforecast($tsdir, $storm); print "
    \n"; print "
    \n"; TSgoogleMap($tsdir, $storm, $which); print "
    \n"; $id = sprintf("stormd", $which); print "
    \n"; print " \n"; print "
    \n"; } function TSsummary($tsdir, $ts_graphics, $storm, $which) { $n = $tsdir . $storm . "/name"; $in = fopen($n, "r"); $header = rtrim(fgets($in)); fclose($in); print "

    $header

    \n"; print "
    \n"; print " \n"; print genSummary($tsdir, $ts_graphics, $storm, $which); print " \n"; print "
    \n"; } function genSummary($tsdir, $ts_graphics, $storm, $which) { $n = $tsdir . $storm . "/summary"; if (file_exists($n)) { $in = fopen($n, "r"); $dateString = rtrim(fgets($in), "\n"); $lon = rtrim(fgets($in), "\n"); $lat = rtrim(fgets($in), "\n"); $speed = rtrim(fgets($in), "\n"); $windSpeed = rtrim(fgets($in), "\n"); $pressure = rtrim(fgets($in), "\n"); $dir = rtrim(fgets($in), "\n"); fclose($in); if ($speed == "NA") { $howFast = "Not Available"; } else { $abDir = abbreviateDir($dir); $howFast = "$speed mph $abDir"; } } $s = " \n"; //$s .= " "; $id = sprintf("#stormd", $which); $s .= "\"$storm\n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= " \n"; $s .= "
    At\n"; $s .= " " . prettyDate($dateString) . "
    Lat/Lon\n"; $s .= " " . formatLatLon($lat, $lon) . "
    Pressure\n"; $s .= " " . $pressure . " mb
    Speed\n"; $s .= " " . $howFast . "
    Winds\n"; $s .= " " . $windSpeed . " mph
    \n"; $s .= " \n"; return($s); } function TSadvisory($ts_dir, $storm) { $advisory = $ts_dir . $storm . "/advisory"; $in = fopen($ts_dir . "$storm/name", "r"); $name = rtrim(fgets($in)); fclose($in); $in = fopen($advisory, "r"); if (!$in) { print "

    No Public Advisory for storm \"$storm\"

    \n"; return(-1); } $inHeader = 1; $advisory = '
    '; $header = ""; $boldIt = 0; while (!feof($in)) { $buffer = rtrim(fgets($in)); if ($inHeader) { if (preg_match("/^HURRICANE\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Hurricane $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^TROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Tropical Storm " . $n . "
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^TROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Tropical Depression " . $n . "
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^EXTRATROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Extratropical Storm " . $n . "
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^EXTRATROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Extratropical Depression " . $n . "
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^SUBTROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Subtropical Depression " . $n . "
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^SUBTROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Subtropical Storm " . $n . "
    " . $matches[2]; $boldIt = 1; } if (preg_match("/^\s*$/", $buffer)) { $advisory .= "
    \n

    "; $inHeader = 0; } } if ($boldIt) { $boldIt = 0; $header = preg_replace("/ADVISORY NUMBER/", "Advisory Number", $header); $header = preg_replace("/INTERMEDIATE/", "Intermediate", $header); print "

    $header

    \n"; } elseif ($inHeader) { if ($header != "") { $advisory .= $buffer; } } else { $advisory .= $buffer; } $advisory .= "\n"; } fclose($in); if ($header == "") { $header = " "; } $advisory .= "
    "; $advisory = preg_replace("/\n\n\n/", "\n", $advisory); $advisory = preg_replace("/\n(.*?)\n(-+?)\n/", "\n\n$1\n", $advisory); //$advisory = preg_replace("/\n\s*\n/", "\n\n

    \n

    \n", $advisory); //$advisory = "

    " . $advisory . "
    "; print $advisory . "\n"; return(1); } function TSdiscussion($ts_dir, $storm) { $discussion = $ts_dir . $storm . "/discussion"; # # Get the name of this storm # $in = fopen($ts_dir . $storm . "/name", "r"); $name = rtrim(fgets($in)); fclose($in); # # Your content here # $in = fopen($discussion, "r"); if (!$in) { print "

    No Discussion for storm \"$storm\"

    \n"; exit(1); } $inHeader = 1; $discussion = "
    "; $header = ""; $boldIt = 0; while (!feof($in)) { $buffer = rtrim(fgets($in)); if ($inHeader) { if (preg_match("/^HURRICANE\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Hurricane $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^TROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Tropical Storm $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^TROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Tropical Depression $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^EXTRATROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Extratropical Storm $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^EXTRATROPICAL Depression\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Extratropical Depression $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^SUBTROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Subtropical Storm $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^SUBTROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Subtropical Depression $n
    " . $matches[2]; $boldIt = 1; } if (preg_match("/^\s*$/", $buffer)) { $discussion .= "

    "; $inHeader = 0; } /* else { if ($discussion != "

    ") { $discussion .= "
    "; } } */ } if ($boldIt) { $boldIt = 0; $header = preg_replace("/DISCUSSION NUMBER/", "Discussion Number", $header); print "

    $header

    \n"; } elseif ($inHeader) { if ($header != "") { $discussion .= $buffer; } } else { $discussion .= $buffer; } $discussion .= "\n"; } fclose($in); if ($header == "") { $header = " "; } $discussion = preg_replace("/\n\s*\n/", "\n

    \n

    \n", $discussion); $d = strpos($discussion, "

    \nFORECAST POSITIONS AND MAX WINDS\n

    "); $realDiscussion = substr($discussion, 0, $d); $ss = strstr($discussion, "

    \nFORECAST POSITIONS AND MAX WINDS\n

    "); $ss = substr($ss, 42+4); print $realDiscussion; print "

    Forecast Positions and Max Winds

    \n" . formattedPos($ss) . "\n"; return(1); } function TSprobabilities($ts_dir, $storm) { # # Display storm probabilities # $advisory = $ts_dir . $storm . "/marine"; # # Get the name of this storm # $in = fopen($ts_dir . $storm . "/name", "r"); $name = rtrim(fgets($in)); fclose($in); $in = fopen($advisory, "r"); if (!$in) { print "

    No Storm Probabilities for storm \"$storm\"

    \n"; return(-1); } $inHeader = 1; $header = ""; $boldIt = 0; while (!feof($in)) { $buffer = rtrim(fgets($in)); if ($inHeader) { if (preg_match("/^HURRICANE\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $hdr1 = "Hurricane $n
    " . $matches[2]; } elseif (preg_match("/^TROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $hdr1 = "Tropical Storm $n
    " . $matches[2]; } elseif (preg_match("/^TROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $hdr1 = "Tropical Depression $n
    " . $matches[2]; } elseif (preg_match("/^EXTRATROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $hdr1 = "Extratropical Storm $n
    " . $matches[2]; } elseif (preg_match("/^EXTRATROPICAL Depression\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $hdr1 = "Extratropical Depression $n
    " . $matches[2]; } elseif (preg_match("/^SUBTROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $hdr1 = "Subtropical Storm $n
    " . $matches[2]; } elseif (preg_match("/^SUBTROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $hdr1 = "Subtropical Depression $n
    " . $matches[2]; } else if (preg_match("/^PROBABILITIES NUMBER/", $buffer, $matches)) { $hdr1 .= $buffer; } else { $hdr2 = $buffer . "
    \n"; break; } } } $hdr1 = preg_replace("/WIND SPEED/", "Wind Speed", $hdr1); $hdr1 = preg_replace("/PROBABILITIES NUMBER/", "Probabilities Number", $hdr1); $hdr1 = preg_replace("/FORECAST\/ADVISORY NUMBER/", "Forecast/Advisory Number", $hdr1); print "

    $hdr1

    \n"; while (!feof($in)) { $buffer = rtrim(fgets($in)); if (preg_match("/^\s*$/", $buffer)) {break;} $hdr2 .= $buffer . "
    "; } print "
    \n"; print "$hdr2\n"; print "
    \n"; print "
    \n"; while (!feof($in)) { print fgets($in); } print "
    \n"; fclose($in); return(1); } function TSforecast($ts_dir, $storm) { $marine = $ts_dir . $storm . "/marine"; # # Get the name of this storm # $in = fopen($ts_dir . $storm . "/name", "r"); $name = rtrim(fgets($in)); fclose($in); # # Your content here # $in = fopen($marine, "r"); if (!$in) { print "

    No Marine Advisory for storm \"$storm\"

    \n"; exit(1); } $inHeader = 1; $advisory = "
    \n"; $header = ""; $boldIt = 0; while (!feof($in)) { $buffer = rtrim(fgets($in)); if ($inHeader) { if (preg_match("/^HURRICANE\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Hurricane $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^TROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Tropical Storm $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^TROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Tropical Depression $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^EXTRATROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Extratropical Storm $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^EXTRATROPICAL Depression\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Extratropical Depression $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^SUBTROPICAL STORM\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Subtropical Storm $n
    " . $matches[2]; $boldIt = 1; } elseif (preg_match("/^SUBTROPICAL DEPRESSION\s(\w+)\s(.*)/", $buffer, $matches)) { $n = ucfirst(strtolower($matches[1])); $header = "Subtropical Depression $n
    " . $matches[2]; $boldIt = 1; } if (preg_match("/^\s*$/", $buffer)) { $advisory .= "\n
    \n"; $inHeader = 0; } else { if ($advisory != "
    \n" && !preg_match("/^\s*$/", $buffer)) { $advisory .= "
    "; } } if ($boldIt) { $boldIt = 0; $header = preg_replace("/FORECAST\/ADVISORY NUMBER/", "Advisory Number", $header); print "

    $header

    \n"; } elseif ($header != "") { $advisory .= $buffer; } if (!$inHeader) { $advisory .= "\n
    \n"; } continue; } $advisory .= $buffer . "\n"; } $advisory .= "
    \n"; fclose($in); print $advisory; return(1); } function TSgoogleMap($tsdir, $storm, $which) { //$id = "map$which"; //print "
    \n"; //print "\n"; print "\n"; } function formattedPos($lines) { $s = ''; $pos = array(); #123456789012345678901234567890 #INITIAL 25/1500Z 26.6N 77.6W 100 KT $pos = explode("\n", $lines); $s = ''; $last = 0; for($i=0; $i/", $l)) {break;} if (preg_match("/^\s*$/", $l)) { if ($last) {break;} else { $last = 1; continue; } } if (preg_match("/^

    /", $l) && $last) {break;} $t = substr($l, 0, 11); $t = preg_replace("/^\s+/", "", $t); $t = preg_replace("/\s+$/", "", $t); $r = substr($l, 12); $r = preg_replace("/^\s+/", "", $r); $f = preg_split("/\s+/", $r); if (count($f) < 7) { for($j=count($f); $j<7; $j++) { $f[$j] = ""; } } $s .= "

    \n" . "" . "" . "" . "" . "" . "\n"; } $s .= "
    $t$f[0]$f[1]$f[2]$f[3] $f[4] $f[5] $f[6]
    \n"; return($s); } function formatLatLon($lat, $lon) { if ($lat < 0) { $lat *= -1; $lat = "$lat°S"; } else { $lat = "$lat°N"; } if ($lon < 0) { $lon *= -1; $lon = "$lon°W"; } else { $lon = "$lon°E"; } return "$lat $lon"; } function abbreviateDir($longDir) { if ($longDir == "NORTH") { return "N"; } elseif (preg_match("/NORTH.NORTHEAST/", $longDir)) { return "NNE"; } elseif ($longDir == "NORTHEAST") { return "NE"; } elseif (preg_match("/EAST.NORTHEAST/", $longDir)) { return "ENE"; } elseif ($longDir == "EAST") { return "E"; } elseif (preg_match("/EAST.SOUTHEAST/", $longDir)) { return "ESE"; } elseif ($longDir == "SOUTHEAST") { return "SE"; } elseif (preg_match("/SOUTH.SOUTHEAST/", $longDir)) { return "SSE"; } elseif ($longDir == "SOUTH") { return "S"; } elseif (preg_match("/SOUTH.SOUTHWEST/", $longDir)) { return "SSW"; } elseif ($longDir == "SOUTHWEST") { return "SW"; } elseif (preg_match("/WEST.SOUTHWEST/", $longDir)) { return "WSW"; } elseif ($longDir == "WEST") { return "W"; } elseif (preg_match("/WEST.NORTHWEST/", $longDir)) { return "WNW"; } elseif ($longDir == "NORTHWEST") { return "NW"; } elseif (preg_match("/NORTH.NORTHWEST/", $longDir)) { return "NNW"; } else { return $longDir; } } function prettyDate($ds) { $f = array(); $f = preg_split("/\s+/", $ds); $f[3] = ucfirst(strtolower($f[3])); $f[4] = ucfirst(strtolower($f[4])); return("$f[0]$f[1] $f[2] $f[3] $f[4] $f[5] $f[6]"); } ?>