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

« back to all changes in this revision

Viewing changes to examples/java/x09.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: x09.java,v 1.15 2004/01/17 16:41:39 rlaboiss Exp $
 
2
// $Id: x09.java,v 1.23 2005/07/03 12:43:39 andrewross Exp $
3
3
//---------------------------------------------------------------------------//
4
4
 
5
5
//---------------------------------------------------------------------------//
6
6
// Copyright (C) 2001, 2002  Geoffrey Furnish
7
7
// Copyright (C) 2002, 2003  Alan W. Irwin
 
8
// Copyright (C) 2004  Andrew Ross
8
9
//
9
10
// This file is part of PLplot.
10
11
//
19
20
//
20
21
// You should have received a copy of the GNU Library General Public License
21
22
// along with PLplot; if not, write to the Free Software
22
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
23
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
23
24
//---------------------------------------------------------------------------//
24
25
 
25
26
//---------------------------------------------------------------------------//
34
35
 
35
36
class x09 {
36
37
 
37
 
    final int XPTS = 35;
38
 
    final int YPTS = 46;
39
 
    final double XSPA =  2./(XPTS-1);
40
 
    final double YSPA =  2./(YPTS-1);
 
38
    static final int XPTS = 35;
 
39
    static final int YPTS = 46;
 
40
    static final double XSPA =  2./(XPTS-1);
 
41
    static final double YSPA =  2./(YPTS-1);
41
42
 
42
43
// polar plot data
43
 
    final int PERIMETERPTS = 100;
44
 
    final int RPTS = 40;
45
 
    final int THETAPTS = 40;
 
44
    static final int PERIMETERPTS = 100;
 
45
    static final int RPTS = 40;
 
46
    static final int THETAPTS = 40;
46
47
   
47
48
// potential plot data
48
 
    final int PPERIMETERPTS = 100;
49
 
    final int PRPTS = 40;
50
 
    final int PTHETAPTS = 64;
51
 
    final int PNLEVEL = 20;
 
49
    static final int PPERIMETERPTS = 100;
 
50
    static final int PRPTS = 40;
 
51
    static final int PTHETAPTS = 64;
 
52
    static final int PNLEVEL = 20;
52
53
   
53
54
    final double clevel[] = {-1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1.};
54
55
// Transformation function
55
56
    final double tr[] = {XSPA, 0.0, -1.0, 0.0, YSPA, -1.0};
56
57
   
57
 
   PLStreamc plsdummy = new PLStreamc();
58
 
   plplotjavac pls = new plplotjavac();
 
58
    PLStream pls = new PLStream();
59
59
 
60
60
// State data used by f2mnmx
61
61
    double fmin, fmax;
88
88
        
89
89
    // Parse and process command line arguments.
90
90
 
91
 
        pls.plParseOpts( args, pls.PL_PARSE_FULL | pls.PL_PARSE_NOPROGRAM );
 
91
        pls.parseopts( args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM );
92
92
    /* Initialize plplot */
93
93
       
94
 
        pls.plinit();
 
94
        pls.init();
95
95
 
96
96
    /* Set up function arrays */
97
97
       
134
134
 
135
135
 
136
136
    // Plot using scaled identity transform used to create xg0 and yg0
137
 
/*      pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
138
 
        pls.plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
139
 
        pls.plcol0(2);
140
 
        pls.plcont( z, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
141
 
        pls.plstyl(mark, space);
142
 
        pls.plcol0(3);
143
 
        pls.plcont(w, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
144
 
        pls.plstyl(mark0, space0);
145
 
        pls.plcol0(1);
146
 
        pls.pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
 
137
/*      pls.setcontlabelparam(0.006, 0.3, 0.1, 0);
 
138
        pls.env(-1.0, 1.0, -1.0, 1.0, 0, 0);
 
139
        pls.col0(2);
 
140
        pls.cont( z, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
 
141
        pls.styl(mark, space);
 
142
        pls.col0(3);
 
143
        pls.cont(w, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
 
144
        pls.styl(mark0, space0);
 
145
        pls.col0(1);
 
146
        pls.lab("X Coordinate", "Y Coordinate", "Streamlines of flow");
147
147
*/
148
 
        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
149
 
