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