1## Copyright (C) 1998, 1999, 2000 Joao Cardoso.
2##
3## This program is free software; you can redistribute it and/or modify it
4## under the terms of the GNU General Public License as published by the
5## Free Software Foundation; either version 2 of the License, or (at your
6## option) any later version.
7##
8## This program is distributed in the hope that it will be useful, but
9## WITHOUT ANY WARRANTY; without even the implied warranty of
10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11## General Public License for more details.
12##
13## This file is part of plplot_octave.
14## It is based on the corresponding demo function of PLplot.
15
16##	plshade demo, using color fill.
17
181;
19
20## Set up transformation function
21
22global nx = 35;	## Default number of data points in x
23global ny = 46;	## Default number of data points in y
24global	tr = [2/(nx-1); 0.0; -1.0; 0.0; 2/(ny-1); -1.0];
25
26function  [tx ty] = mypltr( x, y)
27  global tr
28  tx = tr(1) * x + tr(2) * y + tr(3);
29  ty = tr(4) * x + tr(5) * y + tr(6);
30endfunction
31
32function ix16c
33
34  global tr; global nx; global ny;
35  global PL_COLORBAR_LABEL_BOTTOM;
36  global PL_COLORBAR_SHADE;
37  global PL_COLORBAR_SHADE_LABEL;
38  ## Fundamental settings.  See notes[] for more info.
39
40  ns = 20;		## Default number of shade levels
41
42  notes = [
43	   "To get smoother color variation, increase ns, nx, and ny.  To get faster",
44	   "response (especially on a serial link), decrease them.  A decent but quick",
45	   "test results from ns around 5 and nx, ny around 25."];
46
47  sh_cmap = 1;
48  fill_width = 2.; cont_color = 0;  cont_width = 0.;
49
50  num_axes = 1;
51  n_axis_opts = num_axes;
52  axis_opts = { "bcvtm" };
53  values = zeros(num_axes,ns+1);
54  axis_ticks = zeros(1,1);
55  axis_subticks = zeros(1,1);
56
57  num_labels = 1;
58  label_opts = [ PL_COLORBAR_LABEL_BOTTOM ];
59  labels = { "Magnitude" };
60
61
62  ## Parse and process command line arguments
63
64  ##    plMergeOpts(options, "x16c options", notes);
65  ##    plparseopts(&argc, argv, PL_PARSE_FULL);
66
67  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
68
69  ## Load colour palettes
70  plspal0("cmap0_black_on_white.pal");
71  plspal1("cmap1_gray.pal",1);
72  plscmap0n(3);
73
74  ## Initialize plplot
75  plinit();
76
77  ## Set up data array
78
79  for i = 0:nx-1
80    x = (i - fix(nx / 2)) / fix(nx / 2);
81    j = 0:ny-1;
82    y = (j .- fix(ny / 2)) ./ fix(ny / 2) - 1.0;
83
84    z(i+1,:) = - sin(7.*x) .* cos(7.*y) .+ x*x - y.*y;
85    w(i+1,:) = - cos(7.*x) .* sin(7.*y) .+ 2 .* x .* y;
86  endfor
87
88  zmin=min(min(z));
89  zmax=max(max(z));
90
91  i = 0:ns-1;
92  clevel = (zmin .+ (zmax - zmin) .* (i + 0.5) ./ ns)';
93  i = 0:ns;
94  shedge = zmin + (zmax - zmin) * i / ns;
95
96  ## Set up coordinate grids
97
98  for i = 0:nx-1
99    j = 0:ny-1;
100    [x y] = mypltr( i,  j);
101
102    argx = x * pi/2;
103    argy = y * pi/2;
104    distort = 0.4;
105
106    xg1(i+1,:) = x .+ distort .* cos(argx);
107    yg1(i+1,:) = y .- distort .* cos(argy);
108
109    xg2(i+1,:) = x .+ distort .* cos(argx) .* cos(argy);
110    yg2(i+1,:) = y .- distort .* cos(argx) .* cos(argy);
111  endfor
112
113  xg1 = xg1(:,1);
114  yg1 = yg1(1,:)';
115
116  ## Plot using identity transform
117
118  pladv(0);
119  plvpor(0.1, 0.9, 0.1, 0.9);
120  plwind(-1.0, 1.0, -1.0, 1.0);
121  plpsty(0);
122
123  plshades(z, -1., 1., -1., 1.,
124	   shedge', fill_width,
125	   cont_color, cont_width,
126	   1);
127
128  # Smaller text
129  plschr( 0.0, 0.75 );
130  # Small ticks on the vertical axis
131  plsmaj( 0.0, 0.5 );
132  plsmin( 0.0, 0.5 );
133
134  num_values(1) = ns + 1;
135  values(1,:) = shedge;
136
137  [colorbar_width, colorbar_height] = plcolorbar(
138            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
139            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
140            cont_color, cont_width,
141            label_opts, labels, axis_opts,
142            axis_ticks, axis_subticks,
143            num_values, values );
144
145  # Reset text and tick sizes
146  plschr( 0.0, 1.0 );
147  plsmaj( 0.0, 1.0 );
148  plsmin( 0.0, 1.0 );
149
150  plcol0(1);
151  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
152  plcol0(2);
153
154  ## plcont(w, 1, nx, 1, ny, clevel, tr);
155
156  pllab("distance", "altitude", "Bogon density");
157
158  ## Plot using 1d coordinate transform
159
160  ##  Load colour palettes
161  plspal0("cmap0_black_on_white.pal");
162  plspal1("cmap1_blue_yellow.pal",1);
163  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
164  plscmap0n(3);
165
166  pladv(0);
167  plvpor(0.1, 0.9, 0.1, 0.9);
168  plwind(-1.0, 1.0, -1.0, 1.0);
169  plpsty(0);
170
171  plshades1(z, -1., 1., -1., 1.,
172	    shedge', fill_width,
173	    cont_color, cont_width,
174	    1, xg1, yg1);
175
176  # Smaller text
177  plschr( 0.0, 0.75 );
178  # Small ticks on the vertical axis
179  plsmaj( 0.0, 0.5 );
180  plsmin( 0.0, 0.5 );
181
182  num_values(1) = ns + 1;
183  values(1,:) = shedge;
184
185  [colorbar_width, colorbar_height] = plcolorbar(
186            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
187            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
188            cont_color, cont_width,
189            label_opts, labels, axis_opts,
190            axis_ticks, axis_subticks,
191            num_values, values );
192
193  # Reset text and tick sizes
194  plschr( 0.0, 1.0 );
195  plsmaj( 0.0, 1.0 );
196  plsmin( 0.0, 1.0 );
197
198  plcol0(1);
199  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
200  plcol0(2);
201
202  ## plcont1(w, 1, nx, 1, ny, clevel, xg1, yg1);
203
204  pllab("distance", "altitude", "Bogon density");
205
206  ## Plot using 2d coordinate transform
207
208  ## Load colour palettes
209  plspal0("cmap0_black_on_white.pal");
210  plspal1("cmap1_blue_red.pal",1);
211  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
212  plscmap0n(3);
213
214  pladv(0);
215  plvpor(0.1, 0.9, 0.1, 0.9);
216  plwind(-1.0, 1.0, -1.0, 1.0);
217  plpsty(0);
218
219  plshades2(z, -1., 1., -1., 1.,
220	    shedge', fill_width,
221	    cont_color, cont_width,
222	    0, xg2, yg2);
223
224  # Smaller text
225  plschr( 0.0, 0.75 );
226  # Small ticks on the vertical axis
227  plsmaj( 0.0, 0.5 );
228  plsmin( 0.0, 0.5 );
229
230  num_values(1) = ns + 1;
231  values(1,:) = shedge;
232
233  [colorbar_width, colorbar_height] = plcolorbar(
234            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
235            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
236            cont_color, cont_width,
237            label_opts, labels, axis_opts,
238            axis_ticks, axis_subticks,
239            num_values, values );
240
241  # Reset text and tick sizes
242  plschr( 0.0, 1.0 );
243  plsmaj( 0.0, 1.0 );
244  plsmin( 0.0, 1.0 );
245
246  plcol0(1);
247  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
248  plcol0(2);
249  plcont2(w, 1, nx, 1, ny, clevel, xg2, yg2);
250
251  pllab("distance", "altitude", "Bogon density, with streamlines");
252
253  ## Plot using 2d coordinate transform
254
255  ## Load colour palettes
256  plspal0("");
257  plspal1("",1);
258  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
259  plscmap0n(3);
260
261  pladv(0);
262  plvpor(0.1, 0.9, 0.1, 0.9);
263  plwind(-1.0, 1.0, -1.0, 1.0);
264  plpsty(0);
265
266  plshades2(z, -1., 1., -1., 1.,
267	    shedge', fill_width,
268	    2, 3.,
269	    0, xg2, yg2);
270
271  # Smaller text
272  plschr( 0.0, 0.75 );
273  # Small ticks on the vertical axis
274  plsmaj( 0.0, 0.5 );
275  plsmin( 0.0, 0.5 );
276
277  num_values(1) = ns + 1;
278  values(1,:) = shedge;
279
280  [colorbar_width, colorbar_height] = plcolorbar(
281            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
282            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
283            2, 3,
284            label_opts, labels, axis_opts,
285            axis_ticks, axis_subticks,
286            num_values, values );
287
288  # Reset text and tick sizes
289  plschr( 0.0, 1.0 );
290  plsmaj( 0.0, 1.0 );
291  plsmin( 0.0, 1.0 );
292
293  plcol0(1);
294  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
295  plcol0(2);
296  ## plcont2(w, 1, nx, 1, ny, clevel, xg2, yg2);
297
298  pllab("distance", "altitude", "Bogon density");
299
300  ## Note this exclusion API will probably change.
301
302  ## Plot using 2d coordinate transform and exclusion
303  if (0) ## exclusion not implemented
304    ## Load colour palettes
305    plspal0("cmap0_black_on_white.pal");
306    plspal1("cmap1_gray.pal",1);
307    ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
308    plscmap0n(3);
309
310    pladv(0);
311    plvpor(0.1, 0.9, 0.1, 0.9);
312    plwind(-1.0, 1.0, -1.0, 1.0);
313    plpsty(0);
314
315    plshades2(z, -1., 1., -1., 1.,
316	      shedge', fill_width,
317	      cont_color, cont_width,
318	      0, xg2, yg2);
319
320    plcol0(1);
321    plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
322    pllab("distance", "altitude", "Bogon density with exclusion");
323  endif
324
325### Example with polar coordinates.
326
327  PERIMETERPTS=100;
328  ## Load colour palettes
329  plspal0("cmap0_black_on_white.pal");
330  plspal1("cmap1_gray.pal",1);
331  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
332  plscmap0n(3);
333
334  pladv(0);
335  plvpor( .1, .9, .1, .9 );
336  plwind( -1., 1., -1., 1. );
337
338  plpsty(0);
339
340  ## Build new coordinate matrices.
341
342  for i = 0:nx-1;
343    r = i/ (nx-1);
344    j = 0:ny-1;
345    t = (2*pi/(ny-1))*j;
346    xg2(i+1,:) = r.*cos(t);
347    yg2(i+1,:) = r.*sin(t);
348    z(i+1,:) = exp(-r.*r).*cos(5*pi*r).*cos(5*t);
349  endfor
350
351  ## Need a new shedge to go along with the new data set.
352
353  zmin = min(min(z));
354  zmax = max(max(z));
355
356  i = 0:ns;
357  shedge = zmin + (zmax - zmin) *  i /  ns;
358
359  ##  Now we can shade the interior region.
360  plshades2(z, -1, 1, -1, 1,
361	    shedge', fill_width,
362	    cont_color, cont_width,
363	    0, xg2, yg2);
364
365  # Smaller text
366  plschr( 0.0, 0.75 );
367  # Small ticks on the vertical axis
368  plsmaj( 0.0, 0.5 );
369  plsmin( 0.0, 0.5 );
370
371  num_values(1) = ns + 1;
372  values(1,:) = shedge;
373
374  [colorbar_width, colorbar_height] = plcolorbar(
375            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
376            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
377            cont_color, cont_width,
378            label_opts, labels, axis_opts,
379            axis_ticks, axis_subticks,
380            num_values, values );
381
382  # Reset text and tick sizes
383  plschr( 0.0, 1.0 );
384  plsmaj( 0.0, 1.0 );
385  plsmin( 0.0, 1.0 );
386
387  ## Now we can draw the perimeter.  (If do before, shade stuff may overlap.)
388  i = 0:PERIMETERPTS-1;
389  t = (2*pi/(PERIMETERPTS-1))*i;
390  px = cos(t);
391  py = sin(t);
392
393  plcol0(1);
394  plline(px', py');
395
396  ## And label the plot.
397
398  plcol0(2);
399  pllab( "", "",  "Tokamak Bogon Instability" );
400
401  ## Clean up
402
403  plend1();
404
405endfunction
406
407ix16c
408