1
//--------------------------------------------------------------------------
2
// $Id: x19.java 11301 2010-11-02 17:21:08Z airwin $
3
//--------------------------------------------------------------------------
5
//--------------------------------------------------------------------------
6
// Copyright (C) 2001 Geoffrey Furnish
8
// This file is part of PLplot.
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.
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.
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
//--------------------------------------------------------------------------
24
//--------------------------------------------------------------------------
25
// Implementation of PLplot example 19 in Java.
26
//--------------------------------------------------------------------------
28
package plplot.examples;
32
import java.lang.Math;
34
class MapTransform implements PLCallbackCT {
35
public void coordTransform( double x, double y, double[] xt, double[] yt, Object data )
40
xt[0] = radius * Math.cos( x * Math.PI / 180.0 );
41
yt[0] = radius * Math.sin( x * Math.PI / 180.0 );
45
class Mapform19 implements PLCallbackMapform {
46
public void mapform( double[] x, double[] y )
49
double xp, yp, radius;
50
for ( i = 0; i < x.length; i++ )
53
xp = radius * Math.cos( x[i] * Math.PI / 180.0 );
54
yp = radius * Math.sin( x[i] * Math.PI / 180.0 );
61
class LabelFunc19 implements PLCallbackLabel {
62
// A custom axis labeling function for longitudes and latitudes.
63
public String label( int axis, double value )
66
String direction_label = "";
67
double label_val = 0.0;
69
if ( axis == PLStream.PL_Y_AXIS )
72
if ( label_val > 0.0 )
74
direction_label = " N";
76
else if ( label_val < 0.0 )
78
direction_label = " S";
82
direction_label = "Eq";
85
else if ( axis == PLStream.PL_X_AXIS )
87
label_val = normalize_longitude( value );
88
if ( label_val > 0.0 )
90
direction_label = " E";
92
else if ( label_val < 0.0 )
94
direction_label = " W";
101
if ( axis == PLStream.PL_Y_AXIS && value == 0.0 )
103
// A special case for the equator
104
label = direction_label;
108
label = "" + ( (int) Math.abs( label_val ) ) + direction_label;
113
// "Normalize" longitude values so that they always fall between -180.0
115
double normalize_longitude( double lon )
119
if ( lon >= -180.0 && lon <= 180.0 )
125
times = Math.floor( ( Math.abs( lon ) + 180.0 ) / 360.0 );
128
return ( lon + 360.0 * times );
132
return ( lon - 360.0 * times );
139
PLStream pls = new PLStream();
141
public static void main( String[] args )
146
public x19 ( String[] args )
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();
155
double[] x = new double[1];
156
double[] y = new double[1];
158
// Parse and process command line arguments.
159
pls.parseopts( args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM );
161
// Longitude (x) and latitude (y)
166
// Initialize PLplot.
174
// Setup a custom latitude and longitude-based scaling function.
175
pls.slabelfunc( geolocation_labeler );
178
pls.env( minx, maxx, miny, maxy, 1, 70 );
179
pls.map( nullCallback, "usaglobe", minx, maxx, miny, maxy );
187
pls.env( minx, maxx, miny, maxy, 1, 70 );
188
pls.map( nullCallback, "usaglobe", minx, maxx, miny, maxy );
190
// Clear the labelling function.
191
pls.slabelfunc( nullLabelCallback );
193
// Polar, Northern hemisphere
195
// Create callback object containing mapform function
196
Mapform19 mapform19 = new Mapform19();
201
pls.env( -75., 75., -75., 75., 1, -1 );
202
pls.map( mapform19, "globe", minx, maxx, miny, maxy );
205
pls.meridians( mapform19, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );
208
// Polar, Northern hemisphere, this time with a PLplot-wide transform
213
pls.stransform( map_transform, null );
216
pls.env( -75., 75., -75., 75., 1, -1 );
217
// No need to set the map transform here as the global transform
219
pls.map( nullCallback, "globe", minx, maxx, miny, maxy );
222
pls.meridians( nullCallback, 10.0, 10.0, 0.0, 360.0, -10.0, 80.0 );
224
// Show Baltimore, MD on the map
226
pls.ssym( 0.0, 2.0 );
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" );
233
// For Java, this is how the global transform is cleared
234
pls.stransform( nullCTCallback, null );
240
//--------------------------------------------------------------------------
242
//--------------------------------------------------------------------------