#!/usr/local/bin/perl $file1 = "res.dat"; $file2 = "g/xys"; $Na=57 ; # usage: # y_sig.p file1=out.dat Na=57 # expected input format is like this: # x , y , sigma (top line) # [1] -3.331E-1 -2.464E-1 -2.281E-1 2.440E-1 5.391E-1 # [6] 4.605E-1 -5.062E-1 -2.453E-1 6.215E-2 1.519E-1 # [11] 1.183E-1 -4.556E-2 8.143E-1 -4.035E-1 -1.163E-1 # etc. # (one blank line) # [1] -1.275E+0 -2.185E+0 -2.377E+0 -4.206E+0 -4.133E+0 # [6] -4.307E+0 -1.102E-1 -2.197E+0 -4.092E+0 -4.162E+0 # [11] -4.145E+0 -3.791E+0 -3.072E+0 -6.463E-1 -3.378E+0 # etc. # (one blank line) # [1] 1.060E+0 1.158E+0 1.177E+0 1.259E+0 1.820E+0 # [6] 1.685E+0 9.900E-1 1.159E+0 1.201E+0 1.194E+0 # [11] 1.190E+0 1.244E+0 2.022E+0 1.001E+0 1.249E+0 # read command line arguments eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; open ( S , "<$file1" ) ; open ( GNU , ">$file2" ) ; $_ = ; # read top line print GNU "# " , $_ ; for ( $loop = 1 ; $loop <= 3 ; $loop ++ ) { $j=0; while(($_ = )) { s/E/e/g; s/^[\t\s]*\[[0-9]*\][\t\s]*//; s/\n//; # print ; $i = $j ; ($x[$i++],$x[$i++],$x[$i++],$x[$i++],$x[$i++]) = split ; for ( ; $j < $i ; $j++ ) { $out[$j] .= $x[$j]."\t" ; if ( $loop == 2 ) { $y[$j] = $x[$j] ; } elsif ( $loop ==3 ) { $y[$j] += $x[$j] ; $out[$j] .= $y[$j]."\t" ; $y[$j] -= 2 * $x[$j] ; $out[$j] .= $y[$j] ; } else { $xx[$j] = $x[$j] ; } } } } $J = $j ; @sorted = sort byxx @out[0..$Na] ; for ( $j = 0 ; $j < $#sorted ; $j++ ) { print GNU $sorted[$j] , "\n" ; } print GNU "\n" ; @sorted = sort byxx @out[$Na+1..$J] ; for ( $j = 0 ; $j < $#sorted ; $j++ ) { print GNU $sorted[$j] , "\n" ; } close ( GNU ) ; print "# gnuplot\n plot '$file2' u 1:2:3 w errorb\n"; print "# gnuplot\n plot '$file2' u 1:2 w linesp 2, '$file2' u 1:4 w linesp 5, '$file2' u 1:5 w linesp 5\n"; close ( S ) ; sub byxx { $a <=> $b ; }