File: x16c.m

package info (click to toggle)
plplot 5.15.0%2Bdfsg-19
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 31,312 kB
  • sloc: ansic: 79,707; xml: 28,583; cpp: 20,033; ada: 19,456; tcl: 12,081; f90: 11,431; ml: 7,276; java: 6,863; python: 6,792; sh: 3,274; perl: 828; lisp: 75; makefile: 50; sed: 34; fortran: 5
file content (407 lines) | stat: -rw-r--r-- 10,068 bytes parent folder | download | duplicates (4)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
## Copyright (C) 1998, 1999, 2000 Joao Cardoso.
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the
## Free Software Foundation; either version 2 of the License, or (at your
## option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## This file is part of plplot_octave.
## It is based on the corresponding demo function of PLplot.

##	plshade demo, using color fill.

1;

## Set up transformation function

global nx = 35;	## Default number of data points in x
global ny = 46;	## Default number of data points in y
global	tr = [2/(nx-1); 0.0; -1.0; 0.0; 2/(ny-1); -1.0];

function  [tx ty] = mypltr( x, y)
  global tr
  tx = tr(1) * x + tr(2) * y + tr(3);
  ty = tr(4) * x + tr(5) * y + tr(6);
endfunction

function ix16c

  global tr; global nx; global ny;
  global PL_COLORBAR_LABEL_BOTTOM;
  global PL_COLORBAR_SHADE;
  global PL_COLORBAR_SHADE_LABEL;
  ## Fundamental settings.  See notes[] for more info.

  ns = 20;		## Default number of shade levels

  notes = [
	   "To get smoother color variation, increase ns, nx, and ny.  To get faster",
	   "response (especially on a serial link), decrease them.  A decent but quick",
	   "test results from ns around 5 and nx, ny around 25."];

  sh_cmap = 1;
  fill_width = 2.; cont_color = 0;  cont_width = 0.;

  num_axes = 1;
  n_axis_opts = num_axes;
  axis_opts = { "bcvtm" };
  values = zeros(num_axes,ns+1);
  axis_ticks = zeros(1,1);
  axis_subticks = zeros(1,1);

  num_labels = 1;
  label_opts = [ PL_COLORBAR_LABEL_BOTTOM ];
  labels = { "Magnitude" };


  ## Parse and process command line arguments

  ##    plMergeOpts(options, "x16c options", notes);
  ##    plparseopts(&argc, argv, PL_PARSE_FULL);

  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display

  ## Load colour palettes
  plspal0("cmap0_black_on_white.pal");
  plspal1("cmap1_gray.pal",1);
  plscmap0n(3);

  ## Initialize plplot
  plinit();

  ## Set up data array

  for i = 0:nx-1
    x = (i - fix(nx / 2)) / fix(nx / 2);
    j = 0:ny-1;
    y = (j .- fix(ny / 2)) ./ fix(ny / 2) - 1.0;

    z(i+1,:) = - sin(7.*x) .* cos(7.*y) .+ x*x - y.*y;
    w(i+1,:) = - cos(7.*x) .* sin(7.*y) .+ 2 .* x .* y;
  endfor

  zmin=min(min(z));
  zmax=max(max(z));

  i = 0:ns-1;
  clevel = (zmin .+ (zmax - zmin) .* (i + 0.5) ./ ns)';
  i = 0:ns;
  shedge = zmin + (zmax - zmin) * i / ns;

  ## Set up coordinate grids

  for i = 0:nx-1
    j = 0:ny-1;
    [x y] = mypltr( i,  j);

    argx = x * pi/2;
    argy = y * pi/2;
    distort = 0.4;

    xg1(i+1,:) = x .+ distort .* cos(argx);
    yg1(i+1,:) = y .- distort .* cos(argy);

    xg2(i+1,:) = x .+ distort .* cos(argx) .* cos(argy);
    yg2(i+1,:) = y .- distort .* cos(argx) .* cos(argy);
  endfor

  xg1 = xg1(:,1);
  yg1 = yg1(1,:)';

  ## Plot using identity transform

  pladv(0);
  plvpor(0.1, 0.9, 0.1, 0.9);
  plwind(-1.0, 1.0, -1.0, 1.0);
  plpsty(0);

  plshades(z, -1., 1., -1., 1.,
	   shedge', fill_width,
	   cont_color, cont_width,
	   1);

  # Smaller text
  plschr( 0.0, 0.75 );
  # Small ticks on the vertical axis
  plsmaj( 0.0, 0.5 );
  plsmin( 0.0, 0.5 );

  num_values(1) = ns + 1;
  values(1,:) = shedge;

  [colorbar_width, colorbar_height] = plcolorbar(
            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
            cont_color, cont_width,
            label_opts, labels, axis_opts,
            axis_ticks, axis_subticks,
            num_values, values );

  # Reset text and tick sizes
  plschr( 0.0, 1.0 );
  plsmaj( 0.0, 1.0 );
  plsmin( 0.0, 1.0 );

  plcol0(1);
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
  plcol0(2);

  ## plcont(w, 1, nx, 1, ny, clevel, tr);

  pllab("distance", "altitude", "Bogon density");

  ## Plot using 1d coordinate transform

  ##  Load colour palettes
  plspal0("cmap0_black_on_white.pal");
  plspal1("cmap1_blue_yellow.pal",1);
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
  plscmap0n(3);

  pladv(0);
  plvpor(0.1, 0.9, 0.1, 0.9);
  plwind(-1.0, 1.0, -1.0, 1.0);
  plpsty(0);

  plshades1(z, -1., 1., -1., 1.,
	    shedge', fill_width,
	    cont_color, cont_width,
	    1, xg1, yg1);

  # Smaller text
  plschr( 0.0, 0.75 );
  # Small ticks on the vertical axis
  plsmaj( 0.0, 0.5 );
  plsmin( 0.0, 0.5 );

  num_values(1) = ns + 1;
  values(1,:) = shedge;

  [colorbar_width, colorbar_height] = plcolorbar(
            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
            cont_color, cont_width,
            label_opts, labels, axis_opts,
            axis_ticks, axis_subticks,
            num_values, values );

  # Reset text and tick sizes
  plschr( 0.0, 1.0 );
  plsmaj( 0.0, 1.0 );
  plsmin( 0.0, 1.0 );

  plcol0(1);
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
  plcol0(2);

  ## plcont1(w, 1, nx, 1, ny, clevel, xg1, yg1);

  pllab("distance", "altitude", "Bogon density");

  ## Plot using 2d coordinate transform

  ## Load colour palettes
  plspal0("cmap0_black_on_white.pal");
  plspal1("cmap1_blue_red.pal",1);
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
  plscmap0n(3);

  pladv(0);
  plvpor(0.1, 0.9, 0.1, 0.9);
  plwind(-1.0, 1.0, -1.0, 1.0);
  plpsty(0);

  plshades2(z, -1., 1., -1., 1.,
	    shedge', fill_width,
	    cont_color, cont_width,
	    0, xg2, yg2);

  # Smaller text
  plschr( 0.0, 0.75 );
  # Small ticks on the vertical axis
  plsmaj( 0.0, 0.5 );
  plsmin( 0.0, 0.5 );

  num_values(1) = ns + 1;
  values(1,:) = shedge;

  [colorbar_width, colorbar_height] = plcolorbar(
            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
            cont_color, cont_width,
            label_opts, labels, axis_opts,
            axis_ticks, axis_subticks,
            num_values, values );

  # Reset text and tick sizes
  plschr( 0.0, 1.0 );
  plsmaj( 0.0, 1.0 );
  plsmin( 0.0, 1.0 );

  plcol0(1);
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
  plcol0(2);
  plcont2(w, 1, nx, 1, ny, clevel, xg2, yg2);

  pllab("distance", "altitude", "Bogon density, with streamlines");

  ## Plot using 2d coordinate transform

  ## Load colour palettes
  plspal0("");
  plspal1("",1);
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
  plscmap0n(3);

  pladv(0);
  plvpor(0.1, 0.9, 0.1, 0.9);
  plwind(-1.0, 1.0, -1.0, 1.0);
  plpsty(0);

  plshades2(z, -1., 1., -1., 1.,
	    shedge', fill_width,
	    2, 3.,
	    0, xg2, yg2);

  # Smaller text
  plschr( 0.0, 0.75 );
  # Small ticks on the vertical axis
  plsmaj( 0.0, 0.5 );
  plsmin( 0.0, 0.5 );

  num_values(1) = ns + 1;
  values(1,:) = shedge;

  [colorbar_width, colorbar_height] = plcolorbar(
            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
            2, 3,
            label_opts, labels, axis_opts,
            axis_ticks, axis_subticks,
            num_values, values );

  # Reset text and tick sizes
  plschr( 0.0, 1.0 );
  plsmaj( 0.0, 1.0 );
  plsmin( 0.0, 1.0 );

  plcol0(1);
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
  plcol0(2);
  ## plcont2(w, 1, nx, 1, ny, clevel, xg2, yg2);

  pllab("distance", "altitude", "Bogon density");

  ## Note this exclusion API will probably change.

  ## Plot using 2d coordinate transform and exclusion
  if (0) ## exclusion not implemented
    ## Load colour palettes
    plspal0("cmap0_black_on_white.pal");
    plspal1("cmap1_gray.pal",1);
    ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
    plscmap0n(3);

    pladv(0);
    plvpor(0.1, 0.9, 0.1, 0.9);
    plwind(-1.0, 1.0, -1.0, 1.0);
    plpsty(0);

    plshades2(z, -1., 1., -1., 1.,
	      shedge', fill_width,
	      cont_color, cont_width,
	      0, xg2, yg2);

    plcol0(1);
    plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
    pllab("distance", "altitude", "Bogon density with exclusion");
  endif

