~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/perl/x15.pl

  • 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
#! /usr/bin/env perl
 
2
#
 
3
# Demo x15 for the PLplot PDL binding
 
4
#
 
5
# Shade plot demo
 
6
#
 
7
# Copyright (C) 2004  Rafael Laboissiere
 
8
#
 
9
# This file is part of PLplot.
 
10
#
 
11
# PLplot is free software; you can redistribute it and/or modify
 
12
# it under the terms of the GNU Library General Public License as published
 
13
# by the Free Software Foundation; either version 2 of the License, or
 
14
# (at your option) any later version.
 
15
#
 
16
# PLplot is distributed in the hope that it will be useful,
 
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
# GNU Library General Public License for more details.
 
20
#
 
21
# You should have received a copy of the GNU Library General Public License
 
22
# along with PLplot; if not, write to the Free Software
 
23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
24
 
 
25
# SYNC: x15c.c 1.16
 
26
 
 
27
use PDL;
 
28
use PDL::Graphics::PLplot;
 
29
 
 
30
use constant XPTS => 35;    # Data points in x
 
31
use constant YPTS => 46;    # Data points in y
 
32
 
 
33
$z = zeroes (XPTS, YPTS);
 
34
my $zmin, $zmax;
 
35
 
 
36
# Function prototypes
 
37
 
 
38
sub plot1 ();
 
39
sub plot2 ();
 
40
sub f2mnmx ($);
 
41
sub cmap1_init1 ();
 
42
sub cmap1_init2 ();
 
43
 
 
44
# main
 
45
#
 
46
# Does a variety of shade plots
 
47
 
 
48
sub main {
 
49
 
 
50
    # Parse and process command line arguments
 
51
 
 
52
    plParseOpts (\@ARGV, PL_PARSE_SKIP | PL_PARSE_NOPROGRAM);
 
53
 
 
54
    # Set up color map 0
 
55
    #
 
56
    #  plscmap0n(3);
 
57
    #
 
58
 
 
59
 
 
60
    # Set up color map 1
 
61
 
 
62
    cmap1_init2 ();
 
63
 
 
64
    # Initialize plplot
 
65
 
 
66
    plinit ();
 
67
 
 
68
    # Set up data array
 
69
 
 
70
    my $xx = (sequence (XPTS) - int(XPTS / 2)) / int(XPTS / 2);
 
71
    my $yy = (sequence (YPTS) - int(YPTS / 2)) / int(YPTS / 2) - 1.0;
 
72
    for (my $i = 0; $i < XPTS; $i++) {
 
73
        my $xi = $xx->index ($i);
 
74
        for (my $j = 0; $j < YPTS; $j++) {
 
75
            my $yi = $yy->index ($j);
 
76
            $z->slice ("$i,$j") .= $xi ** 2 - $yi ** 2
 
77
                + ($xi - $yi) / ($xi * $xi + $yi ** 2 + 0.1);
 
78
        }
 
79
    }
 
80
 
 
81
    ($zmin, $zmax) = f2mnmx ($z);
 
82
 
 
83
    plot1 ();
 
84
    plot2 ();
 
85
    plot3 ();
 
86
 
 
87
    plend();
 
88
 
 
89
}
 
90
 
 
91
# cmap1_init1
 
92
#
 
93
# Initializes color map 1 in HLS space
 
94
 
 
95
sub cmap1_init1 () {
 
96
    my $i = pdl [0,       # left boundary
 
97
                 0.45,    # just before center
 
98
                 0.55,    # just after center
 
99
                 1];      # right boundary
 
100
 
 
101
    my $h = pdl [260,     # hue -- low: blue-violet
 
102
                 260,     # only change as we go over vertex
 
103
                 20,      # hue -- high: red
 
104
                 20];     # keep fixed
 
105
 
 
106
    my $l;
 
107
    if (1) {
 
108
        $l = pdl [0.5,      # lightness -- low
 
109
                  0.0,      # lightness -- center
 
110
                  0.0,      # lightness -- center
 
111
                  0.5];     # lightness -- high
 
112
    } else {
 
113
        plscolbg (255, 255, 255);
 
114
        $l = pdl [0.5,      # lightness -- low
 
115
                  1.0,      # lightness -- center
 
116
                  1.0,      # lightness -- center
 
117
                  0.5];     # lightness -- high
 
118
    }
 
119
    my $s = pdl [1,       # maximum saturation
 
120
                 1,       # maximum saturation
 
121
                 1,       # maximum saturation
 
122
                 1];      # maximum saturation
 
123
 
 
124
    plscmap1l (0, $i, $h, $l, $s, pdl ([]));
 
125
}
 
