1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
#
# Miscellaneous neat things you can do using the string variables code
#
iswindows = substr(GPVAL_SYSNAME, 1, 7) eq "Windows"
isos2 = substr(GPVAL_SYSNAME, 1, 4) eq "OS/2"
unset border
set print $EXAMPLE
print ""
print "Exercise substring handling"
print ""
beg = 2
end = 4
print "beg = ",beg," end = ",end
foo = "ABCDEF"
print "foo = ",foo
print "foo[3:5] = ",foo[3:5]
print "foo[1:1] = ",foo[1:1]
print "foo[5:3] = ",foo[5:3]
print "foo[beg:end] = ",foo[beg:end]
print "foo[end:beg] = ",foo[end:beg]
print "foo[5:] = ",foo[5:]
print "foo[5:*] = ",foo[5:*]
print "foo[:] = ",foo[:]
print "foo[*:*] = ",foo[*:*]
print "foo.foo[2:2] = ",foo.foo[2:2]
print "(foo.foo)[2:2]= ",(foo.foo)[2:2]
print ""
print "foo[1:1] eq 'A' && foo[2:2] ne 'X' = ", \
(foo[1:1] eq 'A' && foo[2:2] ne 'X') ? "true" : "false"
unset print
do for [i=1:|$EXAMPLE|] {
set label i $EXAMPLE[i] at graph 0.1, graph (1.0 - i*0.05)
}
unset xtics
unset ytics
set yrange [0:1]
plot 0 lc bgnd notitle
pause -1 "Hit return to continue"
set print $EXAMPLE
print "Exercise string handling functions"
print ""
print "foo = ",foo
print "strlen(foo) = ",strlen(foo)
print "substr(foo,3,4) = ",substr(foo,3,4)
print ""
if (1) {
haystack = time("%H:%M %d %B %Y")
} else if (!iswindows && !isos2) {
haystack = system("date")
} else if (iswindows) {
haystack = system("date /T") . " " . system("time /T")
} else {
haystack = time("%D %T")
}
needle = ":"
S = strstrt(haystack,needle)
print "haystack = \`date\`"
print "haystack = ",haystack
print "needle = ",needle
print "S = strstrt(haystack,needle) = ",S
print "haystack[S-2:S+2] = ",haystack[S-2:S+2]
print "It is now " . haystack[S-2:S+2]
#
print ""
#
foo = sprintf("%40d %40d %40d %40d %40d %40d",1,2,3,4,5,6)
if (strlen(foo) == 245) print "sprintf output of long strings works OK"
if (strlen(foo) != 245) print "sprintf output of long strings BROKEN"
print ""
unset print
unset label
do for [i=1:|$EXAMPLE|] {
set label i $EXAMPLE[i] at graph 0.1, graph (1.0 - i*0.05)
}
unset xtics
unset ytics
set yrange [0:1]
plot 0 lc bgnd notitle
pause -1 "Hit return to continue"
set print $EXAMPLE
print "Exercise word and words functions"
print ""
foo = "word and words can handle 'quoted string'"
print "foo = ",foo
print "words(foo) = ",words(foo)
print "word(foo, 6) = ",word(foo,6)
print ""
foo = "\"double quotes\" or 'single quotes'"
print "foo = ",foo
print "words(foo) = ",words(foo)
print ""
foo = "Apostrophes inside words don't matter"
print "foo = ",foo
print "word(foo, 4) = ",word(foo, 4)
unset print
unset label
do for [i=1:|$EXAMPLE|] {
set label i $EXAMPLE[i] at graph 0.1, graph (1.0 - i*0.05)
}
unset xtics
unset ytics
set yrange [0:1]
plot 0 lc bgnd notitle
pause -1 "Hit return to continue"
reset
#
set xrange [300:400]
set title "String-valued expression in using spec"
plot 'silver.dat' using 1:2 with linespoints notitle, \
'' using 1:2:(sprintf("[%.0f,%.0f]",$1,$2)) with labels
#
pause -1 "Hit return to continue"
#
set xrange [0:1]
set yrange [0:1]
set title "Constant string expressions as plot symbols"
set xrange [250:500]
set auto y
set style data lines
plot 'silver.dat' u 1:2:($3+$1/50.) w filledcurves above title 'Above', \
'' u 1:2:($3+$1/50.) w filledcurves below title 'Below', \
'' u 1:2 lt -1 lw 0.5 notitle, \
'' u 1:($3+$1/50.) lt 3 lw 0.5 notitle, \
'' using 1:2:( ($2>($3+$1/50.)) ? "Up" : "Dn" ) with labels \
title 'plot <foo> using 1:2:( ($3>$2) ? "Up" : "Dn" ) with labels'
#
pause -1 "Hit return to continue"
#
reset
set title "String-valued functions to generate datafile names"
set key title 'file(i) = sprintf("%1d.dat",i); N=2; M=3'
set key left width 25 Left reverse
N = 2
M = 3
file(i) = sprintf("%1d.dat",i)
plot 5*sin(x)/x, file(N), file(M)
#
pause -1 "Hit return to continue"
#
reset
fmt = '%Y-%m-%d %H:%M:%S'
time_str = '2005-05-09 19:44:12'
seconds = strptime(fmt, time_str)
time_str2 = strftime(fmt, seconds+10.)
print ''
print 'time_str = "', time_str, '"'
print '-> seconds = ', seconds
print ' seconds + 10. = ', seconds+10.
print '-> time_str2 = "', time_str2, '"'
#
print ""
#
set xdata time
set key inside left
#set format x '%Y-%m-%d'
fmt = "%d/%m/%y\t%H%M"
print "read_time(fmt, c) =" \
. " strptime(fmt, stringcolumn(c).' '.stringcolumn(c+1))"
read_time(fmt, c) = strptime(fmt, stringcolumn(c).' '.stringcolumn(c+1))
plot 'timedat.dat' skip 1 using (read_time(fmt,1)):3 with histeps, \
'timedat.dat' skip 1 using (read_time(fmt,1)):($3-0.01):2 with labels title ''
#
print ""
pause -1 "Hit return to continue"
#
reset
|