📄 make-graph.pl
字号:
} } close( CON ); } # now if we're making an rtm graph, do it if( defined $param and $rtmgraph ) { open( DAT, "<$datfile" ) or die( "Couldn't open $datfile" ); my @dat = <DAT>; my $statline = shift @dat; # no need for stat names close( DAT ); # read in the convex hull file and find all the combos my @headers = (); open( CON, "<$datfile$j.convex" ) or die( "Couldn't open $datfile$j.convex" ); while( <CON> ) { if( /([\d\.]+) ([\d\.]+)/ ) { if( defined $headerhash{"$1 $2"} ) { push @headers, $headerhash{"$1 $2"}; } else { die( "header not defined: $1 $2" ); } } else { die( "Weird line in $datfile$j.convex: $_" ); } } close( CON ); # get the right parameter position my $parampos; if( $param =~ /^\d+/ ) { $parampos = $param; } else { @statlabels = split( /\s+/, $statline ); foreach my $label (@statlabels) { if( $label =~ /^param(\d+)\)$param/ ) { $parampos = $1 - 1; last; } } if( !defined $parampos ) { die( "No parameter $param found in file $datfile" ); } } # now we have all the headers, so for each one go through # the dat file, pick out the right points my $num_h = 0; my @sheaders = sort {$a <=> $b} @headers; foreach my $h (@sheaders) { my @params = split( /\s+/, $h ); if( $#params < $parampos ) { die( "Not enough params for rtmgraph" ); } # now splice out the parameter we care about shift @params; # forget about the "#" splice( @params, $parampos, 1 ); $h =~ s/\s+/-/g; my $doit = 0; my $newfile = "/tmp/paramplot-$$-$j-$h.dat"; open( OUT, ">$newfile" ) or die( "Couldn't open $newfile" ); my %points = (); my $v; foreach my $d (@dat) { if( $d =~ /^\#/ ) { $doit = 0; my @params2 = split( /\s+/, $d ); shift @params2; # forget about the "#" # now splice out the parameter we care about $v = $params2[$parampos]; splice( @params2, $parampos, 1 ); my $p = 0; for( ; $p <= $#params; $p++ ) { if( $params[$p] != $params2[$p] ) { last; } } if( $p > $#params ) { $points{$v} = $d; $doit = 1; } } elsif( $doit ) { $points{$v} .= $d; } } foreach my $v (sort(keys(%points))) { print OUT $points{$v}; } close( OUT ); push @rtmfiles, $newfile; $xposes{"$newfile"} = $xposes{$datfile}; for( my $k = 0; $k <= $#ystat; $k++ ) { $yposes{"$k-$newfile"} = $yposes{"$k-$datfile"}; } $hullposes{"$newfile"} = $hullposes{$datfile}; $num_h++; if( $num_h > 10 ) { last; } } } # extend the hull if( defined $options{"extend"} and defined $min_y and defined $max_x ) { system( "echo \"$max_x $min_y\" >> $datfile$j.convex" ); system( "sort -n $datfile$j.convex > $datfile$j.convex.tmp; " . "mv $datfile$j.convex.tmp $datfile$j.convex" ); } } $index++; }} # now write the gnuplot fileopen( GP, ">/tmp/paramplot-$$.gnuplot" ) or die( "Couldn't open gp" );print GP <<EOGP;set xlabel "$xlabel"set ylabel "$ylabel[$#ylabel]"EOGP{;}if( $grid ) { print GP "set grid xtics ytics\n"; print GP "show grid\n";}if( defined $xrange ) { print GP "set xrange [$xrange]\n";}if( defined $yrange ) { print GP "set yrange [$yrange]\n";}if (defined $keypos) { print GP "set key $keypos\n";}if( defined $epsfile ) { print GP "set terminal postscript eps $fontsize\n"; print GP "set output \"$epsfile\"\n";}elsif (defined $colorepsfile) { print GP "set terminal postscript eps color $fontsize\n"; print GP "set output \"$colorepsfile\"\n";}elsif (defined $pngfile) { print GP "set terminal png size 400,300\n";#print GP "set terminal png font \"/usr/X11R6/lib/X11/fonts/webfonts/arial.ttf\" 18\n"; print GP "set output \"$pngfile\"\n";} else { print GP "set terminal postscript color $fontsize\n"; print GP "set output \"/tmp/paramplot-$$.eps\"\n";}if( defined $title ) { print GP "set title \"$title\"\n";}foreach my $hull (@hulllabelcmds) { print GP "$hull\n";}print GP "plot ";my $num = $#datfiles + 1;my $i = 0;my @iterfiles = @datfiles;my $type = "points";if( defined $plottype ) { $type = $plottype;}if( @convexfiles ) { @iterfiles = @convexfiles; $type = "lines"; if( defined $plottype ) { $type = $plottype; }}if( defined $param and $rtmgraph and @convexfiles ) { @datfiles = @rtmfiles;}my $yindex = 0;foreach my $file (@iterfiles) { my $xpos = $xposes{$file}; if( @convexfiles ) { $xpos = 1; } if( defined $xop && !@convexfiles ) { # check it for stats my $newxop = $xop; foreach my $x (@xopsplit) { if( defined $xposes{"$file$x"} ) { $newxop =~ s/$x/\$$xposes{"$file$x"}/g; } elsif( defined $xposes{"$i$x"} ) { $newxop =~ s/$x/\$$xposes{"$i$x"}/g; } elsif( !($x =~ /^[\d\.]*$/ ) ) { die( "Can't find a position for $x" ); } } $xpos = "$xpos$newxop"; } my $k = $yindex; for( ; $k <= $#ystat; $k++ ) { my $ypos = $yposes{"$k-$file"}; if( @convexfiles ) { $ypos = 2; } if( defined $yop[$k] && !@convexfiles ) { my $newyop = $yop[$k]; foreach my $y (&get_opsplit($yop[$k])) { if( defined $yposes{"$k-$file$y"} ) { $newyop =~ s/$y/\$$yposes{"$k-$file$y"}/g; } elsif( defined $yposes{"$k-$i$y"} ) { $newyop =~ s/$y/\$$yposes{"$k-$i$y"}/g; } elsif( !($y =~ /^[\d\.]*$/ ) ) { die( "Can't find a position for $y" ); } } $ypos = "$ypos$newyop"; } my $t = "notitle"; my $y = ""; if( $#ylabel > 0 ) { $y = ":$ylabel[$k]"; } if( defined $options{"convex"} && $options{"convex"} eq "both" ) { # we want linespoints to be labeled, so do it here $t = "t \"" . $labelhash{$indats[$i]} . "$y\""; $type = "linespoints"; } elsif( $file =~ /paramplot.*\.(\d+)\.(\d+)\.dat/ ) { my $prefix = ""; if( $labelhash{$indats[$1]} ne "" ) { $prefix = $labelhash{$indats[$1]} . "$y:"; } $t = "t \"" . $prefix . "$paramname=$2\""; } elsif( defined $options{"overallconvex"} and defined $labelhash{"$file.overall"} ) { $t = "t \"" . $labelhash{"$file.overall"} . "$y\""; } else { $t = "t \"" . $labelhash{$indats[$i]} . "$y\""; } print GP "\"$file\" using ($xparen\$$xpos):($yparen[$k]\$$ypos) " . "$t with $type"; # make overall hulls thicker if( defined $options{"overallconvex"} and defined $labelhash{"$file.overall"} ) { print GP " lw 6"; } else { print GP " lw $linewidth"; } if( @convexfiles ) { $yindex++; if( $yindex > $#ystat ) { $yindex = 0; $i++; } last; } elsif( $k != $#ystat ) { print GP ", "; } else { $i++; } } if( $i < $num ) { print GP ", "; } elsif( defined $options{"convex"} && $options{"convex"} eq "both" ) { if( defined $plottype ) { $type = $plottype; } elsif( defined $param and $rtmgraph and @convexfiles ) { $type = "linespoints"; } else { $type = "points"; } # if we want, do it now my $j = 1; foreach my $datfile (@datfiles) { my $oldxpos = $xposes{$datfile}; if( defined $xop ) { # check it for stats my $newxop = $xop; foreach my $x (@xopsplit) { if( defined $xposes{ "$datfile$x"} ) { $newxop =~ s/$x/\$$xposes{"$datfile$x"}/g; } elsif( defined $xposes{ ($j-1) . "$x"} ) { $newxop =~ s/$x/\$$xposes{($j-1) . "$x"}/g; } elsif( !($x =~ /^[\d\.]*$/ ) ) { die( "Can't find a position for $x" ); } } $oldxpos = "$oldxpos$newxop"; } for( my $k = 0; $k <= $#ystat; $k++ ) { my $t; my $y = ""; if( $#ylabel > 0 ) { $y = ":$ylabel[$k]"; } if( defined $param and $rtmgraph and @convexfiles ) { $t = "notitle"; } elsif( defined $options{"convex"} && $options{"convex"} eq "both" ) { $t = "notitle"; } elsif( $datfile =~ /paramplot.*\.(\d+)\.(\d+)\.dat/ ) { my $prefix = ""; if( $labelhash{$indats[$1]} ne "" ) { $prefix = $labelhash{$indats[$1]} . "$y:"; } $t = "t \"" . $prefix . "$paramname=$2\""; } elsif( defined $options{"overallconvex"} and defined $labelhash{"$file.overall"} ) { $t = "t \"" . $labelhash{"$file.overall"} . "$y\""; } else { $t = "t \"" . $labelhash{$indats[$j-1]} . "$y\""; } my $oldypos = $yposes{"$k-$datfile"}; if( defined $yop[$k] ) { my $newyop = $yop[$k]; foreach my $y (&get_opsplit($yop[$k])) { if( defined $yposes{"$k-$datfile$y"} ) { $newyop =~ s/$y/\$$yposes{"$k-$datfile$y"}/g; } elsif( defined $yposes{"$k-" . ($j-1) . "$y"} ) { $newyop =~ s/$y/\$$yposes{"$k-" . ($j-1) . "$y"}/g; } elsif( !($y =~ /^[\d\.]*$/ ) ) { die( "Can't find a position for $y $j" ); } } $oldypos = "$oldypos$newyop"; } my $type_num = ($k+($j-1)*($#ystat+1)+1); if( $type ne "points" ) { print GP ", \"$datfile\" using " . "($xparen\$$oldxpos):($yparen[$k]\$$oldypos) " . "$t with $type lt $type_num lw $linewidth"; } else { print GP ", \"$datfile\" using " . "($xparen\$$oldxpos):($yparen[$k]\$$oldypos) " . "$t with $type lt $type_num pt $type_num"; } } $j++; } }}print GP "\n";close( GP );# now make the graph and display it if desiredsystem( "gnuplot /tmp/paramplot-$$.gnuplot" ) and die( "No gnuplot" );if( (!defined $epsfile) && (!defined $pngfile) && (!defined $colorepsfile)) { system( "gv /tmp/paramplot-$$.eps" ) and die( "No gv" );}# now cleanup timeunlink( "/tmp/paramplot-$$.gnuplot" );if( (!defined $epsfile) && (!defined($pngfile) ) && (!defined $colorepsfile)) { unlink( "/tmp/paramplot-$$.eps" );}if( $xparam or grep( /1/, @yparam ) ) { for( my $i = 0; $i <= $#indats; $i++ ) { unlink( "/tmp/paramplot-$$.$i.new.dat" ); }}if( (defined $param and !$rtmgraph) or (defined $plottype and ($plottype eq "lines" or $plottype eq "linespoints" ) ) ) { foreach my $file (@datfiles) { if( $file =~ /paramplot/ ) { unlink( $file ); } }}foreach my $file (@convexfiles) { unlink( $file );}foreach my $file (@rtmfiles) { unlink( $file );}############################################################sub get_opsplit { my $op = shift; if( !defined $op ) { return (); } my @opsplit = split( /[\*\+\-\/\(\)]/, $op ); for( my $i = 0; $i <= $#opsplit; $i++) { my $o = $opsplit[$i]; if( !defined $o or $o eq "" or $o =~ /\s+/ ) { splice( @opsplit, $i, 1 ); $i--; next; } if( $o =~ /^param\d+$/ ) { die( "Cannot use param ($o) in an operator ($op)" ); } elsif( $o =~ /^[\d\.]+$/ ) { # splice it out of there splice( @opsplit, $i, 1 ); $i--; } elsif( !$o =~ /^.*\:.*/ ) { die( "Wrong format for a value in an operation: $o" ); } elsif( !grep( /$o/, @statlabels) ) { die( "$o not in stats" ); } $i++; } for( my $i = 0; $i <= $#opsplit; $i++) { my $o = $opsplit[$i]; if( !defined $o or $o eq "" or $o =~ /\s+/ ) { splice( @opsplit, $i, 1 ); $i--; next; } } return @opsplit;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -