Skip to content

Commit

Permalink
PDL_SIMPLE_DEVICE in env replaces driver guessing
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Apr 12, 2024
1 parent abd22e8 commit 42a1d02
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- each driver module now publishes which $P:G:S::API_VERSION it conforms to
- PGS::register takes hashref instead of magic var in driver namespace
- loading driver module not eval-ed
- PDL_SIMPLE_DEVICE in env replaces driver guessing

1.010 2024-03-24
- fix PGPLOT to read devices correctly
Expand Down
17 changes: 13 additions & 4 deletions lib/PDL/Graphics/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,6 @@ or "interactive" - though only the leading character is checked. If
you don't specify either C<type> or C<output> (below), the default is
"interactive". If you specify only C<output>, the default is "file".
For PGPLOT, if the type is "interactive", the environment variable
C<PGPLOT_DEV> is set (eg C</NULL>), that will be used as the output
device.
=item output
This should be a window number or name for interactive plots, or a
Expand Down Expand Up @@ -1504,6 +1500,19 @@ legend (if present). The C<with> option will be one of C<points>,
C<lines>, C<bins>, C<errorbars>, C<limitbars>, C<circles>
C<image>, or C<labels>.
=head1 ENVIRONMENT
Setting some environment variables affects operation of the module:
=head2 PDL_SIMPLE_ENGINE
See L</new>.
=head2 PDL_SIMPLE_DEVICE
If this is a meaningful thing for the given engine, this value will be
used instead of the driver module guessing.
=head1 TO-DO
Deal with legend generation. In particular: adding legends with multi-call
Expand Down
28 changes: 19 additions & 9 deletions lib/PDL/Graphics/Simple/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ sub check {
$mod->{valid_terms} = $gpw->{valid_terms};

my $okterm = undef;
for my $term (@disp_terms) {
if ($mod->{valid_terms}{$term}) {
$okterm = $term;
last;
if ($ENV{PDL_SIMPLE_DEVICE}) {
$okterm = 1;
} else {
for my $term (@disp_terms) {
if ($mod->{valid_terms}{$term}) {
$okterm = $term;
last;
}
}
}

Expand Down Expand Up @@ -136,7 +140,7 @@ sub new {
# Do different things for interactive and file types
if($opt->{type} =~ m/^i/i) {
push(@params, title=>$opt->{output}) if defined $opt->{output};
# Interactive - try known terminals
# Interactive - try known terminals unless PDL_SIMPLE_DEVICE given
push @params, font=>"=16", dashed=>1;
if (my $try = $mod->{itype}) {
$gpw = gpwin($mod->{itype}, @params,
Expand All @@ -145,11 +149,17 @@ sub new {
no warnings 'once';
print $PDL::Graphics::Gnuplot::last_plotcmd;
} else {
attempt:for my $try( @disp_terms ) {
eval { $gpw = gpwin($try, @params,
if (my $try = $ENV{PDL_SIMPLE_DEVICE}) {
$gpw = gpwin($try, @params,
($disp_opts->{$try} // {})->{persist} ? (persist=>0) : ()
); };
last attempt if($gpw);
);
} else {
attempt:for my $try( @disp_terms ) {
eval { $gpw = gpwin($try, @params,
($disp_opts->{$try} // {})->{persist} ? (persist=>0) : ()
); };
last attempt if($gpw);
}
}
die "Couldn't start a gnuplot interactive window" unless($gpw);
$mod->{itype} = $gpw->{terminal};
Expand Down
7 changes: 4 additions & 3 deletions lib/PDL/Graphics/Simple/PGPLOT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ sub check {
return 0;
}
delete $mod->{disp_dev};
if ($ENV{PGPLOT_DEV}) {
$mod->{disp_dev} = $ENV{PGPLOT_DEV};
if ($ENV{PDL_SIMPLE_DEVICE} || $ENV{PGPLOT_DEV}) {
$mod->{disp_dev} = $ENV{PDL_SIMPLE_DEVICE} || $ENV{PGPLOT_DEV};
$mod->{disp_dev} =~ s#^/+##;
} else {
TRY:for my $try(qw/XWINDOW XSERVE CGW GW/){
if($mod->{devices}->{$try}) {
Expand Down Expand Up @@ -113,7 +114,7 @@ sub new {
my $dev;

if( $opt->{type} =~ m/^i/i) {
$dev = ( defined($opt->{output}) ? $opt->{output} : "" ) . ($ENV{PGPLOT_DEV} || "/$mod->{disp_dev}");
$dev = ( defined($opt->{output}) ? $opt->{output} : "" ) . "/$mod->{disp_dev}";
} else {
my $ext;

Expand Down
4 changes: 2 additions & 2 deletions lib/PDL/Graphics/Simple/PLplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ sub check {
my $plgDevs = plgDevs();
$mod->{devices} = {map +($_=>1), keys %$plgDevs};

if ( my ($good_dev) = grep $mod->{devices}{$_}, @DEVICES ) {
if ( my ($good_dev) = $ENV{PDL_SIMPLE_DEVICE} || grep $mod->{devices}{$_}, @DEVICES ) {
$mod->{disp_dev} = $good_dev;
} else {
$mod->{ok} = 0;
Expand Down Expand Up @@ -246,7 +246,6 @@ our $plplot_methods = {

plshades( $data->[2], $xmin, $xmax, $ymin, $ymax, $clevel, $fill_width, $cont_color, $cont_width, 0, 0, \&pltr2, $grid );
plFreeGrid($grid);
plflush();

if($ipo->{wedge}) {
# Work around PLplot justify bug
Expand Down Expand Up @@ -382,6 +381,7 @@ sub plot {
} else {
$me->{obj}->xyplot(@data,PLOTTYPE=>$plpm,%plplot_opts);
}
plflush();
}

$me->{obj}->close if $me->{opt}->{type} =~ m/^f/i and !defined($me->{opt}->{multi});
Expand Down

0 comments on commit 42a1d02

Please sign in to comment.