1 // Mesh plot demo.
2 //
3 // Copyright (C) 2008 Werner Smekal
4 // Copyright (C) 2004 Rafael Laboissiere
5 //
6 // This file is part of PLplot.
7 //
8 // PLplot is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU Library General Public License as published
10 // by the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
main(char[][]args)12 //
13 // PLplot is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public License
19 // along with PLplot; if not, write to the Free So ftware
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22
23 import plplot;
24 import std.string;
25 import std.math;
26
27
28 void cmap1_init()
29 {
30 PLFLT[2] i, h, l, s;
31
32 i[] = [ 0.0, 1.0 ]; // boundaries
33 h[] = [ 240.0, 0.0 ]; // blue -> green -> yellow -> red
34 l[] = [ 0.6, 0.6 ];
35 s[] = [ 0.8, 0.8 ];
36
37 plscmap1n( 256 );
38 c_plscmap1l( 0, 2, cast(PLFLT*) i, cast(PLFLT*) h, cast(PLFLT*) l,
39 cast(PLFLT*) s, null );
40 }
41
42
43 //--------------------------------------------------------------------------
44 // main
45 //
46 // Does a series of mesh plots for a given data set, with different
47 // viewing options in each plot.
48 //--------------------------------------------------------------------------
49 int main( char[][] args )
50 {
51 const nlevel = 10;
52 const XPTS = 35; // Data points in x
53 const YPTS = 46; // Data points in y
54
55 int[] opt = [ DRAW_LINEXY, DRAW_LINEXY ];
56
57 PLFLT[] alt = [ 33.0, 17.0 ];
58 PLFLT[] az = [ 24.0, 115.0 ];
59
60 string title[] = [ "#frPLplot Example 11 - Alt=33, Az=24, Opt=3",
61 "#frPLplot Example 11 - Alt=17, Az=115, Opt=3" ];
62
63 PLFLT xx, yy;
64
65 // Parse and process command line arguments
66 plparseopts( args, PL_PARSE_FULL );
67
68 // Initialize plplot
69 plinit();
70
71 PLFLT[XPTS] x;
72 PLFLT[YPTS] y;
73
74 PLFLT[][] z = new PLFLT[][XPTS];
75 for ( int i = 0; i < XPTS; i++ )
76 z[i] = new PLFLT[YPTS];
77
78 for ( int i = 0; i < XPTS; i++ )
79 x[i] = 3. * cast(PLFLT) ( i - ( XPTS / 2 ) ) / cast(PLFLT) ( XPTS / 2 );
80
81 for ( int i = 0; i < YPTS; i++ )
82 y[i] = 3. * cast(PLFLT) ( i - ( YPTS / 2 ) ) / cast(PLFLT) ( YPTS / 2 );
83
84 for ( size_t i = 0; i < XPTS; i++ )
85 {
86 xx = x[i];
87 for ( size_t j = 0; j < YPTS; j++ )
88 {
89 yy = y[j];
90 z[i][j] = 3. * ( 1. - xx ) * ( 1. - xx ) * exp( -( xx * xx ) - ( yy + 1. ) * ( yy + 1. ) ) -
91 10. * ( xx / 5. - pow( xx, 3. ) - pow( yy, 5. ) ) * exp( -xx * xx - yy * yy ) -
92 1. / 3. * exp( -( xx + 1 ) * ( xx + 1 ) - ( yy * yy ) );
93
94 if ( 0 ) // Jungfraujoch/Interlaken
95 {
96 if ( z[i][j] < -1. )
97 z[i][j] = -1.;
98 }
99 }
100 }
101
102 PLFLT zmin, zmax;
103 f2mnmx( z, zmin, zmax );
104
105 PLFLT step = ( zmax - zmin ) / ( nlevel + 1 );
106 PLFLT[nlevel] clevel;
107 for ( size_t i = 0; i < nlevel; i++ )
108 clevel[i] = zmin + step + step * i;
109
110 cmap1_init();
111 for ( size_t k = 0; k < 2; k++ )
112 {
113 for ( size_t i = 0; i < 4; i++ )
114 {
115 pladv( 0 );
116 plcol0( 1 );
117 plvpor( 0.0, 1.0, 0.0, 0.9 );
118 plwind( -1.0, 1.0, -1.0, 1.5 );
119 plw3d( 1.0, 1.0, 1.2, -3.0, 3.0, -3.0, 3.0, zmin, zmax, alt[k], az[k] );
120 plbox3( "bnstu", "x axis", 0.0, 0,
121 "bnstu", "y axis", 0.0, 0,
122 "bcdmnstuv", "z axis", 0.0, 4 );
123
124 plcol0( 2 );
125 switch ( i )
126 {
127 case 0:
128 // wireframe plot
129 plmesh( x, y, z, opt[k] );
130 break;
131 case 1:
132 // magnitude colored wireframe plot
133 plmesh( x, y, z, opt[k] | MAG_COLOR );
134 break;
135 case 2:
136 // magnitude colored wireframe plot with sides
137 plot3d( x, y, z, opt[k] | MAG_COLOR, 1 );
138 break;
139 case 3:
140 // magnitude colored wireframe plot with base contour
141 plmeshc( x, y, z, opt[k] | MAG_COLOR | BASE_CONT, clevel );
142 break;
143 default:
144 break;
145 }
146
147 plcol0( 3 );
148 plmtex( "t", 1.0, 0.5, 0.5, title[k] );
149 }
150 }
151
152 plend();
153 return 0;
154 }
155
156 //--------------------------------------------------------------------------
157 // f2mnmx
158 //
159 // Returns min & max of input 2d array.
160 //--------------------------------------------------------------------------
161 void f2mnmx( PLFLT[][] f, out PLFLT fmn, out PLFLT fmx )
162 {
163 fmx = f[0][0];
164 fmn = fmx;
165
166 for ( int i = 0; i < f.length; i++ )
167 {
168 for ( int j = 0; j < f[i].length; j++ )
169 {
170 fmx = fmax( fmx, f[i][j] );
171 fmn = fmin( fmn, f[i][j] );
172 }
173 }
174 }
175