Rev 475 | Go to most recent revision | Details | 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 \ |
||
15 | void, function f(x) to be plotted \ |
||
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\ |
||
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 | |||
26 | |||
27 | !exit |
||
28 | |||
29 | :proc |
||
30 | |||
31 | !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 |
||
32 | |||
33 | slib_parm=!item 1 to 11 of $wims_read_parm |
||
34 | !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 |
||
35 | |||
36 | slib_point=!item 12 to -1 of $wims_read_parm |
||
37 | |||
38 | |||
39 | !default slib_xd=8 |
||
40 | !default slib_yd=8 |
||
41 | !default slib_xo=1 |
||
42 | !default slib_yo=1 |
||
43 | !default slib_xs=1 |
||
44 | !default slib_ys=1 |
||
45 | !default slib_correct=[] |
||
46 | |||
47 | slib_labx=!word 2 to -1 of $slib_xs |
||
48 | slib_laby=!word 2 to -1 of $slib_ys |
||
49 | slib_xs=!word 1 of $slib_xs |
||
50 | slib_ys=!word 1 of $slib_ys |
||
51 | |||
52 | slib_maxx=!word 1 of $slib_labx |
||
53 | !if $slib_maxx = max |
||
54 | slib_labx = !word 2 to -1 of $slib_labx |
||
55 | !! we need to compute the X step slib_xs, given the values |
||
56 | !! of the total width slib_xd, abscissa of origin slib_xo |
||
57 | !! and knowing that slib_xs currently means a maximum value. |
||
58 | !! slib_xd-slib_xo must be be sufficient to display ticks greater |
||
59 | !! than the current value of slib_xs, the tick step being a multiple |
||
60 | !! of 1, 2 or 5. |
||
61 | slib_log=$[log10($slib_xs/($slib_xd-$slib_xo))] |
||
62 | slib_logint=$[floor($slib_log)] |
||
63 | slib_logmant=$[$slib_log-$slib_logint] |
||
64 | !if $slib_logmant > $[log10(5)] |
||
65 | slib_xs=1e$[$slib_logint+1] |
||
66 | !else |
||
67 | !if $slib_logmant > $[log10(2)] |
||
68 | slib_xs=5e$slib_logint |
||
69 | !else |
||
70 | slib_xs=2e$slib_logint |
||
71 | !endif |
||
72 | !endif |
||
73 | !else |
||
74 | slib_maxx=$empty |
||
75 | !endif |
||
76 | |||
77 | slib_maxy=!word 1 of $slib_laby |
||
78 | !if $slib_maxy = max |
||
79 | slib_laby = !word 2 to -1 of $slib_laby |
||
80 | !! we need to compute the Y step slib_ys, given the values |
||
81 | !! of the total height slib_yd, ordinate of origin slib_yo |
||
82 | !! and knowing that slib_ys currently means a maximum value. |
||
83 | !! slib_yd-slib_yo must be be sufficient to display ticks greater |
||
84 | !! than the current value of slib_ys, the tick step being a multiple |
||
85 | !! of 1, 2 or 5. |
||
86 | slib_log=$[log10($slib_ys/($slib_yd-$slib_yo))] |
||
87 | slib_logint=$[floor($slib_log)] |
||
88 | slib_logmant=$[$slib_log-$slib_logint] |
||
89 | !if $slib_logmant > $[log10(5)] |
||
90 | slib_ys=1e$[$slib_logint+1] |
||
91 | !else |
||
92 | !if $slib_logmant > $[log10(2)] |
||
93 | slib_ys=5e$slib_logint |
||
94 | !else |
||
95 | slib_ys=2e$slib_logint |
||
96 | !endif |
||
97 | !endif |
||
98 | !else |
||
99 | slib_maxy=$empty |
||
100 | !endif |
||
101 | |||
102 | slib_dc=!declosing $slib_dc |
||
103 | |||
104 | slib_correct=!declosing $slib_correct |
||
105 | slib_point=!declosing $slib_point |
||
106 | |||
107 | slib_bg=!declosing $slib_bg |
||
108 | !default slib_bg=240,233,255 |
||
109 | |||
110 | slib_lc=!declosing $slib_lc |
||
111 | !default slib_lc=255,220,180 |
||
112 | |||
113 | slib_dc=!declosing $slib_dc |
||
114 | !default slib_dc=10,10,10 |
||
115 | |||
116 | !!!!!!!!!!!!!!!!! begin grid !!!!!!!!!!!!!!!!!!!!!!!!! |
||
117 | |||
118 | slib_grey=128,128,128 |
||
119 | |||
120 | slib_dessin = new 60*$slib_xd,60*$slib_yd\ |
||
121 | xrange -0.5, 10*$slib_xd-0.5\ |
||
122 | yrange -0.5, 10*$slib_yd-0.5\ |
||
123 | fill 1,1,$slib_bg |
||
124 | |||
125 | !! traits fins tous les millimetres |
||
126 | slib_dessin=$slib_dessin\ |
||
127 | linewidth 1\ |
||
128 | parallel 0, 0, 0, 10*$slib_yd, 1, 0, 10*$slib_xd+1, $slib_lc\ |
||
129 | parallel 0, 0, 10*$slib_xd, 0, 0, 1, 10*$slib_yd+1, $slib_lc |
||
130 | |||
131 | !! traits gros tous les centimetres |
||
132 | slib_dessin=$slib_dessin\ |
||
133 | linewidth 3\ |
||
134 | parallel 0, 0, 0, 10*$slib_yd, 10, 0, $slib_xd+1, $slib_lc\ |
||
135 | parallel 0, 0, 10*$slib_xd, 0, 0, 10, $slib_yd+1, $slib_lc |
||
136 | |||
137 | !! axe_x |
||
138 | slib_dessin=$slib_dessin\ |
||
139 | linewidth 3\ |
||
140 | hline 0, $[10*$slib_yo], $slib_grey\ |
||
141 | line $[10*$slib_xd-3],$[10*$slib_yo-1],$[10*$slib_xd-1],$[10*$slib_yo], $slib_grey\ |
||
142 | line $[10*$slib_xd-3],$[10*$slib_yo+1],$[10*$slib_xd-1],$[10*$slib_yo], $slib_grey\ |
||
143 | parallel 0,$[10*$slib_yo+1],0,$[10*$slib_yo-1], 10, 0, $slib_xd+1, $slib_grey |
||
144 | |||
145 | slib_val=$[-$slib_xo*$slib_xs] |
||
146 | slib_dessin=$slib_dessin\ |
||
147 | linewidth 1 |
||
148 | !for slib_x from 0 to 10*$slib_xd step 10 |
||
149 | slib_dessin=$slib_dessin\ |
||
150 | text blue,$[$slib_x+1],$[10*$slib_yo-1],medium,$slib_val |
||
151 | slib_val=$[$slib_val+$slib_xs] |
||
152 | !next slib_x |
||
153 | !if $slib_labx != $empty |
||
154 | slib_dessin=$slib_dessin\ |
||
155 | text blue,$[$slib_x-20],$[10*$slib_yo-6],medium,$slib_labx |
||
156 | !endif |
||
157 | |||
158 | !! axe_y |
||
159 | slib_dessin=$slib_dessin\ |
||
160 | linewidth 3\ |
||
161 | vline $[10*$slib_xo],0, $slib_grey\ |
||
162 | line $[10*$slib_xo-1],$[10*$slib_yd-3],$[10*$slib_xo],$[10*$slib_yd-1], $slib_grey\ |
||
163 | line $[10*$slib_xo+1],$[10*$slib_yd-3],$[10*$slib_xo],$[10*$slib_yd-1], $slib_grey\ |
||
164 | parallel $[10*$slib_xo+1],0,$[10*$slib_xo-1], 0, 0, 10, $slib_yd+1, $slib_grey |
||
165 | |||
166 | slib_val=$[-$slib_yo*$slib_ys] |
||
167 | slib_dessin=$slib_dessin\ |
||
168 | linewidth 1 |
||
169 | !for slib_y from 0 to 10*$slib_yd step 10 |
||
170 | slib_dessin=$slib_dessin\ |
||
171 | text blue,$[10*$slib_xo+1],$[$slib_y-1],medium,$slib_val |
||
172 | slib_val=$[$slib_val+$slib_ys] |
||
173 | !next slib_y |
||
174 | !if $slib_laby != $empty |
||
175 | slib_dessin=$slib_dessin\ |
||
176 | text blue,$[10*$slib_xo-9],$[$slib_y-10],medium,$slib_laby |
||
177 | !endif |
||
178 | |||
179 | !!!!!!!!!!!!!!!!! end grid !!!!!!!!!!!!!!!!!!!!!!!!! |
||
180 | |||
181 | !! red dots : the correct list |
||
182 | n1=!itemcnt $slib_correct |
||
183 | !for i from 1 to $n1 step 2 |
||
184 | !if $i < $n1 |
||
185 | slib_x=!item $i of $slib_correct |
||
186 | slib_x=$[10*$slib_x/$slib_xs] |
||
187 | slib_y=!item $[$i+1] of $slib_correct |
||
188 | slib_y=$[10*$slib_y/$slib_ys] |
||
189 | slib_x1=$[10*$slib_xo+$slib_x-0.6] |
||
190 | slib_x2=$[10*$slib_xo+$slib_x+0.6] |
||
191 | slib_y1=$[10*$slib_yo+$slib_y-0.6] |
||
192 | slib_y2=$[10*$slib_yo+$slib_y+0.6] |
||
193 | !! add one red dot |
||
194 | slib_dessin=$slib_dessin\ |
||
195 | linewidth 2\ |
||
196 | line $slib_x1,$slib_y1,$slib_x2,$slib_y2,red\ |
||
197 | line $slib_x2,$slib_y1,$slib_x1,$slib_y2,red |
||
198 | !endif $i < $n1 |
||
199 | !next i |
||
200 | |||
201 | !! the function : blue thin curve |
||
202 | slib_f = !replace internal x by ($slib_xs/10*(x-10*$slib_xo)) in $slib_f |
||
203 | slib_f = 10*($slib_f)/$slib_ys+10*$slib_yo |
||
204 | slib_dessin=$slib_dessin\ |
||
205 | plot blue, $slib_f |
||
206 | |||
207 | !! black dots |
||
208 | n2=!itemcnt $slib_point |
||
209 | !for i from 1 to $n2 step 2 |
||
210 | !if $i < $n2 |
||
211 | slib_x=!item $i of $slib_point |
||
212 | slib_x=$[10*$slib_x/$slib_xs] |
||
213 | slib_y=!item $[$i+1] of $slib_point |
||
214 | slib_y=$[10*$slib_y/$slib_ys] |
||
215 | slib_x1=$[10*$slib_xo+$slib_x-0.6] |
||
216 | slib_x2=$[10*$slib_xo+$slib_x+0.6] |
||
217 | slib_y1=$[10*$slib_yo+$slib_y-0.6] |
||
218 | slib_y2=$[10*$slib_yo+$slib_y+0.6] |
||
219 | !! add one '$slib_dc' dot |
||
220 | slib_dessin=$slib_dessin\ |
||
221 | linewidth 2\ |
||
222 | line $slib_x1,$slib_y1,$slib_x2,$slib_y2,$slib_dc\ |
||
223 | line $slib_x2,$slib_y1,$slib_x1,$slib_y2,$slib_dc |
||
224 | !endif $i < $n2 |
||
225 | !next i |
||
226 | |||
227 | slib_out= $slib_dessin |