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

define("IEM_APPID", 73);
$t = new MyView();
$t->iemss = True;
$t->iem_resource = "ASOS1MIN";
$t->title = "ASOS One Minute Data Download";

$aend = get_iemprop("asos.1min.end");
$archive_end = "N/A";
if (!is_null($aend)) {
    $asos_archive_end = new DateTime($aend);
    $archive_end = $asos_archive_end->format('d M Y');
}
$bogus = 0;

$y1select = yearSelect(2000, date("Y"), "year1");
$m1select = monthSelect($bogus, "month1");
$d1select = daySelect("1", "day1");
$h1select = hourSelect($bogus, "hour1");
$min1select = minuteSelect($bogus, "minute1");

$y2select = yearSelect(2000, date("Y"), "year2");
$m2select = monthSelect(date("m"), "month2");
$d2select = daySelect(date("d"), "day2");
$h2select = hourSelect($bogus, "hour2");
$min2select = minuteSelect($bogus, "minute2");

$t->headextra = <<<EOM
<style type="text/css">
#map {
    width: 100%;
    height: 450px;
    border: 2px solid black;
}
</style>
EOM;
$t->content = <<<EOM
<ol class="breadcrumb">
 <li><a href="/ASOS/">ASOS Mainpage</a></li>
 <li class="active">Download ASOS 1 minute interval data</li>
</ol>

<p>Each month, the National Centers for Environmental Information (NCEI) provides
<a href="https://www.ncei.noaa.gov/data/automated-surface-observing-system-one-minute-pg1/access/">an archive of one
minute interval data</a> from the ASOS sites in the United States.  Unfortunately,
the data format of this information is brutal to work with.  Fortunately for
you, the IEM <a href="https://github.com/akrherz/iem/blob/main/scripts/ingestors/asos_1minute/parse_ncei_asos1minute.py">processes this information</a> and provides it for download here. The
archive is available up until:
<strong>{$archive_end}</strong>.  There is
a different interface to download the <a href="/request/download.phtml">routine hourly</a>
observations from this network and for sites over the entire globe.</p>

<p><a class="btn btn-secondary" href="/cgi-bin/request/asos1min.py?help"><i class="bi bi-file-text" aria-hidden="true"></i> Backend Documentation</a> exists for those that
wish to script against this service.</p>

<form method="GET" action="/cgi-bin/request/asos1min.py" name="dl">
<div class="form2url"></div>

<div class="row">
<div class="col-md-6">

<p><h3>1. Select Station:</h3><br>
<i>Select One or More or All stations in the network.</i><br>
<br />
<div id="iemss" data-network="ASOS1MIN" data-name="station" data-supports-all="0"></div>

</div>
<div class="col-md-6">

<h3>2. Timezone of Observations:</h3>
<i>The timestamps used in the downloaded files will be set in the
timezone you specify.</i>
<SELECT name="tz">
    <option value="UTC">UTC Time</option>
    <option value="America/New_York">Eastern Time</option>
    <option value="America/Chicago">Central Time</option>
    <option value="America/Denver">Mountain Time</option>
    <option value="America/Los_Angeles">Pacific Time</option>
    <option value="America/Anchorage">Alaska/Anchorage Time</option>
</SELECT>

<h3>3. Select Start/End Time:</h3><br>
<i>This timestamp is in the timezone you selected above.</i>
<table class="table table-sm">
<thead>
  <tr>
    <td></td>
    <th>Year</th><th>Month</th><th>Day</th>
    <th>Hour</th><th>Minute</th>
  </tr>
</thead>
<tbody>
  <tr>
    <th>Start:</th>
    <td>{$y1select}</td><td>{$m1select}</td><td>{$d1select}</td>
    <td>{$h1select}</td><td>{$min1select}</td>
  </tr>

  <tr>
    <th>End:</th>
    <td>{$y2select}</td><td>{$m2select}</td><td>{$d2select}</td>
    <td>{$h2select}</td><td>{$min2select}</td>
  </tr>
</tbody>
</table>

<h3>4. Select Variables:</h3><br>
<select size=5 name="vars" MULTIPLE>
  <option value="tmpf">Air Temperature [F]</option>
  <option value="dwpf">Dew Point Temperature [F]</option>
  <option value="sknt">Wind Speed [knots]</option>
  <option value="drct">Wind Direction</option>
  <option value="gust_drct">5 sec gust Wind Direction</option>
  <option value="gust_sknt">5 sec gust Wind Speed [knots]</option>
  <option value="vis1_coeff">Visibility 1 Coefficient</option>
  <option value="vis1_nd">Visibility 1 Night/Day</option>
  <option value="vis2_coeff">Visibility 2 Coefficient</option>
  <option value="vis2_nd">Visibility 2 Night/Day</option>
  <option value="vis3_coeff">Visibility 3 Coefficient</option>
  <option value="vis3_nd">Visibility 3 Night/Day</option>
  <option value="ptype">Precip Type Code</option>
  <option value="precip">1 minute precip [inches]</option>
  <option value="pres1">Sensor 1 Station Pressure [inches]</option>
  <option value="pres2">Sensor 2 Station Pressure [inches]</option>
  <option value="pres3">Sensor 3 Station Pressure [inches]</option>
</select>

<h3>5. Data Sampling?</h3><br>
<i>Data is potentially available every minute, but you don't have to download
it at that frequency. This setting <b>does not bin</b> the values, but rather
filters based on your interval of choice.</i>
<select name="sample">
<option value="1min">Every Minute
<option value="5min">Every 5 Minutes
<option value="10min">Every 10 Minutes
<option value="20min">Every 20 Minutes
<option value="1hour">Every Hour
</select>

<h3>6. How to view?</h3>

<p>The "Plot in Chart" option was removed here due to its poor performance.
Please try <a href="/plotting/auto/?q=211">Autoplot 211</a> instead.</p>

<p><select name="what">
  <option value="download">Download to Disk</option>
  <option value="view">View on-line</option>
</select></p>

<h3>7. Data Delimitation:</h3><br>
How shall the output values be seperated?
<br>
<select name="delim">
    <option value="comma">Comma</option>
    <option value="tab">Tab</option>
</select>

<h3>8. Include Station Latitude & Longitude values?</h3>
<img src="/images/gisready.png"><br>
<div class="story">
 <select name="gis">
   <option value="no">No
   <option value="yes">Yes
 </select>
</div>

<p><h3>Submit Form:</h3><br>
<input type="submit" value="Process Data Request">
<input type="reset">

</div></div>

</form>

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