<%args>
$mjd => undef
$nn => undef
$imgtype => 'epsc'
</%args>

<%init>
my %typemap = (
    epsc => 'application/postscript',
    eps => 'application/postscript',
    png => 'image/png',
);
use PS::MOPS::Lib qw(:all);
my $model = $m->notes('MODEL');
my $inst = $m->notes('INST');
my $config = $inst->getConfig();
my $gmt_offset_hours = $config->{site}->{gmt_offset_hours};
if ($nn) {
    $mjd = mopslib_nn2mjd($nn, $gmt_offset_hours);
}

die "bogus image type: $imgtype" unless exists($typemap{$imgtype});
$r->content_type($typemap{$imgtype});

my $title;
if ($nn) {
    $title = "MOPS SSM Detection Density, Night Number $nn";
}
else {
    $title = "MOPS SSM Detection Density, MJD $mjd";
}
my $stuff = join '', `obsTool --instance $model --density --$imgtype --title "$title" --mjd $mjd`;
$m->clear_buffer;
$m->print($stuff);
$m->abort;
</%init>
