<?php
require_once "../../../config/settings.inc.php";
require_once "../../../include/myview.php";
require_once "../../../include/forms.php";
require_once "../../../include/database.inc.php";

$network = isset($_REQUEST["network"]) ? xssafe($_REQUEST["network"]) : "IA_RWIS";

define("IEM_APPID", 63);
$t = new MyView();
$t->iem_resource = "RWIS";
$t->iemss = True;
$t->title = "RWIS Data Download";

$startyr = ($network == 'IA_RWIS') ? 1995 : 2009;
$ys1 = yearSelect($startyr, date("Y"), "year1");
$ms1 = monthSelect("1", "month1");
$ds1 = daySelect("1", "day1");
$hs1 = hourSelect("0", "hour1");
$ys2 = yearSelect($startyr, date("Y"), "year2");
$ms2 = monthSelect(date("m"), "month2");
$ds2 = daySelect(date("d"), "day2");
$hs2 = hourSelect("23", "hour2");

$ar = array(
    "Etc/UTC" => "Coordinated Universal Time (UTC)",
    "America/New_York" => "America/New_York (EST/EDT)",
    "America/Chicago" => "America/Chicago (CST/CDT)",
    "America/Denver" => "America/Denver (MST/MDT)",
    "America/Los_Angeles" => "America/Los_Angeles (PST/PDT)",
    "America/Anchorage" => "America/Anchorage (AKST/AKDT)",
);
$tzselect = make_select("tz", "Etc/UTC", $ar);

$sselect = selectNetworkType("RWIS", $network);

$t->content = <<<EOM
<nav aria-label="breadcrumb">
  <ol class="breadcrumb">
    <li class="breadcrumb-item"><a href="/RWIS/">RWIS Homepage</a></li>
    <li class="breadcrumb-item active" aria-current="page">Download</li>
  </ol>
</nav>

<div class="row">
  <div class="col-12">
    <h3 class="mb-3">RWIS Atmospheric / Surface Data Download</h3>
  </div>
</div>

<div class="row mb-4">
  <div class="col-12">
    <div class="alert alert-info" role="alert">
  <i class="bi bi-info-circle me-2" aria-hidden="true"></i>
      The IEM archives RWIS information for the network in Iowa based on a direct
      feed from the DOT. We also archive other states based on an archive provided
      by the <a href="https://madis.ncep.noaa.gov/" class="alert-link">MADIS project</a>.
      Data for Iowa dates back to 1995, whereas archive availability for other states
      varies based on their participation within MADIS.
    </div>
  </div>
</div>

<div class="row mb-4">
  <div class="col-12">
    <a href="/cgi-bin/request/rwis.py?help" class="btn btn-primary">
      <i class="bi bi-file-text me-2" aria-hidden="true"></i>Backend Documentation
    </a>
  </div>
</div>

<div class="row mb-4">
  <div class="col-12">
    <div class="card">
      <div class="card-header">
        <h5 class="card-title mb-0">Network Selection</h5>
      </div>
      <div class="card-body">
        <form method="GET" name="s" class="d-flex align-items-center gap-3">
          <label class="form-label mb-0 fw-bold">Available States:</label>
          {$sselect}
          <button type="submit" class="btn btn-secondary">Select Network</button>
        </form>
      </div>
    </div>
  </div>
</div>

<form target="_blank" method="GET" action="/cgi-bin/request/rwis.py" name="iemss">
<div class="form2url"></div>
<input type="hidden" name="minute1" value="0">
<input type="hidden" name="minute2" value="0">
<input type="hidden" name="network" value="{$network}">

