~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/octave/x16c.m

  • Committer: Joachim Erfle
  • Date: 2013-07-24 13:53:41 UTC
  • Revision ID: joachim.erfle@desy.de-20130724135341-1qojpp701zsn009p
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
18
1;
 
19
 
 
20
## Set up transformation function 
 
21
 
 
22
global nx = 35; ## Default number of data points in x 
 
23
global ny = 46; ## Default number of data points in y 
 
24
global  tr = [2/(nx-1); 0.0; -1.0; 0.0; 2/(ny-1); -1.0];
 
25
 
 
26
function  [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);
 
30
endfunction
 
31
 
 
32
function ix16c
 
33
 
 
34
  global tr; global nx; global ny;
 
35
  ## Fundamental settings.  See notes[] for more info. 
 
36
 
 
37
  ns = 20;              ## Default number of shade levels 
 
38
 
 
39
  notes = [
 
40
           "To get smoother color variation, increase ns, nx, and ny.  To get faster",
 
41
           "response (especially on a serial link), decrease them.  A decent but quick",
 
42
           "test results from ns around 5 and nx, ny around 25."];
 
43
 
 
44
  sh_cmap = 1;
 
45
  fill_width = 2; cont_color = 0;  cont_width = 0;
 
46
  min_color = 1; min_width = 0; max_color = 0; max_width = 0;
 
47
 
 
48
  ## Parse and process command line arguments 
 
49
 
 
50
  ##    plMergeOpts(options, "x16c options", notes);
 
51
  ##    plparseopts(&argc, argv, PL_PARSE_FULL);
 
52
 
 
53
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display 
 
54
 
 
55
  ## Load colour palettes
 
56
  plspal0("cmap0_black_on_white.pal");
 
57
  plspal1("cmap1_gray.pal",1);
 
58
  plscmap0n(3);
 
59
 
 
60
  ## Initialize plplot 
 
61
  plinit();
 
62
 
 
63
  ## Set up data array 
 
64
 
 
65
  for i = 0:nx-1
 
66
    x = (i - fix(nx / 2)) / fix(nx / 2);
 
67
    j = 0:ny-1;
 
68
    y = (j .- fix(ny / 2)) ./ fix(ny / 2) - 1.0;
 
69
 
 
70
    z(i+1,:) = - sin(7.*x) .* cos(7.*y) .+ x*x - y.*y;
 
71
    w(i+1,:) = - cos(7.*x) .* sin(7.*y) .+ 2 .* x .* y;
 
72
  endfor
 
73
 
 
74
  zmin=min(min(z));
 
75
  zmax=max(max(z));
 
76
 
 
77
  i = 0:ns-1;
 
78
  clevel = (zmin .+ (zmax - zmin) .* (i + 0.5) ./ ns)';
 
79
  i = 0:ns;
 
80
  shedge = zmin + (zmax - zmin) * i / ns;
 
81
  
 
82
  ## Set up coordinate grids 
 
83
 
 
84
  for i = 0:nx-1
 
85
    j = 0:ny-1;
 
86
    [x y] = mypltr( i,  j);
 
87
 
 
88
    argx = x * pi/2;
 
89
    argy = y * pi/2;
 
90
    distort = 0.4;
 
91
 
 
92
    xg1(i+1,:) = x .+ distort .* cos(argx);
 
93
    yg1(i+1,:) = y .- distort .* cos(argy);
 
94
 
 
95
    xg2(i+1,:) = x .+ distort .* cos(argx) .* cos(argy);
 
96
    yg2(i+1,:) = y .- distort .* cos(argx) .* cos(argy);
 
97
  endfor
 
98
 
 
99
  xg1 = xg1(:,1);
 
100
  yg1 = yg1(1,:)';
 
101
 
 
102
  ## Plot using identity transform 
 
103
 
 
104
  pladv(0);
 
105
  plvpor(0.1, 0.9, 0.1, 0.9);
 
106
  plwind(-1.0, 1.0, -1.0, 1.0);
 
107
  plpsty(0);
 
108
 
 
109
  plshades(z, -1., 1., -1., 1., 
 
110
           shedge', fill_width,
 
111
           cont_color, cont_width,
 
112
           1);
 
113
 
 
114
  plcol0(1);
 
115
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
 
116
  plcol0(2);
 
117
  
 
118
  ## plcont(w, 1, nx, 1, ny, clevel, tr);
 
119
  
 
120
  pllab("distance", "altitude", "Bogon density");
 
121
 
 
122
  ## Plot using 1d coordinate transform 
 
123
 
 
124
  ##  Load colour palettes
 
125
  plspal0("cmap0_black_on_white.pal");
 
126
  plspal1("cmap1_blue_yellow.pal",1);
 
127
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
 
128
  plscmap0n(3);
 
129
 
 
130
  pladv(0);
 
131
  plvpor(0.1, 0.9, 0.1, 0.9);
 
132
  plwind(-1.0, 1.0, -1.0, 1.0);
 
133
  plpsty(0);
 
134
 
 
135
  plshades1(z, -1., 1., -1., 1., 
 
136
            shedge', fill_width,
 
137
            cont_color, cont_width,
 
138
            1, xg1, yg1);
 
139
 
 
140
  plcol0(1);
 
141
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
 
142
  plcol0(2);
 
143
 
 
144
  ## plcont1(w, 1, nx, 1, ny, clevel, xg1, yg1);
 
