source: trunk/SRC/ToBeReviewed/PLOTS/VECTEUR/velovect.pro @ 163

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1;
2;+
3;
4; @file_comments
5; Produce a two-dimensional velocity field plot.
6;
7; A directed arrow is drawn at each point showing the direction and
8; magnitude of the field.
9;               
10; @categories
11; Plotting, two-dimensional.
12;
13;
14; @param U {in}{required}
15; The X component of the two-dimensional field. 
16; U must be a two-dimensional array.
17;
18; @param V {in}{required}
19; The Y component of the two dimensional field.  Y must have
20; the same dimensions as X.  The vector at point [i,j] has a
21; magnitude of:
22;
23;       (U[i,j]^2 + V[i,j]^2)^0.5
24;
25; and a direction of:
26;
27;       ATAN2(V[i,j],U[i,j]).
28;
29; @param X {in}{optional}{type=vector}
30; Optional abscissa values.  X must be a vector with a length
31; equal to the first dimension of U and V.
32;
33; @param Y {in}{optional}{type=vector}
34; Optional ordinate values.  Y must be a vector with a length
35; equal to the first dimension of U and V.
36;
37; @keyword COLOR
38; The color index used for the plot.
39;
40; @keyword DOTS
41; Set this keyword to 1 to place a dot at each missing point.
42; Set this keyword to 0 or omit it to draw nothing for missing
43; points.  Has effect only if MISSING is specified.
44;
45; @keyword LENGTH {default=1.0}
46; Length factor.  The default of 1.0 makes the longest (U,V)
47; vector the length of a cell.
48;
49; @keyword MISSING
50;  Missing data value.  Vectors with a LENGTH greater
51; than MISSING are ignored.
52;
53; @keyword OVERPLOT
54; Set this keyword to make VELOVECT "overplot".  That is, the
55; current graphics screen is not erased, no axes are drawn, and
56; the previously established scaling remains in effect.
57;
58; @keyword CLIP
59;
60; @keyword NOCLIP
61;
62; @keyword _EXTRA
63; Used to pass your keywords.
64;
65; @restrictions
66; Plotting on the selected device is performed.  System
67; variables concerning plotting are changed.
68; Note:   All other keywords are passed directly to the PLOT procedure
69;       and may be used to set option such as TITLE, POSITION,
70;       NOERASE, etc.
71;
72; @history
73;       DMS, RSI, Oct., 1983.
74;       For Sun, DMS, RSI, April, 1989.
75;       Added TITLE, Oct, 1990.
76;       Added POSITION, NOERASE, COLOR, Feb 91, RES.
77;       August, 1993.  Vince Patrick, Adv. Visualization Lab, U. of Maryland,
78;               fixed errors in math.
79;       August, 1993. DMS, Added _EXTRA keyword inheritance.
80;       January, 1994, KDB. Fixed integer math which produced 0 and caused
81;                           divide by zero errors.
82;       December, 1994, MWR. Added _EXTRA inheritance for PLOTS and OPLOT.
83;       June, 1995, MWR. Removed _EXTRA inheritance for PLOTS and changed
84;                        OPLOT to PLOTS.
85;       September, 1996, GGS. Changed denominator of x_step and y_step vars.
86;       February, 1998, DLD.  Add support for CLIP and NO_CLIP keywords.
87;       June, 1998, DLD.  Add support for OVERPLOT keyword.
88;
89; Copyright (c) 1983-1998, Research Systems, Inc.  All rights reserved.
90;       Unauthorized reproduction prohibited.
91;
92; @version
93; $Id$
94;
95;-
96;
97PRO velovect,U,V,X,Y, Missing = Missing, Length = length, Dots = dots,  $
98        Color=color, CLIP=clip, NOCLIP=noclip, OVERPLOT=overplot, _EXTRA=extra
99;
100  compile_opt idl2, strictarrsubs
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.