        pls.plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
150
 
        pls.plcol0(2);
151
 
        pls.plcont(z, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
152
 
        pls.plstyl(mark, space);
153
 
        pls.plcol0(3);
154
 
        pls.plcont(w, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
155
 
        pls.plstyl(mark0, space0);
156
 
        pls.plcol0(1);
157
 
        pls.pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
158
 
        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
 
148
        pls.setcontlabelparam(0.006, 0.3, 0.1, 1);
 
149
        pls.env(-1.0, 1.0, -1.0, 1.0, 0, 0);
 
150
        pls.col0(2);
 
151
        pls.cont(z, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
 
152
        pls.styl(mark, space);
 
153
        pls.col0(3);
 
154
        pls.cont(w, 1, XPTS, 1, YPTS, clevel, xg0, yg0 );
 
155
        pls.styl(mark0, space0);
 
156
        pls.col0(1);
 
157
        pls.lab("X Coordinate", "Y Coordinate", "Streamlines of flow");
 
158
        pls.setcontlabelparam(0.006, 0.3, 0.1, 0);
159
159
 
160
160
    // Plot using 1d coordinate transform
161
 
        pls.plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
162
 
        pls.plcol0(2);
163
 
        pls.plcont(z, 1, XPTS, 1, YPTS, clevel, xg1, yg1 );
164
 
        pls.plstyl(mark, space);
165
 
        pls.plcol0(3);
166
 
        pls.plcont(w, 1, XPTS, 1, YPTS, clevel, xg1, yg1) ;
167
 
        pls.plstyl(mark0, space0);
168
 
        pls.plcol0(1);
169
 
        pls.pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
 
161
        pls.env(-1.0, 1.0, -1.0, 1.0, 0, 0);
 
162
        pls.col0(2);
 
163
        pls.cont(z, 1, XPTS, 1, YPTS, clevel, xg1, yg1 );
 
164
        pls.styl(mark, space);
 
165
        pls.col0(3);
 
166
        pls.cont(w, 1, XPTS, 1, YPTS, clevel, xg1, yg1) ;
 
167
        pls.styl(mark0, space0);
 
168
        pls.col0(1);
 
169
        pls.lab("X Coordinate", "Y Coordinate", "Streamlines of flow");
170
170
 
171
 
/*      pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
172
 
        pls.plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
173
 
        pls.plcol0(2);
174
 
        pls.plcont(z, 1, XPTS, 1, YPTS, clevel, xg1, yg1 );
175
 
        pls.plstyl(mark, space);
176
 
        pls.plcol0(3);
177
 
        pls.plcont(w, 1, XPTS, 1, YPTS, clevel, xg1, yg1 );
178
 
        pls.plstyl(mark0, space0);
179
 
        pls.plcol0(1);
180
 
        pls.pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
181
 
        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
 
171
/*      pls.setcontlabelparam(0.006, 0.3, 0.1, 1);
 
172
        pls.env(-1.0, 1.0, -1.0, 1.0, 0, 0);
 
173
        pls.col0(2);
 
174
        pls.cont(z, 1, XPTS, 1, YPTS, clevel, xg1, yg1 );
 
175
        pls.styl(mark, space);
 
176
        pls.col0(3);
 
177
        pls.cont(w, 1, XPTS, 1, YPTS, clevel, xg1, yg1 );
 
178
        pls.styl(mark0, space0);
 
179
        pls.col0(1);
 
180
        pls.lab("X Coordinate", "Y Coordinate", "Streamlines of flow");
 
181
        pls.setcontlabelparam(0.006, 0.3, 0.1, 0);
182
182
*/
183
183
    // Plot using 2d coordinate transform
184
 
        pls.plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
185
 
        pls.plcol0(2);
186
 
        pls.plcont(z, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
187
 
        pls.plstyl(mark, space);
188
 
        pls.plcol0(3);
189
 
        pls.plcont(w, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
190
 
        pls.plstyl(mark0, space0);
191
 
        pls.plcol0(1);
192
 
        pls.pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
 
184
        pls.env(-1.0, 1.0, -1.0, 1.0, 0, 0);
 
185
        pls.col0(2);
 
186
        pls.cont(z, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
 
187
        pls.styl(mark, space);
 
188
        pls.col0(3);
 
189
        pls.cont(w, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
 
190
        pls.styl(mark0, space0);
 
191
        pls.col0(1);
 
192
        pls.lab("X Coordinate", "Y Coordinate", "Streamlines of flow");
193
193
 
194
 
/*      pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
195
 
        pls.plenv(-1.0, 1.0, -1.0, 1.0, 0, 0);
196
 
        pls.plcol0(2);
197
 
        pls.plcont(z, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
198
 
        pls.plstyl(mark, space);
199
 
        pls.plcol0(3);
200
 
        pls.plcont(w, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
201
 
        pls.plstyl(mark0, space0);
202
 
        pls.plcol0(1);
203
 
        pls.pllab("X Coordinate", "Y Coordinate", "Streamlines of flow");
204
 
        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
 
194
/*      pls.setcontlabelparam(0.006, 0.3, 0.1, 1);
 
195
        pls.env(-1.0, 1.0, -1.0, 1.0, 0, 0);
 
196
        pls.col0(2);
 
197
        pls.cont(z, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
 
198
        pls.styl(mark, space);
 
199
        pls.col0(3);
 
200
        pls.cont(w, 1, XPTS, 1, YPTS, clevel, xg2, yg2 );
 
201
        pls.styl(mark0, space0);
 
202
        pls.col0(1);
 
203
        pls.lab("X Coordinate", "Y Coordinate", "Streamlines of flow");
 
204
        pls.setcontlabelparam(0.006, 0.3, 0.1, 0);
205
205
*/
206
206
        polar();
207
 
/*        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
 
207
/*        pls.setcontlabelparam(0.006, 0.3, 0.1, 1);
208
208
        polar();
209
 
        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
 
209
        pls.setcontlabelparam(0.006, 0.3, 0.1, 0);
210
210
*/
211
211
        potential();
212
 
/*        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 1);
 
212
/*        pls.setcontlabelparam(0.006, 0.3, 0.1, 1);
213
213
        potential();
214
 
        pls.pl_setcontlabelparam(0.006, 0.3, 0.1, 0);
 
214
        pls.setcontlabelparam(0.006, 0.3, 0.1, 0);
215
215
*/
216
 
        pls.plend();
 
216
        pls.end();
217
217
    }
218
218
 
219
219
    void polar()
228
228
        double t, r, theta;
229
229
        double [] lev = new double[10];
230
230
 
231
 
        pls.plenv(-1., 1., -1., 1., 0, -2);
232
 
        pls.plcol0(1);
 
231
        pls.env(-1., 1., -1., 1., 0, -2);
 
232
        pls.col0(1);
233
233
       
234
234
    // Perimeter
235
235
        for (i = 0; i < PERIMETERPTS; i++) {
237
237
            px[i] = Math.cos(t);
238
238
            py[i] = Math.sin(t);
239
239
        }
240
 
        pls.plline(px, py);
 
240
        pls.line(px, py);
241
241
               
242
242
    // Create data to be contoured.
243
243
   
255
255
            lev[i] = 0.05 + 0.10*(double) i;
256
256
        }
257
257
 
258
 
        pls.plcol0(2);
259
 
        pls.plcont( z, 1, RPTS, 1, THETAPTS, lev, xg, yg );
260
 
        pls.plcol0(1);
261
 
        pls.pllab("", "", "Polar Contour Plot");
 
258
        pls.col0(2);
 
259
        pls.cont( z, 1, RPTS, 1, THETAPTS, lev, xg, yg );
 
260
        pls.col0(1);
 
261
        pls.lab("", "", "Polar Contour Plot");
262
262
    }
263
263
 
264
264
// Compute min and max value of a 2-d array.
288
288
        double [][] yg = new double[PRPTS][PTHETAPTS] ;
289
289
        double [][] z = new double[PRPTS][PTHETAPTS] ;
290
290
        int nlevelneg, nlevelpos;
291
 
        double dz, clevel;
 
291
        double dz, clev;
292
292
        double [] clevelneg_store = new double[PNLEVEL];
293
293
        double [] clevelpos_store = new double[PNLEVEL];
294
294
        int  ncollin, ncolbox, ncollab;
376
376
        nlevelneg = 0;
377
377
        nlevelpos = 0;
378
378
        for (i = 0; i < PNLEVEL; i++) {
379
 
            clevel = zmin + ((double) i + 0.5)*dz;
380
 
            if (clevel <= 0.)
381
 
                clevelneg_store[nlevelneg++] = clevel;
 
379
            clev = zmin + ((double) i + 0.5)*dz;
 
380
            if (clev <= 0.)
 
381
                clevelneg_store[nlevelneg++] = clev;
382
382
            else
383
 
                clevelpos_store[nlevelpos++] = clevel;
 
383
                clevelpos_store[nlevelpos++] = clev;
384
384
        }
385
385
    // Colours!
386
386
        ncollin = 11;
388
388
        ncollab = 2;
389
389
 
390
390
    // Finally start plotting this page!
391
 
        pls.pladv(0);
392
 
        pls.plcol0(ncolbox);
393
 
 
394
 
        pls.plvpas(0.1, 0.9, 0.1, 0.9, 1.0);
395
 
        pls.plwind(xpmin, xpmax, ypmin, ypmax);
396
 
        pls.plbox("", 0., 0, "", 0., 0);
397
 
 
398
 
        pls.plcol0(ncollin);
 
391
        pls.adv(0);
 
392
        pls.col0(ncolbox);
 
393
 
 
394
        pls.vpas(0.1, 0.9, 0.1, 0.9, 1.0);
 
395
        pls.wind(xpmin, xpmax, ypmin, ypmax);
 
396
        pls.box("", 0., 0, "", 0., 0);
 
397
 
 
398
        pls.col0(ncollin);
399
399
        if(nlevelneg >0) {
400
400
           // Negative contours
401
 
           pls.pllsty(2);
 
401
           pls.lsty(2);
402
402
           // The point here is to copy results into an array of the correct size
403
403
           // which is essential for the java wrapper of plplot to work correctly.
404
404
           double [] clevelneg = new double[nlevelneg];
405
405
           System.arraycopy(clevelneg_store, 0, clevelneg, 0, nlevelneg);
406
 
           pls.plcont( z, 1, PRPTS, 1, PTHETAPTS, clevelneg, xg, yg );
 
406
           pls.cont( z, 1, PRPTS, 1, PTHETAPTS, clevelneg, xg, yg );
407
407
        }
408
408
 
409
409
        if(nlevelpos >0) {
410
410
           // Positive contours
411
 
           pls.pllsty(1);
 
411
           pls.lsty(1);
412
412
           double [] clevelpos = new double[nlevelpos];
413
413
           // The point here is to copy results into an array of the correct size
414
414
           // which is essential for the java wrapper of plplot to work correctly.
415
415
           System.arraycopy(clevelpos_store, 0, clevelpos, 0, nlevelpos);
416
 
           pls.plcont( z, 1, PRPTS, 1, PTHETAPTS, clevelpos, xg, yg );
 
416
           pls.cont( z, 1, PRPTS, 1, PTHETAPTS, clevelpos, xg, yg );
417
417
        }
418
418
                 
419
419
    // Draw outer boundary
423
423
            py[i] = y0 + rmax*Math.sin(t);
424
424
        }
425
425
 
426
 
        pls.plcol0(ncolbox);
427
 
        pls.plline(px, py);
 
426
        pls.col0(ncolbox);
 
427
        pls.line(px, py);
428
428
               
429
 
        pls.plcol0(ncollab);
430
 
        pls.pllab("", "", "Shielded potential of charges in a conducting sphere");
 
429
        pls.col0(ncollab);
 
430
        pls.lab("", "", "Shielded potential of charges in a conducting sphere");
431
431
    }
432
432
}
433
433