source: trunk/mesoscale/PLOT/MINIMAL/vector.pro @ 85

Last change on this file since 85 was 85, checked in by aslmd, 14 years ago

LMD_MM_MARS et LMD_LES_MARS: ajout des routines IDL pour tracer les sorties --> voir mesoscale/PLOT

  • Property svn:executable set to *
File size: 3.6 KB
Line 
1; vector.pro
2; vector plotting routine
3; see http://cgam.nerc.ac.uk/graphics/idl.php for more details
4
5; Calling procedure:
6; VECTOR, U, V, X, Y
7; U and V are the vector components as two dimensional arrays.
8; X and Y are the vectors locations as one dimensional arrays.
9;
10; Optional parameters:
11; LENGTH: Length of the vector, default=1 which is 300 pixels.
12; OVERPLOT: Set this to overplot the current graphics plot.
13; STRIDE: Pick every nth vector for plotting.
14; TYPE:   Type of arrow head. 0-4, default=0
15; ANGLE:  Angle of vector head in degrees, default=22.5.
16; HEAD_LEN: Length of the arrow head relative to shaft, default=0.3
17; ALIGN:  Alignment of arrow.  Default is 0.5, range=0.0 to 1.0.
18; REF_MAG: Arrow magnitude.
19; REF_POS: Position for reference vector in normalised coordinates [x,y].
20; REF_TEXT: Text to place to the left of the reference vector.
21; COLOR: Color index of vectors
22               
23PRO VECTOR, u,v,x,y, LENGTH = length,$
24        Color=color, STRIDE=stride, ALIGN=align, $
25        REF_MAG=ref_mag, TYPE=type, ANGLE=angle, HEAD_LEN=head_len,$
26        REF_POS=ref_pos, REF_TEXT=ref_text, OVERPLOT=overplot, _EXTRA=extra
27
28;Check mapping is cylindrical or not set - reject if otherwise.
29IF ((!MAP.PROJECTION NE 0) AND (!MAP.PROJECTION NE 8)) THEN BEGIN
30  PRINT, 'Mapping must be cylindrical or unset to use the vector routine'
31  RETURN
32ENDIF
33
34;Basic checks of the input data
35a=SIZE(u)
36b=SIZE(v)
37c=SIZE(x)
38d=SIZE(y)
39IF ((a[0] NE 2) OR (b[0] NE 2)) THEN BEGIN
40  PRINT, 'u and v must be two dimensional'
41  RETURN
42ENDIF
43IF (TOTAL(ABS(b[0:2]-a[0:2])) NE 0) THEN BEGIN
44  PRINT, 'u and v must have the same size'
45  RETURN
46ENDIF
47IF ((c[0] NE 1) AND (d[0] NE 1)) THEN BEGIN
48  PRINT, 'x and y must be one dimensional'
49  RETURN
50ENDIF
51IF ((c[1]-a[1]) NE 0) THEN BEGIN
52  PRINT, 'u and x have mismatched sizes'
53  RETURN
54ENDIF
55IF ((d[1]-b[2]) NE 0) THEN BEGIN
56  PRINT, 'v and y have mismatched sizes'
57  RETURN
58ENDIF
59
60;Initialise parameters if undefined
61IF (N_ELEMENTS(STRIDE) EQ 0) THEN stride=0
62IF N_ELEMENTS(LENGTH) EQ 0 THEN length=1.0
63IF N_ELEMENTS(COLOR) EQ 0 THEN color = !P.COLOR
64IF (N_ELEMENTS(ANGLE) EQ 0) THEN angle=22.5
65IF (N_ELEMENTS(HEAD_LEN) EQ 0) THEN head_len=0.3
66IF (N_ELEMENTS(TYPE) EQ 0) THEN TYPE=0
67IF (N_ELEMENTS(ALIGN) EQ 0) THEN align=0.5     
68IF (N_ELEMENTS(REF_TEXT) EQ 0) THEN ref_text=' '
69IF (N_ELEMENTS(REF_MAG) EQ 0) THEN BEGIN
70  maxmag=MAX(ABS(SQRT(u^2.+v^2.)))
71ENDIF ELSE BEGIN
72  maxmag=ref_mag
73ENDELSE
74
75;Setup the plot area if undefined
76IF (NOT KEYWORD_SET(overplot)) THEN BEGIN
77  xs=x[0]-(x(1)-x(0))
78  xf=x[N_ELEMENTS(x)-1]+(x(1)-x(0))
79  ys=y[0]-(y(1)-y(0))
80  yf=y[N_ELEMENTS(y)-1]+(y(1)-y(0)) 
81  PLOT,[xs,xf],[ys,yf], XSTYLE=1, YSTYLE=1, /NODATA,$
82       COLOR=color, _EXTRA = extra
83ENDIF
84
85;Do stride data reduction if needed     
86IF (stride GT 1) THEN BEGIN
87  mypts=FLTARR(a[1], a[2])
88  mypts[*,*]=0.0           
89  FOR iy=0,a[2]-1,stride DO BEGIN
90  FOR ix=0,a[1]-1,stride DO BEGIN
91    IF ( ((ix/stride) EQ FIX(ix/stride)) AND $
92         ((iy/stride) EQ FIX(iy/stride)) ) THEN mypts[ix,iy]=1.0
93  ENDFOR
94  ENDFOR
95  pts=WHERE(mypts LT 1.0)
96  u[pts]=0.0
97  v[pts]=0.0
98ENDIF
99
100;Main vector plotting loop
101FOR ix=0, N_ELEMENTS(x)-1 DO BEGIN
102FOR iy=0, N_ELEMENTS(y)-1 DO BEGIN
103  PLOT_VECTOR, u(ix,iy), v(ix,iy), x(ix), y(iy), type=type, $
104               angle=angle, head_len=head_len,$
105               maxmag=maxmag, align=align, length=length,$
106               color=color, cstyle=0
107ENDFOR
108ENDFOR
109
110;Plot a reference vector if requested
111IF (N_ELEMENTS(REF_POS) NE 0) THEN BEGIN
112  PLOT_VECTOR, maxmag, 0.0, ref_pos[0], ref_pos[1], type=type, $
113               angle=angle, ref_text=ref_text, head_len=head_len,$
114               maxmag=maxmag, align=align, length=length,$
115               color=color, cstyle=1
116ENDIF
117
118END
119
Note: See TracBrowser for help on using the repository browser.