145
 
 
146
  pllab("distance", "altitude", "Bogon density");
 
147
 
 
148
  ## Plot using 2d coordinate transform 
 
149
 
 
150
  ## Load colour palettes
 
151
  plspal0("cmap0_black_on_white.pal");
 
152
  plspal1("cmap1_blue_red.pal",1);
 
153
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
 
154
  plscmap0n(3);
 
155
 
 
156
  pladv(0);
 
157
  plvpor(0.1, 0.9, 0.1, 0.9);
 
158
  plwind(-1.0, 1.0, -1.0, 1.0);
 
159
  plpsty(0);
 
160
 
 
161
  plshades2(z, -1., 1., -1., 1., 
 
162
            shedge', fill_width,
 
163
            cont_color, cont_width,
 
164
            0, xg2, yg2);
 
165
 
 
166
  plcol0(1);
 
167
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
 
168
  plcol0(2);
 
169
  plcont2(w, 1, nx, 1, ny, clevel, xg2, yg2);
 
170
 
 
171
  pllab("distance", "altitude", "Bogon density, with streamlines");
 
172
 
 
173
  ## Plot using 2d coordinate transform 
 
174
 
 
175
  ## Load colour palettes
 
176
  plspal0("");
 
177
  plspal1("",1);
 
178
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
 
179
  plscmap0n(3);
 
180
 
 
181
  pladv(0);
 
182
  plvpor(0.1, 0.9, 0.1, 0.9);
 
183
  plwind(-1.0, 1.0, -1.0, 1.0);
 
184
  plpsty(0);
 
185
 
 
186
  plshades2(z, -1., 1., -1., 1., 
 
187
            shedge', fill_width,
 
188
            2, 3,
 
189
            0, xg2, yg2);
 
190
 
 
191
  plcol0(1);
 
192
  plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
 
193
  plcol0(2);
 
194
  ## plcont2(w, 1, nx, 1, ny, clevel, xg2, yg2);
 
195
 
 
196
  pllab("distance", "altitude", "Bogon density");
 
197
 
 
198
  ## Note this exclusion API will probably change. 
 
199
  
 
200
  ## Plot using 2d coordinate transform and exclusion
 
201
  if (0) ## exclusion not implemented
 
202
    ## Load colour palettes
 
203
    plspal0("cmap0_black_on_white.pal");
 
204
    plspal1("cmap1_gray.pal",1);
 
205
    ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
 
206
    plscmap0n(3);
 
207
 
 
208
    pladv(0);
 
209
    plvpor(0.1, 0.9, 0.1, 0.9);
 
210
    plwind(-1.0, 1.0, -1.0, 1.0);
 
211
    plpsty(0);
 
212
 
 
213
    plshades2(z, -1., 1., -1., 1., 
 
214
              shedge', fill_width,
 
215
              cont_color, cont_width,
 
216
              0, xg2, yg2);
 
217
 
 
218
    plcol0(1);
 
219
    plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0);
 
220
    pllab("distance", "altitude", "Bogon density with exclusion");
 
221
  endif
 
222
 
 
223
### Example with polar coordinates. 
 
224
 
 
225
  PERIMETERPTS=100;
 
226
  ## Load colour palettes
 
227
  plspal0("cmap0_black_on_white.pal");
 
228
  plspal1("cmap1_gray.pal",1);
 
229
  ## Reduce colors in cmap 0 so that cmap 1 is useful on a 16-color display
 
230
  plscmap0n(3);
 
231
 
 
232
  pladv(0);
 
233
  plvpor( .1, .9, .1, .9 );
 
234
  plwind( -1., 1., -1., 1. );
 
235
 
 
236
  plpsty(0);
 
237
 
 
238
  ## Build new coordinate matrices. 
 
239
  
 
240
  for i = 0:nx-1;
 
241
    r = i/ (nx-1);
 
242
    j = 0:ny-1;
 
243
    t = (2*pi/(ny-1))*j;
 
244
    xg2(i+1,:) = r.*cos(t);
 
245
    yg2(i+1,:) = r.*sin(t);
 
246
    z(i+1,:) = exp(-r.*r).*cos(5*pi*r).*cos(5*t);
 
247
  endfor
 
248
 
 
249
  ## Need a new shedge to go along with the new data set. 
 
250
 
 
251
  zmin = min(min(z));
 
252
  zmax = max(max(z));
 
253
 
 
254
  i = 0:ns;
 
255
  shedge = zmin + (zmax - zmin) *  i /  ns;
 
256
 
 
257
  ##  Now we can shade the interior region. 
 
258
  plshades2(z, -1, 1, -1, 1, 
 
259
            shedge', fill_width,
 
260
            cont_color, cont_width,
 
261
            0, xg2, yg2);
 
262
 
 
263
  ## Now we can draw the perimeter.  (If do before, shade stuff may overlap.) 
 
264
  i = 0:PERIMETERPTS-1;
 
265
  t = (2*pi/(PERIMETERPTS-1))*i;
 
266
  px = cos(t);
 
267
  py = sin(t);
 
268
 
 
269
  plcol0(1);
 
270
  plline(px', py');
 
271
  
 
272
  ## And label the plot.
 
273
 
 
274
  plcol0(2);
 
275
  pllab( "", "",  "Tokamak Bogon Instability" );
 
276
 
 
277
  ## Clean up 
 
278
 
 
279
  plend1();
 
280
 
 
281
endfunction
 
282
 
 
283
ix16c