<div class="row">
  <div class="col-lg-7 mb-4">
    <div class="card h-100">
      <div class="card-header">
        <h5 class="card-title mb-0">1. Select Station(s)</h5>
      </div>
      <div class="card-body">
        <div id="iemss" data-network="{$network}"></div>
      </div>
    </div>
  </div>

  <div class="col-lg-5 mb-4">
    <div class="card h-100">
      <div class="card-header">
        <h5 class="card-title mb-0">Data Request Configuration</h5>
      </div>
      <div class="card-body">

        <div class="mb-4">
          <h6 class="fw-bold">2. Select Start/End Time</h6>
          <p class="text-muted small mb-3">
          Times are in timezone you select in step 5 below. If you are
          requesting a text download, you can request up to 500 station-years
          of data. HTML and excel are limited to 1 station-years worth.</p>
          <div class="table-responsive">
            <table class="table table-sm">
              <thead>
                <tr>
                  <th scope="col"></th>
                  <th scope="col">Year</th>
                  <th scope="col">Month</th>
                  <th scope="col">Day</th>
                  <th scope="col">Hour</th>
                </tr>
              </thead>
              <tbody>
                <tr>
                  <th scope="row">Start:</th>
                  <td>{$ys1}</td>
                  <td>{$ms1}</td>
                  <td>{$ds1}</td>
                  <td>{$hs1}</td>
                </tr>
                <tr>
                  <th scope="row">End:</th>
                  <td>{$ys2}</td>
                  <td>{$ms2}</td>
                  <td>{$ds2}</td>
                  <td>{$hs2}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>

        <div class="mb-4">
          <h6 class="fw-bold">3. Select Variables</h6>
          <p class="text-muted small mb-2">The label value within parenthesis is the output column name.</p>
          <select size="5" name="vars" multiple class="form-select">
            <option value="tmpf">Air Temperature [F] (tmpf)</option>
            <option value="dwpf">Dew Point Temperature [F] (dwpf)</option>
            <option value="feel">Feels Like Temperature [F] (feel)</option>
            <option value="relh">Relative Humidity [%] (relh)</option>
            <option value="sknt">Wind Speed [knots] (sknt)</option>
            <option value="drct">Wind Direction [degree N] (drct)</option>
            <option value="gust">Wind Gust [knots] (gust)</option>
            <option value="tfs0">Pavement Sensor0 Temperature [F] (tfs0)</option>
            <option value="tfs0_text">Pavement Sensor0 Condition (tfs0_text)</option>
            <option value="tfs1">Pavement Sensor1 Temperature [F] (tfs1)</option>
            <option value="tfs1_text">Pavement Sensor1 Condition (tfs1_text)</option>
            <option value="tfs2">Pavement Sensor2 Temperature [F] (tfs2)</option>
            <option value="tfs2_text">Pavement Sensor2 Condition (tfs2_text)</option>
            <option value="tfs3">Pavement Sensor3 Temperature [F] (tfs3)</option>
            <option value="tfs3_text">Pavement Sensor3 Condition (tfs3_text)</option>
            <option value="subf">Subsurface Temperature [F] (subf)</option>
          </select>
          <div class="form-text">
            <strong>See below for discussion on "Pavement Sensor Condition"</strong>
          </div>
        </div>

        <div class="mb-4">
          <h6 class="fw-bold">4. How to view?</h6>
          <select name="what" class="form-select">
            <option value="txt">Download as Delimited Text File</option>
            <option value="excel">Download as Excel</option>
            <option value="html">View as HTML webpage</option>
          </select>
        </div>

        <div class="mb-4">
          <h6 class="fw-bold">5. Timezone of Timestamps</h6>
          <p class="text-muted small mb-2">This controls the timezone used for presenting the timestamps in the downloaded file.</p>
          {$tzselect}
        </div>

        <div class="mb-4">
          <h6 class="fw-bold">6. Data Delimitation</h6>
          <p class="text-muted small mb-2">How shall the output values be separated?</p>
          <select name="delim" class="form-select">
            <option value="comma">Comma</option>
            <option value="space">Space</option>
            <option value="tab">Tab</option>
          </select>
        </div>

        <div class="mb-4">
          <h6 class="fw-bold">7. Include Lat / Lons?
            <img src="/images/gisready.png" alt="GIS Ready" class="ms-2">
          </h6>
          <select name="gis" class="form-select">
            <option value="no">No</option>
            <option value="yes">Yes</option>
          </select>
        </div>

        <div class="mb-0">
          <h6 class="fw-bold">8. Submit Form</h6>
          <div class="d-grid gap-2 d-md-flex">
            <button type="submit" class="btn btn-primary flex-fill">
              <i class="bi bi-download me-2" aria-hidden="true"></i>Process Data Request
            </button>
            <button type="reset" class="btn btn-outline-secondary">
              <i class="bi bi-arrow-counterclockwise me-2" aria-hidden="true"></i>Reset
            </button>
          </div>
        </div>

      </div>
    </div>
  </div>
</div>

