File: iterate.dem

package info (click to toggle)
gnuplot 6.0.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,940 kB
  • sloc: ansic: 95,319; cpp: 7,590; makefile: 2,470; javascript: 2,328; sh: 1,531; lisp: 664; perl: 304; pascal: 191; tcl: 88; python: 46
file content (71 lines) | stat: -rw-r--r-- 2,122 bytes parent folder | download | duplicates (6)
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
set title "Iteration within plot command"
set xrange [0:3]
set label 1 "plot for [n=2:10] sin(x*n)/n" at graph .95, graph .92 right
plot for [n=2:10] sin(x*n)/n notitle lw (13-n)/2
pause -1 "Hit return to continue"
reset

set title "Iteration over all available data in a file"
set view 38., 341.
unset xtics
unset ytics
unset ztics
set border 0
set lmargin at screen 0.09
set rmargin at screen 0.90
set key outside below samplen 0.6
set key title "splot for [scan=1:*] 'whale.dat' index scan"
set key maxrows 6
splot for [i=1:*] "whale.dat" index i title sprintf("scan %d",i) with lines
pause -1 "Hit return to continue"
reset


# Dynamic reevaluation of iteration limits
# inner loop refers to the control variable of an outer loop
#
set key opaque box height 1 title "Dynamic iteration limits"
set title "plot for [i=1:4] for [k=i:i] for [j=1:k] 10*k + cos(j*x)"
plot for [i=1:4] for [k=i:i] for [j=1:k] 10*k + cos(j*x) lw j \
     title sprintf("k=%d  j=%d", i, j)
pause -1 "Hit return to continue"

# More iteration tests (no graph output)
#
print "\ndynamic reevaluation of numeric iteration limits"
array J[3] = [ 1, 4, 3 ]
print "\nJ =",J
Output = ""
print "do for [i=1:3] for [j=J[i]:3] { save(i,j) }"
do for [i=1:3] for [j=J[i]:3] { Output = Output . sprintf("%d-%d ",i,j) }
print Output

array J[3] = [ 4, 1, 3 ]
print "\nJ =",J
Output = ""
print "do for [i=1:3] for [j=J[i]:3] { save(i,j) }"
do for [i=1:3] for [j=J[i]:3] { Output = Output . sprintf("%d-%d ",i,j) }
print Output

print ""
Output = ""
print "do for [i=1:4] for [k=i:i] for [j=1:k] { save(i,j) }"
do for [i=1:4] for [k=i:i] for [j=1:k] { Output = Output . sprintf("%d-%d ",i,j) }
print Output

print "\ndynamic reevaluation of iteration string"

array A[3] = [ "a b", "", "d" ]
print "A = ", A

print 'do for [ i = 1:|A| ] { do for [ j in A[i]] { print "".i.": ".j }}'
Output = ""
do for [ i = 1:|A| ] { do for [ j in A[i]] { Output = Output."  ".i.": ".j }}
print Output

print 'do for [ i = 1:|A| ] for [ j in A[i]] { print "".i.": ".j }'
Output = ""
do for [ i = 1:|A| ] for [ j in A[i]] { Output = Output."  ".i.": ".j }
print Output

reset