1
// $Id: plvect.c 11759 2011-06-01 17:41:34Z airwin $
3
// Vector plotting routines.
5
// Copyright (C) 2004 Andrew Ross
7
// This file is part of PLplot.
9
// PLplot is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Library General Public License as published
11
// by the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// PLplot is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU Library General Public License for more details.
19
// You should have received a copy of the GNU Library General Public License
20
// along with PLplot; if not, write to the Free Software
21
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29
// Static function prototypes
31
static void plP_plotvect( PLFLT x, PLFLT y, PLFLT u, PLFLT v, PLFLT scale );
33
//--------------------------------------------------------------------------
36
// Set the style of the arrow used by plvect
37
//--------------------------------------------------------------------------
40
c_plsvect( const PLFLT *arrowx, const PLFLT *arrowy, PLINT npts, PLINT fill )
45
free_mem( plsc->arrow_x );
47
free_mem( plsc->arrow_y );
49
if ( ( ( plsc->arrow_x = (PLFLT *) malloc( npts * sizeof ( PLFLT ) ) ) == NULL ) ||
50
( ( plsc->arrow_y = (PLFLT *) malloc( npts * sizeof ( PLFLT ) ) ) == NULL ) )
52
plexit( "c_plsvect: Insufficient memory" );
55
plsc->arrow_npts = npts;
56
plsc->arrow_fill = fill;
57
for ( i = 0; i < npts; i++ )
59
plsc->arrow_x[i] = arrowx[i];
60
plsc->arrow_y[i] = arrowy[i];
65
// Plot an individual vector
68
plP_plotvect( PLFLT x, PLFLT y, PLFLT u, PLFLT v, PLFLT scale )
70
PLFLT uu, vv, px0, py0, dpx, dpy;
77
if ( uu == 0.0 && vv == 0.0 )
80
if ( ( ( a_x = (PLINT *) malloc( sizeof ( PLINT ) * ( plsc->arrow_npts ) ) ) == NULL ) ||
81
( ( a_y = (PLINT *) malloc( sizeof ( PLINT ) * ( plsc->arrow_npts ) ) ) == NULL ) )
83
plexit( "plP_plotvect: Insufficient memory" );
89
pldebug( "plP_plotvect", "%f %f %d %d\n", x, y, px0, py0 );
91
dpx = plP_wcpcx( x + 0.5 * uu ) - px0;
92
dpy = plP_wcpcy( y + 0.5 * vv ) - py0;
94
// transform arrow -> a
96
for ( j = 0; j < plsc->arrow_npts; j++ )
98
a_x[j] = (PLINT) ( plsc->arrow_x[j] * dpx - plsc->arrow_y[j] * dpy + px0 );
99
a_y[j] = (PLINT) ( plsc->arrow_x[j] * dpy + plsc->arrow_y[j] * dpx + py0 );
103
plP_draphy_poly( a_x, a_y, plsc->arrow_npts );
104
if ( plsc->arrow_fill )
106
plP_plfclp( a_x, a_y, plsc->arrow_npts, plsc->clpxmi, plsc->clpxma,
107
plsc->clpymi, plsc->clpyma, plP_fill );
110
free( (void *) a_x );
111
free( (void *) a_y );
117
// Routine to plot a vector array with arbitrary coordinate
118
// and vector transformations
120
void plfvect( PLFLT ( *getuv )( PLINT, PLINT, PLPointer ),
121
PLPointer up, PLPointer vp,
122
PLINT nx, PLINT ny, PLFLT scale,
123
void ( *pltr )( PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer ),
124
PLPointer pltr_data )
127
PLFLT **u, **v, **x, **y;
128
PLFLT lscale, dx, dy, dxmin, dymin, umax, vmax;
130
plAlloc2dGrid( &u, nx, ny );
131
plAlloc2dGrid( &v, nx, ny );
132
plAlloc2dGrid( &x, nx, ny );
133
plAlloc2dGrid( &y, nx, ny );
135
for ( j = 0; j < ny; j++ )
137
for ( i = 0; i < nx; i++ )
139
u[i][j] = getuv( i, j, up );
140
v[i][j] = getuv( i, j, vp );
141
pltr( (PLFLT) i, (PLFLT) j, &x[i][j], &y[i][j], pltr_data );
145
// Calculate apropriate scaling if necessary
148
if ( nx <= 1 && ny <= 1 )
150
fprintf( stderr, "plfvect: not enough points for autoscaling\n" );
155
for ( j = 0; j < ny; j++ )
157
for ( i = 0; i < nx; i++ )
159
for ( j1 = j; j1 < ny; j1++ )
161
for ( i1 = 0; i1 < nx; i1++ )
163
dx = fabs( x[i1][j1] - x[i][j] );
164
dy = fabs( y[i1][j1] - y[i][j] );
167
dxmin = ( dx < dxmin ) ? dx : dxmin;
171
dymin = ( dy < dymin ) ? dy : dymin;
179
for ( j = 0; j < ny; j++ )
181
for ( i = 0; i < nx; i++ )
183
umax = ( u[i][j] > umax ) ? u[i][j] : umax;
184
vmax = ( v[i][j] > vmax ) ? v[i][j] : vmax;
189
lscale = ( umax < vmax ) ? umax : vmax;
190
lscale = 1.5 / lscale;
193
scale = -scale * lscale;
201
for ( j = 0; j < ny; j++ )
203
for ( i = 0; i < nx; i++ )
205
plP_plotvect( x[i][j], y[i][j], u[i][j], v[i][j], scale );
209
plFree2dGrid( u, nx, ny );
210
plFree2dGrid( v, nx, ny );
211
plFree2dGrid( x, nx, ny );
212
plFree2dGrid( y, nx, ny );
216
c_plvect( const PLFLT **u, const PLFLT **v, PLINT nx, PLINT ny, PLFLT scale,
217
void ( *pltr )( PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer ),
218
PLPointer pltr_data )
220
plfvect( plf2eval1, (PLPointer) u, (PLPointer) v,
221
nx, ny, scale, pltr, pltr_data );