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