1## Copyright (C) 1998, 1999, 2000  Joao Cardoso
2## Copyright (C) 2004  Rafael Laboissiere
3##
4## This program is free software; you can redistribute it and/or modify it
5## under the terms of the GNU General Public License as published by the
6## Free Software Foundation; either version 2 of the License, or (at your
7## option) any later version.
8##
9## This program is distributed in the hope that it will be useful, but
10## WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12## General Public License for more details.
13##
14## This file is part of plplot_octave.
15## It is based on the corresponding demo function of PLplot, but doesn't
16## use the tk driver.
17
18#	Demo of multiple stream/window capability
19#
20## Plots several simple functions from other example programs.
21#
22## This version sends the output of the first 4 plots (one page) to two
23## independent streams.
24
251;
26
27function ix14c(fname2,strm)
28
29  if (nargin < 2)
30    strm = stdout;
31  endif
32
33  xleng0 = 400; yleng0 = 300; xoff0 = 200; yoff0 = 200;
34  xleng1 = 400; yleng1 = 300; xoff1 = 500; yoff1 = 500;
35
36  ## The geometry strings MUST be in writable memory */
37
38  geometry_master = "500x410+100+200";
39  geometry_slave  = "500x410+650+200";
40
41  ## Set up first stream */
42
43  plSetOpt("geometry", geometry_master);
44  plssub(2,2);
45  plinit();
46
47  device = sprintf("%s",plgdev);
48  if(isempty(device))
49    device = "xwin";
50  endif
51
52  [fam, num, bmax] = plgfam();
53
54  fprintf(strm,"Demo of multiple output streams via the %s driver.\n", device);
55  fprintf(strm,"Running with the second stream as slave to the first.\n");
56  ##fprintf(strm,"To advance to the next plot, press the third mouse button\n");
57  ##fprintf(strm,"or the enter key in the first (left) window\n");
58  fprintf(strm,"\n");
59
60  ## This is an entirely bogus message since the output file name is
61  ## set by the function arguments - but it does ensure that stdout
62  ## is identical to the C version of the example for ctest.
63  if (strm != stdout)
64    fprintf(strm,"Enter graphics output file name: ");
65  endif
66
67  ## fflush(strm);
68
69  ## Start next stream */
70
71  plsstrm(1);
72
73  plSetOpt("geometry", geometry_slave);
74
75  ## Turn off pause to make this a slave (must follow master) */
76  plspause(0);
77
78  ## This is an addition to the C version to allow second file name to be
79  ## set as a function argument. This is required for the test scripts.
80  if (nargin >= 1)
81    plsfnam(fname2);
82  endif
83
84  plsdev(device);
85  plsfam(fam,num,bmax);
86  ## Currently number of digits in format number can only be
87  ## set via the command line option
88  plSetOpt( "fflen", "2" );
89  plinit();
90
91  ## Set up the data & plot */
92  ## Original case */
93
94  plsstrm(0);
95
96  xscale = 6.;
97  yscale = 1.;
98  xoff = 0.;
99  yoff = 0.;
100  plot1(xoff,xscale,yoff,yscale);
101
102  ## Set up the data & plot */
103
104  xscale = 1.;
105  yscale = 1.e+6;
106  plot1(xoff,xscale,yoff,yscale);
107
108  ## Set up the data & plot */
109
110  xscale = 1.;
111  yscale = 1.e-6;
112  digmax = 2;
113  plsyax(digmax, 0);
114  plot1(xoff,xscale,yoff,yscale);
115
116  ## Set up the data & plot */
117
118  xscale = 1.;
119  yscale = 0.0014;
120  yoff = 0.0185;
121  digmax = 5;
122  plsyax(digmax, 0);
123  plot1(xoff,xscale,yoff,yscale);
124
125  ## To slave */
126  ## The pleop() ensures the eop indicator gets lit. */
127
128  plsstrm(1);
129  plot4();
130  pleop();
131
132  ## Back to master */
133
134  plsstrm(0);
135  plot2();
136  plot3();
137
138  ## To slave */
139
140  plsstrm(1);
141  plot5();
142  pleop();
143
144  ## Back to master to wait for user to advance */
145
146  plsstrm(0);
147  pleop();
148
149  ## Call plend1 to finish off. */
150  ## close slave first
151  plsstrm(1);
152  plend1();
153  ## close master
154  plsstrm(0);
155  plend1();
156
157endfunction
158
159function plot1(xoff,xscale,yoff,yscale)
160
161  for i=0:59
162    x(i+1) = xoff + xscale * (i + 1) / 60.0;
163    y(i+1) = yoff + yscale * x(i+1).^2.;
164  endfor
165
166  xmin = min(x);
167  xmax = max(x);
168  ymin = min(y);
169  ymax = max(y);
170
171  for i=0:5
172    xs(i+1) = x(i * 10 + 3 +1);
173    ys(i+1) = y(i * 10 + 3 +1);
174  endfor
175
176  ## Set up the viewport and window using PLENV. The range in X is */
177  ## 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are */
178  ## scaled separately (just = 0), and we just draw a labelled */
179  ## box (axis = 0). */
180
181  plcol0(1);
182  plenv(xmin, xmax, ymin, ymax, 0, 0);
183  plcol0(6);
184  pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2");
185
186  ## Plot the data points */
187
188  plcol0(9);
189  plpoin(xs', ys', 9);
190
191  ## Draw the line through the data */
192
193  plcol0(4);
194  plline(x', y');
195  plflush;#pleop();
196
197endfunction
198
199function plot2()
200
201  ## Set up the viewport and window using PLENV. The range in X is -2.0 to
202  ##       10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately
203  ##       (just = 0), and we draw a box with axes (axis = 1).
204
205  plcol0(1);
206  plenv(-2.0, 10.0, -0.4, 1.2, 0, 1);
207  plcol0(2);
208  pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function");
209
210  ## Fill up the arrays */
211
212  for i=0:99
213    x(i+1) = (i - 19.0) / 6.0;
214    y(i+1) = 1.0;
215    if (x(i+1) != 0.0)
216      y(i+1) = sin(x(i+1)) / x(i+1);
217    endif
218  endfor
219
220  ## Draw the line */
221
222  plcol0(3);
223  plline(x', y');
224  plflush;#pleop();
225endfunction
226
227function plot3()
228
229  space0 = []; mark0 = []; space1 = [1500]; mark1 = [1500];
230  ## For the final graph we wish to override the default tick intervals, and
231  ##       so do not use PLENV */
232
233  pladv(0);
234
235  ## Use standard viewport, and define X range from 0 to 360 degrees, Y range
236  ##       from -1.2 to 1.2. */
237
238  plvsta();
239  plwind(0.0, 360.0, -1.2, 1.2);
240
241  ## Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y. */
242
243  plcol0(1);
244  plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2);
245
246  ## Superimpose a dashed line grid, with 1.5 mm marks and spaces. plstyl
247  ##       expects a pointer!! */
248
249  plstyl(mark1, space1);
250  plcol0(2);
251  plbox("g", 30.0, 0, "g", 0.2, 0);
252  plstyl(mark0, space0);
253
254  plcol0(3);
255  pllab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function");
256
257  for i = 0:100
258    x(i+1) = 3.6 * i;
259    y(i+1) = sin(x(i+1) * pi / 180.0);
260  endfor
261
262  plcol0(4);
263  plline(x', y');
264  plflush;#pleop();
265
266endfunction
267
268function plot4()
269
270  dtr = pi / 180.0;
271
272  zz=0:360;
273  x0 = cos(dtr * zz');
274  y0 = sin(dtr * zz');
275
276
277  ## Set up viewport and window, but do not draw box */
278
279  plenv(-1.3, 1.3, -1.3, 1.3, 1, -2);
280
281  for i = 1:10
282    x = 0.1 * i * x0;
283    y = 0.1 * i * y0;
284
285    ## Draw circles for polar grid */
286
287    plline(x, y);
288  endfor
289
290  plcol0(2);
291  for i = 0:11
292    theta = 30.0 * i;
293    dx = cos(dtr * theta);
294    dy = sin(dtr * theta);
295
296    ## Draw radial spokes for polar grid */
297
298    pljoin(0.0, 0.0, dx, dy);
299    text=sprintf("%d", round(theta));
300
301    ## Write labels for angle */
302
303    if (dx >= -0.00001)
304      plptex(dx, dy, dx, dy, -0.15, text);
305    else
306      plptex(dx, dy, -dx, -dy, 1.15, text);
307    endif
308  endfor
309
310  ## Draw the graph */
311
312  r = sin(dtr * (5 * zz'));
313  x = x0 .* r;
314  y = y0 .* r;
315
316  plcol0(3);
317  plline(x, y);
318
319  plcol0(4);
320  plmtex("t", 2.0, 0.5, 0.5,
321	 "#frPLplot Example 3 - r(#gh)=sin 5#gh");
322  plflush;#pleop();
323endfunction
324
325## Demonstration of contour plotting */
326
327function plot5()
328
329  XPTS=      35;
330  YPTS=      46;
331  XSPA=      2./(XPTS-1);
332  YSPA=      2./(YPTS-1);
333
334  tr=[XSPA, 0.0, -1.0, 0.0, YSPA, -1.0]';
335
336  ## this is builtin in plplot_octave
337  ## It is based on the corresponding demo function of PLplot.##
338  ## mypltr(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data)
339  ## {
340  ##    *tx = tr(0) * x + tr(1) * y + tr(2);
341  ##    *ty = tr(3) * x + tr(4) * y + tr(5);
342  ## }
343
344  clevel =[-1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1.]';
345
346  mark = [1500]; space = [1500];
347
348  ## Set up function arrays */
349
350  for i = 0:XPTS-1
351    xx = (i - fix(XPTS / 2)) / fix(XPTS / 2);
352    for j = 0:YPTS-1
353      yy = (j - fix(YPTS / 2)) / fix(YPTS / 2) - 1.0;
354      z(i+1,j+1) = xx * xx - yy * yy;
355      w(i+1,j+1) = 2 * xx * yy;
356    endfor
357  endfor
358
359  plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
360  plcol0(2);
361  plcont(z, 1, XPTS, 1, YPTS, clevel, tr);
362  plstyl(mark, space);
363  plcol0(3);
364  plcont(w, 1, XPTS, 1, YPTS, clevel, tr);
365  plcol0(1);
366  pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
367  plflush;#pleop();
368endfunction
369
370if (exist("file2","var"))
371  if (exist("strm","var"))
372    ix14c(file2,strm);
373  else
374    ix14c(file2);
375  endif
376else
377  ix14c()
378endif
379