Skip to content

Commit 2cf943a

Browse files
committed
improved plplot cheat and used it with gsl
1 parent 152f6fa commit 2cf943a

8 files changed

Lines changed: 280 additions & 74 deletions

File tree

‎cheat/c.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ int main(int argc, char** argv)
21722172
}
21732173
}
21742174

2175-
//switch
2175+
//#switch
21762176
{
21772177
int i, j;
21782178
for( i=-1; i<3; i++ )

‎gsl/cheat.c‎

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <gsl/gsl_matrix.h>
77
#include <gsl/gsl_odeiv2.h>
88
#include <gsl/gsl_sf_bessel.h>
9+
#include <gsl/gsl_statistics.h>
10+
11+
#include <plplot/plplot.h>
912

1013
/*
1114
solves:
@@ -79,13 +82,17 @@ int main (void)
7982
double y[2] = { 1.0, 0.0 };
8083

8184
//number of points to print
82-
int nPts = 1000;
85+
const int nPts = 1000;
8386

8487
//time interval between each print
8588
double dt = t1 / nPts;
8689

90+
//prepare to get the output
8791
FILE* fp = fopen( "ode.tmp", "w" );
88-
for (i = 1; i <= nPts; i++)
92+
double datax[nPts];
93+
double datay[nPts];
94+
95+
for (i = 0; i < nPts; i++)
8996
{
9097
double ti = i * dt;
9198

@@ -99,15 +106,45 @@ int main (void)
99106
break;
100107
}
101108

102-
//get output:
103-
fprintf( fp, "%.5e %.5e %.5e\n", t, y[0], y[1] );
104-
printf( "%.5e %.5e %.5e\n", t, y[0], y[1] );
105-
}
106-
fclose(fp);
107-
gsl_odeiv2_driver_free(d);
109+
//#get output
110+
111+
//to a file:
112+
113+
fprintf( fp, "%.5e %.5e %.5e\n", t, y[0], y[1] );
108114

109-
//if you want to see the points with gnuplot (you do =)):
110-
//system( "gnuplot -e 'p \"ode.tmp\" u 2:3 w lines; pause -1'" );
115+
//to stdout:
116+
117+
printf( "%.5e %.5e %.5e\n", t, y[0], y[1] );
118+
119+
//to array
120+
121+
datax[i] = y[0];
122+
datay[i] = y[1];
123+
}
124+
125+
//finalize
126+
fclose(fp);
127+
gsl_odeiv2_driver_free(d);
128+
129+
//plot
130+
131+
//#plplot
132+
133+
plsdev("xwin");
134+
plinit();
135+
plenv(
136+
gsl_stats_min( datax, 1, nPts),
137+
gsl_stats_max( datax, 1, nPts),
138+
gsl_stats_min( datay, 1, nPts),
139+
gsl_stats_max( datay, 1, nPts),
140+
0,
141+
1
142+
);
143+
plstring( nPts, datax, datay, "*" );
144+
plend();
145+
146+
//#gnuplot
147+
//system( "gnuplot -e 'p \"ode.tmp\" u 2:3 w lines; pause -1'" );
111148
}
112149

113150
return 0;

‎gsl/makefile‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ override CFLGS ?= -Wall -std=c++0x -pedantic-errors -O3
77
override DEFINES ?= #-DPOSIX #for -DDEBUG and -DPROFILE, used dedicated DEFINES
88
override IN_EXT ?= .c
99
override IN_DIR ?= ./
10-
override INCLUDE_DIRS ?= -I/usr/include/GL
11-
override LIBS ?= -lgsl -lgslcblas -lm
10+
override INCLUDE_DIRS ?= #-I/usr/include/GL
11+
override LIBS ?= -lgsl -lgslcblas -lm -lplplotd
1212
override PREDEF ?= #-DDEBUG -DPROFILE -DWINDOWS #preprocessor defines
1313
override RUN_ARGS ?= #0 1 #passed as command line args to bin on run
1414
override OUT_DIR ?= _out/
@@ -44,3 +44,5 @@ clean:
4444

4545
install_ubuntu_deps:
4646
sudo aptitude install -y libgsl0-dev gsl-doc-info
47+
#if you will use plplot:
48+
sudo aptitude install -y libplplot-dev plplot11-driver-xwin

‎makefile.single_out‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ override DEBUG_FLAGS ?=
1010
override DEFINES ?= #-DPOSIX #for -DDEBUG and -DPROFILE, used dedicated DEFINES
1111
override IN_EXT ?= .cpp
1212
override IN_DIR ?= ./
13-
override INCLUDE_DIRS ?= -I/usr/include/GL
13+
override INCLUDE_DIRS ?= #-L/usr/include/GL
1414
override LIBS ?= #-lglut -lGLU -lGL
1515
override PREDEF ?= #-DDEBUG -DPROFILE -DWINDOWS #preprocessor defines
1616
override RUN_ARGS ?= #0 1 #passed as command line args to bin on run

‎plplot/c.c‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎plplot/cheat.c‎

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
this file shows how to use blas and lapack with the standard
3+
interfaces provided by their respective projects, repectively through
4+
`cblas.h` and `lapacke.h`
5+
*/
6+
7+
#include <assert.h>
8+
#include <math.h>
9+
#include <stdbool.h>
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
13+
#include <plplot/plplot.h>
14+
15+
int main(void)
16+
{
17+
enum CTES { NPTS = 100 };
18+
const double PI = acos(-1.0);
19+
const double PI_2 = PI/2.0;
20+
21+
int i;
22+
int plot_type;
23+
PLFLT delta;
24+
PLFLT datax[NPTS];
25+
PLFLT datay[NPTS];
26+
PLFLT datay2[NPTS];
27+
28+
//generate data
29+
delta = 2.0 * PI / (double) NPTS;
30+
for ( i = 0; i < NPTS; i++ )
31+
{
32+
datax[i] = (PLFLT)i;
33+
datay[i] = sin( i * delta );
34+
datay2[i] = sin( i * delta + PI_2 );
35+
}
36+
37+
//#plsdev
38+
39+
//must come before plinit! (constructor args)
40+
41+
//decides where output will go
42+
43+
plsdev("xwin");
44+
45+
//plot to file
46+
47+
//plsdev("svg");
48+
//plsfnam("a.svg");
49+
50+
//must always come before plotting calls:
51+
plinit();
52+
53+
plot_type = 0;
54+
55+
switch(plot_type)
56+
{
57+
//#scatter
58+
case 0:
59+
60+
//#plenv
61+
62+
//<http://plplot.sourceforge.net/docbook-manual/plplot-html-5.9.9/scales.html>
63+
64+
//general plotting params
65+
66+
//customizations can be made with:
67+
//plvpor, plvasp, plvpas, plwind, plbox
68+
69+
//mandatory, unless you set all other customizations with their respective functions
70+
71+
plenv( 0.0, (PLFLT)NPTS, -1.0, 1.0, 0, 1 );
72+
//xmin, xmax, ymin, ymax, just, type
73+
//just:
74+
//- 0: scale x/y indepedently
75+
//- 1: same scale for x/y.
76+
//type:
77+
//0: box
78+
//1: + axes
79+
//2: + grids
80+
81+
//#plcol0 #map0
82+
83+
//color map for axes, labels
84+
85+
//different from colors for the actual plot
86+
//where colors may have meanings such as legend
87+
//or values
88+
89+
//there is the concept of current color
90+
91+
//0 black (default background)
92+
//1 red (default foreground)
93+
//2 yellow
94+
//3 green
95+
//4 aquamarine
96+
//5 pink
97+
//6 wheat
98+
//7 grey
99+
//8 brown
100+
//9 blue
101+
//10 BlueViolet
102+
//11 cyan
103+
//12 turquoise
104+
//13 magenta
105+
//14 salmon
106+
//15 white
107+
108+
plcol0( 1 );
109+
110+
plstring( NPTS, datax, datay, "*" );
111+
112+
plcol0( 2 );
113+
plstring( NPTS, datax, datay2, "+" );
114+
//glyph to draw
115+
116+
//#labels
117+
118+
plcol0( 3 );
119+
120+
//see <#text formatting> for how to format text
121+
122+
pllab(
123+
"#frbottom label $x^2$",
124+
"#frleft label",
125+
"#frplstring" //title
126+
);
127+
128+
//#histogram
129+
case 1:
130+
131+
plhist(
132+
NPTS,
133+
datay,
134+
-1.1, //xrange left
135+
1.1, // right
136+
44, //how many bars to plot (it averages points?)
137+
0 //option flags
138+
);
139+
140+
pllab( "", "", "#frplhist" );
141+
}
142+
143+
144+
//#customizing view
145+
146+
//#plvport
147+
148+
//set viewport
149+
150+
//mandatory for plstring
151+
152+
/*plvpor( 0.0, (PLFLT)NPTS, -1.0, 1.0 );*/
153+
//xmin, xmax, ymin, ymax
154+
155+
/*plbox( "bclnst", 0.0, 0, "bnstv", 0.0, 0 );*/
156+
157+
//#plwind
158+
159+
/*plwind( -2.0, 3.0, -100.0, 0.0 );*/
160+
161+
//#plbox
162+
163+
/*plbox( "", 0.0, 0, "cmstv", 30.0, 3 );*/
164+
165+
//#text formatting
166+
167+
//#plsesc
168+
169+
//change escape char to (default '#'):
170+
171+
//plsesc( '@' );
172+
173+
//#in strings
174+
175+
//#u: move up to the superscript position (ended with #d)
176+
//#d: move down to subscript position (ended with #u)
177+
//#b: backspace (to allow overprinting)
178+
//##: number symbol
179+
//#+: toggle overline mode
180+
//#-: toggle underline mode
181+
//#gx: Greek letter corresponding to Roman letter x (see below)
182+
//#fn: switch to normal (sans-serif) font
183+
//#fr: switch to Roman (serif) font
184+
//#fi: switch to italic font
185+
//#fs: switch to script font
186+
//#(nnn): Hershey character nnn (1 to 4 decimal digits)
187+
//#[nnn]: unicode character nnn (nnn can be decimal or hexadecimal [e.g., starting with 0x]) (UNICODE ONLY).
188+
//#<0x8nnnnnnn>: absolute FCI to be used to change fonts in mid-string. (nnnnnnn must be exactly 7 digits). (UNICODE ONLY).
189+
//#<0xmn>: change just one attribute of the FCI in mid-string where m is the hexdigit and n is the hexpower. If more than two digits are given (so long as the eighth digit does not mark this as an absolute FCI, see above) they are ignored. (UNICODE ONLY).
190+
//#<FCI COMMAND STRING/>: the FCI COMMAND STRING is currently one of "sans-serif", "serif", "monospace", "script", "symbol", "upright", "italic", "oblique" "medium", or "bold" (without the surrounding quotes). These FCI COMMAND STRINGS change one attribute of the FCI according to their name. (UNICODE ONLY).
191+
192+
plend();
193+
194+
//multiple windows
195+
196+
/*plsdev("xwin");*/
197+
/*plinit();*/
198+
/*plhist(*/
199+
/*NPTS,*/
200+
/*datay,*/
201+
/*-1.1,*/
202+
/*1.1,*/
203+
/*44,*/
204+
/*0*/
205+
/*);*/
206+
/*plend();*/
207+
208+
return EXIT_SUCCESS;
209+
}

0 commit comments

Comments
 (0)