~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/java/x08.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: x08.java 11301 2010-11-02 17:21:08Z airwin $
 
3
//--------------------------------------------------------------------------
 
4
 
 
5
//--------------------------------------------------------------------------
 
6
// Copyright (C) 2001  Geoffrey Furnish
 
7
// Copyright (C) 2001, 2002, 2003, 2004  Alan W. Irwin
 
8
// Copyright (C) 2002  Maurice LeBrun
 
9
// Copyright (C) 2002  Joao Cardoso
 
10
// Copyright (C) 2004  Andrew Ross
 
11
//
 
12
// This file is part of PLplot.
 
13
//
 
14
// PLplot is free software; you can redistribute it and/or modify
 
15
// it under the terms of the GNU Library General Public License as published by
 
16
// the Free Software Foundation; version 2 of the License.
 
17
//
 
18
// PLplot is distributed in the hope that it will be useful,
 
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
// GNU Library General Public License for more details.
 
22
//
 
23
// You should have received a copy of the GNU Library General Public License
 
24
// along with PLplot; if not, write to the Free Software
 
25
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 
26
//--------------------------------------------------------------------------
 
27
 
 
28
//--------------------------------------------------------------------------
 
29
// Implementation of PLplot example 8 in Java.
 
30
//--------------------------------------------------------------------------
 
31
 
 
32
package plplot.examples;
 
33
 
 
34
import plplot.core.*;
 
35
 
 
36
import java.lang.Math;
 
