Subversion Repositories wimsdev

Rev

Rev 20 | Rev 4162 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
!if  $wims_read_parm!=slib_header
2
 !goto proc
3
!endif
4
slib_title=Graphic paper sheet with function plot and red correct plot preloaded
5
slib_parms=12\
6
8,x_dimension (cm) \
7
8,y_dimension (cm) \
8
1,x_orig (cm) \
9
1,y_orig (cm) \
10
1,x_step (delta x for 1 cm on the paper or max value for x and optional label ) \
11
1,y_step (delta y for 1 cm on the paper or max value for y and optional label) \
12
[240,233,255],background color \
13
[255,220,180],lines color \
14
[10,10,10],dots color \
475 georgesk 15
void, function f(x) or [x(t), y(t)] to be plotted \
20 reyssat 16
[], list of dots enclosed in brackets (the correct plot)\
17
void,list of dots (an even count of coordinates : x1,y1,x2,y2,etc.)
18
slib_author=Georges KHAZNADAR
19
slib_out=Source for insdraw-ing a graph paper with the dots on it
20
slib_comment=if color are three numbers, \
21
put them in brackets ; there may be no dots.<br>\
22
See the other syntaxes in the slib graphpaper/millimetre
23
slib_example= ,,,,,,,,,sin(x),[],0,0,1.2,1.5,2.4,3.2\
475 georgesk 24
12,8,0,0,1 max t (ms),1 max U (V),blue,red,[255,128,128],sin(x),[0,0,1.3,1.4,2.5,3],0,0,1.2,1.5,2.4,3.2 \
25
,,,,,,,,,[cos(6.28*t),sin(6.28*t)],[],0,0,1.2,1.5,2.4,3.2
20 reyssat 26
 
27
 
28
!exit
29
 
30
:proc
31
 
32
!reset slib_xd, slib_yd, slib_bg, slib_lc, slib_dc, slib_point, slib_xo, slib_yo, slib_xs, slib_ys, slib_correct slib_f, slib_labx, slib_laby, slib_maxx, slib_maxy
33
 
34
slib_parm=!item 1 to 11 of $wims_read_parm
35
!distribute item $slib_parm into slib_xd, slib_yd, slib_xo, slib_yo, slib_xs, slib_ys, slib_bg, slib_lc, slib_dc, slib_f, slib_correct
36
 
37
slib_point=!item 12 to -1 of $wims_read_parm
38
 
39
 
40
!default slib_xd=8
41
!default slib_yd=8
42
!default slib_xo=1
43
!default slib_yo=1
44
!default slib_xs=1
45
!default slib_ys=1
46
!default slib_correct=[]
47
 
475 georgesk 48
slib_f = !declosing $slib_f
49
 
20 reyssat 50
slib_labx=!word 2 to -1 of $slib_xs
51
slib_laby=!word 2 to -1 of $slib_ys
52
slib_xs=!word 1 of $slib_xs
53
slib_ys=!word 1 of $slib_ys
54
 
55
slib_maxx=!word 1 of $slib_labx
56
!if $slib_maxx = max
57
  slib_labx = !word 2 to -1 of $slib_labx
58
  !! we need to compute the X step slib_xs, given the values
59
  !! of the total width slib_xd, abscissa of origin slib_xo
60
  !! and knowing that slib_xs currently means a maximum value.
61
  !! slib_xd-slib_xo must be be sufficient to display ticks greater
62
  !! than the current value of slib_xs, the tick step being a multiple
63
  !! of 1, 2 or 5.
64
  slib_log=$[log10($slib_xs/($slib_xd-$slib_xo))]
65
  slib_logint=$[floor($slib_log)]
66
  slib_logmant=$[$slib_log-$slib_logint]
67
  !if $slib_logmant > $[log10(5)]
68
     slib_xs=1e$[$slib_logint+1]
69
  !else
70
    !if $slib_logmant > $[log10(2)]
71
      slib_xs=5e$slib_logint
72
    !else
73
      slib_xs=2e$slib_logint
74
    !endif
75
  !endif
76
!else
77
  slib_maxx=$empty
78
!endif
79
 
