NOAA-style Climate Reports

\n"; $now_month = sprintf("%02d",$now['mon']); $now_year = $now['year']; $prior_month = $now['mon'] - 1; $prior_year = $now['year']; $last_year = $prior_year -1; if ($prior_month < 1) {$prior_month = 12; $prior_year--;} $prior_month = sprintf("%02d",$prior_month); print "\n"; print "\n"; if ($Naming == 'WL') { // check for month/year rollover and update if(! file_exists("$NOAAdir/NOAA$prior_year-$prior_month.TXT") and file_exists($LastMonthFile) ) { print "\n"; if (copy($LastMonthFile,"$NOAAdir/NOAA$prior_year-$prior_month.TXT")) { print "\n"; } else { print "\n"; } } if(! file_exists("$NOAAdir/NOAA$last_year.TXT") and file_exists($LastYearFile) ) { print "\n"; if (copy($LastYearFile,"$NOAAdir/NOAA$last_year.TXT")) { print "\n"; } else { print "\n"; } } } $months = array( "01"=>"Jan", "02"=>"Feb", "03"=>"Mar", "04"=>"Apr", "05"=>"May", "06"=>"Jun", "07"=>"Jul", "08"=>"Aug", "09"=>"Sep", "10"=>"Oct", "11"=>"Nov", "12"=>"Dec" ); if ($handle = opendir("$NOAAdir")) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $files[] = $file; } } closedir($handle); sort($files); $lastyear = ''; echo "
\n";
  // set up the files and find the first and last year for reports
  $first_year = "";
 
  foreach ($files as $key => $file) {
	if ($Naming == 'WL') {
       $year = substr($file,4,4);
	} elseif ($Naming == 'VWS') {
       $year = substr($file,0,4);
	}

   if (! preg_match("/^\d{4}$/",$year) ) { continue;} //make sure year is numeric
   

    $filesfound["$file"] = 1;
    if (!$first_year) { $first_year = $year; }
    $last_year = $year;
  }  
 
 if (! $first_year) {
   echo "

Sorry... no NOAA-style reports found.

"; echo ""; return; } // now create the index links based on which files we have // for ($y = $first_year; $y <= $now_year; $y++) { // above will do ascending sort by year in index // but we like the Index links sorted in descending year so // newest reports are at the top of the list // for ($y = $now_year; $y >= $first_year; $y--) { $yy = sprintf("%04d",$y); if ($Naming == 'WL') {$t = "NOAA$yy.TXT"; } if ($Naming == 'VWS') {$t = "$yy.txt"; } if ($filesfound[$t] || $yy == $now_year) { echo "$yy: "; } else { echo " $yy: "; } for ($m = 1; $m <= 12; $m++) { $mm = sprintf("%02d",$m); if ($Naming == 'WL') {$testfile = "NOAA$yy-$mm.TXT";} if ($Naming == 'VWS') {$testfile = "$yy" . "_" . "$mm.txt"; } if ($filesfound[$testfile]) { echo "" . $months[$mm]. " "; } else { if ($yy == $now_year && $mm == $now_month) { echo "" . $months[$mm] ." "; } else { echo "" . $months[$mm] ." "; } } if ($m < 12) { echo "| "; } else { echo "\n"; } } } // Now give out the reports if (! $yr && ! $mo) { // special for 'current month' echo "
Report for $now_year $now_month\n"; $rpt = implode("",file("$ThisMonthFile")); echo "
\n"; $rpt = preg_replace('|<|Uis','<',$rpt); echo $rpt; } if ($yr == $now_year && ! $mo) { // special for current year echo "
Report for $now_year\n"; $rpt = implode("",file("$ThisYearFile")); echo "
\n"; $rpt = preg_replace('|<|Uis','<',$rpt); echo $rpt; } else { // otherwise, process the requested year or year/month if ($yr) { if ($mo) { // month given if ($Naming == 'WL') {$testfile = "NOAA$yr-$mo.TXT";} if ($Naming == 'VWS') {$testfile = "$yr" . "_" . "$mo.txt";} } else { // no month given if ($Naming == 'WL') {$testfile = "NOAA$yr.TXT";} if ($Naming == 'VWS') {$testfile = "$yr.txt";} } // no month given if ($filesfound[$testfile]) { echo "
Report for $yr $mo\n"; $rpt = implode("",file("$NOAAdir/$testfile")); echo "
\n"; $rpt = preg_replace('|<|Uis','<',$rpt); echo $rpt; } else { echo "
Sorry, no report for $yr $mo.

\n"; } } } } echo "
\n"; // echo "------- debugging -----\n"; // print_r($filesfound); if (! $IncludeMode ) { ?>