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

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

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
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
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;
100PRO VELOVECT,U,V,X,Y, Missing = Missing, Length = length, Dots = dots,  $
101        Color=color, CLIP=clip, NOCLIP=noclip, OVERPLOT=overplot, _EXTRA=extra
102;
103  compile_opt idl2, strictarrsubs
104;
105        on_error,2                      ;Return to caller if an error occurs
106        s = size(u)
107        t = size(v)
108        if s[0] ne 2 then begin
109baduv:   message, 'U and V parameters must be 2D and same size.'
110                endif
111        if total(abs(s[0:2]-t[0:2])) ne 0 then goto,baduv
112;
113        if n_params(0) lt 3 then x = findgen(s[1]) else $
114                if n_elements(x) ne s[1] then begin
115badxy:                  message, 'X and Y arrays have incorrect size.'
116                        endif
117        if n_params(1) lt 4 then y = findgen(s[2]) else $
118                if n_elements(y) ne s[2] then goto,badxy
119;
120        if n_elements(missing) le 0 then missing = 1.0e30
121        if n_elements(length) le 0 then length = 1.0
122
123        mag = sqrt(u^2.+v^2.)             ;magnitude.
124                ;Subscripts of good elements
125        nbad = 0                        ;# of missing points
126        if n_elements(missing) gt 0 then begin
127                good = where(mag lt missing)
128                if keyword_set(dots) then bad = where(mag ge missing, nbad)
129        endif else begin
130                good = lindgen(n_elements(mag))
131        endelse
132
133        ugood = u[good]
134        vgood = v[good]
135        x0 = min(x)                     ;get scaling
136        x1 = max(x)
137        y0 = min(y)
138        y1 = max(y)
139        x_step=(x1-x0)/(s[1]-1.0)   ; Convert to float. Integer math
140        y_step=(y1-y0)/(s[2]-1.0)   ; could result in divide by 0
141
142        maxmag=max([max(abs(ugood/x_step)),max(abs(vgood/y_step))])
143        sina = length * (ugood/maxmag)
144        cosa = length * (vgood/maxmag)
145;
146        if n_elements(title) le 0 then title = ''
147        ;--------------  plot to get axes  ---------------
148        if n_elements(color) eq 0 then color = !p.color
149        if n_elements(noclip) eq 0 then noclip = 1
150        x_b0=x0-x_step
151        x_b1=x1+x_step
152        y_b0=y0-y_step
153        y_b1=y1+y_step
154        if (not keyword_set(overplot)) then begin
155          if n_elements(position) eq 0 then begin
156            plot,[x_b0,x_b1],[y_b1,y_b0],/nodata,/xst,/yst, $
157              color=color, _EXTRA = extra
158          endif else begin
159            plot,[x_b0,x_b1],[y_b1,y_b0],/nodata,/xst,/yst, $
160              color=color, _EXTRA = extra
161          endelse
162        endif
163        if n_elements(clip) eq 0 then $
164            clip = [!x.crange[0],!y.crange[0],!x.crange[1],!y.crange[1]]
165;
166        r = .3                          ;len of arrow head
167        angle = 22.5 * !dtor            ;Angle of arrowhead
168        st = r * sin(angle)             ;sin 22.5 degs * length of head
169        ct = r * cos(angle)
170;
171        for i=0,n_elements(good)-1 do begin     ;Each point
172                x0 = x[good[i] mod s[1]]        ;get coords of start & end
173                dx = sina[i]
174                x1 = x0 + dx
175                y0 = y[good[i] / s[1]]
176                dy = cosa[i]
177                y1 = y0 + dy
178                xd=x_step
179                yd=y_step
180                plots,[x0,x1,x1-(ct*dx/xd-st*dy/yd)*xd, $
181                        x1,x1-(ct*dx/xd+st*dy/yd)*xd], $
182                      [y0,y1,y1-(ct*dy/yd+st*dx/xd)*yd, $
183                        y1,y1-(ct*dy/yd-st*dx/xd)*yd], $
184                      color=color,clip=clip,noclip=noclip, _EXTRA = extra
185                endfor
186        if nbad gt 0 then $             ;Dots for missing?
187                PLOTS, x[bad mod s[1]], y[bad / s[1]], psym=3, color=color, $
188                       clip=clip,noclip=noclip, _EXTRA = extra
189end
Note: See TracBrowser for help on using the repository browser.