Image obtained by using color PostScript driver (psc) and then converted to animated gif using ImageMagick convert tool.
1 #pragma _ipath "./" 2 #include "plcdemos.h" 3 4 static PLFLT x[101], y[101]; 5 static PLFLT xscale, yscale, xoff, yoff, xs[6], ys[6]; 6 static PLINT space0 = 0, mark0 = 0, space1 = 1500, mark1 = 1500; 7 8 void plot1(); 9 void plot2(); 10 void plot3(); 11 void plot4(); 12 void plot5(); 13 14 15 int 16 main(int argc, char *argv[]) 17 { 18 int i, digmax; 19 int xleng0 = 400, yleng0 = 300, xoff0 = 200, yoff0 = 200; 20 int xleng1 = 400, yleng1 = 300, xoff1 = 500, yoff1 = 500; 21 22 23 char geometry_master[] = "500x410+100+200"; 24 char geometry_slave[] = "500x410+650+200"; 25 26 char driver[80]; 27 28 29 (void) plParseOpts(&argc, argv, PL_PARSE_FULL); 30 31 plgdev(driver); 32 33 printf("Demo of multiple output streams via the %s driver.\n", driver); 34 printf("Running with the second stream as slave to the first.\n"); 35 printf("\n"); 36 37 38 plsetopt("geometry", geometry_master); 39 40 plsdev(driver); 41 plssub(2, 2); 42 plinit(); 43 44 45 plsstrm(1); 46 47 48 plsetopt("geometry", geometry_slave); 49 plspause(0); 50 plsdev(driver); 51 plinit(); 52 53 54 plsstrm(0); 55 56 xscale = 6.; 57 yscale = 1.; 58 xoff = 0.; 59 yoff = 0.; 60 plot1(); 61 62 63 xscale = 1.; 64 yscale = 1.e+6; 65 plot1(); 66 67 68 xscale = 1.; 69 yscale = 1.e-6; 70 digmax = 2; 71 plsyax(digmax, 0); 72 plot1(); 73 74 75 xscale = 1.; 76 yscale = 0.0014; 77 yoff = 0.0185; 78 digmax = 5; 79 plsyax(digmax, 0); 80 plot1(); 81 82 83 plsstrm(1); 84 plot4(); 85 pleop(); 86 87 88 plsstrm(0); 89 plot2(); 90 plot3(); 91 92 93 plsstrm(1); 94 plot5(); 95 pleop(); 96 97 98 plsstrm(0); 99 pleop(); 100 101 102 plend(); 103 exit(0); 104 } 105 106 107 void 108 plot1(void) 109 { 110 int i; 111 PLFLT xmin, xmax, ymin, ymax; 112 113 for (i = 0; i < 60; i++) { 114 x[i] = xoff + xscale * (i + 1) / 60.0; 115 y[i] = yoff + yscale * pow(x[i], 2.); 116 } 117 118 xmin = x[0]; 119 xmax = x[59]; 120 ymin = y[0]; 121 ymax = y[59]; 122 123 for (i = 0; i < 6; i++) { 124 xs[i] = x[i * 10 + 3]; 125 ys[i] = y[i * 10 + 3]; 126 } 127 128 129 plcol0(1); 130 plenv(xmin, xmax, ymin, ymax, 0, 0); 131 plcol0(6); 132 pllab("(x)", "(y)", "#frPLplot Example 1 - y=x#u2"); 133 134 135 plcol0(9); 136 plpoin(6, xs, ys, 9); 137 138 139 plcol0(4); 140 plline(60, x, y); 141 plflush(); 142 } 143 144 145 146 void 147 plot2(void) 148 { 149 int i; 150 151 152 plcol0(1); 153 plenv(-2.0, 10.0, -0.4, 1.2, 0, 1); 154 plcol0(2); 155 pllab("(x)", "sin(x)/x", "#frPLplot Example 1 - Sinc Function"); 156 157 158 for (i = 0; i < 100; i++) { 159 x[i] = (i - 19.0) / 6.0; 160 y[i] = 1.0; 161 if (x[i] != 0.0) 162 y[i] = sin(x[i]) / x[i]; 163 } 164 165 166 plcol0(3); 167 plline(100, x, y); 168 plflush(); 169 } 170 171 172 void 173 plot3(void) 174 { 175 int i; 176 177 178 pladv(0); 179 180 181 plvsta(); 182 plwind(0.0, 360.0, -1.2, 1.2); 183 184 185 plcol0(1); 186 plbox("bcnst", 60.0, 2, "bcnstv", 0.2, 2); 187 188 189 plstyl(1, &mark1, &space1); 190 plcol0(2); 191 plbox("g", 30.0, 0, "g", 0.2, 0); 192 plstyl(0, &mark0, &space0); 193 194 plcol0(3); 195 pllab("Angle (degrees)", "sine", "#frPLplot Example 1 - Sine function"); 196 197 for (i = 0; i < 101; i++) { 198 x[i] = 3.6 * i; 199 y[i] = sin(x[i] * PI / 180.0); 200 } 201 202 plcol0(4); 203 plline(101, x, y); 204 plflush(); 205 } 206 207 208 void 209 plot4(void) 210 { 211 int i, j; 212 PLFLT dtr, theta, dx, dy, r; 213 char text[3]; 214 PLFLT x0[361], y0[361]; 215 PLFLT x[361], y[361]; 216 217 dtr = PI / 180.0; 218 for (i = 0; i <= 360; i++) { 219 x0[i] = cos(dtr * i); 220 y0[i] = sin(dtr * i); 221 } 222 223 224 plenv(-1.3, 1.3, -1.3, 1.3, 1, -2); 225 for (i = 1; i <= 10; i++) { 226 for (j = 0; j <= 360; j++) { 227 x[j] = 0.1 * i * x0[j]; 228 y[j] = 0.1 * i * y0[j]; 229 } 230 231 232 plline(361, x, y); 233 } 234 235 plcol0(2); 236 for (i = 0; i <= 11; i++) { 237 theta = 30.0 * i; 238 dx = cos(dtr * theta); 239 dy = sin(dtr * theta); 240 241 242 pljoin(0.0, 0.0, dx, dy); 243 sprintf(text, "%d", ROUND(theta)); 244 245 246 if (dx >= -0.00001) 247 plptex(dx, dy, dx, dy, -0.15, text); 248 else 249 plptex(dx, dy, -dx, -dy, 1.15, text); 250 } 251 252 253 for (i = 0; i <= 360; i++) { 254 r = sin(dtr * (5 * i)); 255 x[i] = x0[i] * r; 256 y[i] = y0[i] * r; 257 } 258 plcol0(3); 259 plline(361, x, y); 260 261 plcol0(4); 262 plmtex("t", 2.0, 0.5, 0.5, 263 "#frPLplot Example 3 - r(#gh)=sin 5#gh"); 264 plflush(); 265 } 266 267 268 269 #define XPTS 35 270 #define YPTS 46 271 #define XSPA 2./(XPTS-1) 272 #define YSPA 2./(YPTS-1) 273 274 PLFLT tr[6] = 275 {XSPA, 0.0, -1.0, 0.0, YSPA, -1.0}; 276 277 void 278 mypltr(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data) 279 { 280 *tx = tr[0] * x + tr[1] * y + tr[2]; 281 *ty = tr[3] * x + tr[4] * y + tr[5]; 282 } 283 284 static PLFLT clevel[11] = 285 {-1., -.8, -.6, -.4, -.2, 0, .2, .4, .6, .8, 1.}; 286 287 void 288 plot5(void) 289 { 290 int i, j; 291 PLFLT xx, yy; 292 PLFLT **z, **w; 293 static PLINT mark = 1500, space = 1500; 294 295 296 plAlloc2dGrid(&z, XPTS, YPTS); 297 plAlloc2dGrid(&w, XPTS, YPTS); 298 299 for (i = 0; i < XPTS; i++) { 300 xx = (double) (i - (XPTS / 2)) / (double) (XPTS / 2); 301 for (j = 0; j < YPTS; j++) { 302 yy = (double) (j - (YPTS / 2)) / (double) (YPTS / 2) - 1.0; 303 z[i][j] = xx * xx - yy * yy; 304 w[i][j] = 2 * xx * yy; 305 } 306 } 307 308 plenv(-1.0, 1.0, -1.0, 1.0, 0, 0); 309 plcol0(2); 310 plcont(z, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL); 311 plstyl(1, &mark, &space); 312 plcol0(3); 313 plcont(w, XPTS, YPTS, 1, XPTS, 1, YPTS, clevel, 11, mypltr, NULL); 314 plcol0(1); 315 pllab("X Coordinate", "Y Coordinate", "Streamlines of flow"); 316 plflush(); 317 318 plFree2dGrid(z, XPTS, YPTS); 319 plFree2dGrid(w, XPTS, YPTS); 320 321 }
Code description
- 1
- $Id: x14c.c,v 1.26 2004/06/14 21:51:54 rlaboiss Exp $ Demo of multiple stream/window capability (requires Tk or Tcl-DP). Maurice LeBrun IFS, University of Texas at Austin Copyright (C) 2004 Alan W. Irwin This file is part of PLplot. PLplot is free software; you can redistribute it and/or modify it under the terms of the GNU General Library Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. PLplot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with PLplot; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- 14
- --------------------------------------------------------------------------*\ * main * * Plots several simple functions from other example programs. * * This version sends the output of the first 4 plots (one page) to two * independent streams. \*--------------------------------------------------------------------------
- 22
- Select either TK or DP driver and use a small window
- 22
- Using DP results in a crash at the end due to some odd cleanup problems
- 22
- The geometry strings MUST be in writable memory
- 28
- plplot initialization
- 28
- Parse and process command line arguments
- 37
- Set up first stream
- 44
- Start next stream
- 47
- Turn off pause to make this a slave (must follow master)
- 53
- Set up the data & plot
- 53
- Original case
- 62
- Set up the data & plot
- 67
- Set up the data & plot
- 74
- Set up the data & plot
- 82
- To slave
- 82
- The pleop() ensures the eop indicator gets lit.
- 87
- Back to master
- 92
- To slave
- 97
- Back to master to wait for user to advance
- 101
- Call plend to finish off.
- 106
- ===============================================================
- 128
- Set up the viewport and window using PLENV. The range in X is
- 128
- 0.0 to 6.0, and the range in Y is 0.0 to 30.0. The axes are
- 128
- scaled separately (just = 0), and we just draw a labelled
- 128
- box (axis = 0).
- 134
- Plot the data points
- 138
- Draw the line through the data
- 145
- ===============================================================
- 151
- Set up the viewport and window using PLENV. The range in X is -2.0 to 10.0, and the range in Y is -0.4 to 2.0. The axes are scaled separately (just = 0), and we draw a box with axes (axis = 1).
- 157
- Fill up the arrays
- 165
- Draw the line
- 171
- ===============================================================
- 177
- For the final graph we wish to override the default tick intervals, and so do not use PLENV
- 180
- Use standard viewport, and define X range from 0 to 360 degrees, Y range from -1.2 to 1.2.
- 184
- Draw a box with ticks spaced 60 degrees apart in X, and 0.2 in Y.
- 188
- Superimpose a dashed line grid, with 1.5 mm marks and spaces. plstyl expects a pointer!!
- 207
- ===============================================================
- 223
- Set up viewport and window, but do not draw box
- 231
- Draw circles for polar grid
- 241
- Draw radial spokes for polar grid
- 245
- Write labels for angle
- 246
- Slightly off zero to avoid floating point logic flips at 90 and 270 deg.
- 252
- Draw the graph
- 267
- ===============================================================
- 268
- Demonstration of contour plotting
- 295
- Set up function arrays
- 318
- Clean up