📄 make-graph.pl
字号:
my %vals_used = (); my $num_stats; my $newfile = "/tmp/paramplot-$$.$index.new.dat"; open( DAT, ">>$newfile" ) or die( "Couldn't open tmp: $newfile" ); for( my $i = 1; $i <= $#dat; $i++ ) { my $line = $dat[$i]; if( $line =~ /^\#\s*(\d[\d\s]+)\:?$/ ) { my @params = split( /\s+/, $1 ); if( $xparam && $#params < $xpos) { die( "Wrong param number $xpos for \"@params\"" ); } if( $xparam ) { $last_valx = $params[$xpos]; } for( my $j = 0; $j <= $#ystat; $j++ ) { if( $yparam[$j] && $#params < $ypos[$j] ) { die( "Wrong param number $ypos[$j] for \"@params\"" ); } if( $yparam[$j] ) { $last_valy[$j] = $params[$ypos[$j]]; } } if( $hullparam && $#params < $hullpos) { die( "Wrong param number $hullpos for \"@params\"" ); } if( $hullparam ) { $last_valhull = $params[$hullpos]; } print DAT $line; } elsif( $line =~ /^([^\#]*)$/ ) { my $newline = "$1 "; $newline =~ s/\n//; if( !defined $num_stats ) { my @s = split( /\s+/, $newline ); $num_stats = $#s + 1; } if( $xparam ) { $newline .= "$last_valx "; } for( my $j = 0; $j <= $#ystat; $j++ ) { if( $yparam[$j] ) { $newline .= "$last_valy[$j] "; } } if( $hullparam ) { $newline .= "$last_valhull "; } print DAT "$newline\n"; $dat[$i] = "$newline\n"; } } # at what positions are these params? # (only set these after looking at all files, so it's not messed # up on the next loop) my $i = 0; if( $xparam ) { $i++; $xpos = $num_stats + $i; } $xposes{$newfile} = $xpos; for( my $j = 0; $j <= $#ystat; $j++ ) { if( $yparam[$j] ) { $i++; $ypos[$j] = $num_stats + $i; } $yposes{"$j-$newfile"} = $ypos[$j]; } if( $hullparam ) { $i++; $hullpos = $num_stats + $i; } $hullposes{$newfile} = $hullpos; close( DAT ); $labelhash{"$newfile"} = $labelhash{$datfile}; $datfile = $newfile; } # if we're coloring the plot by params, better break the data apart if( defined $param and !$rtmgraph ) { my $last_val = -1; my %vals_used = (); # if given the name of a parameter, find it's position now my $parampos; if( $param =~ /^\d+/ ) { $parampos = $param; } else { @statlabels = split( /\s+/, $dat[0] ); foreach my $label (@statlabels) { if( $label =~ /^param(\d+)\)$param/ ) { $parampos = $1 - 1; last; } } if( !defined $parampos ) { die( "No parameter $param found in file $datfile" ); } } for( my $i = 1; $i <= $#dat; $i++ ) { my $line = $dat[$i]; my $newfile = "/tmp/paramplot-$$.$index.$last_val.dat"; if( $line =~ /^\#\s*(\d[\d\s]+)\:?$/ ) { my @params = split( /\s+/, $1 ); if( $#params < $parampos ) { die( "Wrong param number $param for \"@params\"" ); } $last_val = $params[$parampos]; } elsif( $line =~ /^([^\#]*)$/ and (!%paramvals || defined $paramvals{$last_val} ) ) { $vals_used{$last_val} = "true"; open( DAT, ">>$newfile" ) or die("Couldn't open tmp: $newfile"); print DAT "$1"; close( DAT ); } foreach my $o (@xopsplit) { $xposes{"$newfile$o"} = $xposes{"$index$o"}; } for( my $j = 0; $j <= $#ystat; $j++ ) { foreach my $o (&get_opsplit($yop[$j])) { $yposes{"$j-$newfile$o"} = $yposes{"$j-$index$o"}; } } foreach my $o (@hullopsplit) { $hullposes{"$newfile$o"} = $hullposes{"$index$o"}; } } my @keys = keys(%vals_used); my @skeys = sort {$a <=> $b} @keys; foreach my $val (@skeys) { my $newfile = "/tmp/paramplot-$$.$index.$val.dat"; push @datfiles, $newfile; $xposes{$newfile} = $xpos; for( my $j = 0; $j <= $#ystat; $j++ ) { $yposes{"$j-$newfile"} = $ypos[$j]; } $hullposes{$newfile} = $hullpos; } # do we also want the overall hull? if( defined $options{"overallconvex"} ) { push @datfiles, "$datfile"; my $l = ""; if( $options{"overallconvex"} ne "" ) { $l = ""; if( $labelhash{$indats[$index]} ne "" ) { $l = ":"; } $l = $l . $options{"overallconvex"}; } $labelhash{"$datfile.overall"} = $labelhash{$indats[$index]} . $l; } } else { push @datfiles, "$datfile"; } $index++;}# if we're wanting to do lines later on, we need to sort these by the x-axisif( defined $plottype and ($plottype eq "lines" or $plottype eq "linespoints" ) ) { for( my $i = 0; $i <= $#datfiles; $i++ ) { my $datfile = $datfiles[$i]; open( DAT, "<$datfile" ) or die( "Couldn't open $datfile" ); my $lastheader = ""; my %svals = (); while( <DAT> ) { if( /^\#/ ) { $lastheader = $_; } else { my @vals = split( /\s+/ ); # transform the x before sorting my $conxop = ""; if( defined $xop ) { # check it for stats $conxop = $xop; foreach my $x (@xopsplit) { if( defined $xposes{"$datfile$x"} ) { $conxop =~ s/$x/$vals[$xposes{"$datfile$x"}-1]/g; } elsif( defined $xposes{"$index$x"} ) { $conxop =~ s/$x/$vals[$xposes{"$index$x"}-1]/g; } elsif( !($x =~ /^[\d\.]*$/ ) ) { die( "Can't find a position for $x" ); } } } my $conx = eval("$xparen" . $vals[$xposes{$datfile}-1] . "$conxop"); if( !defined $conx ) { $conx = 0; } if( !defined $svals{$conx} ) { $svals{$conx} = "$lastheader$_"; } else { $svals{$conx} .= "$lastheader$_"; } } } close( DAT ); # now print the lines out in sorted order to the new file my $newfile; if( $datfile =~ /paramplot.*\.(\d+)\.(\d+)\.dat/ ) { $newfile = $datfile; } else { $newfile = "/tmp/paramplot-$$-sort$i.dat"; } open( SORT, ">$newfile" ) or die("Couldn't write to $newfile"); my @sorted = sort {$a <=> $b} keys(%svals); foreach my $k (@sorted) { print SORT $svals{$k};# print $lines; } close( SORT ); # now fix all the data $xposes{"$newfile"} = $xposes{$datfile}; for( my $j = 0; $j <= $#ystat; $j++ ) { $yposes{"$j-$newfile"} = $yposes{"$j-$datfile"}; } $hullposes{"$newfile"} = $hullposes{$datfile}; $datfiles[$i] = $newfile; }}# if necessary, run each file through the convexinator{;}my @convexfiles = ();my %uniqhash;if( defined $options{"convex"} ) { my $index = 0; foreach my $datfile (@datfiles) { for( my $j = 0; $j <= $#ystat; $j++ ) { open( DAT, "<$datfile" ) or die( "Couldn't open $datfile" ); open( CON, ">$datfile.con" ) or die("Couldn't write to $datfile.con"); my %headerhash = (); my %valshash = (); my $h; my $max_x; my $min_y; while( <DAT> ) { if( /^\#/ ) { $h = $_; next; } else { my $v = $_; my @vals = split( /\s+/ ); # do these operations before computing the hull! my $conxop = ""; my $conyop = ""; if( defined $xop ) { # check it for stats $conxop = $xop; foreach my $x (@xopsplit) { if( defined $xposes{"$datfile$x"} ) { $conxop =~ s/$x/$vals[$xposes{"$datfile$x"}-1]/g; } elsif( defined $xposes{"$index$x"} ) { $conxop =~ s/$x/$vals[$xposes{"$index$x"}-1]/g; } elsif( !($x =~ /^[\d\.]*$/ ) ) { die( "Can't find a position for $x" ); } } } $conyop = ""; if( defined $yop[$j] ) { $conyop = $yop[$j]; foreach my $y (&get_opsplit($yop[$j])) { if( defined $yposes{"$j-$datfile$y"} ) { $conyop =~ s/$y/$vals[$yposes{"$j-$datfile$y"}-1]/g; } elsif( defined $yposes{"$j-$index$y"} ) { $conyop =~ s/$y/$vals[$yposes{"$j-$index$y"}-1]/g; } elsif( !($y =~ /^[\d\.]*$/ ) ) { die( "Can't find a position for $y" ); } } } my $conx = eval("$xparen" . $vals[$xposes{$datfile}-1] . "$conxop"); if( !defined $conx ) { $conx = 0; } my $cony = eval("$yparen[$j]" . $vals[$yposes{"$j-$datfile"}-1] . "$conyop"); if( !defined $cony ) { $cony = 0; } if ($cony=~/\./) { }else{ $cony .=".0"; #jy: find-convex.py always spits out dicimal points } if ($conx=~/\./) { }else{ $conx .=".0"; } if (!defined($uniqhash{"$conx $cony"})) { $uniqhash{"$conx $cony"} = 1; }else{ while( defined($uniqhash{"$conx $cony"} ) ) { $conx += rand() * 0.00001; # make sure it doesn't have too many digits, otherwise # python will return a different number my $tmpconx = int ($conx*10000000); $conx = ($tmpconx*1.0)/10000000.0; } $uniqhash{"$conx $cony"} = 1; } # we might need to figure out what this line was later if (!defined($headerhash{"$conx $cony"})) { $headerhash{"$conx $cony"} = $h; } # restrain number of y digits my $tmpcony = int ($cony*10000000); $cony = ($tmpcony*1.0)/10000000.0; # add at least one digit if ($cony =~/\./) { }else{ $cony = $cony.".0"; } print CON "$conx $cony\n"; if( !defined $max_x or $conx > $max_x ) { $max_x = $conx; } if( !defined $min_y or $cony < $min_y ) { $min_y = $cony; } if( defined $options{"hulllabel"} ) { $valshash{"$conx $cony"} = $v; } undef $h; } } undef %uniqhash; close( DAT ); close( CON ); # now run it through the convexinator system( "$con_cmd $datfile.con > $datfile$j.convex" ) and die( "Couldn't run ./find_convexhull.py $datfile.con" ); unlink( "$datfile.con" ); push @convexfiles, "$datfile$j.convex"; $xposes{"$datfile$j.convex"} = $xposes{$datfile}; for( my $k = 0; $k <= $#ystat; $k++ ) { $yposes{"$k-$datfile$j.convex"} = $yposes{"$k-$datfile"}; } $hullposes{"$datfile$j.convex"} = $hullposes{$datfile}; if( defined $options{"overallconvex"} and !($datfile =~ /paramplot/) ) { $labelhash{"$datfile$j.convex.overall"} = $labelhash{"$datfile.overall"}; } # now figure out the hull labels if( defined $options{"hulllabel"} ) { my @vals = (); open( CON, "<$datfile$j.convex" ) or die( "Couldn't open $datfile$j.convex" ); while( <CON> ) { if( /([\d\.]+) ([\d\.]+)/ ) { if( defined $valshash{"$1 $2"} ) { my $xval = $1; my $yval = $2; # figure out what the hull label # for this point should be. my @v = split( /\s+/, $valshash{"$xval $yval"} ); my $hulleval = ""; if( defined $hullop ) { # check it for stats $hulleval = $hullop; foreach my $hull (@hullopsplit) { if( defined $hullposes{"$datfile$hull"} ) { $hulleval =~ s/$hull/$v[$hullposes{"$datfile$hull"}-1]/g; } elsif(defined $hullposes{"$index$hull"}){ $hulleval =~ s/$hull/$v[$hullposes{"$index$hull"}-1]/g; } elsif( !($hull =~ /^[\d\.]*$/ ) ) { die("Can't find a position for $hull"); } } } my $hullval = eval("$hullparen" . $v[$hullposes{$datfile}-1] . "$hulleval"); # make sure this point will be inside the range # before labelling the point if( (defined $xrange and ($xval < $xmin or $xval > $xmax)) or (defined $yrange and ($yval < $ymin or $yval > $ymax)) ) { next; } push( @hulllabelcmds, "set label \"$hullval\" at $xval,$yval " . "font \"Times-Roman,16\"" ); } else { die( "val not defined: $1 $2 $datfile$j.convex" ); } } else { die( "Weird line in $datfile$j.convex: $_" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -