Initial release of Maemo 5 port of gnuplot
[gnuplot] / demo / stringvar.dem
1 #
2 # Miscellaneous neat things you can do using the string variables code
3 #
4 set print "stringvar.tmp"
5 print ""
6 print "Exercise substring handling"
7 print ""
8 beg = 2
9 end = 4
10 print "beg = ",beg," end = ",end
11 foo = "ABCDEF"
12 print "foo           = ",foo
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]
24 print ""
25 unset print
26
27 set label 1 system("cat stringvar.tmp") at graph 0.1, graph 0.9
28 unset xtics
29 unset ytics
30 set yrange [0:1]
31 plot 0
32
33 pause -1 "Hit return to continue"
34
35
36 set print "stringvar.tmp"
37 print "Exercise string handling functions"
38 print ""
39 print "foo          = ",foo
40 print "strlen(foo)  = ",strlen(foo)
41 print "substr(foo,3,4) = ",substr(foo,3,4)
42 print ""
43 haystack = "`date`"
44 needle = ":"
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]
52 #
53 print ""
54 print "words(haystack)   = ",words(haystack)
55 print "word(haystack,5)  = ",word(haystack,5)
56 #
57 print ""
58 #
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"
62 print ""
63
64 unset print
65 set label 1 system("cat stringvar.tmp") at graph 0.1, graph 0.9
66 unset xtics
67 unset ytics
68 set yrange [0:1]
69 plot 0
70
71 pause -1 "Hit return to continue"
72 reset
73 #
74 set xrange [300:400]
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
78 #
79 pause -1 "Hit return to continue"
80 #
81 set xrange [0:1]
82 set yrange [0:1]
83 set title "Constant string expressions as plot symbols"
84 set xrange [250:500]
85 set auto y
86 set style data lines
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'
93 #
94 pause -1 "Hit return to continue"
95 #
96 plot 'silver.dat' \
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'
101 #
102 pause -1 "Hit return to continue"
103 #
104 reset
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
108 N = 2
109 M = 3
110 file(i) = sprintf("%1d.dat",i)
111 plot 5*sin(x)/x, file(N), file(M)
112 #
113 pause -1 "Hit return to continue"
114 #
115 reset
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.)
120 print ''
121 print 'time_str          = "', time_str, '"'
122 print '-> seconds        = ', seconds
123 print '   seconds + 10.  = ', seconds+10.
124 print '-> time_str2      = "', time_str2, '"'
125 #
126 print ""
127 #
128 set xdata time
129 set key inside left
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 ''
137 #
138 print ""
139 pause -1 "Hit return to continue"
140 #
141 reset