~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/java/x19.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: x19.java 11301 2010-11-02 17:21:08Z airwin $
 
3
//--------------------------------------------------------------------------
 
4
 
 
5
//--------------------------------------------------------------------------
 
6
// Copyright (C) 2001  Geoffrey Furnish
 
7
//
 
8
// This file is part of PLplot.
 
9
//
 
10
// PLplot is free software; you can redistribute it and/or modify
 
11
// it under the terms of the GNU Library General Public License as published by
 
12
// the Free Software Foundation; version 2 of the License.
 
13
//
 
14
// PLplot is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU Library General Public License for more details.
 
18
//
 
19
// You should have received a copy of the GNU Library General Public License
 
20
// along with PLplot; if not, write to the Free Software
 
21
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 
22
//--------------------------------------------------------------------------
 
23
 
 
24
//--------------------------------------------------------------------------
 
25
// Implementation of PLplot example 19 in Java.
 
26
//--------------------------------------------------------------------------
 
27
 
 
28
package plplot.examples;
 
29
 
 
30
import plplot.core.*;
 
31
 
 
32
import java.lang.Math;
 
33
 
 
34
class MapTransform implements PLCallbackCT {
 
35
    public void coordTransform( double x, double y, double[] xt, double[] yt, Object data )
 
36
    {
 
37
        double radius;
 
38
 
 
39
        radius = 90.0 - y;
 
40
        xt[0]  = radius * Math.cos( x * Math.PI / 180.0 );
 
41
        yt[0]  = radius * Math.sin( x * Math.PI / 180.0 );
 
42
    }
 
43
}
 
44
 
 
45
class Mapform19 implements PLCallbackMapform {
 
46
    public void mapform( double[] x, double[] y )
 
47
    {
 
48
        int    i;
 
49
        double xp, yp, radius;
 
50
        for ( i = 0; i < x.length; i++ )
 
51
        {
 
52
            radius = 90.0 - y[i];
 
53
            xp     = radius * Math.cos( x[i] * Math.PI / 180.0 );
 
54
            yp     = radius * Math.sin( x[i] * Math.PI / 180.0 );
 
55
            x[i]   = xp;
 
56
            y[i]   = yp;
 
57
        }
 
58
    }
 
59
}
 
60
 
 
61
class LabelFunc19 implements PLCallbackLabel {
 
62
    // A custom axis labeling function for longitudes and latitudes.
 
63
    public String label( int axis, double value )
 
64
    {
 
65
        String label           = "";
 
66
        String direction_label = "";
 
67
        double label_val       = 0.0;
 
68
 
 
69
        if ( axis == PLStream.PL_Y_AXIS )
 
70
        {
 
71
            label_val = value;
 
72
            if ( label_val > 0.0 )
 
73
            {
 
74
                direction_label = " N";
 
75
            }
 
76
            else if ( label_val < 0.0 )
 
77
            {
 
78
                direction_label = " S";
 
79
            }
 
80
            else
 
81
            {
 
82
                direction_label = "Eq";
 
83
            }
 
84
        }
 
85
        else if ( axis == PLStream.PL_X_AXIS )
 
86
        {
 
87
            label_val = normalize_longitude( value );
 
88
            if ( label_val > 0.0 )
 
89
            {
 
90
                direction_label = " E";
 
91
            }
 
92
            else if ( label_val < 0.0 )
 
93
            {
 
94
                direction_label = " W";
 
95
            }
 
96
            else
 
97
            {
 
98
                direction_label = "";
 
99
            }
 
100
        }
 
101
        if ( axis == PLStream.PL_Y_AXIS && value == 0.0 )
 
102
        {
 
103
            // A special case for the equator
 
104
            label = direction_label;
 
105
        }
 
106
        else
 
107
        {
 
108
            label = "" + ( (int) Math.abs( label_val ) ) + direction_label;
 
109
        }
 
110
        return label;
 
111
    }
 
112
 
 
113
    // "Normalize" longitude values so that they always fall between -180.0
 
114
    // and 180.0
 
115
    double normalize_longitude( double lon )
 
116
    {
 
117
        double times;
 
118
 
 
119
        if ( lon >= -180.0 && lon <= 180.0 )
 
120
        {
 
121
            return ( lon );
 
122
        }
 
123
        else
 
124
        {
 
125
            times = Math.floor( ( Math.abs( lon ) + 180.0 ) / 360.0 );
 
126
            if ( lon < 0.0 )
 
127
            {
 
128
                return ( lon + 360.0 * times );
 
129
            }
 
130
            else
 
131
            {
 
132
                return ( lon - 360.0 * times );
 
133
            }
 
134
        }
 
135
    }
 
136
}
 