126
 
 
127
# cmap1_init2
 
128
#
 
129
# Initializes color map 1 in HLS space
 
130
 
 
131
sub cmap1_init2 () {
 
132
    my $i = pdl [0,       # left boundary
 
133
                 0.45,    # just before center
 
134
                 0.55,    # just after center
 
135
                 1];      # right boundary
 
136
 
 
137
    my $h = pdl [260,     # hue -- low: blue-violet
 
138
                 260,     # only change as we go over vertex
 
139
                 20,      # hue -- high: red
 
140
                 20];     # keep fixed
 
141
 
 
142
    my $l;
 
143
    if (1) {
 
144
        $l = pdl [0.6,      # lightness -- low
 
145
                  0.0,      # lightness -- center
 
146
                  0.0,      # lightness -- center
 
147
                  0.6];     # lightness -- high
 
148
    } else {
 
149
        plscolbg (255, 255, 255);
 
150
        $l = pdl [0.5,      # lightness -- low
 
151
                  1.0,      # lightness -- center
 
152
                  1.0,      # lightness -- center
 
153
                  0.5];     # lightness -- high
 
154
    }
 
155
    my $s = pdl [1,       # maximum saturation
 
156
                 0.5,     # maximum saturation
 
157
                 0.5,     # maximum saturation
 
158
                 1];      # maximum saturation
 
159
 
 
160
    plscmap1l (0, $i, $h, $l, $s, pdl ([]));
 
161
}
 
162
 
 
163
# plot1
 
164
#
 
165
# Illustrates a single shaded region
 
166
 
 
167
sub plot1 () {
 
168
    my $sh_cmap = 0;
 
169
    my $min_color = 0;
 
170
    my $min_width = 0;
 
171
    my $max_color = 0;
 
172
    my $max_width = 0;
 
173
 
 
174
    pladv (0);
 
175
    plvpor (0.1, 0.9, 0.1, 0.9);
 
176
    plwind (-1.0, 1.0, -1.0, 1.0);
 
177
 
 
178
    # Plot using identity transform
 
179
 
 
180
    my $shade_min = $zmin + ($zmax - $zmin) * 0.4;
 
181
    my $shade_max = $zmin + ($zmax - $zmin) * 0.6;
 
182
    my $sh_color = 7;
 
183
    my $sh_width = 2;
 
184
    my $min_color = 9;
 
185
    my $max_color = 2;
 
186
    my $min_width = 2;
 
187
    my $max_width = 2;
 
188
 
 
189
    plpsty (8);
 
190
    plshade1 ($z, -1, 1, -1, 1,
 
191
              $shade_min, $shade_max, $sh_cmap, $sh_color, $sh_width,
 
192
              $min_color, $min_width, $max_color, $max_width,
 
193
              1, "", "", 0);
 
194
 
 
195
    plcol0 (1);
 
196
    plbox (0.0, 0, 0.0, 0, "bcnst", "bcnstv");
 
197
    plcol0 (2);
 
198
    pllab ("distance", "altitude", "Bogon flux");
 
199
}
 
200
 
 
201
# plot2
 
202
#
 
203
# Illustrates multiple adjacent shaded regions, using different fill
 
204
# patterns for each region
 
