<%args>
$imgtype => 'png'
$nn => undef
$xrange => 2.0
$binsize => 0.05
</%args>

<%init>
use File::Slurp;
use File::Temp qw/tempfile/;
use PS::MOPS::Lib qw/mopslib_nn2mjd/;

my $model = $m->notes('MODEL');
my $inst = $m->notes('INST');
my $config = $inst->getConfig();
my $gmt_offset_hours = $config->{site}->{gmt_offset_hours};

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 $stuff = join '', `orbhistplot --xrange $xrange --binsize $binsize --title '$model' --instance $model --terminal $imgtype | gnuplot`;
my $stuff = join '', `orbhistplot --title '$model' --instance $model --terminal $imgtype | gnuplot | pngtopnm | pnmscale --xysize 600 440 | pnmtopng`;
$m->clear_buffer;
$m->print($stuff);
$m->abort;
</%init>
