<%args>
$field_id
$imgtype => 'png'
$hilightobj => undef
$nonsynthetic => 1
$log => undef
</%args>

<%init>
my $model = $m->notes('MODEL');
my %typemap = (
    epsc => 'application/postscript',
    eps => 'application/postscript',
    png => 'image/png',
);

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

my $title;

my $ns_str = 'grep -v NS';
if ($nonsynthetic) {
    $title = "Apparent Magnitude Distribution, Nonsynthetic";
    $ns_str = 'grep NS';
}
else {
    $title = "Apparent Magnitude Distribution, Synthetic";
}

my $log_str = '--log';
unless ($log) {
    $log_str = '';
}

my $cmd = qq{obsTool --instance $model --detections $field_id | $ns_str | listogram $log_str --bins=50 --column=4 --terminal=$imgtype --xsize 300 --ysize 160 --title "$title"};
my $stuff = join '', `$cmd`;
$m->clear_buffer;
$m->print($stuff);
$m->abort;
</%init>
