<& /htmlheader &>
<script type="text/javascript" src="/hammer/hammer.js"></script>
<& fieldmap.js, tjd => $tjd, show_plan => 's23456' &>
<& modelheader &>

<table width="90%"><tr>

<td valign="top">
<div class="L18bold"><% $tjd_str %></div>
<div class="L14"><% "$utdate_str OC $ocnum" %></div>

<h3>Chunks Ingested</h3>
<ul>
% foreach my $ch (sort keys %chunky) {
<li><% "$ch ($chunky{$ch})" %></li>
% }
</ul>

<h3>Czaring</h3>
<ul>
% if ($have_quads or $have_mds) {
<li><a target="_blank" href="http://neverland.ifa.hawaii.edu/sc/mops/<% $ocnum %>/<% $tjd %>.html">Serge's summary</a></li>
% }
% if ($have_quads) {
<li><a target="_blank" href="/czar/<% $model %>/tracklets.html?sort=d&limit=100&nn=<% $nn %>&minv=0.1">Quads</a></li>
% }
% if ($have_mds) {
<li><a target="_blank" href="/czar/<% $model %>/tracklets.html?sort=d&limit=100&minv=.1&nn=<% $nn %>&sm=MD">MDs</a></li>
% }
<li><a target="_blank" href="comets.html?limit=100&nn=<% $nn %>">Comets</a></li>
<li><a target="_blank" href="dobjs.html?sort=d&limit=100&nn=<% $nn %>">Derived Objects</a></li>
<li><a target="_blank" href="/submitted_neos.html?tjd=<% $tjd %>">Submitted NEOs</a></li>
</ul>

<h3>Efficiency</h3>
<ul>
<li><a target="_blank" href="/model/<% $model %>/efft.html?nn=<% $nn %>">Tracklets</a></li>
<li><a target="_blank" href="/model/<% $model %>/effl.html?nn=<% $nn %>">Derived objects and PANDAs</a></li>
</ul>

<div>
<a href="/model/<% $model %>/fields.html?nn=<% $nn %>">Night <% $tjd %> field list</a><br>
<a href="/model/<% $model %>/nightlyindex.html">Old index page</a>
</div>

</td>

<td align="right" valign="top">
    <canvas id="map" width="700" height="467" style="border: 1px solid #333333; background-color: #000000;">
    <p>Your lame browser doesn't support canvas.</p>
    </canvas>
</td>

</tr></table>

<!-- czar page footer -->
<hr align="left" width="90%">
<table width="90%"><tr>
<td align="left">&lt;-<a href="?tjd=<% $prev_tjd %>"><% $prev_tjd_str %></a><br><% "$prev_utdate_str OC $prev_oc" %>
</td>
<td align="right"><a href="?tjd=<% $next_tjd %>"><% $next_tjd_str %></a>-&gt;<br><% "$next_utdate_str OC $next_oc" %>
</td>
</tr></table>

<& /htmlfooter &>

<%args>
$today => undef
$nn => undef
$tjd => undef
$utdate => undef
</%args>

<%init>
use Astro::Time;
use PS::MOPS::Lib;
use PS::MOPS::DC::Field;
my $inst = $m->notes('INST');
my $mc = $inst->getConfig();
my $model = $m->notes('MODEL');
my $dbh = $inst->dbh;

# Today's info.
my ($year, $mon, $day);
my $today_nn;
my $today_tjd;
my @schmoo = gmtime;
$year = $schmoo[5] + 1900;
$mon = $schmoo[4] + 1;
$day = $schmoo[3];
$today_tjd = int(cal2mjd($day, $mon, $year, 0)) - 50000;
$today_nn = $today_tjd - 1 + 50000;
my $today_tjd_str = sprintf "TJD %d", $today_nn + 1 - 50000;
my $today_utdate_str = mopslib_mjd2utctimestr($tjd + 50000);
$today_utdate_str =~ s/T.*//; # trim everything after date
my $today_oc = mopslib_mjd2ocnum($today_nn);

# User info.
if ($tjd) {
    $nn = $tjd - 1 + 50000;
}
elsif ($utdate) {
    if ($utdate =~ /today/) {
        $nn = $today_nn;
    }
    elsif ($utdate =~ /^(\d\d\d\d)[\/.-]?(\d\d)[\/.-]?(\d\d)$/) {
        ($year, $mon, $day) = ($1, $2, $3);
        $nn = int(cal2mjd($day, $mon, $year, 0)) - 1;
    }
}
else {
    # nothing specified, use latest.
    ($nn) = $dbh->selectrow_array('select nn from fields order by nn desc limit 1');
    $nn = $today_nn unless $nn; # no fields, oh well
}

$tjd = $nn - 50000 + 1;
my $tjd_str = sprintf "TJD %d", $nn + 1 - 50000;
my $utdate_str = mopslib_mjd2utctimestr($tjd + 50000);
$utdate_str =~ s/T.*//; # trim everything after date
$utdate_str .= ' UT';
my $ocnum = mopslib_mjd2ocnum($nn);

my $next_tjd = $tjd + 1;
my $next_nn = $nn + 1;
my $next_tjd_str = sprintf "TJD %d", $next_tjd;
my $next_utdate_str = mopslib_mjd2utctimestr($next_tjd + 50000);
$next_utdate_str =~ s/T.*//; # trim everything after date
$next_utdate_str .= ' UT';
my $next_oc = mopslib_mjd2ocnum($next_tjd + 50000);

my $prev_tjd = $tjd - 1;
my $prev_nn = $nn - 1;
my $prev_tjd_str = sprintf "TJD %d", $prev_tjd;
my $prev_utdate_str = mopslib_mjd2utctimestr($prev_tjd + 50000);
$prev_utdate_str =~ s/T.*//; # trim everything after date
$prev_utdate_str .= ' UT';
my $prev_oc = mopslib_mjd2ocnum($prev_tjd + 50000);


# Now get some field/chunk information.
my $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr;
select survey_mode, count(*) ct from fields
where nn=?
group by survey_mode
SQL
$sth->execute($tjd + 50000 - 1) or die $sth->errstr;
my $have_mds;
my $have_quads;
my %chunky;
while (my $href = $sth->fetchrow_hashref) {
    if ($href->{survey_mode} =~ /^MD/) {
        $have_mds = 1;
    }
    else {
        $have_quads = 1;
    }
    $chunky{$href->{survey_mode}} = $href->{ct};
}

</%init>