### Example with polar coordinates.

  PERIMETERPTS=100;
  ## Load colour palettes
  plspal0("cmap0_black_on_white.pal");
  plspal1("cmap1_gray.pal",1);
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
  plscmap0n(3);

  pladv(0);
  plvpor( .1, .9, .1, .9 );
  plwind( -1., 1., -1., 1. );

  plpsty(0);

  ## Build new coordinate matrices.

  for i = 0:nx-1;
    r = i/ (nx-1);
    j = 0:ny-1;
    t = (2*pi/(ny-1))*j;
    xg2(i+1,:) = r.*cos(t);
    yg2(i+1,:) = r.*sin(t);
    z(i+1,:) = exp(-r.*r).*cos(5*pi*r).*cos(5*t);
  endfor

  ## Need a new shedge to go along with the new data set.

  zmin = min(min(z));
  zmax = max(max(z));

  i = 0:ns;
  shedge = zmin + (zmax - zmin) *  i /  ns;

  ##  Now we can shade the interior region.
  plshades2(z, -1, 1, -1, 1,
	    shedge', fill_width,
	    cont_color, cont_width,
	    0, xg2, yg2);

  # Smaller text
  plschr( 0.0, 0.75 );
  # Small ticks on the vertical axis
  plsmaj( 0.0, 0.5 );
  plsmin( 0.0, 0.5 );

  num_values(1) = ns + 1;
  values(1,:) = shedge;

  [colorbar_width, colorbar_height] = plcolorbar(
            bitor(PL_COLORBAR_SHADE, PL_COLORBAR_SHADE_LABEL), 0,
            0.005, 0.0, 0.0375, 0.875, 0, 1, 1, 0.0, 0.0,
            cont_color, cont_width,
            label_opts, labels, axis_opts,
            axis_ticks, axis_subticks,
            num_values, values );

  # Reset text and tick sizes
  plschr( 0.0, 1.0 );
  plsmaj( 0.0, 1.0 );
  plsmin( 0.0, 1.0 );

  ## Now we can draw the perimeter.  (If do before, shade stuff may overlap.)
  i = 0:PERIMETERPTS-1;
  t = (2*pi/(PERIMETERPTS-1))*i;
  px = cos(t);
  py = sin(t);

  plcol0(1);
  plline(px', py');

  ## And label the plot.

  plcol0(2);
  pllab( "", "",  "Tokamak Bogon Instability" );

  ## Clean up

  plend1();

endfunction

ix16c