<table border=1 cellspacing=0 cellpadding=2 width="100%">
<tr>
<th class="darkheader"> Tracklet ID </th>
<th class="darkheader"> Status </th>
<th class="darkheader"> Classification </th>
<th class="darkheader"> Known As </th>
<th class="darkheader"> V<sub>tot</sub> (deg/day) </th>
<th class="darkheader"> Pos Ang (deg) </th>
<th class="darkheader"> Digest </th>
<th class="darkheader"> GCR (arcsec) </th>

</tr>
<tr>
% if ($trkId) {
<td align="left" width=25%> 

<span class="L18bold"><% $trk->trackletId %></span><br>
<a target="_blank" href="mpcheckt.html?trkId=<% $trkId%>">MPCheck</a><br>
Digest <a target="_blank" href="neodigest.html?trkId=T<% $trkId%>">MOPS</a>|
<a target="_blank" href="mpcneodigest.html?trkId=T<% $trkId%>">MPC</a>|
<a target="_blank" href="neoburn.html?trkId=<% $trkId%>">OORB</a>|
<a target="_blank" href="alldigest.html?trkId=<% $trkId%>">All</a><br>
Detections <a target="_blank" href="mtmpc.txt?id=T<% $trkId%>">MPC</a> | <a target="_blank" href="mtdes.txt?id=T<% $trkId%>">DES</a>
<p>
<a target="_blank" href="<% qq{/czar/$model/tracklet?tid=$trkId} %>">Czar page for this tracklet</a>

% if (@submitted) {
% my ($disp, $desig, $mpc_desig, $submitter) = @submitted;
<hr>
Submitted as <span class="L14bold"><% qq{<a href="/submitted_details.html?desig=$desig">$desig</a> by $submitter} %></span><br>
<% $mpc_desig || '' %>
% }

</td>
% } else {
<td align="center"> <% sprintf qq{<a target="_blank" href="/czar/$model/tracklet?tid=%s">%s</a>}, $trk->trackletId, $trk->trackletId %> </td>
% }
<td align="center"> <span class="L14"><% $TRACKLET_STATUS_DESCS{$trk->status} %> </span></td>
<td align="center"> <span class="L14"><% $MOPS_EFF_DESCS{$trk->classification} %> </span></td>
<td align="center"> 
    <span class="L14bold"><& /mpc_link, desig => $known_desig &></span>
% if ($known_str) {
    <br><br><span class="L12"><% $known_str %></span>
% }
</td>
<td align="center"> <& /lib/motionblock, trk => $trk &> </td>
<td align="center"> 
    <span class="L14"><% sprintf "%.1f", $trk->posAng %> </span>
</td>
<td align="center">
    <div class="L14bold"> <% sprintf "%.1f", $trk->digest %></div><br>
    <div class="L12"> <% sprintf "Prob %.2f", $trk->probability %></div> 
</td>
<td align="center"> <span class="L14"><% sprintf "%.2f", $trk->gcr_arcsec %> </span></td>

<tr>
<td colspan=8> <& detracklet_table, zip_name => "T$trkId", dets => $dets_ref, resids => $orbitId ? 1 : 0, special => $special &> </td><p>
</tr>
</table>

<%args>
$trk => undef
$trkId => undef
$orbitId => undef
$special => undef
</%args>

<%init>
use PS::MOPS::DC::Orbit;
use PS::MOPS::Constants qw(:all);
use PS::MOPS::GCR;
use PS::MOPS::JPLEPH;
use PS::MOPS::DC::Tracklet;
use PS::MOPS::DC::Known;
use PS::MOPS::DC::Field;

my $inst = $m->notes('INST');
my $model = $m->notes('MODEL');

if ($trkId) {
    $trk = modct_retrieve($inst, trackletId => $trkId);
}

my $dets_ref = $trk->detections;
my $field = modcf_retrieve($inst, fieldId => $trk->fieldId);

# If an orbit ID is specified, get per-detection residuals and stich them into the detections.
if ($orbitId) {
    my $orb = modco_retrieve($inst, orbitId => $orbitId);
    my $resid_stuff = jpleph_calcDetectionResiduals(orbit => $orb, detections_ref => $dets_ref);

    foreach my $det (@{$dets_ref}) {
        $det->{dra} = $resid_stuff->{$det->detId}->{dra};
        $det->{ddec} = $resid_stuff->{$det->detId}->{ddec};
        $det->{dtot} = $resid_stuff->{$det->detId}->{dtot};
    }
}

my $known_desig = 'N/A';
my $known_str = '';
if ($trk->knownId) {
    my $k = modck_lookup($inst, knownId => $trk->knownId);
    $known_desig = $k->{known_name};
    if ($k->{e} > 0) {
        $known_str = sprintf "a=%.3f, e=%.3f, i=%.2f, H<sub>V</sub>=%.2f", $k->{q} / (1 - $k->{e}), $k->{e}, $k->{i}, $k->{h_v};
    }
    else {
        $known_str = sprintf "q=%.3f, e=%.3f, i=%.2f, H<sub>V</sub>=%.2f", $k->{q}, $k->{e}, $k->{i}, $k->{h_v};
    }
}

# If this tracklet has been submitted, set a flag indicating is submission disposition.
my $dbh = $inst->dbh;
my @submitted = $dbh->selectrow_array(<<"SQL", undef, $model, $trkId);
select disposition, desig, mpc_desig, submitter from export.mpc_sub where dbname=? and tracklet_id=? limit 1
SQL

</%init>
