<table border=0 cellpadding=2 cellspacing=0>
<tr>
% foreach my $foo (@stamps) {
% my $det = $foo->{det};

<td align="center" valign="center">
% if ($foo->{diff}) {
<img width="<% $size %>" height"<% $size %>" src="/model/<% $dbname %>/stamp.jpg?file=<% $foo->{diff} %>">
% } elsif ($foo->{chip}) {
<img width="<% $size %>" height"<% $size %>" src="/model/<% $dbname %>/stamp.jpg?file=<% $foo->{chip} %>">
% } else {
<b>N/A</b>
% }
</td>
% }
</tr></table>

<%args>
$size => 75
$dets
$short => 1
$in_nn => undef
</%args>

<%init>
use Digest::MD5;
use Data::Dumper;
use PS::MOPS::Lib qw(mopslib_filt2V);

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

my $dbname = $inst->dbname;
my @stamps;
my $dfile;

foreach my $det (@{$dets}) {
    my $det_id = $det->{detId};
    my $id = sprintf "%010d", $det_id;
    my $nn = $in_nn || int($det->{epoch}) - 1;  # TJD to MOPS nn
    my $dreldir = join('/', 'MD', split '', substr(uc(Digest::MD5::md5_hex($id)), 0, 5));
    my $creldir = join('/', 'MC', split '', substr(uc(Digest::MD5::md5_hex($id)), 0, 5));

    $dfile = $inst->getEnvironment('VARDIR') . "/stamps/$dreldir/MD-$id.fits";
    my ($dir) = $det_id =~ /(\d)$/;
    if (!-f $dfile) {
        $dfile = "/data/mops13.0/stamp-store/stamps/special-stamps/$dbname-auto/$nn/$dir/D$det_id.fits";
        if (!-f $dfile) {
            $dfile = "/data/mops13.0/stamp-store/stamps/special-stamps/$dbname-auto/$nn/D$det_id.fits";
        }
    }
    my $have_dfile = -f $dfile;

    my $cfile = $inst->getEnvironment('VARDIR') . "/stamps/$nn/$det_id.fits";
    if (!-f $cfile) {
        $cfile = "/data/mops13.0/stamp-store/stamps/special-stamps/$dbname-auto/$nn/$dir/C$det_id.fits";
        if (!-f $cfile) {
            $cfile = "/data/mops13.0/stamp-store/stamps/special-stamps/$dbname-auto/$nn/C$det_id.fits";
        }
    }
    my $have_cfile = -f $cfile;

    if ($have_dfile) {
        push @stamps, { diff => $dfile, det => $det };
    }
    elsif ($have_cfile) {
        push @stamps, { chip => $cfile, det => $det };
    }
    else {
        push @stamps, { none => undef, foo => $cfile, det => $det };
    }

}
</%init>
