2 # Miscellaneous neat things you can do using the string variables code
4 set print "stringvar.tmp"
6 print "Exercise substring handling"
10 print "beg = ",beg," end = ",end
13 print "foo[3:5] = ",foo[3:5]
14 print "foo[1:1] = ",foo[1:1]
15 print "foo[5:3] = ",foo[5:3]
16 print "foo[beg:end] = ",foo[beg:end]
17 print "foo[end:beg] = ",foo[end:beg]
18 print "foo[5:] = ",foo[5:]
19 print "foo[5:*] = ",foo[5:*]
20 print "foo[:] = ",foo[:]
21 print "foo[*:*] = ",foo[*:*]
22 print "foo.foo[2:2] = ",foo.foo[2:2]
23 print "(foo.foo)[2:2]= ",(foo.foo)[2:2]
27 set label 1 system("cat stringvar.tmp") at graph 0.1, graph 0.9
33 pause -1 "Hit return to continue"
36 set print "stringvar.tmp"
37 print "Exercise string handling functions"
40 print "strlen(foo) = ",strlen(foo)
41 print "substr(foo,3,4) = ",substr(foo,3,4)
45 S = strstrt(haystack,needle)
46 print "haystack = \`date\`"
47 print "haystack = ",haystack
48 print "needle = ",needle
49 print "S = strstrt(haystack,needle) = ",S
50 print "haystack[S-2:S+2] = ",haystack[S-2:S+2]
51 print "It is now " . haystack[S-2:S+2]
54 print "words(haystack) = ",words(haystack)
55 print "word(haystack,5) = ",word(haystack,5)
59 foo = sprintf("%40d %40d %40d %40d %40d %40d",1,2,3,4,5,6)
60 if (strlen(foo) == 245) print "sprintf output of long strings works OK"
61 if (strlen(foo) != 245) print "sprintf output of long strings BROKEN"
65 set label 1 system("cat stringvar.tmp") at graph 0.1, graph 0.9
71 pause -1 "Hit return to continue"
75 set title "String-valued expression in using spec"
76 plot 'silver.dat' using 1:2 with linespoints notitle, \
77 '' using 1:2:(sprintf("[%.0f,%.0f]",$1,$2)) with labels
79 pause -1 "Hit return to continue"
83 set title "Constant string expressions as plot symbols"
87 plot 'silver.dat' u 1:2:($3+$1/50.) w filledcurves above title 'Above', \
88 '' u 1:2:($3+$1/50.) w filledcurves below title 'Below', \
89 '' u 1:2 lt -1 lw 0.5 notitle, \
90 '' u 1:($3+$1/50.) lt 3 lw 0.5 notitle, \
91 '' using 1:2:( ($2>($3+$1/50.)) ? "Up" : "Dn" ) with labels \
92 title 'plot <foo> using 1:2:( ($3>$2) ? "Up" : "Dn" ) with labels'
94 pause -1 "Hit return to continue"
97 u 1:2 lt -1 lw 0.5 notitle, \
98 '' u 1:($3+$1/50.) lt 3 lw 0.5 notitle, \
99 '' using 1:2:( ($2>($3+$1/50.)) ? "J" : "D" ) with labels font "WingDings,28"\
100 title 'Same thing using character glyphs from WingDings font'
102 pause -1 "Hit return to continue"
105 set title "String-valued functions to generate datafile names"
106 set key title 'file(i) = sprintf("%1d.dat",i); N=2; M=3'
107 set key left width 25 Left reverse
110 file(i) = sprintf("%1d.dat",i)
111 plot 5*sin(x)/x, file(N), file(M)
113 pause -1 "Hit return to continue"
116 fmt = '%Y-%m-%d %H:%M:%S'
117 time_str = '2005-05-09 19:44:12'
118 seconds = strptime(fmt, time_str)
119 time_str2 = strftime(fmt, seconds+10.)
121 print 'time_str = "', time_str, '"'
122 print '-> seconds = ', seconds
123 print ' seconds + 10. = ', seconds+10.
124 print '-> time_str2 = "', time_str2, '"'
130 #set format x '%Y-%m-%d'
131 fmt = "%d/%m/%y\t%H%M"
132 print "read_time(fmt, c) =" \
133 . " strptime(fmt, stringcolumn(c).' '.stringcolumn(c+1))"
134 read_time(fmt, c) = strptime(fmt, stringcolumn(c).' '.stringcolumn(c+1))
135 plot 'timedat.dat' using (read_time(fmt,1)):3 with histeps, \
136 'timedat.dat' using (read_time(fmt,1)):($3-0.01):2 with labels title ''
139 pause -1 "Hit return to continue"