~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/java/x11.java

  • 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
//--------------------------------------------------------------------------
 
2
// $Id: x11.java 11301 2010-11-02 17:21:08Z airwin $
 
3
//--------------------------------------------------------------------------
 
4
 
 
5
//--------------------------------------------------------------------------
 
6
// Copyright (C) 2001  Geoffrey Furnish
 
7
// Copyright (C) 2001, 2002, 2003  Alan W. Irwin
 
8
// Copyright (C) 2004  Andrew Ross
 
9
//
 
10
// This file is part of PLplot.
 
11
//
 
12
// PLplot is free software; you can redistribute it and/or modify
 
13
// it under the terms of the GNU Library General Public License as published by
 
14
// the Free Software Foundation; version 2 of the License.
 
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
 
 
26
//--------------------------------------------------------------------------
 
27
// Implementation of PLplot example 11 in Java.
 
28
//--------------------------------------------------------------------------
 
29
 
 
30
package plplot.examples;
 
31
 
 
32
import plplot.core.*;
 
33
 
 
34
import java.lang.Math;
 
35
 
 
36
class x11 {
 
37
    PLStream         pls = new PLStream();
 
38
 
 
39
    static final int XPTS   = 35;
 
40
    static final int YPTS   = 46;
 
41
    static final int LEVELS = 10;
 
42
 
 
43
    static int       opt[] = { 3, 3 };
 
44
    static double    alt[] = { 33.0, 17.0 };
 
45
    static double    az[]  = { 24.0, 115.0 };
 
46
 
 
47
    static           String[] title =
 
48
    {
 
49
        "#frPLplot Example 11 - Alt=33, Az=24, Opt=3",
 
50
        "#frPLplot Example 11 - Alt=17, Az=115, Opt=3"
 
51
    };
 
52
 
 
53
    void cmap1_init()
 
54
    {
 
55
        double [] i    = new double[2];
 
56
        double [] h    = new double[2];
 
57
        double [] l    = new double[2];
 
58
        double [] s    = new double[2];
 
59
        boolean [] rev = new boolean[2];
 
60
 
 
61
        i[0] = 0.0;         // left boundary
 
62
        i[1] = 1.0;         // right boundary
 
63
 
 
64
        h[0] = 240;         // blue -> green -> yellow ->
 
65
        h[1] = 0;           // -> red
 
66
 
 
67
        l[0] = 0.6;
 
68
        l[1] = 0.6;
 
69
 
 
70
        s[0] = 0.8;
 
71
        s[1] = 0.8;
 
72
 
 
73
        rev[0] = false;         // interpolate on front side of colour wheel.
 
74
        rev[1] = false;         // interpolate on front side of colour wheel.
 
75
 
 
76
        pls.scmap1n( 256 );
 
77
        pls.scmap1l( false, i, h, l, s, rev );
 
78
    }
 
79
 
 
80
// Does a series of mesh plots for a given data set, with different viewing
 
81
// options in each plot.
 
82
 
 
83
    public static void main( String[] args )
 
84
    {
 
85
        new x11( args );
 
86
    }
 
87
 
 
88
    public x11( String[] args )
 
89
    {
 
90
        int i, j, k;
 
91
 
 
92
        double[] x   = new double[ XPTS ];
 
93
        double[] y   = new double[ YPTS ];
 
94
        double[][] z = new double[XPTS][YPTS];
 
95
        double zmin = Double.MAX_VALUE, zmax = Double.MIN_VALUE;
 
96
 
 
97
        double xx, yy;
 
98
        int    nlevel = LEVELS;
 
99
        double[] clevel = new double[LEVELS];
 
100
        double step;
 
101
 
 
102
 
 
103
        // Parse and process command line arguments.
 
104
 
 
105
        pls.parseopts( args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM );
 
106
 
 
107
        // Initialize plplot.
 
108
 
 
109
        pls.init();
 
110
 
 
111
        for ( i = 0; i < XPTS; i++ )
 
112
            x[i] = 3. * (double) ( i - ( XPTS / 2 ) ) / (double) ( XPTS / 2 );
 
113
 
 
114
        for ( j = 0; j < YPTS; j++ )
 
115
            y[j] = 3. * (double) ( j - ( YPTS / 2 ) ) / (double) ( YPTS / 2 );
 
116
 
 
117
        for ( i = 0; i < XPTS; i++ )
 
118
        {
 
119
            xx = x[i];
 
120
            for ( j = 0; j < YPTS; j++ )
 
121
            {
 
122
                yy      = y[j];
 
123
                z[i][j] = 3. * ( 1. - xx ) * ( 1. - xx ) * Math.exp( -( xx * xx ) - ( yy + 1. ) * ( yy + 1. ) ) -
 
124
                          10. * ( xx / 5. - Math.pow( xx, 3. ) - Math.pow( yy, 5. ) ) * Math.exp( -xx * xx - yy * yy ) -
 
125
                          1. / 3. * Math.exp( -( xx + 1 ) * ( xx + 1 ) - ( yy * yy ) );
 
126
                if ( false ) // Jungfraujoch/Interlaken
 
127
                {
 
128
                    if ( z[i][j] < -1. )
 
129
                        z[i][j] = -1.;
 
130
                }
 
131
                if ( zmin > z[i][j] )
 
132
                    zmin = z[i][j];
 
133
                if ( zmax < z[i][j] )
 
134
                    zmax = z[i][j];
 
135
            }
 
136
        }
 
137
 
 
138
        step = ( zmax - zmin ) / ( nlevel + 1 );
 
139
        for ( i = 0; i < nlevel; i++ )
 
140
            clevel[i] = zmin + step + step * i;
 
141
 
 
142
        cmap1_init();
 
143
        for ( k = 0; k < 2; k++ )
 
144
        {
 
145
            for ( i = 0; i < 4; i++ )
 
146
            {
 
147
                pls.adv( 0 );
 
148
                pls.col0( 1 );
 
149
                pls.vpor( 0.0, 1.0, 0.0, 0.9 );
 
150
                pls.wind( -1.0, 1.0, -1.0, 1.5 );
 
151
 
 
152
                pls.w3d( 1.0, 1.0, 1.2, -3.0, 3.0, -3.0, 3.0, zmin, zmax,
 
153
                    alt[k], az[k] );
 
154
                pls.box3( "bnstu", "x axis", 0.0, 0,
 
155
                    "bnstu", "y axis", 0.0, 0,
 
156
                    "bcdmnstuv", "z axis", 0.0, 4 );
 
157
 
 
158
                pls.col0( 2 );
 
159
 
 
160
                // wireframe plot
 
161
                if ( i == 0 )
 
162
                    pls.mesh( x, y, z, opt[k] );
 
163
 
 
164
                // magnitude colored wireframe plot
 
165
                else if ( i == 1 )
 
166
                    pls.mesh( x, y, z, opt[k] | PLStream.MAG_COLOR );
 
167
 
 
168
                // magnitude colored wireframe plot with sides
 
169
                else if ( i == 2 )
 
170
                    pls.plot3d( x, y, z, opt[k] | PLStream.MAG_COLOR, true );
 
171
 
 
172
                // magnitude colored wireframe plot with base contour
 
173
                else if ( i == 3 )
 
174
                    pls.meshc( x, y, z, opt[k] | PLStream.MAG_COLOR | PLStream.BASE_CONT,
 
175
                        clevel );
 
176
 
 
177
 
 
178
                pls.col0( 3 );
 
179
                pls.mtex( "t", 1.0, 0.5, 0.5, title[k] );
 
180
            }
 
181
        }
 
182
 
 
183
        pls.end();
 
184
    }
 
185
}
 
186
 
 
187
//--------------------------------------------------------------------------
 
188
//                              End of x11.java
 
189
//--------------------------------------------------------------------------