001: //---------------------------------------------------------------------------//
002: //$Id: x01.java,v 1.1 2004/12/27 04:42:01 solent Exp $
003: //---------------------------------------------------------------------------//
004:
005: //---------------------------------------------------------------------------//
006: //Copyright (C) 2001 Geoffrey Furnish
007: //Copyright (C) 2001, 2002 Alan W. Irwin
008: //Copyright (C) 2004 Andrew Ross
009: //
010:
011: //
012: //This file is part of PLplot.
013: //
014: //PLplot is free software; you can redistribute it and/or modify
015: //it under the terms of the GNU Library General Public License as published by
016: //the Free Software Foundation; version 2 of the License.
017: //
018: //PLplot is distributed in the hope that it will be useful,
019: //but WITHOUT ANY WARRANTY; without even the implied warranty of
020: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
021: //GNU Library General Public License for more details.
022: //
023: //You should have received a copy of the GNU Library General Public License
024: //along with PLplot; if not, write to the Free Software
025: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
026: //---------------------------------------------------------------------------//
027:
028: //---------------------------------------------------------------------------//
029: //Implementation of PLplot example 1 in Java.
030: //---------------------------------------------------------------------------//
031:
032: package test.plplot.examples;
033:
034: import test.plplot.core.*;
035:
036: import java.lang.Math;
037:
038: class x01 {
039:
040: double xscale, yscale, xoff, yoff;
041: PLStreamc plsdummy = new PLStreamc();
042: plplotjavac pls = new plplotjavac();
043:
044: public static void main(String[] args) {
045: x01 x = new x01(args);
046: }
047:
048: public x01(String[] args) {
049:
050: // plplot initialization
051: // Divide page into 2x2 plots unless user overrides.
052:
053: pls.plssub(2, 2);
054:
055: // Parse and process command line arguments.
056:
057: // plMergeOpts(options, "x01c options", notes);
058: pls.plParseOpts(args, pls.PL_PARSE_FULL
059: | pls.PL_PARSE_NOPROGRAM);
060:
061: //Print out version number.
062:
063: StringBuffer version = new StringBuffer(80);
064: // plgver no longer works for unexplained reasons.
065: pls.plgver(version);
066: System.out.println("PLplot library version: " + version);
067:
068: // Initialize PLplot.
069: pls.plinit();
070:
071: // Select the multi-stroke font.
072: pls.plfontld(1);
073:
074: // Set up the data
075: // Original case
076:
077: xscale = 6.;
078: yscale = 1.;
079: xoff = 0.;
080: yoff = 0.;
081:
082: // Do a plot
083: plot1(0);
084:
085: // Set up the data
086:
087: xscale = 1.;
088: yscale = 0.0014;
089: yoff = 0.0185;
090:
091: // Do a plot
092:
093: int digmax = 5;
094: pls.plsyax(digmax, 0);
095:
096: plot1(1);
097:
098: plot2();
099:
100: plot3();
101:
102: // Let's get some user input
103:
104: // if (locate_mode) {
105: // for (;;) {
106: // if (! plGetCursor(&gin)) break;
107: // if (gin.keysym == PLK_Escape) break;
108:
109: // pltext();
110: // if (gin.keysym < 0xFF && isprint(gin.keysym))
111: // printf("wx = %f, wy = %f, dx = %f, dy = %f, c = '%c'\n",
112: // gin.wX, gin.wY, gin.dX, gin.dY, gin.keysym);
113: // else
114: // printf("wx = %f, wy = %f, dx = %f, dy = %f, c = 0x%02x\n",
115: // gin.wX, gin.wY, gin.dX, gin.dY, gin.keysym);
116:
117: // plgra();
118: // }
119: // }
120:
121: // Don't forget to call plend() to finish off!
122: pls.plend();
123: }
124:
125: void plot1(int do_test) {
126: int i;
127: double xmin, xmax, ymin, ymax;
128: double x[] = new double[60];
129: double y[] = new double[60];
130: double xs[] = new double[6];
131: double ys[] = new double[6];
132:
133: for (i = 0; i < 60; i++) {
134: x[i] = xoff + xscale * (i + 1) / 60.0;
135: y[i] = yoff + yscale * Math.pow(x[i], 2.);
136: }
137:
138: xmin = x[0];
139: xmax = x[59];
140: ymin = y[0];
141: ymax = y[59];
142:
143: for (i = 0; i < 6; i++) {
144: xs[i] = x[i * 10 + 3];
145: ys[i] = y[i * 10 + 3];
146: }
147:
148: // Set up the viewport and window using PLENV. The range in X is 0.0 to
149: // 6.0, and the range in Y is 0.0 to 30.0. The axes are scaled separately
150: // (just = 0), and we just draw a labelled box (axis = 0).
151:
152: pls.plcol0(1);
153: pls.plenv(xmin, xmax, ymin, ymax, 0, 0);
154: pls.plcol0(2);
155: pls.pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2");
156:
157: // Plot the data points.
158:
159: pls.plcol0(4);
160: pls.plpoin(xs, ys, 9);
161:
162: // Draw the line through the data.
163:
164: pls.plcol0(3);
165: pls.plline(x, y);
166: }
167:
168: void plot2() {
169: int i;
170: double x[] = new double[100];
171: double y[] = new double[100];
172:
173: // Set up the viewport and window using PLENV. The range in X is -2.0 to
174: // 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled
175: // separately (just = 0), and we draw a box with axes (axis = 1).
176:
177: pls.plcol0(1);
178: pls.plenv(-2.0, 10.0, -0.4, 1.2, 0, 1);
179: pls.plcol0(2);
180: pls.pllab("(x)", "sin(x)/x",
181: "#frPLplot Example 1 - Sinc Function");
182:
183: // Fill up the arrays.
184:
185: for (i = 0; i < 100; i++) {
186: x[i] = (i - 19.0) / 6.0;
187: y[i] = 1.0;
188: if (x[i] != 0.0)
189: y[i] = Math.sin(x[i]) / x[i];
190: }
191:
192: // Draw the line.
193:
194: pls.plcol0(3);
195: pls.plwid(2);
196: pls.plline(x, y);
197: pls.plwid(1);
198: }
199:
200: void plot3() {
201: int i;
202: int space0[] = {};
203: int mark0[] = {};
204: int space1[] = { 1500 };
205: int mark1[] = { 1500 };
206: double x[] = new double[101];
207: double y[] = new double[101];
208:
209: // For the final graph we wish to override the default tick intervals,
210: // and so do not use plenv().
211:
212: pls.pladv(0);
213:
214: // Use standard viewport, and define X range from 0 to 360 degrees, Y
215: // range from -1.2 to 1.2.
216:
217: pls.plvsta();
218: pls.plwind(0.0, 360.0, -1.2, 1.2);
219:
220: // Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
221:
222: pls.plcol0(1);
223: pls.plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2);
224:
225: // Superimpose a dashed line grid, with 1.5 mm marks and spaces.
226: // plstyl expects a pointer!
227:
228: pls.plstyl(mark1, space1);
229: pls.plcol0(2);
230: pls.plbox("g", 30.0, 0, "g", 0.2, 0);
231: pls.plstyl(mark0, space0);
232:
233: pls.plcol0(3);
234: pls.pllab("Angle (degrees)", "sine",
235: "#frPLplot Example 1 - Sine function");
236:
237: for (i = 0; i < 101; i++) {
238: x[i] = 3.6 * i;
239: y[i] = Math.sin(x[i] * Math.PI / 180.0);
240: }
241:
242: pls.plcol0(4);
243: pls.plline(x, y);
244: }
245: }
246:
247: //---------------------------------------------------------------------------//
248: // End of x01.java
249: //---------------------------------------------------------------------------//
|