Skip to content

Commit

Permalink
fix PGPLOT to read devices correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 24, 2024
1 parent 14ccd97 commit 85dddc6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- fix PGPLOT to read devices correctly

1.009 2023-01-28
- Prima driver now working again - thanks @dk

Expand Down
32 changes: 13 additions & 19 deletions lib/PDL/Graphics/Simple/PGPLOT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package PDL::Graphics::Simple::PGPLOT;

use File::Temp qw/tempfile/;
use PDL::Options q/iparse/;
use IPC::Open2;

use PDL;

Expand All @@ -36,31 +37,26 @@ print $@;
sub check {
my $force = shift;
$force = 0 unless(defined($force));

return $mod->{ok} unless( $force or !defined($mod->{ok}) );

eval 'use PDL::Graphics::PGPLOT::Window;';
if($@) {
if ($@) {
$mod->{ok} = 0;
$mod->{msg} = $@;
return 0;
}

# Module loaded OK, now try to extract valid devices from it
my ($fh,$tf) = tempfile('pgg_pgplot_XXXX');
close $fh;

my $cmd = qq{|perl -e "use PGPLOT; open STDOUT,q[>$tf] or die; open STDERR,STDOUT or die; pgopen(q[?])"};
open FOO,$cmd;
print FOO "?\n";
close FOO;
open FOO,"<$tf";
my @lines = grep /^\s+\//, (<FOO>) ;
close FOO;
unlink $tf;

my @lines = eval {
open2(my $chld_out, my $chld_in, $^X, qw(-MPGPLOT -e pgopen(q[?])));
print $chld_in "?\n";
close $chld_in;
grep /^\s+\//, <$chld_out>;
};
if ($@) {
$mod->{ok} = 0;
$mod->{msg} = $@;
return 0;
}
$mod->{devices} = { map { chomp; s/^\s*\///; s/\s.*//; ($_,1) } @lines };

delete $mod->{disp_dev};
TRY:for my $try(qw/XWINDOW XSERVE CGW GW/){
if($mod->{devices}->{$try}) {
Expand All @@ -73,13 +69,11 @@ sub check {
$mod->{msg} = "Couldn't identify a PGPLOT display device -- giving up.\n";
return 0;
}

unless( $mod->{devices}->{'VCPS'} ) {
$mod->{ok} = 0;
$mod->{msg} = "Couldn't find the VCPS file-output device -- giving up.\n";
return 0;
}

$mod->{ok} = 1;
return 1;
}
Expand Down

0 comments on commit 85dddc6

Please sign in to comment.