/******************************************************************************
*
* END OF MODIFIABLE CODE
*
* You should not need to change anything further unless you want to make
* code changes on your own.
*
*******************************************************************************/
$DATE="";
$NAME="";
$LOCATION="";
// Returns whether needle was found in haystack
function is_substr($haystack, $needle){
$pos = strpos($haystack, $needle);
if ($pos === false) {
return false;
} else {
return true;
}
}
// Used to display info in proper cell
function dost($instring, $switch){
if ($switch) {
echo "
${instring} | ";
} else {
echo "${instring} | ";
}
}
// Use to display title info cells
function dohd($instring) {
echo "${instring} | ";
}
// Start of main routine
$NOAAFILE = fopen("$FILETOPROCESS", "r");
if (!$NOAAFILE) {
echo "No File Found [$FILETOPROCESS]
\n";
exit;
}
$START= 0;
$ODD = 0;
while (!feof($NOAAFILE)) {
$buffer = rtrim( fgets($NOAAFILE, 4096) );
$PROC_DONE = 0;
// Found Main Heading so we can get Date and Time values
if ( is_substr($buffer, "MONTHLY CLIMATOLOGICAL SUMMARY") ) {
$values = preg_split ("/\s+/", $buffer);
$DATE = "MONTHLY CLIMATOLOGICAL SUMMARY
for $values[5] $values[6]";
$PROC_DONE = 1;
}
// Found Location information
if ( is_substr( $buffer, "NAME: ")) {
$string = preg_replace("/NAME: /","", $buffer);
$string = preg_replace("/ CITY: /","- ",$string);
$string = preg_replace("/ STATE: /",", ", $string);
$NAME = $string;
$PROC_DONE = 1;
}
// Found Elevation and compass settings
if ( is_substr( $buffer, "ELEV: ")) {
$LOCATION = $buffer;
$PROC_DONE = 1;
// Start of Formatted output
echo '';
echo "${DATE}
${NAME}
${LOCATION}
";
echo "Note: Temp's are listed in ${TEMP}, Rain in ${RAIN}, ";
echo "and Wind Speed in ${WIND}
";
echo "\n";
dohd("DAY");
dohd("MEAN TEMP");
dohd("HIGH");
dohd("TIME");
dohd("LOW");
dohd("TIME");
dohd("HEAT DEG DAYS");
dohd("COOL DEG DAYS");
dohd("RAIN");
dohd("AVG WIND SPEED");
dohd("HIGH");
dohd("TIME");
dohd("DOM DIR");
echo "
\n";
$START = 1;
next;
}
// Found line of dashes before real data table. Turn on parsing
if (! $PROC_DONE ) {
if ( $START == 1 && is_substr($buffer, '------------------------') ) {
$START = 2;
$PROC_DONE = 1;
}
}
// Found last line of dashed after data table, Turn parsing off
if ( ! $PROC_DONE ) {
if ( $START == 2 && is_substr($buffer, '------------------------') ) {
$START = 3;
$PROC_DONE = 1;
}
}
// IF Parsing is on (START=2) and not a line of dashes, this must be a valid row
if ( ! $PROC_DONE) {
if ( $START == 2 && !is_substr($buffer, "--------") ){
$value = preg_split ("/\s+/", $buffer);
$val2 = $value[1];
// Check for null data. Line with date, but no data. Turn off parsing
if (strlen ($val2) == 0 ) {
$START = 3;
$PROC_DONE = 1;
} else {
if ($ODD != 1) {
$ODD = 1;
} else {
$ODD = 0;
}
echo "";
dost($value[0],$ODD);
dost($value[1],$ODD);
dost($value[2],$ODD);
dost($value[3],$ODD);
dost($value[4],$ODD);
dost($value[5],$ODD);
dost($value[6],$ODD);
dost($value[7],$ODD);
dost($value[8],$ODD);
dost($value[9],$ODD);
dost($value[10],$ODD);
dost($value[11],$ODD);
dost($value[12],$ODD);
echo "
\n";
}
$PROC_DONE = 1;
}
}
}
fclose($NOAAFILE);
echo "
";
/**********************************************************************
* End of Script
***********************************************************************/
?>