| 1 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 4 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 6 | ### Gnuplot backend for PDL::Graphics:Simple | ||||||||||||||||||||||||||||||||||||||||||
| 7 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 8 | ### See the PDL::Graphics::Simple docs for details | ||||||||||||||||||||||||||||||||||||||||||
| 9 | ### | ||||||||||||||||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||
| 12 | package PDL::Graphics::Simple::Gnuplot; | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use File::Temp qw/tempfile/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use PDL::Options q/iparse/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use PDL; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our $required_PGG_version = 1.5; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | our $mod = { | |||||||||||||||||||||||||||||||||||||||||
| 20 | shortname => 'gnuplot', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | module=>'PDL::Graphics::Simple::Gnuplot', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | engine => 'PDL::Graphics::Gnuplot', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | synopsis=> 'Gnuplot 2D/3D (versatile; beautiful output)', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | pgs_version=> '1.005' | ||||||||||||||||||||||||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | PDL::Graphics::Simple::register( 'PDL::Graphics::Simple::Gnuplot' ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | our $filetypes = { | |||||||||||||||||||||||||||||||||||||||||
| 29 | ps => ['pscairo','postscript'], | ||||||||||||||||||||||||||||||||||||||||||
| 30 | dxf => 'dxf', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | png => ['pngcairo','png'], | ||||||||||||||||||||||||||||||||||||||||||
| 32 | pdf => ['pdfcairo','pdf'], | ||||||||||||||||||||||||||||||||||||||||||
| 33 | txt => 'dumb', | ||||||||||||||||||||||||||||||||||||||||||
| 34 | jpg => 'jpeg', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | svg => 'svg', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | gif => 'gif' | ||||||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | ########## | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # PDL::Graphics::Simple::Gnuplot::check | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # Checker | ||||||||||||||||||||||||||||||||||||||||||
| 44 | sub check { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | my $force = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=9 SCAR=34.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | ▶ | $force = 0 unless(defined($force)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | return $mod->{ok} unless( $force or !defined($mod->{ok}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$force or not defined $mod->{"ok"}
MC/DC50%1/2
$force or not defined $mod->{"ok"}
$force
not defined $mod->{"ok"}
Truth table66%2/3
A or not(B)
A= $forceB= not defined $mod->{"ok"}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Eval PDL::Graphics::Gnuplot. Require relatively recent version. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # We don't specify the version in the 'use', so we can issue a | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # warning on an older version. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | eval 'use PDL::Graphics::Gnuplot;'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | if($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | $mod->{ok} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | $mod->{msg} = $@; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if($PDL::Graphics::Gnuplot::VERSION < $required_PGG_version) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $mod->{msg} = sprintf("PDL::Graphics::Gnuplot was found, but is too old (v%s < v%s). Ignoring it.\n", | |||||||||||||||||||||||||||||||||||||||||
| 61 | $PDL::Graphics::Gnuplot::VERSION, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | $required_PGG_version | ||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $mod->{ok} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $gpw; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | eval '$gpw = gpwin();'; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $mod->{ok} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $mod->{msg} = $@; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | die "PDL::Graphics::Simple: PDL::Graphics::Gnuplot didn't construct properly.\n\t$@"; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $mod->{valid_terms} = $gpw->{valid_terms}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | unless( $mod->{valid_terms}->{'x11'} or $mod->{valid_terms}->{'wxt'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mod->{"valid_terms"}{"x11"} or $mod->{"valid_terms"}{"wxt"}
MC/DC0%0/2
$mod->{"valid_terms"}{"x11"} or $mod->{"valid_terms"}{"wxt"}
$mod->{"valid_terms"}{"x11"}
$mod->{"valid_terms"}{"wxt"}
Truth table0%0/3
A or B
A= $mod->{"valid_terms"}{"x11"}B= $mod->{"valid_terms"}{"wxt"}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $mod->{ok} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $s = "Gnuplot exists but yours doesn't support either the x11 or wxt terminal\n"; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $mod->{msg} = $s; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | die "PDL::Graphics::SImple: $s"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $mod->{ok} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | ########## | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # PDL::Graphics::Simple::Gnuplot::new | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # Constructor | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | our $new_defaults = { | |||||||||||||||||||||||||||||||||||||||||
| 93 | size => [6,4.5,'in'], | ||||||||||||||||||||||||||||||||||||||||||
| 94 | type => '', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | output => '', | ||||||||||||||||||||||||||||||||||||||||||
| 96 | multi=>undef | ||||||||||||||||||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=24 SCAR=64.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $opt_in = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $opt_in = {} unless(defined($opt_in)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $opt = { iparse( $new_defaults, $opt_in ) }; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $gpw; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # Force a recheck on failure, in case the user fixed gnuplot. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | # Also loads PDL::Graphics::Gnuplot. | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | unless(check()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | die "$mod->{shortname} appears nonfunctional\n" unless(check(1)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # Generate the @params array to feed to gnuplot | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @params; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | push( @params, "size" => $opt->{size} ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | # tempfile gets set if we need to write to a temporary file for image conversion | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $conv_tempfile = ''; | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # Do different things for interactive and file types | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if($opt->{type} =~ m/^i/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | push(@params, "title"=>$opt->{output}) if(defined($opt->{output})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | # Interactive - try WXT, X11 in that order. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # (aqua doesn't have a "persist" option we can set to 0) | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if($mod->{itype}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $gpw = gpwin($mod->{itype}, @params, persist=>0, font=>"=16" ); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | print $PDL::Graphics::Gnuplot::last_plotcmd; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | attempt:for my $try( 'wxt', 'x11' ) { | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | eval { $gpw = gpwin($try, @params, persist=>0, font=>"=16",dashed=>1); }; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | last attempt if($gpw); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | die "Couldn't start a gnuplot interactive window" unless($gpw); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $mod->{itype} = $gpw->{terminal}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # File output - parse out file type, and then see if we support it. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # (Maybe the parsing part could be pushed into a utility routine...) | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | # Filename extension -- 2-4 characters | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $ext; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if($opt->{output} =~ m/\.(\w{2,4})$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $ext = $1; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $ext = '.png'; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | print STDERR "PDL::Graphics::Simple::Gnuplot: Warning - defaulting to .png type for file '$opt->{output}'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $opt->{ext} = $ext; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | ########## | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # Scan through the supported file types. Gnuplot has several drivers for some | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # of the types, so we search until we find a valid one. | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # At the end, $ft has either a valid terminal name from the table (at top), | ||||||||||||||||||||||||||||||||||||||||||
| 155 | # or undef. | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $ft = $filetypes->{$ext}; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if(ref $ft eq ARRAY) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | try:for my $try(@$ft) { | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if($mod->{valid_terms}->{$try}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $ft = $try; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | last try; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if(ref($ft)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $ft = undef; | |||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } elsif(!defined($mod->{valid_terms}->{$ft})) { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $ft = undef; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # Now $ext has the file type - check if its a supported type. If not, make a | ||||||||||||||||||||||||||||||||||||||||||
| 172 | # tempfilename to hold gnuplot's output. | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | unless( defined($ft) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | unless($mod->{valid_terms}->{'pscairo'} or $mod->{valid_terms}->{'postscript'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mod->{"valid_terms"}{"pscairo"} or $mod->{"valid_terms"}{"postscript"}
MC/DC0%0/2
$mod->{"valid_terms"}{"pscairo"} or $mod->{"valid_terms"}{"postscript"}
$mod->{"valid_terms"}{"pscairo"}
$mod->{"valid_terms"}{"postscript"}
Truth table0%0/3
A or B
A= $mod->{"valid_terms"}{"pscairo"}B= $mod->{"valid_terms"}{"postscript"}
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | die "PDL::Graphics::Simple: $ext isn't a valid output file type for your gnuplot,\n\tand it doesn't support .ps either. Sorry, I give up.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # Term is invalid but png is supported - set up a tempfile for conversion. | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my($fh); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ($fh,$conv_tempfile) = tempfile('pgs_gnuplot_XXXX'); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | unlink($conv_tempfile); # just to be sure; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $conv_tempfile .= ".ps"; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $ft = $mod->{valid_terms}->{'pscairo'} ? 'pscairo' : 'postscript'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | push(@params, "output" => ($conv_tempfile || $opt->{output}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$conv_tempfile || $opt->{'output'}
MC/DC0%0/2
$conv_tempfile || $opt->{'output'}
$conv_tempfile
$opt->{'output'}
Truth table0%0/3
A || B
A= $conv_tempfileB= $opt->{'output'}
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | push(@params, "color" => 1 ) if( $PDL::Graphics::Gnuplot::termTab->{$ft}->{'color'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | push(@params, "dashed" => 1 ) if( $PDL::Graphics::Gnuplot::termTab->{$ft}->{'dashed'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $gpw = gpwin( $ft, @params ); | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $me = { opt => $opt, conv_fn => $conv_tempfile, obj=>$gpw }; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # Deal with multiplot setup... | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if(defined($opt->{multi})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $me->{nplots} = $opt->{multi}->[0] * $opt->{multi}->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $me->{plot_no} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $me->{nplots} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return bless($me, 'PDL::Graphics::Simple::Gnuplot'); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # PDL::Graphics::Simple::Gnuplot::plot | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # plot | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | our $curve_types = { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | points => 'points', | ||||||||||||||||||||||||||||||||||||||||||
| 213 | lines => 'lines', | ||||||||||||||||||||||||||||||||||||||||||
| 214 | bins => 'histeps', | ||||||||||||||||||||||||||||||||||||||||||
| 215 | errorbars => 'yerrorbars', | ||||||||||||||||||||||||||||||||||||||||||
| 216 | limitbars => 'yerrorbars', | ||||||||||||||||||||||||||||||||||||||||||
| 217 | image => 'image', | ||||||||||||||||||||||||||||||||||||||||||
| 218 | circles => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | my($me, $po, $co, @data) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my $ang = PDL->xvals(362)*3.14159/180; | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my $c = $ang->cos; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $s = $ang->sin; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $s->slice("361") .= $c->slice("361") .= PDL->pdl(1.1)->acos; # NaN | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | my $dr = $data[2]->flat; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | my $dx = ($data[0]->flat->slice("*1") + $dr->slice("*1") * $c)->flat; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $dy = ($data[1]->flat->slice("*1") + $dr->slice("*1") * $s)->flat; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $co->{with} = "lines"; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | return [ $co, $dx, $dy ]; | |||||||||||||||||||||||||||||||||||||||||
| 229 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 230 | labels => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my($me, $po, $co, @data) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my $label_list = ($po->{label} or []); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$po->{'label'} || []
MC/DC0%0/1
$po->{'label'} || []
$po->{'label'}
Truth table0%0/2
A
A= $po->{'label'}
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | for my $i(0..$data[0]->dim(0)-1) { | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $j = ""; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $s = $data[2]->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if( $s =~ s/^([\<\>\| ])// ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $j = $1; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my @spec = ("$s", at=>[$data[0]->at($i), $data[1]->at($i)]); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | push(@spec,"left") if($j eq '<'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | push(@spec,"center") if($j eq '|'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | push(@spec,"right") if($j eq '>'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | push( @{$label_list}, \@spec ); | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $po->{label} = $label_list; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $co->{with} = "labels"; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return [ $co, [$po->{xrange}->[0]], [$po->{yrange}->[0]], [""] ]; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | sub plot { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | my $me = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plot: not called CC=29 SCAR=67.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $ipo = shift; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | my $po = { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | title => $ipo->{title}, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | xlab => $ipo->{xlabel}, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | ylab => $ipo->{ylabel}, | ||||||||||||||||||||||||||||||||||||||||||
| 262 | key => $ipo->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 263 | xrange => $ipo->{xrange}, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | yrange => $ipo->{yrange}, | ||||||||||||||||||||||||||||||||||||||||||
| 265 | cbrange => $ipo->{crange}, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | colorbox => $ipo->{wedge}, | ||||||||||||||||||||||||||||||||||||||||||
| 267 | justify => $ipo->{justify}>0 ? $ipo->{justify} : undef, | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | clut => 'sepia', | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if( defined($ipo->{legend}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $legend = ""; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if( $ipo->{legend} =~ m/l/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $legend .= ' left '; | |||||||||||||||||||||||||||||||||||||||||
| 275 | } elsif($ipo->{legend} =~ m/r/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $legend .= ' right '; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $legend .= ' center '; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if( $ipo->{legend} =~ m/t/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $legend .= ' top '; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } elsif( $ipo->{legend} =~ m/b/i) { | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $legend .= ' bottom '; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $legend .= ' center '; | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $po->{key} = $legend; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $po->{logscale} = [$ipo->{logaxis}] if($ipo->{logaxis}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | unless($ipo->{oplot}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $me->{curvestyle} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | my @arglist = ($po); | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | for my $block(@_) { | |||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $ct = $curve_types->{ $block->[0]->{with} }; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | unless(defined($ct)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | die "PDL::Graphics::Simple::Gnuplot: undefined curve type $ct"; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | if(ref($ct) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | $block = &$ct($me, $po, @$block); | |||||||||||||||||||||||||||||||||||||||||
| 306 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $block->[0]->{with} = $ct; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # Now parse out curve options and deal with line styles... | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | my $co = shift @$block; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my $gco = {}; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $gco->{with} = $co->{with}; | |||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | unless($co->{with} eq 'labels') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if(defined($co->{style}) and $co->{style}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $co->{"style"} and $co->{"style"}
MC/DC0%0/2
defined $co->{"style"} and $co->{"style"}
defined $co->{"style"}
$co->{"style"}
Truth table0%0/3
A and B
A= defined $co->{"style"}B= $co->{"style"}
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $me->{curvestyle} = $co->{style}; | |||||||||||||||||||||||||||||||||||||||||
| 319 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | $me->{curvestyle}++; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $gco->{linetype} = $me->{curvestyle}; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if( defined($co->{width}) and $co->{width} and $co->{with} !~ m/^label/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $co->{"width"} and $co->{"width"} and not $co->{"with"} =~ /^label/
defined $co->{"width"} and $co->{"width"}
MC/DC0%0/3
defined $co->{"width"} and $co->{"width"} and not $co->{"with"} =~ /^label/
defined $co->{"width"}
$co->{"width"}
not $co->{"with"} =~ /^label/
Truth table0%0/4
A and B and not(C)
A= defined $co->{"width"}B= $co->{"width"}C= not $co->{"with"} =~ /^label/
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $s; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if($co->{with} =~ m/^points/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $gco->{pointsize} = $co->{width}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $gco->{linewidth} = $co->{width}; | |||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | $gco->{legend} = $co->{key} if(defined($co->{key})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | push(@arglist, ($gco, @$block)); | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if($me->{nplots}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | unless($me->{plot_no}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $me->{obj}->multiplot( layout=>[$me->{opt}->{multi}->[0], $me->{opt}->{multi}->[1]] ); | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if($ipo->{oplot}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | delete $po->{logaxis}; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | delete $po->{xrange}; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | delete $po->{yrange}; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | delete $po->{cbrange}; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | delete $po->{justify}; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $me->{obj}->replot(@arglist); | |||||||||||||||||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $me->{obj}->plot(@arglist); | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if($me->{nplots}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $me->{plot_no}++; | |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if($me->{plot_no} >= $me->{nplots}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $me->{obj}->end_multi(); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $me->{plot_no} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $me->{obj}->close() if($me->{opt}->{type} =~ m/^f/i); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | $me->{obj}->close() if($me->{opt}->{type} =~ m/^f/i); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if($me->{opt}->{type} =~ m/^f/i and $me->{conv_fn}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$me->{"opt"}{"type"} =~ /^f/i and $me->{"conv_fn"}
MC/DC0%0/2
$me->{"opt"}{"type"} =~ /^f/i and $me->{"conv_fn"}
$me->{"opt"}{"type"} =~ /^f/i
$me->{"conv_fn"}
Truth table0%0/3
A and B
A= $me->{"opt"}{"type"} =~ /^f/iB= $me->{"conv_fn"}
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | print "converting $me->{conv_fn} to $me->{opt}->{output}..."; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | $a = rim($me->{conv_fn}); | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | wim($a->slice('-1:0:-1')->mv(1,0), $me->{opt}->{output}); | |||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | unlink($me->{conv_fn}); | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||