1 //-------------------------------------------------------------------------- 2 // Copyright (C) 2004 Andrew Ross 3 // Copyright (C) 2004-2014 Alan W. Irwin 4 // 5 // This file is part of PLplot. 6 // 7 // PLplot is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU Library General Public License as published by 9 // the Free Software Foundation; version 2 of the License. 10 // 11 // PLplot is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Library General Public License for more details. 15 // 16 // You should have received a copy of the GNU Library General Public License 17 // along with PLplot; if not, write to the Free Software 18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 //-------------------------------------------------------------------------- 20 // 21 //-------------------------------------------------------------------------- 22 // Implementation of PLplot example 17 in Java. 23 //-------------------------------------------------------------------------- 24 25 package plplot.examples; 26 27 import plplot.core.*; 28 import static plplot.core.plplotjavacConstants.*; 29 30 class x17 { 31 // Class data 32 PLStream pls = new PLStream(); 33 34 // plerror is not implement in java at this time 35 static int pl_errcode = 0; 36 static String errmsg = null; 37 38 x17( String[] args )39 x17( String[] args ) 40 { 41 int id1[] = new int[1]; 42 int n, nsteps = 1000; 43 boolean autoy, acc; 44 double y1, y2, y3, y4, ymin, ymax, xlab, ylab; 45 double t, tmin, tmax, tjump, dt, noise; 46 int colbox, collab; 47 int colline[] = new int[4]; 48 int styline[] = new int[4]; 49 String legline[] = new String[4]; 50 51 52 // Parse and process command line arguments. 53 pls.parseopts( args, PL_PARSE_FULL | PL_PARSE_NOPROGRAM ); 54 55 // If db is used the plot is much more smooth. However, because of the 56 // async X behaviour, one does not have a real-time scripcharter. 57 // pls.setopt("db", ""); 58 // pls.setopt("np", ""); 59 // Specify some reasonable defaults for ymin and ymax 60 // The plot will grow automatically if needed (but not shrink) 61 62 ymin = -0.1; 63 ymax = 0.1; 64 65 // Specify initial tmin and tmax -- this determines length of window. 66 // Also specify maximum jump in t 67 // This can accomodate adaptive timesteps 68 69 tmin = 0.; 70 tmax = 10.; 71 tjump = 0.3; // percentage of plot to jump 72 73 // Axes options same as plbox. 74 // Only automatic tick generation and label placement allowed 75 // Eventually I'll make this fancier 76 77 colbox = 1; 78 collab = 3; 79 styline[0] = colline[0] = 2; // pens color and line style 80 styline[1] = colline[1] = 3; 81 styline[2] = colline[2] = 4; 82 styline[3] = colline[3] = 5; 83 84 legline[0] = "sum"; // pens legend 85 legline[1] = "sin"; 86 legline[2] = "sin*noi"; 87 legline[3] = "sin+noi"; 88 89 xlab = 0.; ylab = 0.25; // legend position 90 91 autoy = true; // autoscale y 92 acc = true; // don't scrip, accumulate 93 94 // Initialize PLplot. 95 pls.init(); 96 97 pls.adv( 0 ); 98 pls.vsta(); 99 100 // Register our error variables with PLplot 101 // From here on, we're handling all errors here 102 103 //pls.sError(&pl_errcode, errmsg); 104 105 pls.stripc( id1, "bcnst", "bcnstv", 106 tmin, tmax, tjump, ymin, ymax, 107 xlab, ylab, 108 autoy, acc, 109 colbox, collab, 110 colline, styline, legline, 111 "t", "", "Strip chart demo" ); 112 113 if ( pl_errcode != 0 ) 114 { 115 System.out.println( errmsg ); 116 pls.end(); 117 System.exit( 1 ); 118 } 119 120 // Let plplot handle errors from here on 121 122 //pls.sError(NULL, NULL); 123 124 autoy = false; // autoscale y 125 acc = true; // accumulate/ 126 127 // This is to represent a loop over time 128 // Let's try a random walk process 129 130 y1 = y2 = y3 = y4 = 0.0; 131 dt = 0.1; 132 133 for ( n = 0; n < nsteps; n++ ) 134 { 135 try { 136 Thread.sleep( 10 ); 137 } 138 catch ( InterruptedException e ) { 139 } 140 t = n * dt; 141 noise = pls.randd() - 0.5; 142 y1 = y1 + noise; 143 y2 = Math.sin( t * Math.PI / 18. ); 144 y3 = y2 * noise; 145 y4 = y2 + noise / 3.; 146 147 // There is no need for all pens to have the same number of 148 // points or beeing equally time spaced. 149 150 if ( n % 2 != 0 ) 151 pls.stripa( id1[0], 0, t, y1 ); 152 if ( n % 3 != 0 ) 153 pls.stripa( id1[0], 1, t, y2 ); 154 if ( n % 4 != 0 ) 155 pls.stripa( id1[0], 2, t, y3 ); 156 if ( n % 5 != 0 ) 157 pls.stripa( id1[0], 3, t, y4 ); 158 // pls.eop(); // use double buffer (-db on command line) 159 } 160 161 // Destroy strip chart and it's memory 162 pls.stripd( id1[0] ); 163 164 pls.end(); 165 } 166 main( String[] args )167 public static void main( String[] args ) 168 { 169 new x17( args ); 170 } 171 } 172 173 174 //-------------------------------------------------------------------------- 175 // End of x17.java 176 //-------------------------------------------------------------------------- 177