80
slib_maxy=!word 1 of $slib_laby
81
!if $slib_maxy = max
82
  slib_laby = !word 2 to -1 of $slib_laby
83
  !! we need to compute the Y step slib_ys, given the values
84
  !! of the total height slib_yd, ordinate of origin slib_yo
85
  !! and knowing that slib_ys currently means a maximum value.
86
  !! slib_yd-slib_yo must be be sufficient to display ticks greater
87
  !! than the current value of slib_ys, the tick step being a multiple
88
  !! of 1, 2 or 5.
89
  slib_log=$[log10($slib_ys/($slib_yd-$slib_yo))]
90
  slib_logint=$[floor($slib_log)]
91
  slib_logmant=$[$slib_log-$slib_logint]
92
  !if $slib_logmant > $[log10(5)]
93
     slib_ys=1e$[$slib_logint+1]
94
  !else
95
    !if $slib_logmant > $[log10(2)]
96
      slib_ys=5e$slib_logint
97
    !else
98
      slib_ys=2e$slib_logint
99
    !endif
100
  !endif
101
!else
102
  slib_maxy=$empty
103
!endif
104
 
105
slib_dc=!declosing $slib_dc
106
 
107
slib_correct=!declosing $slib_correct
108
slib_point=!declosing $slib_point
109
 
110
slib_bg=!declosing $slib_bg
111
!default slib_bg=240,233,255
112
 
113
slib_lc=!declosing $slib_lc
114
!default slib_lc=255,220,180
115
 
116
slib_dc=!declosing $slib_dc
117
!default slib_dc=10,10,10
118
 
119
!!!!!!!!!!!!!!!!! begin grid !!!!!!!!!!!!!!!!!!!!!!!!!
120
 
121
slib_grey=128,128,128
122
 
123
slib_dessin = new 60*$slib_xd,60*$slib_yd\
124
xrange -0.5, 10*$slib_xd-0.5\
125
yrange -0.5, 10*$slib_yd-0.5\
126
fill 1,1,$slib_bg
127
 
128
!! traits fins tous les millimetres
129
slib_dessin=$slib_dessin\
130
linewidth 1\
131
parallel 0, 0, 0, 10*$slib_yd, 1, 0, 10*$slib_xd+1, $slib_lc\
132
parallel 0, 0, 10*$slib_xd, 0, 0, 1, 10*$slib_yd+1, $slib_lc
133
 
134
!! traits gros tous les centimetres
135
slib_dessin=$slib_dessin\
136
linewidth 3\
137
parallel 0, 0, 0, 10*$slib_yd, 10, 0, $slib_xd+1, $slib_lc\
138
parallel 0, 0, 10*$slib_xd, 0, 0, 10, $slib_yd+1, $slib_lc
139
 
140
!! axe_x
141
slib_dessin=$slib_dessin\
142
linewidth 3\
143
hline 0, $[10*$slib_yo], $slib_grey\
144
line $[10*$slib_xd-3],$[10*$slib_yo-1],$[10*$slib_xd-1],$[10*$slib_yo], $slib_grey\
145
line $[10*$slib_xd-3],$[10*$slib_yo+1],$[10*$slib_xd-1],$[10*$slib_yo], $slib_grey\
146
parallel 0,$[10*$slib_yo+1],0,$[10*$slib_yo-1], 10, 0, $slib_xd+1, $slib_grey
147
 
148
slib_val=$[-$slib_xo*$slib_xs]
149
slib_dessin=$slib_dessin\
150
linewidth 1
151
!for slib_x from 0 to  10*$slib_xd step 10
152
 slib_dessin=$slib_dessin\
153
 text blue,$[$slib_x+1],$[10*$slib_yo-1],medium,$slib_val
154
 slib_val=$[$slib_val+$slib_xs]
155
!next slib_x
156
!if $slib_labx != $empty
157
  slib_dessin=$slib_dessin\
158
  text blue,$[$slib_x-20],$[10*$slib_yo-6],medium,$slib_labx
159
!endif
160
 