205
 
 
206
sub plot2 () {
 
207
 
 
208
    my $nlin = pdl [1, 1, 1, 1, 1, 2, 2, 2, 2, 2];
 
209
    my $inc = pdl [ [450, 0], [-450, 0], [0, 0], [900, 0], 
 
210
                    [300, 0], [450,-450], [0, 900], [0, 450], 
 
211
                    [450, -450], [0, 900] ];
 
212
    my $spa = pdl [ [2000, 2000], [2000, 2000], [2000, 2000], 
 
213
                    [2000, 2000], [2000, 2000], [2000, 2000], 
 
214
                    [2000, 2000], [2000, 2000], [4000, 4000], 
 
215
                    [4000, 2000] ];
 
216
 
 
217
    my $sh_cmap = 0;
 
218
    my $min_color = 0;
 
219
    my $min_width = 0;
 
220
    my $max_color = 0;
 
221
    my $max_width = 0;
 
222
    my $sh_width = 2;
 
223
 
 
224
    pladv (0);
 
225
    plvpor (0.1, 0.9, 0.1, 0.9);
 
226
    plwind (-1.0, 1.0, -1.0, 1.0);
 
227
 
 
228
    # Plot using identity transform
 
229
 
 
230
    for (my $i = 0; $i < 10; $i++) {
 
231
        my $shade_min = $zmin + ($zmax - $zmin) * $i / 10.0;
 
232
        my $shade_max = $zmin + ($zmax - $zmin) * ($i + 1) / 10.0;
 
233
        my $sh_color = $i + 6;
 
234
        my $n = $nlin->slice("($i)");
 
235
        my $nm1 = $n - 1;
 
236
        plpat ($n, $inc->slice("0:$nm1,($i)"), $spa->slice("0:$nm1,($i)"));
 
237
 
 
238
        plshade1 ($z, -1, 1, -1, 1,
 
239
                  $shade_min, $shade_max, $sh_cmap, $sh_color, $sh_width,
 
240
                  $min_color, $min_width, $max_color, $max_width,
 
241
                  1, "", "", 0);
 
242
    }
 
243
 
 
244
    plcol0 (1);
 
245
    plbox (0.0, 0, 0.0, 0, "bcnst", "bcnstv");
 
246
    plcol0 (2);
 
247
    pllab ("distance", "altitude", "Bogon flux");
 
248
}
 
249
 
 
250
# plot3
 
251
#
 
252
# Illustrates shaded regions in 3d, using a different fill pattern for 
 
253
# each region.
 
254
 
 
255
sub plot3 () {
 
256
 
 
257
    my $xx = pdl [ [-1.0, 1.0, 1.0, -1.0, -1.0],
 
258
                    [-1.0, 1.0, 1.0, -1.0, -1.0] ];
 
259
    my $yy = pdl [ [1.0, 1.0, 0.0, 0.0, 1.0], 
 
260
                   [-1.0, -1.0, 0.0, 0.0, -1.0] ];
 
261
    my $zz = pdl [ [0.0, 0.0, 1.0, 1.0, 0.0], 
 
262
                   [0.0, 0.0, 1.0, 1.0, 0.0] ];
 
263
 
 
264
    pladv (0);
 
265
    plvpor (0.1, 0.9, 0.1, 0.9);
 
266
    plwind (-1.0, 1.0, -1.0, 1.0);
 
267
    plw3d (1., 1., 1., -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30., -40,);
 
268
    
 
269
    # Plot using identity transform
 
270
    
 
271
    plcol0 (1);
 
272
    plbox3 (0.0, 0, 0.0, 0, 0.5, 0, "bntu", "X", "bntu", "Y", "bcdfntu", "Z");
 
273
    plcol0 (2);
 
274
    pllab ("","","3-d polygon filling");
 
275
    
 
276
    plcol0 (3);
 
277
    plpsty (1);
 
278
    plline3 ($xx->slice(":,0"), $yy->slice(":,0"), $zz->slice(":,0"));
 
279
    plfill3 (4, $xx->slice("0:4,0"), $yy->slice("0:4,0"), $zz->slice("0:4,0"));
 
280
    plpsty (2);
 
281
    plline3 ($xx->slice(":,1"), $yy->slice(":,1"), $zz->slice(":,1"));
 
282
    plfill3 (4, $xx->slice("0:4,1"), $yy->slice("0:4,1"), $zz->slice("0:4,1"));
 
283
    
 
284
}
 
285
 
 
286
# f2mnmx
 
287
#
 
288
# Returns min & max of input 2d array
 
289
 
 
290
sub f2mnmx ($) {
 
291
    my $f = shift;
 
292
    return (min ($f), max ($f));
 
293
}
 
294
 
 
295
main ();