~ubuntu-branches/ubuntu/intrepid/plplot/intrepid

« back to all changes in this revision

Viewing changes to examples/c/x22c.c

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2006-11-04 10:19:34 UTC
  • mfrom: (2.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061104101934-mlirvdg4gpwi6i5q
Tags: 5.6.1-10
* Orphaning the package
* debian/control: Changed the maintainer to the Debian QA Group

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: x22c.c,v 1.8 2004/06/14 21:51:54 rlaboiss Exp $
 
1
/* $Id: x22c.c,v 1.14 2006/05/27 21:05:09 hbabcock Exp $
2
2
 
3
3
    Simple vector plot example
4
4
    Copyright (C) 2004 Andrew Ross <andrewross@users.sourceforge.net>
19
19
 
20
20
    You should have received a copy of the GNU Library General Public License
21
21
    along with PLplot; if not, write to the Free Software
22
 
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
22
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
23
 
24
24
*/
25
25
 
26
26
#include "plcdemos.h"
27
 
#include "plevent.h"
28
27
 
29
28
/* Pairs of points making the line segments used to plot the user defined arrow */
30
29
static PLFLT arrow_x[6] = {-0.5, 0.5, 0.3, 0.5, 0.3, 0.5};
35
34
/*--------------------------------------------------------------------------*\
36
35
 * main
37
36
 *
38
 
 * Generates several simple vector plots.  
 
37
 * Generates several simple vector plots.
39
38
 \*--------------------------------------------------------------------------*/
40
39
 
41
 
/* 
42
 
 * Vector plot of the circulation about the origin 
 
40
/*
 
41
 * Vector plot of the circulation about the origin
43
42
 */
44
43
void
45
44
circulation() {
94
93
 
95
94
}
96
95
 
97
 
/* 
98
 
 * Vector plot of flow through a constricted pipe 
 
96
/*
 
97
 * Vector plot of flow through a constricted pipe
99
98
 */
100
99
void
101
100
constriction() {
161
160
 
162
161
 
163
162
 
164
 
f2mnmx(PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmin, PLFLT *fmax)
 
163
void f2mnmx(PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmin, PLFLT *fmax)
165
164
{
166
165
    int i, j;
167
166
 
176
175
    }
177
176
}
178
177
 
179
 
/* 
180
 
 * Vector plot of the gradient of a shielded potential (see example 9) 
 
178
/*
 
179
 * Vector plot of the gradient of a shielded potential (see example 9)
181
180
 */
182
181
void potential() {
 
182
#if !defined(WIN32)
183
183
    const int nper = 100;
184
184
    const int nlevel = 10;
185
185
    const int nr = 20;
186
186
    const int ntheta = 20;
187
 
  
 
187
#else
 
188
#define nper    100
 
189
#define nlevel   10
 
190
#define nr       20
 
191
#define ntheta   20
 
192
#endif
 
193
 
188
194
    int i,j;
189
195
    PLFLT eps, q1, d1, q1i, d1i, q2, d2, q2i, d2i;
190
196
    PLFLT div1, div1i, div2, div2i;
193
199
    PLFLT px[nper], py[nper], clevel[nlevel];
194
200
    PLcGrid2 cgrid2;
195
201
 
196
 
  
 
202
 
197
203
    /* Create data to be plotted */
198
204
    plAlloc2dGrid(&cgrid2.xg,nr,ntheta);
199
205
    plAlloc2dGrid(&cgrid2.yg,nr,ntheta);
229
235
    for (i = 0; i < nr; i++) {
230
236
        r = 0.5 + (double) i;
231
237
        for (j = 0; j < ntheta; j++) {
232
 
            theta = 2.*PI/(ntheta-1)*(0.5+(double)j);
 
238
            theta = 2.*M_PI/(ntheta-1)*(0.5+(double)j);
233
239
            x = r*cos(theta);
234
240
            y = r*sin(theta);
235
241
            cgrid2.xg[i][j] = x;
239
245
            div2 = sqrt(pow(x-d2, 2.) + pow(y+d2, 2.) + pow(eps, 2.));
240
246
            div2i = sqrt(pow(x-d2i, 2.) + pow(y+d2i, 2.) + pow(eps, 2.));
241
247
            z[i][j] = q1/div1 + q1i/div1i + q2/div2 + q2i/div2i;
242
 
            u[i][j] = -q1*(x-d1)/pow(div1,3.) - q1i*(x-d1i)/pow(div1i,3.0) 
 
248
            u[i][j] = -q1*(x-d1)/pow(div1,3.) - q1i*(x-d1i)/pow(div1i,3.0)
243
249
                - q2*(x-d2)/pow(div2,3.) - q2i*(x-d2i)/pow(div2i,3.);
244
 
            v[i][j] = -q1*(y-d1)/pow(div1,3.) - q1i*(y-d1i)/pow(div1i,3.0) 
 
250
            v[i][j] = -q1*(y-d1)/pow(div1,3.) - q1i*(y-d1i)/pow(div1i,3.0)
245
251
                - q2*(y+d2)/pow(div2,3.) - q2i*(y+d2i)/pow(div2i,3.);
246
252
        }
247
253
    }
262
268
    plcont(z,nr,ntheta,1,nr,1,ntheta,clevel,nlevel,pltr2,(void *) &cgrid2);
263
269
    pllsty(1);
264
270
    plcol0(1);
265
 
    
 
271
 
266
272
    /* Plot the vectors of the gradient of the potential */
267
273
    plcol0(2);
268
274
    plvect(u,v,nr,ntheta,25.0,pltr2,(void *)&cgrid2);
270
276
 
271
277
    /* Plot the perimeter of the cylinder */
272
278
    for (i=0;i<nper;i++) {
273
 
        theta = (2.*PI/(nper-1))*(double)i;
 
279
        theta = (2.*M_PI/(nper-1))*(double)i;
274
280
        px[i] = rmax*cos(theta);
275
281
        py[i] = rmax*sin(theta);
276
282
    }
277
283
    plline(nper,px,py);
278
 
    
 
284
 
279
285
    plFree2dGrid(z,nr,ntheta);
280
286
    plFree2dGrid(cgrid2.xg,nr,ntheta);
281
287
    plFree2dGrid(cgrid2.yg,nr,ntheta);
288
294
int
289
295
main(int argc, char *argv[])
290
296
{
291
 
    int i, j;
292
297
    PLINT narr, fill;
293
298
 
294
299
    /* Parse and process command line arguments */
295
300
 
296
 
    plParseOpts(&argc, argv, PL_PARSE_FULL);
 
301
    plparseopts(&argc, argv, PL_PARSE_FULL);
297
302
 
298
303
    /* Initialize plplot */
299
304
 
304
309
    narr = 6;
305
310
    fill = 0;
306
311
 
307
 
    /* Set arrow style using arrow_x and arrow_y then 
 
312
    /* Set arrow style using arrow_x and arrow_y then
308
313
       plot using these arrows.*/
309
314
    plsvect(arrow_x, arrow_y, narr, fill);
310
315
    constriction();
311
316
 
312
 
    /* Set arrow style using arrow2_x and arrow2_y then 
 
317
    /* Set arrow style using arrow2_x and arrow2_y then
313
318
       plot using these filled arrows. */
314
319
    fill = 1;
315
320
    plsvect(arrow2_x, arrow2_y, narr, fill);