161
!! axe_y
162
slib_dessin=$slib_dessin\
163
linewidth 3\
164
vline $[10*$slib_xo],0, $slib_grey\
165
line $[10*$slib_xo-1],$[10*$slib_yd-3],$[10*$slib_xo],$[10*$slib_yd-1], $slib_grey\
166
line $[10*$slib_xo+1],$[10*$slib_yd-3],$[10*$slib_xo],$[10*$slib_yd-1], $slib_grey\
167
parallel $[10*$slib_xo+1],0,$[10*$slib_xo-1], 0, 0, 10, $slib_yd+1, $slib_grey
168
 
169
slib_val=$[-$slib_yo*$slib_ys]
170
slib_dessin=$slib_dessin\
171
linewidth 1
172
!for slib_y from 0 to  10*$slib_yd step 10
173
 slib_dessin=$slib_dessin\
174
 text blue,$[10*$slib_xo+1],$[$slib_y-1],medium,$slib_val
175
 slib_val=$[$slib_val+$slib_ys]
176
!next slib_y
177
!if $slib_laby != $empty
178
  slib_dessin=$slib_dessin\
179
  text blue,$[10*$slib_xo-9],$[$slib_y-10],medium,$slib_laby
180
!endif
181
 
182
!!!!!!!!!!!!!!!!! end grid !!!!!!!!!!!!!!!!!!!!!!!!!
183
 
184
!! red dots : the correct list
185
n1=!itemcnt $slib_correct
186
!for i from 1 to $n1 step 2
187
!if $i < $n1
188
 slib_x=!item $i of $slib_correct
189
 slib_x=$[10*$slib_x/$slib_xs]
190
 slib_y=!item $[$i+1] of $slib_correct
191
 slib_y=$[10*$slib_y/$slib_ys]
192
 slib_x1=$[10*$slib_xo+$slib_x-0.6]
193
 slib_x2=$[10*$slib_xo+$slib_x+0.6]
194
 slib_y1=$[10*$slib_yo+$slib_y-0.6]
195
 slib_y2=$[10*$slib_yo+$slib_y+0.6]
196
 !! add one red dot
197
 slib_dessin=$slib_dessin\
198
 linewidth 2\
199
 line $slib_x1,$slib_y1,$slib_x2,$slib_y2,red\
200
 line $slib_x2,$slib_y1,$slib_x1,$slib_y2,red
201
!endif $i < $n1
202
!next i
203
 
204
!! the function : blue thin curve
475 georgesk 205
slib_n = !itemcnt $slib_f
206
!if $slib_n = 1
207
  slib_f = !replace internal x by ($slib_xs/10*(x-10*$slib_xo)) in $slib_f
208
  slib_f = 10*($slib_f)/$slib_ys+10*$slib_yo
209
!else
210
  slib_x = !item 1 of $slib_f
211
  slib_y = !item 2 of $slib_f
212
  slib_x = 10*($slib_x/$slib_xs+$slib_xo)
213
  slib_y = 10*($slib_y/$slib_ys+$slib_yo)
214
  slib_f = $slib_x, $slib_y
215
!endif
216
 
20 reyssat 217
slib_dessin=$slib_dessin\
218
plot blue, $slib_f
219
 
220
!! black dots
221
n2=!itemcnt $slib_point
222
!for i from 1 to $n2 step 2
223
!if $i < $n2
224
 slib_x=!item $i of $slib_point
225
 slib_x=$[10*$slib_x/$slib_xs]
226
 slib_y=!item $[$i+1] of $slib_point
227
 slib_y=$[10*$slib_y/$slib_ys]
228
 slib_x1=$[10*$slib_xo+$slib_x-0.6]
229
 slib_x2=$[10*$slib_xo+$slib_x+0.6]
230
 slib_y1=$[10*$slib_yo+$slib_y-0.6]
231
 slib_y2=$[10*$slib_yo+$slib_y+0.6]
232
 !! add one '$slib_dc' dot
233
 slib_dessin=$slib_dessin\
234
 linewidth 2\
235
 line $slib_x1,$slib_y1,$slib_x2,$slib_y2,$slib_dc\
236
 line $slib_x2,$slib_y1,$slib_x1,$slib_y2,$slib_dc
237
!endif $i < $n2
238
!next i
239
 
240
slib_out= $slib_dessin