137
 
 
138
class x19 {
 
139
    PLStream pls = new PLStream();
 
140
 
 
141
    public static void main( String[] args )
 
142
    {
 
143
        new x19( args );
 
144
    }
 
145
 
 
146
    public x19 ( String[] args )
 
147
    {
 
148
        double            minx, maxx, miny, maxy;
 
149
        PLCallbackMapform nullCallback        = null;
 
150
        PLCallbackLabel   nullLabelCallback   = null;
 
151
        PLCallbackCT      nullCTCallback      = null;
 
152
        LabelFunc19       geolocation_labeler = new LabelFunc19();
 
153
        MapTransform      map_transform       = new MapTransform();
 
154
 
 
155
        double[] x = new double[1];
 
156
        double[] y = new double[1];
 
157
 
 
158
        // Parse and process command line arguments.
 
159
        pls.parseopts( args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM );
 
160
 
 
161
        // Longitude (x) and latitude (y)
 
162
 
 
163
        miny = -70;
 
164
        maxy = 80;
 
165
 
 
166
        // Initialize PLplot.
 
167
        pls.init();
 
168
        // Cartesian plots
 
169
        // Most of world
 
170
 
 
171
        minx = 190;
 
172
        maxx = 190 + 360;
 
173
 
 
174
        // Setup a custom latitude and longitude-based scaling function.
 
175
        pls.slabelfunc( geolocation_labeler );
 
176
 
 
177
        pls.col0( 1 );
 
178
        pls.env( minx, maxx, miny, maxy, 1, 70 );
 
179
        pls.map( nullCallback, "usaglobe", minx, maxx, miny, maxy );
 
180
 
 
181
        // The Americas
 
182
 
 
183
        minx = 190;
 
184
        maxx = 340;
 
185
 
 
186
        pls.col0( 1 );
 
187
        pls.env( minx, maxx, miny, maxy, 1, 70 );
 
188
        pls.map( nullCallback, "usaglobe", minx, maxx, miny, maxy );
 
189
 
 
190
        // Clear the labelling function.
 
191
        pls.slabelfunc( nullLabelCallback );
 
192
 
 
193
        // Polar, Northern hemisphere
 
194
 
 
195
        // Create callback object containing mapform function
 
196
        Mapform19 mapform19 = new Mapform19();
 
197
 
 
198
        minx = 0;
 
199
        maxx = 360;
 
200
 
 
201
        pls.env( -75., 75., -75., 75., 1, -1 );
 
202
        pls.map( mapform19, "globe", minx, maxx, miny, maxy );
 
203
 
 
204
        pls.lsty( 2 );
 
205
        pls.meridians( mapform19, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );
 
206
 
 
207
 
 
208
        // Polar, Northern hemisphere, this time with a PLplot-wide transform
 
209
 
 
210
        minx = 0;
 
211
        maxx = 360;
 
212
 
 
213
        pls.stransform( map_transform, null );
 
214
 
 
215
        pls.lsty( 1 );
 
216
        pls.env( -75., 75., -75., 75., 1, -1 );
 
217
        // No need to set the map transform here as the global transform
 
218
        // will be used.
 
219
        pls.map( nullCallback, "globe", minx, maxx, miny, maxy );
 
220
 
 
221
        pls.lsty( 2 );
 
222
        pls.meridians( nullCallback, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );
 
223
 
 
224
        // Show Baltimore, MD on the map
 
225
        pls.col0( 2 );
 
226
        pls.ssym( 0.0, 2.0 );
 
227
        x[0] = -76.6125;
 
228
        y[0] = 39.2902778;
 
229
        pls.poin( x, y, 18 );
 
230
        pls.ssym( 0.0, 1.0 );
 
231
        pls.ptex( -76.6125, 43.0, 0.0, 0.0, 0.0, "Baltimore, MD" );
 
232
 
 
233
        // For Java, this is how the global transform is cleared
 
234
        pls.stransform( nullCTCallback, null );
 
235
 
 
236
        pls.end();
 
237
    }
 
238
}
 
239
 
 
240
//--------------------------------------------------------------------------
 
241
//                              End of x19.java
 
242
//--------------------------------------------------------------------------