37
 
 
38
class x08 {
 
39
    static final int XPTS = 35;
 
40
    static final int YPTS = 46;
 
41
 
 
42
    PLStream         pls = new PLStream();
 
43
 
 
44
    static double    alt[] = { 60.0, 20.0 };
 
45
    static double    az[]  = { 30.0, 60.0 };
 
46
 
 
47
    static           String[] title =
 
48
    {
 
49
        "#frPLplot Example 8 - Alt=60, Az=30",
 
50
        "#frPLplot Example 8 - Alt=20, Az=60",
 
51
    };
 
52
    // cmap1_init1
 
53
 
 
54
    // Initializes color map 1 in HLS space.
 
55
    // Basic grayscale variation from half-dark (which makes more interesting
 
56
    // looking plot compared to dark) to light.
 
57
    // An interesting variation on this:
 
58
    // s[1] = 1.0
 
59
 
 
60
    void cmap1_init( int gray )
 
61
    {
 
62
        double [] i    = new double[2];
 
63
        double [] h    = new double[2];
 
64
        double [] l    = new double[2];
 
65
        double [] s    = new double[2];
 
66
        boolean [] rev = new boolean[2];
 
67
 
 
68
        i[0] = 0.0;         // left boundary
 
69
        i[1] = 1.0;         // right boundary
 
70
 
 
71
        if ( gray == 1 )
 
72
        {
 
73
            h[0] = 0.0;        // hue -- low: red (arbitrary if s=0)
 
74
            h[1] = 0.0;        // hue -- high: red (arbitrary if s=0)
 
75
 
 
76
            l[0] = 0.5;        // lightness -- low: half-dark
 
77
            l[1] = 1.0;        // lightness -- high: light
 
78
 
 
79
            s[0] = 0.0;        // minimum saturation
 
80
            s[1] = 0.0;        // minimum saturation
 
81
        }
 
82
        else
 
83
        {
 
84
            h[0] = 240; // blue -> green -> yellow ->
 
85
            h[1] = 0;   // -> red
 
86
 
 
87
            l[0] = 0.6;
 
88
            l[1] = 0.6;
 
89
 
 
90
            s[0] = 0.8;
 
91
            s[1] = 0.8;
 
92
        }
 
93
 
 
94
        rev[0] = false;         // interpolate on front side of colour wheel.
 
95
        rev[1] = false;         // interpolate on front side of colour wheel.
 
96
 
 
97
        pls.scmap1n( 256 );
 
98
        pls.scmap1l( false, i, h, l, s, rev );
 
99
    }
 
100
 
 
101
// Does a series of 3-d plots for a given data set, with different viewing
 
102
// options in each plot.
 
103
 
 
104
    public static void main( String[] args )
 
105
    {
 
106
        new x08( args );
 
107
    }
 
108
 
 
109
    public x08( String[] args )
 
110
    {
 
111
        int       i, j, k;
 
112
        final int LEVELS = 10;
 
113
 
 
114
        double[] x   = new double[ XPTS ];
 
115
        double[] y   = new double[ YPTS ];
 
116
        double[][] z = new double[XPTS][YPTS];
 
117
        double clevel[]     = new double[LEVELS];
 
118
        double clev_null [] = new double[0];
 
119
 
 
120
        double xx, yy, r;
 
121
        double zmin = Double.MAX_VALUE, zmax = Double.MIN_VALUE;
 
122
 
 
123
        int    ifshade;
 
124
 
 
125
        // Parse and process command line arguments.
 
126
 
 
127
        pls.parseopts( args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM );
 
128
        boolean rosen = true;
 
129
 
 
130
        // Initialize plplot.
 
131
 
 
132
        pls.init();
 
133
 
 
134
        for ( i = 0; i < XPTS; i++ )
 
135
        {
 
136
            x[i] = (double) ( i - ( XPTS / 2 ) ) / (double) ( XPTS / 2 );
 
137
            if ( rosen )
 
138
                x[i] *= 1.5;
 
139
        }
 
140
 
 
141
        for ( j = 0; j < YPTS; j++ )
 
142
        {
 
143
            y[j] = (double) ( j - ( YPTS / 2 ) ) / (double) ( YPTS / 2 );
 
144
            if ( rosen )
 
145
                y[j] += 0.5;
 
146
        }
 
147
 
 
148
        for ( i = 0; i < XPTS; i++ )
 
149
        {
 
150
            xx = x[i];
 
151
            for ( j = 0; j < YPTS; j++ )
 
152
            {
 
153
                yy = y[j];
 
154
                if ( rosen )
 
155
                {
 
156
                    z[i][j] = Math.pow( 1. - xx, 2. ) + 100 *
 
157
                              Math.pow( yy - Math.pow( xx, 2. ), 2. );
 
158
                    // The log argument may be zero for just the right grid.
 
159
                    if ( z[i][j] > 0. )
 
160
                        z[i][j] = Math.log( z[i][j] );
 
161
                    else
 
162
                        z[i][j] = -5.; // -MAXFLOAT would mess-up up the scale
 
163
                }
 
164
                else
 
165
                {
 
166
                    r       = Math.sqrt( xx * xx + yy * yy );
 
167
                    z[i][j] = Math.exp( -r * r ) * Math.cos( 2.0 * Math.PI * r );
 
168
                }
 
169
                if ( zmin > z[i][j] )
 
170
                    zmin = z[i][j];
 
171
                if ( zmax < z[i][j] )
 
172
                    zmax = z[i][j];
 
173
            }
 
174
        }
 
175
 
 
176
        double step = ( zmax - zmin ) / ( LEVELS + 1 );
 
177
        for ( i = 0; i < LEVELS; i++ )
 
178
            clevel[i] = zmin + step * ( i + 1 );
 
179
 
 
180
        pls.lightsource( 1., 1., 1. );
 
181
        for ( k = 0; k < 2; k++ )
 
182
        {
 
183
            for ( ifshade = 0; ifshade < 4; ifshade++ )
 
184
            {
 
185
                pls.adv( 0 );
 
186
                pls.vpor( 0.0, 1.0, 0.0, 0.9 );
 
187
                pls.wind( -1.0, 1.0, -0.9, 1.1 );
 
188
                pls.col0( 3 );
 
189
                pls.mtex( "t", 1.0, 0.5, 0.5, title[k] );
 
190
                pls.col0( 1 );
 
191
                if ( rosen )
 
192
                    pls.w3d( 1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax,
 
193
                        alt[k], az[k] );
 
194
                else
 
195
                    pls.w3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax,
 
196
                        alt[k], az[k] );
 
197
                pls.box3( "bnstu", "x axis", 0.0, 0,
 
198
                    "bnstu", "y axis", 0.0, 0,
 
199
                    "bcdmnstuv", "z axis", 0.0, 0 );
 
200
 
 
201
                pls.col0( 2 );
 
202
 
 
203
                if ( ifshade == 0 ) // diffuse light surface plot
 
204
                {
 
205
                    cmap1_init( 1 );
 
206
                    // with new interface haven't yet made null work so have
 
207
                    // to put in specific zero-length array.
 
208
                    pls.surf3d( x, y, z, 0, clev_null );
 
209
                }
 
210
                else if ( ifshade == 1 )   // magnitude colored plot
 
211
                {
 
212
                    cmap1_init( 0 );
 
213
                    pls.surf3d( x, y, z, PLStream.MAG_COLOR, clev_null );
 
214
                }
 
215
                else if ( ifshade == 2 )   //  magnitude colored plot with faceted squares
 
216
                {
 
217
                    cmap1_init( 0 );
 
218
                    pls.surf3d( x, y, z, PLStream.MAG_COLOR | PLStream.FACETED, clev_null );
 
219
                }
 
220
                else                     // magnitude colored plot with contours
 
221
                {
 
222
                    cmap1_init( 0 );
 
223
                    pls.surf3d( x, y, z, PLStream.MAG_COLOR | PLStream.SURF_CONT | PLStream.BASE_CONT, clevel );
 
224
                }
 
225
            }
 
226
        }
 
227
 
 
228
        pls.end();
 
229
    }
 
230
}
 
231
 
 
232
//--------------------------------------------------------------------------
 
233
//                              End of x08.java
 
234
//--------------------------------------------------------------------------