#!/usr/bin/perl

do "config.pl" ;
do "mdate.pl" ;

use CGI;
$cgi = new CGI;

print "Content-type: text/html\n\n";
print <<EOFHTML;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>MM5 Smoke and Fire Weather Resources</TITLE>
<!--<LINK rel=StyleSheet href="blah.css" type="text/css" media=screen>//-->
<META name="keywords" content="Bluesky, rains, blueskyrains, forest service, environmental protection agency, epa, smoke modeling, smoke, model, data, map">
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
font-family:    sans-serif ;
font-size:      small ;
}

table {
font-size:      small ;
}

-->
</style>
</HEAD>
<BODY>

<p><b>Weather Data for BEHAVE:</b></p>

This information is for preliminary planning only.  It is not a substitute for
direct, on-site observations on the day of the planned burn.</p>

<p>BEHAVE is a program to predict rate of spread and flame length for wildland
fires.  By selecting a time and location below, you can obtain MM5 forecast
values for temperature, wind speed and direction, and relative humidity for use
in BEHAVE calculations.</p>

<p>When you choose a time and location, you will receive three sets of weather
forecast values.  These three sets of weather values provide an estimate of the
range of conditions that may occur during a fire at the time and location
specified.  If using them in BEHAVE produces fire characteristics that vary
widely, this indicates that a fire could show a similar range of behaviors.</p>

<p>The first set of weather values reflects surface conditions, with wind speed
and direction at 10 meters.  These are the standard BEHAVE input values.  The
second set reflects the average conditions in the layer of air near the surface
that is freely mixing down to the surface.  The third set of values reflects
the air likely to mix down to the surface during a fire that develops a
coherent, vertical plume.</p>

      
<!-- Data selection -->
<blockquote>
<form action="behave.cgi" method="GET">
<h3>Select the geographic location,  date and time below to extract weather data for input into a fire behavior model:</h3>
  <!-- Latitude and Longitude -->
  <table cellpadding="4">
    <tr>
      <td align="right"><b>Longitude W</b> (decimal):</td>
      <td align="left"><input type="text" name="lon"></td>
    </tr>
    <tr>
      <td align="right"><b>Latitude N</b> (decimal):</td>
      <td align="left"><input type="text" name="lat"></td>
    </tr>
                 
  <!-- Date and Time -->
    <tr>
      <td align="right"><b>Date</b></td>
      
EOFHTML

# Extract available dates from the names of NetCDF files in data directory
if (-d "data/behave/") {
	chdir("data/behave/");
	# For each NetCDF file
	while (<*.nc>) {
		# Create a hash of unique dates (only the keys matter)
		# NOTE: these dates are in PST!
		if (m/^(........)(08)\.nc/) {
#			$dateHash{add_delta_hours($1, -8)} = "1";
			$dateHash{"{$1}00"} = "1";
		}
	}
} else {
	die "Data directory does not exist ($!)";
}

# Sort the keys of the date hash
@dataSet = sort keys %dateHash;

# Specify a date formatting for the option menu
$fmt = '%Y %b %d';

# Today's date (to be chosen by default in the option menu)
pack_date(Localtime()) =~ /^(........)(..)$/;
$today = $1;

# Print the date selection menu
print "<!-- Date Selection -->\n";
print "<td align=\"left\"><select size=\"1\" name=\"date\">\n";
while (<@dataSet>) {
	print "<option value=\"";
	# Prune hours for option value
	m/^(........)(..)$/;
	print $1;
	# Set the default selection equal to today's date
	($1 eq $today)? print "\" selected=\"true\">" : print "\">";
	print strfgmtime($_, $fmt);
#	print strflocaltime($_, $fmt);
	print "</option>";
}
print "</select></td>\n";

print <<EOFHTML;

    <tr>
      <td align="right"><b>Hour (Local)</b></td>
      <!-- Time selection -->
      <td align="left"><select size="1" name="ttt">
          <option value="00">00</option>
          <option value="01">01</option>
          <option value="02">02</option>
          <option value="03">03</option>
          <option value="04">04</option>
          <option value="05">05</option>
          <option value="06">06</option>
          <option value="07">07</option>
          <option value="08">08</option>
          <option value="09">09</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
      </select></td>
    </tr>
      <td align="right"><b>Time Zone</b></td>
      <!-- Time zone selection -->
      <td align="left"><select size="1" name="tz1">
        <option value="E">Eastern</option>
        <option value="C">Central</option>
        <option value="M">Mountain</option>
        <option value="P" selected="true">Pacific</option>
      </select></td>
    </tr>

    <tr>
<!-- Reset -->
      <td align="right"><input type="reset" value="Reset" name="reset" class="button"></td>
<!-- Submit -->
      <td align="left"><input type="submit"  class="button"></td>
    </tr>
</table>

</form>
</blockquote>

Day: (select Today or Tomorrow)<br>
Time: (Data are available from 0001 Today to 2000 EDT (1900 CDT) Tomorrow.)<br>
Time zone: (radio buttons for EDT, CDT, MDT, PDT)<br><br>

To obtain information on weather from past days, please contact the AirFire team.<br>

<p>The BEHAVE 3-layer data generator was developed at <A
href="http://www.ncrs.fs.fed.us/eamc" target="_top">the Eastern Area Modeling
Consortium</A>.</p>

</BODY>
</HTML>
EOFHTML
