~ubuntu-branches/ubuntu/intrepid/plplot/intrepid

« back to all changes in this revision

Viewing changes to examples/java/x01.java

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2006-11-04 10:19:34 UTC
  • mfrom: (2.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061104101934-mlirvdg4gpwi6i5q
Tags: 5.6.1-10
* Orphaning the package
* debian/control: Changed the maintainer to the Debian QA Group

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//---------------------------------------------------------------------------//
2
 
// $Id: x01.java,v 1.21 2004/06/17 12:41:02 andrewross Exp $
 
2
// $Id: x01.java,v 1.31 2006/05/17 22:51:20 airwin Exp $
3
3
//---------------------------------------------------------------------------//
4
4
 
5
5
//---------------------------------------------------------------------------//
22
22
//
23
23
// You should have received a copy of the GNU Library General Public License
24
24
// along with PLplot; if not, write to the Free Software
25
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
25
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
26
26
//---------------------------------------------------------------------------//
27
27
 
28
28
//---------------------------------------------------------------------------//
38
38
class x01 {
39
39
 
40
40
    double xscale, yscale, xoff, yoff;
41
 
    PLStreamc plsdummy = new PLStreamc();
42
 
    plplotjavac pls = new plplotjavac();
 
41
    PLStream pls = new PLStream();
 
42
 
 
43
    // Set this to true to test the xormod method
 
44
    static boolean test_xor = false;
 
45
 
 
46
    static boolean locate_mode = false;
 
47
    static int fontset = 1;
 
48
    static String f_name = null;
43
49
 
44
50
   public static void main( String[] args ) 
45
51
     {
52
58
    // plplot initialization
53
59
    // Divide page into 2x2 plots unless user overrides.
54
60
 
55
 
        pls.plssub(2, 2);
 
61
        pls.ssub(2, 2);
56
62
 
57
63
    // Parse and process command line arguments.
58
64
 
59
65
//         plMergeOpts(options, "x01c options", notes);
60
 
        pls.plParseOpts( args, pls.PL_PARSE_FULL|pls.PL_PARSE_NOPROGRAM );
 
66
        pls.parseopts( args, PLStream.PL_PARSE_FULL|PLStream.PL_PARSE_NOPROGRAM );
61
67
 
62
68
// Print out version number.
63
69
 
64
70
        StringBuffer version = new StringBuffer(80);
65
71
        // plgver no longer works for unexplained reasons.
66
 
        pls.plgver(version);
 
72
        pls.gver(version);
67
73
        System.out.println("PLplot library version: " + version);
68
74
 
69
75
    // Initialize PLplot.
70
 
        pls.plinit();
 
76
        pls.init();
71
77
 
72
78
    // Select the multi-stroke font.
73
 
        pls.plfontld( 1 );
 
79
        if (fontset == 1) 
 
80
            pls.fontld( 1 );
 
81
        else
 
82
            pls.fontld( 0 );
74
83
 
75
84
    // Set up the data
76
85
    // Original case
81
90
        yoff = 0.;
82
91
 
83
92
    // Do a plot
84
 
        plot1(0);
 
93
        plot1(false);
85
94
 
86
95
    // Set up the data
87
96
 
92
101
    // Do a plot
93
102
 
94
103
        int digmax = 5;
95
 
        pls.plsyax(digmax, 0);
 
104
        pls.syax(digmax, 0);
96
105
 
97
 
        plot1(1);
 
106
        plot1(true);
98
107
 
99
108
        plot2();
100
109
 
101
110
        plot3();
102
111
 
 
112
        // Test option to save file
 
113
        if (f_name != null) {
 
114
        }
103
115
    // Let's get some user input
104
116
 
105
117
//         if (locate_mode) {
120
132
//         }
121
133
 
122
134
    // Don't forget to call plend() to finish off!
123
 
        pls.plend();
 
135
        pls.end();
124
136
    }
125
137
 
126
 
    void plot1( int do_test )
 
138
    void plot1( boolean do_test )
127
139
    {
128
140
        int i;
129
141
        double xmin, xmax, ymin, ymax;
131
143
        double y[] = new double[60];
132
144
        double xs[] = new double[6];
133
145
        double ys[] = new double[6];
 
146
        boolean st[] = new boolean[1];
 
147
        double xx[] = new double[1];
 
148
        double yy[] = new double[1];
134
149
 
135
150
        for( i=0; i < 60; i++ )
136
151
        {
153
168
    // 6.0, and the range in Y is 0.0 to 30.0. The axes are scaled separately
154
169
    // (just = 0), and we just draw a labelled box (axis = 0).
155
170
 
156
 
        pls.plcol0(1);
157
 
        pls.plenv( xmin, xmax, ymin, ymax, 0, 0 );
158
 
        pls.plcol0(2);
159
 
        pls.pllab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" );
 
171
        pls.col0(1);
 
172
        pls.env( xmin, xmax, ymin, ymax, 0, 0 );
 
173
        pls.col0(2);
 
174
        pls.lab( "(x)", "(y)", "#frPLplot Example 1 - y=x#u2" );
160
175
 
161
176
    // Plot the data points.
162
177
 
163
 
        pls.plcol0(4);
164
 
        pls.plpoin( xs, ys, 9 );
 
178
        pls.col0(4);
 
179
        pls.poin( xs, ys, 9 );
165
180
 
166
181
    // Draw the line through the data.
167
182
 
168
 
        pls.plcol0(3);
169
 
        pls.plline(x, y);
 
183
        pls.col0(3);
 
184
        pls.line(x, y);
 
185
 
 
186
        // xor mode enable erasing a line/point/text by replotting it again
 
187
        // it does not work in double buffering mode, however
 
188
 
 
189
        if (do_test && test_xor ) {
 
190
            pls.xormod(true, st); // enter xor mode
 
191
            if (st[0]) {
 
192
                for (i=0; i<60; i++) {
 
193
                    xx[0] = x[i];
 
194
                    yy[0] = y[i];
 
195
                    pls.poin(xx, yy,9);    // draw a point
 
196
                    try {
 
197
                        Thread.sleep(50);           // wait a little
 
198
                    }
 
199
                    catch (InterruptedException ie) {
 
200
                    }
 
201
                    pls.flush();        // force an update of the tk driver
 
202
                    pls.poin(xx, yy,9);    // erase point
 
203
                }
 
204
                pls.xormod(false, st);       // leave xor mode
 
205
            }
 
206
        }
 
207
 
170
208
    }
171
209
 
172
210
    void plot2()
179
217
    // 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled
180
218
    // separately (just = 0), and we draw a box with axes (axis = 1).
181
219
 
182
 
        pls.plcol0(1);
183
 
        pls.plenv(-2.0, 10.0, -0.4, 1.2, 0, 1);
184
 
        pls.plcol0(2);
185
 
        pls.pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function");
 
220
        pls.col0(1);
 
221
        pls.env(-2.0, 10.0, -0.4, 1.2, 0, 1);
 
222
        pls.col0(2);
 
223
        pls.lab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function");
186
224
 
187
225
    // Fill up the arrays.
188
226
 
195
233
 
196
234
    // Draw the line.
197
235
 
198
 
        pls.plcol0(3);
199
 
        pls.plwid(2);
200
 
        pls.plline(x, y);
201
 
        pls.plwid(1);
 
236
        pls.col0(3);
 
237
        pls.wid(2);
 
238
        pls.line(x, y);
 
239
        pls.wid(1);
202
240
    }
203
241
 
204
242
    void plot3()
214
252
    // For the final graph we wish to override the default tick intervals,
215
253
    // and so do not use plenv().
216
254
 
217
 
        pls.pladv(0);
 
255
        pls.adv(0);
218
256
 
219
257
    // Use standard viewport, and define X range from 0 to 360 degrees, Y
220
258
    // range from -1.2 to 1.2.
221
259
 
222
 
        pls.plvsta();
223
 
        pls.plwind( 0.0, 360.0, -1.2, 1.2 );
 
260
        pls.vsta();
 
261
        pls.wind( 0.0, 360.0, -1.2, 1.2 );
224
262
 
225
263
    // Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
226
264
 
227
 
        pls.plcol0(1);
228
 
        pls.plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2);
 
265
        pls.col0(1);
 
266
        pls.box("bcnst", 60.0, 2, "bcnstv", 0.2, 2);
229
267
 
230
268
    // Superimpose a dashed line grid, with 1.5 mm marks and spaces. 
231
269
    // plstyl expects a pointer!
232
270
 
233
 
        pls.plstyl(mark1, space1);
234
 
        pls.plcol0(2);
235
 
        pls.plbox("g", 30.0, 0, "g", 0.2, 0);
236
 
        pls.plstyl(mark0, space0);
 
271
        pls.styl(mark1, space1);
 
272
        pls.col0(2);
 
273
        pls.box("g", 30.0, 0, "g", 0.2, 0);
 
274
        pls.styl(mark0, space0);
237
275
 
238
 
        pls.plcol0(3);
239
 
        pls.pllab( "Angle (degrees)", "sine",
 
276
        pls.col0(3);
 
277
        pls.lab( "Angle (degrees)", "sine",
240
278
                 "#frPLplot Example 1 - Sine function" );
241
279
 
242
280
        for (i = 0; i < 101; i++) {
244
282
            y[i] = Math.sin(x[i] * Math.PI / 180.0);
245
283
        }
246
284
 
247
 
        pls.plcol0(4);
248
 
        pls.plline(x, y);
 
285
        pls.col0(4);
 
286
        pls.line(x, y);
249
287
    }
250
288
}
251
289