source: trunk/PLOTS/VECTEUR/velovect.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1; $Id$
2;
3; Copyright (c) 1983-1998, Research Systems, Inc.  All rights reserved.
4;       Unauthorized reproduction prohibited.
5
6PRO VELOVECT,U,V,X,Y, Missing = Missing, Length = length, Dots = dots,  $
7        Color=color, CLIP=clip, NOCLIP=noclip, OVERPLOT=overplot, _EXTRA=extra
8;
9;+
10; NAME:
11;       VELOVECT
12;
13; PURPOSE:
14;       Produce a two-dimensional velocity field plot.
15;
16;       A directed arrow is drawn at each point showing the direction and
17;       magnitude of the field.
18;               
19; CATEGORY:
20;       Plotting, two-dimensional.
21;
22; CALLING SEQUENCE:
23;       VELOVECT, U, V [, X, Y]
24;
25; INPUTS:
26;       U:      The X component of the two-dimensional field. 
27;               U must be a two-dimensional array.
28;
29;       V:      The Y component of the two dimensional field.  Y must have
30;               the same dimensions as X.  The vector at point [i,j] has a
31;               magnitude of:
32;
33;                       (U[i,j]^2 + V[i,j]^2)^0.5
34;
35;               and a direction of:
36;
37;                       ATAN2(V[i,j],U[i,j]).
38;
39; OPTIONAL INPUT PARAMETERS:
40;       X:      Optional abcissae values.  X must be a vector with a length
41;               equal to the first dimension of U and V.
42;
43;       Y:      Optional ordinate values.  Y must be a vector with a length
44;               equal to the first dimension of U and V.
45;
46; KEYWORD INPUT PARAMETERS:
47;       COLOR:  The color index used for the plot.
48;
49;       DOTS:   Set this keyword to 1 to place a dot at each missing point.
50;               Set this keyword to 0 or omit it to draw nothing for missing
51;               points.  Has effect only if MISSING is specified.
52;
53;       LENGTH: Length factor.  The default of 1.0 makes the longest (U,V)
54;               vector the length of a cell.
55;
56;       MISSING: Missing data value.  Vectors with a LENGTH greater
57;               than MISSING are ignored.
58;
59;       OVERPLOT: Set this keyword to make VELOVECT "overplot".  That is, the
60;               current graphics screen is not erased, no axes are drawn, and
61;               the previously established scaling remains in effect.
62;
63;
64;       Note:   All other keywords are passed directly to the PLOT procedure
65;               and may be used to set option such as TITLE, POSITION,
66;               NOERASE, etc.
67; OUTPUTS:
68;       None.
69;
70; COMMON BLOCKS:
71;       None.
72;
73; SIDE EFFECTS:
74;       Plotting on the selected device is performed.  System
75;       variables concerning plotting are changed.
76;
77; RESTRICTIONS:
78;       None.
79;
80; PROCEDURE:
81;       Straightforward.  Unrecognized keywords are passed to the PLOT
82;       procedure. 
83;
84; MODIFICATION HISTORY:
85;       DMS, RSI, Oct., 1983.
86;       For Sun, DMS, RSI, April, 1989.
87;       Added TITLE, Oct, 1990.
88;       Added POSITION, NOERASE, COLOR, Feb 91, RES.
89;       August, 1993.  Vince Patrick, Adv. Visualization Lab, U. of Maryland,
90;               fixed errors in math.
91;       August, 1993. DMS, Added _EXTRA keyword inheritance.
92;       January, 1994, KDB. Fixed integer math which produced 0 and caused
93;                           divide by zero errors.
94;       December, 1994, MWR. Added _EXTRA inheritance for PLOTS and OPLOT.
95;       June, 1995, MWR. Removed _EXTRA inheritance for PLOTS and changed
96;                        OPLOT to PLOTS.
97;       September, 1996, GGS. Changed denominator of x_step and y_step vars.
98;       February, 1998, DLD.  Add support for CLIP and NO_CLIP keywords.
99;       June, 1998, DLD.  Add support for OVERPLOT keyword.
100;-
101;
102        on_error,2                      ;Return to caller if an error occurs
103        s = size(u)
104        t = size(v)
105        if s[0] ne 2 then begin
106baduv:   message, 'U and V parameters must be 2D and same size.'
107                endif
108        if total(abs(s[0:2]-t[0:2])) ne 0 then goto,baduv
109;
110        if n_params(0) lt 3 then x = findgen(s[1]) else $
111                if n_elements(x) ne s[1] then begin
112badxy:                  message, 'X and Y arrays have incorrect size.'
113                        endif
114        if n_params(1) lt 4 then y = findgen(s[2]) else $
115                if n_elements(y) ne s[2] then goto,badxy
116;
117        if n_elements(missing) le 0 then missing = 1.0e30
118        if n_elements(length) le 0 then length = 1.0
119
120        mag = sqrt(u^2.+v^2.)             ;magnitude.
121                ;Subscripts of good elements
122        nbad = 0                        ;# of missing points
123        if n_elements(missing) gt 0 then begin
124                good = where(mag lt missing)
125                if keyword_set(dots) then bad = where(mag ge missing, nbad)
126        endif else begin
127                good = lindgen(n_elements(mag))
128        endelse
129
130        ugood = u[good]
131        vgood = v[good]
132        x0 = min(x)                     ;get scaling
133        x1 = max(x)
134        y0 = min(y)
135        y1 = max(y)
136        x_step=(x1-x0)/(s[1]-1.0)   ; Convert to float. Integer math
137        y_step=(y1-y0)/(s[2]-1.0)   ; could result in divide by 0
138
139        maxmag=max([max(abs(ugood/x_step)),max(abs(vgood/y_step))])
140        sina = length * (ugood/maxmag)
141        cosa = length * (vgood/maxmag)
142;
143        if n_elements(title) le 0 then title = ''
144        ;--------------  plot to get axes  ---------------
145        if n_elements(color) eq 0 then color = !p.color
146        if n_elements(noclip) eq 0 then noclip = 1
147        x_b0=x0-x_step
148        x_b1=x1+x_step
149        y_b0=y0-y_step
150        y_b1=y1+y_step
151        if (not keyword_set(overplot)) then begin
152          if n_elements(position) eq 0 then begin
153            plot,[x_b0,x_b1],[y_b1,y_b0],/nodata,/xst,/yst, $
154              color=color, _EXTRA = extra
155          endif else begin
156            plot,[x_b0,x_b1],[y_b1,y_b0],/nodata,/xst,/yst, $
157              color=color, _EXTRA = extra
158          endelse
159        endif
160        if n_elements(clip) eq 0 then $
161            clip = [!x.crange[0],!y.crange[0],!x.crange[1],!y.crange[1]]
162;
163        r = .3                          ;len of arrow head
164        angle = 22.5 * !dtor            ;Angle of arrowhead
165        st = r * sin(angle)             ;sin 22.5 degs * length of head
166        ct = r * cos(angle)
167;
168        for i=0,n_elements(good)-1 do begin     ;Each point
169                x0 = x[good[i] mod s[1]]        ;get coords of start & end
170                dx = sina[i]
171                x1 = x0 + dx
172                y0 = y[good[i] / s[1]]
173                dy = cosa[i]
174                y1 = y0 + dy
175                xd=x_step
176                yd=y_step
177                plots,[x0,x1,x1-(ct*dx/xd-st*dy/yd)*xd, $
178                        x1,x1-(ct*dx/xd+st*dy/yd)*xd], $
179                      [y0,y1,y1-(ct*dy/yd+st*dx/xd)*yd, $
180                        y1,y1-(ct*dy/yd-st*dx/xd)*yd], $
181                      color=color,clip=clip,noclip=noclip, _EXTRA = extra
182                endfor
183        if nbad gt 0 then $             ;Dots for missing?
184                PLOTS, x[bad mod s[1]], y[bad / s[1]], psym=3, color=color, $
185                       clip=clip,noclip=noclip, _EXTRA = extra
186end
Note: See TracBrowser for help on using the repository browser.