<?php
require_once "../../config/settings.inc.php";
define("IEM_APPID", 27);
require_once "../../include/forms.php";
require_once "../../include/database.inc.php";
require_once "../../include/myview.php";
require_once "../../include/network.php";
$nt = new NetworkTable("NSTLFLUX");
$t = new MyView();
$t->title = "NLAE Flux Sites";

$ys = yearSelect(2002, date("Y"), "syear");
$ms = monthSelect(1, "smonth");
$ds = daySelect(1, "sday");

$ys2 = yearSelect(2002, date("Y"), "eyear");
$ms2 = monthSelect(date("m"), "emonth");
$ds2 = daySelect(date("d"), "eday");

$rows = "";
$pg_conn = iemdb("other");
$sql = "SELECT * from flux_meta ORDER by sts ASC";
$rs = pg_query($pg_conn, $sql);

while ($row = pg_fetch_assoc($rs)) {
    $rows .= sprintf(
        "<tr><th>%s</th><td>%s</td><td>%.4f</td>
            <td>%.4f</td><td>%s</td><td>%s</td></tr>",
        $row["station"],
        $row["surface"],
        $nt->table[$row["station"]]['lat'],
        $nt->table[$row["station"]]['lon'],
        substr($row["sts"], 0, 10),
        substr($row["ets"], 0, 10)
    );
}

$sselect = networkMultiSelect("NSTLFLUX", '', array(), 'station[]');

$t->content = <<<EOM

<h3>USDA-ARS-National Laboratory for Agriculture and the Environment Flux Sites</h3>

<p>The IEM is pleased to host the data from a set of observing platforms operated by the USDA-ARS-National Laboratory for Agriculture and the Environment (NLAE).  These sites directly measure and derive numerous air and soil flux values.

<div class="alert alert-info">These raw data have not been subjected to the
<a href="https://www.ars.usda.gov/midwest-area/ames/nlae/"
class="alert-link">National Laboratory for Agriculture and the Environment's</a>
quality control or quality assurance procedures. The correction factor's are
calculated within a <a href="https://campbellsci.com/"
class="alert-link">Campbell Scientific, Inc</a> (Logan, UT) provided flux program
for the CR5000 dataloggers. The WPL corrections are based on the equations
found in Webb, E.K., G.I. Pearman, and R. Leuning, 1980. Correction of flux
measurements for density effects due to heat and water vapor transfer.</div>

<p>They are released for limited public use as preliminary data to be
used only with appropriate caution.

<p>
<a href="plots.phtml" class="btn btn-secondary"><i class="bi bi-graph-up" aria-hidden="true"></i> Generate daily time series plots</a>
<a href="vars.phtml" class="btn btn-secondary"><i class="bi bi-search" aria-hidden="true"></i> View variables collected from this network</a>.

<form method="GET" action="/cgi-bin/request/nlaeflux.py" name="single">
<h3>Download Data:</h3><br />

<p>This form will give you all variables for the day interval of your choice.
<br />Timestamps and date periods are in UTC.

<table>
<tr>
  <th>Select Station(s):</th>
  <th>Year:</th>
  <th>Month:</th>
  <th>Day:</th></tr>

<tr>
  <td rowspan='2'>{$sselect}</td>
  <td>{$ys}</td>
  <td>{$ms}</td>
  <td>{$ds}</td>
</tr>
<tr>
  <td>{$ys2}</td>
  <td>{$ms2}</td>
  <td>{$ds2}</td>
</tr>
</table>
<input type="submit" value="Download Data">
</form>

<br clear="left" />
<p>

<table class="table table-striped table-sm">
<thead><tr><th colspan="6" align="left">Site Information:</th></tr></thead>
<tr><th align="left">ID</th><th align="left">Status</th><th align="left">Lat</th><th align="left">Lon</th><th
align="left">First Observation</th><th align="left">Last Observation</th></tr></thead>
<tbody>
{$rows}
</tbody>
</table><p>

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