#!/usr/bin/tclsh
set auto_noexec 1
if {$argc == 0} {
puts "error: there is no parameters"
exit
}
set tdir .
#--------------------------------------------------------------
# begin of gnuplot_data |
set gnuplot_data {
set terminal postscript eps enhanced color size (Gx)cm,(Gy)cm
set output fileout
set noxtic
set noytic
set nokey
unset border
set xrange [-1:1]
set yrange [-1:1]
set zrange [-1:1]
set xtics (0) format ""
set ytics (0) format ""
set grid xtics ytics lt 1 lc 0
set size square 0.25,0.4
set rmargin 1
set lmargin 1
set tmargin 0
set bmargin 0
set trange [0:2*pi]
set multiplot
set origin 0.05,0.55
set xlabel "l_x" offset 0,1
unset ylabel
set label 1 "l_y" left offset first -1.3,0
set parametric
plot cos(t),-sin(t) w l lw 2 lc 0,\
0.8*cos(t),-0.8*sin(t) w l lt 4 lw 1 lc 0,\
0.6*cos(t),-0.6*sin(t) w l lt 4 lw 1 lc 0,\
0.4*cos(t),-0.4*sin(t) w l lt 4 lw 1 lc 0,\
0.2*cos(t),-0.2*sin(t) w l lt 4 lw 1 lc 0
unset parametric
plot filein u 2:3 w l lw 2
unset label 1
set origin 0.35,0.55
set xlabel "l_y"
unset ylabel
set label 2 "l_z" left offset first -1.3,0
set parametric
plot cos(t),-sin(t) w l lw 2 lc 0,\
0.8*cos(t),-0.8*sin(t) w l lt 4 lw 1 lc 0,\
0.6*cos(t),-0.6*sin(t) w l lt 4 lw 1 lc 0,\
0.4*cos(t),-0.4*sin(t) w l lt 4 lw 1 lc 0,\
0.2*cos(t),-0.2*sin(t) w l lt 4 lw 1 lc 0
unset parametric
plot filein u 3:4 w l lw 2
unset label 2
set origin 0.65,0.55
set xlabel "l_x"
unset ylabel
set label 3 "l_z" left offset first -1.3,0
set parametric
plot cos(t),-sin(t) w l lw 2 lc 0,\
0.8*cos(t),-0.8*sin(t) w l lt 4 lw 1 lc 0,\
0.6*cos(t),-0.6*sin(t) w l lt 4 lw 1 lc 0,\
0.4*cos(t),-0.4*sin(t) w l lt 4 lw 1 lc 0,\
0.2*cos(t),-0.2*sin(t) w l lt 4 lw 1 lc 0
unset parametric
plot filein u 2:4 w l lw 2
unset label 3
set size nosquare 0.80,0.4
set origin 0.10,0.1
set tmargin 1
set bmargin 1
set lmargin 2
set border
set xtics 1 format "%.0f"
set ytics 0.5 format "%.1f"
set mxtics 5
set mytics 5
unset grid
set xrange [0:xt]
set yrange [-1.1:1.1]
set xlabel "x" offset 0,0
unset ylabel
#set label 4 "l_x, l_y, l_z" at graph -0.15, graph 0.5
set label 4 "l_x, l_y, l_z" left offset -10,0
set key box linestyle -1
plot filein u 1:2 title " l_x" w l lt 1 lw 2 lc 1,\
filein u 1:3 title " l_y" w l lt 1 lw 2 lc 2,\
filein u 1:4 title " l_z" w l lt 1 lw 2 lc 3
set nomultiplot
}
# end of gnuplot_data |
#-----------------------------------------------------------
if {[lindex $argv 0] eq "-t"} {
if {$argc > 0} {
if {[file isdirectory [lindex $argv 1]]} {
set tdir [lindex $argv 1]
} else {
puts "error: must be \"-t <target dir>\""
}
set argv [lreplace $argv 0 1]
} else {
puts "error: must be \"-t <target dir>\""
set argv [lreplace $argv 0 0]
}
}
foreach a $argv {
if {[file isfile $a]} {
set xt [lindex [exec cat $a | tail -1] 0]
set gnuplot_input [open "|gnuplot" w]
#setting values of gnuplot user-defined variables
set Gx 12
set Gy 9
puts $gnuplot_input\
"fileout = \"[file join $tdir [file rootname [file tail $a]]].eps\"
filein = \"$a\"
xt = $xt
Gx = $Gx
Gy = $Gy"
#writing of main data
puts $gnuplot_input $gnuplot_data
flush $gnuplot_input
close $gnuplot_input
#correcting of eps-file
set fs [open [file join $tdir [file rootname [file tail $a]]].eps r]
set fdata [split [read $fs] \n]
for {set i 0} {$i < [llength $fdata]} {incr i} {
if {[string first "BoundingBox" [lindex $fdata $i]] >= 0} {
lset fdata $i "%%BoundingBox: 50 50 [expr {28*$Gx + 30}] [expr {28*$Gy + 50}]"
break
}
}
close $fs
set fs [open [file join $tdir [file rootname [file tail $a]]].eps w]
set fdata [join $fdata \n]
puts $fs $fdata
close $fs
} else {
puts "error: \"$a\" is not a file"
}
}