<div class="row mt-5">
  <div class="col-12">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title mb-0">Pavement Sensor Condition Explanation</h4>
      </div>
      <div class="card-body">
        <div class="alert alert-secondary" role="alert">
          <i class="bi bi-info-circle me-2" aria-hidden="true"></i>
          The following applies to most of the Iowa RWIS sensors and is passed along by
          the Iowa RWIS Coordinator.
        </div>

        <p>The data is taken from the <a href="https://my.vaisala.net/en/roads/products/roadweathersensors/Pages/FP2000.aspx" target="_blank" rel="noopener">Vaisala FP2000</a>.
        These readings can be lumped into four general categories: wet, dry, snow/ice, error.
        The sensor gives quite a few more, especially in the snow/ice realm but functionally
        it is difficult to distinguish clear differences between them.</p>

        <h5 class="mt-4 mb-3">From the glossary:</h5>

        <div class="table-responsive">
          <table class="table table-striped table-hover">
            <thead class="table-dark">
              <tr>
                <th scope="col">Status</th>
                <th scope="col">Description</th>
              </tr>
            </thead>
            <tbody>

<tr><th>Snow/Ice Warning</th>

<td>Continuous film of ice and water mixture at or below freezing (32°F / 0°C) with insufficient chemical to keep the mixture from freezing.
This status can only be reported at Vaisala ESP and SP sites when precipitation occurs.
</td></tr>
<tr><th>Ice Warning</th>

<td>Continuous film of ice and water mixture at or below freezing (32°F / 0°C) with insufficient chemical to keep the mixture from freezing.
This status can only be reported at NTCIP sites.
</td></tr>
<tr><th>Snow Warning</th>

<td>This status can be reported at NTCIP sites, but will not be reported by Vaisala NTCIP sites.
</td></tr>
<tr><th>Wet Below Freezing</th>

<td>Moisture on pavement sensor with a surface temperature below freezing (32°F / 0°C).
This status will only be reported at Vaisala SCAN Detector sites.
</td></tr>
<tr><th>Ice Watch</th>

<td>Thin or spotty film of moisture at or below freezing (32°F / 0°C).
This status can only be reported at NTCIP sites when precipitation is not occurring.
</td></tr>
<tr><th>Snow/IceWatch</th>

<td>Thin or spotty film of moisture at or below freezing (32°F / 0°C).
This status can only be reported at Vaisala ESP and SP sites when precipitation is not occurring.
</td></tr>
<tr><th>Snow Watch</th>

<td>This status can be reported at NTCIP sites, but is not detected at Vaisala NTCIP sites.
</td></tr>
<tr><th>Frost</th>

<td>Moisture on pavement at or below freezing (32°F / 0°C) with a pavement temperature at or below the dew point temperature.
This status can only be reported by Vaisala ESP, SP, and NTCIP sites when precipitation is not occurring.
</td></tr>
<tr><th>Chemical Wet</th>

<td>Continuous film of water and ice mixture at or below freezing (32°F or 0°C) with enough chemical to keep the mixture from freezing.
This status can only be reported by Vaisala ESP, SP, and NTCIP sites when precipitation occurs.
</td></tr>
<tr><th>Wet</th>

<td>Continuous film of moisture on the pavement sensor with a surface temperature above freezing (32°F or 0°C).
This status can be reported by Vaisala ESP, SP, SCAN Detector, and NTCIP sites when precipitation has occurred.
</td></tr>
<tr><th>Damp</th>

<td>Thin or spotty film of moisture above freezing (32°F or 0°C).
This status can only be reported by Vaisala ESP, and SP sites when precipitation is not occurring.
</td></tr>
<tr><th>Trace Moisture</th>

<td>Thin or spotty film of moisture above freezing (32°F or 0°C). Surface moisture occurred without precipitation being detected.
This status will only be reported at NTCIP sites when precipitation is not occurring.
</td></tr>
<tr><th>Absorption at Dew Point, Absorption, & Dew</th>

<td>These statuses can be reported at NTCIP sites, but are not currently detected at Vaisala NTCIP sites.
</td></tr>
<tr><th>Dry</th>

<td>Absence of moisture on the surface sensor.
This status can be reported by Vaisala ESP, SP, SCAN Dectector, and NTCIP sites.
</td></tr>
<tr><th>Other</th>

<td>Other is the standard NTCIP ESS surface condition code to handle conditions not explicitly included in this table. This status will only be reported NTCIP by sensors installed at NTCIP ESS sites.
</td></tr>
<tr><th>No Report</th>

<td>The surface sensor is not operating properly and requires maintenance.
This status will only be reported by Vaisala ESP and SP sites.</td></tr>

<tr><th>Error</th>

<td>The surface sensor is not operating properly and requires maintenance.
This status will only be reported by NTCIP sites.</td></tr>

</tbody>
</table>


</form>
EOM;
$t->render('single.phtml');
