#!/usr/local/bin/perl -w # # example usage: # n3_to_g.p file1 | gnuplot # n3_to_g.p pointfile=po linefile=li psfile=po.ps dx=0.1 file1 | gnuplot # my example usage: # n3_to_g.p xmin=0.0 xmax=1.0 xy3 | gnuplot # # turns one plus three numbers per line, given in file 1, into # new files and gnuplot commands rendering those three points # as a little vertical spider # # fixed parameter dx (how big a horizontal separation to make) # # each line of input # # x y1 y2 y3 # # gives as output # # pointfile: # # x y1 # x+dx y2 # x y3 # # linefile: # # x y1 # x y3 # # x ybar # x+dx ybar # x+dx y2 # $pointfile = "p" ; $linefile = "l" ; $linestyle = "1 1" ; $pointstyle = "3 3" ; $n = 3 ; # number of y points per line $dx = 0.02 ; $ps=1; # whether to write to ps file when doing gnuplot stuff. $psfile = "p.ps" ; $xmin = 1 ; $xmax = -1 ; $sx = 0.4 ; $sy = 0.4 ; # # this allows you to change files on command line eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; open ( P , ">$pointfile" ) ; open ( L , ">$linefile" ) ; # # while(<>){ s/^\s*// ; # remove the initial space @a = split ; if ( $#a == $n ) { $x = $a[0] ; $x2 = sprintf ( "%10g" , $x + $dx ) ; for ( $tot = 0.0 , $i = 1; $i <= $n ; $i ++ ) { $tot += $a[$i] ; # } # $ybar = sprintf ( "%10g" , $tot / $n ) ; print P "$x\t$a[1]\n" ; # print P "$x2\t$a[2]\n" ; print P "$x\t$a[3]\n" ; print P "\n" ; print L "$x\t$a[1]\n" ; print L "$x\t$a[3]\n" ; print L "\n" ; print L "$x\t$ybar\n" ; print L "$x2\t$ybar\n" ; print L "$x2\t$a[2]\n" ; print L "\n" ; } elsif ( $#a == 0 ) { # blank line print STDERR "blank line 0" ; } elsif ( $#a == -1 ) { # blank line print STDERR "blank line -1" ; } else { print STDERR "warning, strange line $_" ; } } close (P) ; close (L) ; # # talk to gnuplot # print STDOUT "#\n# gnuplot\n set size $sx,$sy; set nologs x; set nologs y; set nokey\n" ; if ( $xmax > $xmin ) { printf STDOUT "set xrange [%7.3g:%7.3g]\n", $xmin, $xmax ; } if ( $ps ) { print STDOUT "set output '$psfile'\n" ; print STDOUT "set term post\n" ; } print STDOUT "plot '$pointfile' u 1:2 w p $pointstyle, " ; print STDOUT " '$linefile' u 1:2 w lines $linestyle " ; print STDOUT "\n" ;