|
| 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