|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
# Miscellaneous neat things you can do using the string variables code
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
iswindows = substr(GPVAL_SYSNAME, 1, 7) eq "Windows"
|
|
Packit |
0986c0 |
unset border
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
set print $EXAMPLE
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
print "Exercise substring handling"
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
beg = 2
|
|
Packit |
0986c0 |
end = 4
|
|
Packit |
0986c0 |
print "beg = ",beg," end = ",end
|
|
Packit |
0986c0 |
foo = "ABCDEF"
|
|
Packit |
0986c0 |
print "foo = ",foo
|
|
Packit |
0986c0 |
print "foo[3:5] = ",foo[3:5]
|
|
Packit |
0986c0 |
print "foo[1:1] = ",foo[1:1]
|
|
Packit |
0986c0 |
print "foo[5:3] = ",foo[5:3]
|
|
Packit |
0986c0 |
print "foo[beg:end] = ",foo[beg:end]
|
|
Packit |
0986c0 |
print "foo[end:beg] = ",foo[end:beg]
|
|
Packit |
0986c0 |
print "foo[5:] = ",foo[5:]
|
|
Packit |
0986c0 |
print "foo[5:*] = ",foo[5:*]
|
|
Packit |
0986c0 |
print "foo[:] = ",foo[:]
|
|
Packit |
0986c0 |
print "foo[*:*] = ",foo[*:*]
|
|
Packit |
0986c0 |
print "foo.foo[2:2] = ",foo.foo[2:2]
|
|
Packit |
0986c0 |
print "(foo.foo)[2:2]= ",(foo.foo)[2:2]
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
print "foo[1:1] eq 'A' && foo[2:2] ne 'X' = ", \
|
|
Packit |
0986c0 |
(foo[1:1] eq 'A' && foo[2:2] ne 'X') ? "true" : "false"
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset print
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
do for [i=1:|$EXAMPLE|] {
|
|
Packit |
0986c0 |
set label i $EXAMPLE[i] at graph 0.1, graph (1.0 - i*0.05)
|
|
Packit |
0986c0 |
}
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset xtics
|
|
Packit |
0986c0 |
unset ytics
|
|
Packit |
0986c0 |
set yrange [0:1]
|
|
Packit |
0986c0 |
plot 0 lc bgnd notitle
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
pause -1 "Hit return to continue"
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
set print $EXAMPLE
|
|
Packit |
0986c0 |
print "Exercise string handling functions"
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
print "foo = ",foo
|
|
Packit |
0986c0 |
print "strlen(foo) = ",strlen(foo)
|
|
Packit |
0986c0 |
print "substr(foo,3,4) = ",substr(foo,3,4)
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
if (!iswindows) {
|
|
Packit |
0986c0 |
haystack = system("date")
|
|
Packit |
0986c0 |
} else {
|
|
Packit |
0986c0 |
haystack = system("date /T") . " " . system("time /T")
|
|
Packit |
0986c0 |
}
|
|
Packit |
0986c0 |
needle = ":"
|
|
Packit |
0986c0 |
S = strstrt(haystack,needle)
|
|
Packit |
0986c0 |
print "haystack = \`date\`"
|
|
Packit |
0986c0 |
print "haystack = ",haystack
|
|
Packit |
0986c0 |
print "needle = ",needle
|
|
Packit |
0986c0 |
print "S = strstrt(haystack,needle) = ",S
|
|
Packit |
0986c0 |
print "haystack[S-2:S+2] = ",haystack[S-2:S+2]
|
|
Packit |
0986c0 |
print "It is now " . haystack[S-2:S+2]
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
print "words(haystack) = ",words(haystack)
|
|
Packit |
0986c0 |
print "word(haystack,5) = ",word(haystack,5)
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
foo = sprintf("%40d %40d %40d %40d %40d %40d",1,2,3,4,5,6)
|
|
Packit |
0986c0 |
if (strlen(foo) == 245) print "sprintf output of long strings works OK"
|
|
Packit |
0986c0 |
if (strlen(foo) != 245) print "sprintf output of long strings BROKEN"
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset print
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset label
|
|
Packit |
0986c0 |
do for [i=1:|$EXAMPLE|] {
|
|
Packit |
0986c0 |
set label i $EXAMPLE[i] at graph 0.1, graph (1.0 - i*0.05)
|
|
Packit |
0986c0 |
}
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset xtics
|
|
Packit |
0986c0 |
unset ytics
|
|
Packit |
0986c0 |
set yrange [0:1]
|
|
Packit |
0986c0 |
plot 0 lc bgnd notitle
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
pause -1 "Hit return to continue"
|
|
Packit |
0986c0 |
set print $EXAMPLE
|
|
Packit |
0986c0 |
print "Exercise word and words functions"
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
foo = "word and words can handle 'quoted string'"
|
|
Packit |
0986c0 |
print "foo = ",foo
|
|
Packit |
0986c0 |
print "words(foo) = ",words(foo)
|
|
Packit |
0986c0 |
print "word(foo, 6) = ",word(foo,6)
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
foo = "\"double quotes\" or 'single quotes'"
|
|
Packit |
0986c0 |
print "foo = ",foo
|
|
Packit |
0986c0 |
print "words(foo) = ",words(foo)
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
foo = "Apostrophes inside words don't matter"
|
|
Packit |
0986c0 |
print "foo = ",foo
|
|
Packit |
0986c0 |
print "word(foo, 4) = ",word(foo, 4)
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset print
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset label
|
|
Packit |
0986c0 |
do for [i=1:|$EXAMPLE|] {
|
|
Packit |
0986c0 |
set label i $EXAMPLE[i] at graph 0.1, graph (1.0 - i*0.05)
|
|
Packit |
0986c0 |
}
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
unset xtics
|
|
Packit |
0986c0 |
unset ytics
|
|
Packit |
0986c0 |
set yrange [0:1]
|
|
Packit |
0986c0 |
plot 0 lc bgnd notitle
|
|
Packit |
0986c0 |
|
|
Packit |
0986c0 |
pause -1 "Hit return to continue"
|
|
Packit |
0986c0 |
reset
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
set xrange [300:400]
|
|
Packit |
0986c0 |
set title "String-valued expression in using spec"
|
|
Packit |
0986c0 |
plot 'silver.dat' using 1:2 with linespoints notitle, \
|
|
Packit |
0986c0 |
'' using 1:2:(sprintf("[%.0f,%.0f]",$1,$2)) with labels
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
pause -1 "Hit return to continue"
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
set xrange [0:1]
|
|
Packit |
0986c0 |
set yrange [0:1]
|
|
Packit |
0986c0 |
set title "Constant string expressions as plot symbols"
|
|
Packit |
0986c0 |
set xrange [250:500]
|
|
Packit |
0986c0 |
set auto y
|
|
Packit |
0986c0 |
set style data lines
|
|
Packit |
0986c0 |
plot 'silver.dat' u 1:2:($3+$1/50.) w filledcurves above title 'Above', \
|
|
Packit |
0986c0 |
'' u 1:2:($3+$1/50.) w filledcurves below title 'Below', \
|
|
Packit |
0986c0 |
'' u 1:2 lt -1 lw 0.5 notitle, \
|
|
Packit |
0986c0 |
'' u 1:($3+$1/50.) lt 3 lw 0.5 notitle, \
|
|
Packit |
0986c0 |
'' using 1:2:( ($2>($3+$1/50.)) ? "Up" : "Dn" ) with labels \
|
|
Packit |
0986c0 |
title 'plot <foo> using 1:2:( ($3>$2) ? "Up" : "Dn" ) with labels'
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
pause -1 "Hit return to continue"
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
reset
|
|
Packit |
0986c0 |
set title "String-valued functions to generate datafile names"
|
|
Packit |
0986c0 |
set key title 'file(i) = sprintf("%1d.dat",i); N=2; M=3'
|
|
Packit |
0986c0 |
set key left width 25 Left reverse
|
|
Packit |
0986c0 |
N = 2
|
|
Packit |
0986c0 |
M = 3
|
|
Packit |
0986c0 |
file(i) = sprintf("%1d.dat",i)
|
|
Packit |
0986c0 |
plot 5*sin(x)/x, file(N), file(M)
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
pause -1 "Hit return to continue"
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
reset
|
|
Packit |
0986c0 |
fmt = '%Y-%m-%d %H:%M:%S'
|
|
Packit |
0986c0 |
time_str = '2005-05-09 19:44:12'
|
|
Packit |
0986c0 |
seconds = strptime(fmt, time_str)
|
|
Packit |
0986c0 |
time_str2 = strftime(fmt, seconds+10.)
|
|
Packit |
0986c0 |
print ''
|
|
Packit |
0986c0 |
print 'time_str = "', time_str, '"'
|
|
Packit |
0986c0 |
print '-> seconds = ', seconds
|
|
Packit |
0986c0 |
print ' seconds + 10. = ', seconds+10.
|
|
Packit |
0986c0 |
print '-> time_str2 = "', time_str2, '"'
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
set xdata time
|
|
Packit |
0986c0 |
set key inside left
|
|
Packit |
0986c0 |
#set format x '%Y-%m-%d'
|
|
Packit |
0986c0 |
fmt = "%d/%m/%y\t%H%M"
|
|
Packit |
0986c0 |
print "read_time(fmt, c) =" \
|
|
Packit |
0986c0 |
. " strptime(fmt, stringcolumn(c).' '.stringcolumn(c+1))"
|
|
Packit |
0986c0 |
read_time(fmt, c) = strptime(fmt, stringcolumn(c).' '.stringcolumn(c+1))
|
|
Packit |
0986c0 |
plot 'timedat.dat' skip 1 using (read_time(fmt,1)):3 with histeps, \
|
|
Packit |
0986c0 |
'timedat.dat' skip 1 using (read_time(fmt,1)):($3-0.01):2 with labels title ''
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
print ""
|
|
Packit |
0986c0 |
pause -1 "Hit return to continue"
|
|
Packit |
0986c0 |
#
|
|
Packit |
0986c0 |
reset
|