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