source: trunk/SRC/ToBeReviewed/PLOTS/VECTEUR/ajoutvect.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: 9.6 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Overprint vectors in a field traced by plt.
8;
9; @categories
10; Graphics
11;
12; @param VECTEUR {in}{required}{type=vector}
13; It is a structure with 2 elements containing we 2 matrices U and V of
14; values of the zonal and meridian component of the field of vectors to
15; be traced.
16;      For ex:
17;       vecteur={matriceu:lec('unsurface'),matricev:lec('vnsurface')}
18;       rq:the name of elements of  vector does not have any importance.
19;       vecteur={u:lec('unsurface'),v:lec('vnsurface')} goes well too.
20;
21; @keyword UNVECTSUR {type=scalar or array}
22; It is a scalar n or an array with 2 elements [n1,n2].
23; In the first case, we will trace a vector on n following x and y.
24; In the second case, we will trace a vector on n1 following x and a
25; vector n2 following n2
26;   Comments: To trace all vectors following y and one vector on two
27; following x, put unvectsur=[2,1]
28;
29; @keyword VECTMIN {in}{required}
30; Minimum norme of vectors to be traced
31;
32; @keyword VECTMAX {in}{required}
33; Maximum norme of vectors to be traced
34;
35; @keyword _EXTRA
36; Used to pass your keywords
37;
38; @uses
39; common.pro           
40;
41; @history
42; Sebastien Masson (smasson\@lodyc.jussieu.fr)
43;                       10/3/1999
44;                       11/6/1999 compatibilite avec NAN et la lecture
45;                       des structures.
46;
47; @version
48; $Id$
49;
50;-
51;------------------------------------------------------------
52;------------------------------------------------------------
53;------------------------------------------------------------
54pro ajoutvect,vecteur, vectlegende, UNVECTSUR=unvectsur,VECTMIN=vectmin, VECTMAX=vectmax, _EXTRA = ex
55;
56  compile_opt idl2, strictarrsubs
57;
58@common
59   tempsun = systime(1)         ; For key_performance
60;----------------------------------------------------------------------------
61;
62   u = litchamp(vecteur.(0))
63   u = checkfield(u, 'plt', TYPE = 'xy', /NOQUESTION)
64   v = litchamp(vecteur.(1))
65   v = checkfield(v, 'plt', TYPE = 'xy', /NOQUESTION)
66;-----------------------------------------------------------
67;-----------------------------------------------------------
68; We recuperate possible informations on fields
69;-----------------------------------------------------------
70   grilleu = litchamp(vecteur.(0), /grid)
71   if grilleu EQ '' then grilleu = 'U'
72   grillev = litchamp(vecteur.(1), /grid)
73   if grillev EQ '' then grillev = 'V'
74
75   IF grilleu EQ 'V' AND grillev EQ 'U' THEN inverse = 1
76   IF grilleu EQ grillev THEN interpolle  = 0 ELSE interpolle = 1
77   if keyword_set(inverse) then begin
78      rien = u
79      u = v
80      v = rien
81   endif
82;------------------------------------------------------------
83; We find common points between u and v
84;------------------------------------------------------------
85   if interpolle then begin
86      indicexu = (lindgen(jpi))[firstxu:firstxu+nxu-1]
87      indicexv = (lindgen(jpi))[firstxv:firstxv+nxv-1]
88      indicex = inter(indicexu, indicexv)
89      indiceyu = (lindgen(jpj))[firstyu:firstyu+nyu-1]
90      indiceyv = (lindgen(jpj))[firstyv:firstyv+nyv-1]
91      indicey = inter(indiceyu, indiceyv)
92      nx = n_elements(indicex)
93      ny = n_elements(indicey)
94      indice2d = lindgen(jpi, jpj)
95      indice2d = indice2d[indicex[0]:indicex[0]+nx-1,indicey[0]:indicey[0]+ny-1]
96;------------------------------------------------------------
97; extraction of u and v on the appropriated domain
98;------------------------------------------------------------
99      case 1 of
100         (size(u))[0] NE 2 OR (size(v))[0] NE 2: return
101         (size(u))[1] EQ nxu AND (size(u))[2] EQ nyu AND $
102          (size(v))[1] EQ nxv AND (size(v))[2] EQ nyv:BEGIN
103            if nxu NE nx then $
104             if indicex[0] EQ firstxu then u = u[0:nx-1, *] ELSE u = u[1: nx, *]
105            IF nxv NE nx THEN $
106             if indicex[0] EQ firstxv then v = v[0:nx-1, *] ELSE v = v[1: nx, *]
107            IF nyu NE ny THEN $
108             if indicey[0] EQ firstyu then u = u[*, 0:ny-1] ELSE u = u[*, 1: ny]
109            IF nyv NE ny THEN $
110             if indicey[0] EQ firstyv then v = v[*, 0:ny-1] ELSE v = v[*, 1: ny]
111         END
112         (size(u))[1] EQ jpi AND (size(u))[2] EQ jpj AND $
113          (size(v))[1] EQ jpi AND (size(v))[2] EQ jpj:BEGIN
114            u = u[indice2d]
115            v = v[indice2d]
116         END
117         ELSE:BEGIN
118            ras = report('problemes d''adequation entre la taille du domaine et la taille des matrices necessaires a tracer des vecteurs')
119            return
120         end
121      endcase
122;------------------------------------------------------------------
123; We reshape u and v to make sure that none dimension has been erased.
124;------------------------------------------------------------------
125      if ny EQ 1 then begin
126         u = reform(u, nx, ny)
127         v = reform(v, nx, ny)
128      endif
129;------------------------------------------------------------------
130; construction of u and v at points T
131;-----------------------------------------------------------
132      a=u[0,*]
133      u=(u+shift(u,1,0))/2.
134      if NOT keyword_set(key_periodic) OR nx NE jpi then u[0,*]=a
135      a=v[*,0]
136      v=(v+shift(v,0,1))/2.
137      if NOT keyword_set(key_periodic) OR nx NE jpi then v[*,0]=a
138;----------------------------------------------------------------------------
139; attribution of the mask and of longitude and latitude arrays.
140; We recuperate the complete grid to establish a big mask extensive
141; in the four directions to cover points for which a land point has
142; been considerated (do a small drawing)
143;----------------------------------------------------------------------------
144      vargrid='T'
145      msku = (umask())[indice2d+jpi*jpj*firstzt]
146      mskv = (vmask())[indice2d+jpi*jpj*firstzt]
147      glam = glamt[indice2d]
148      gphi = gphit[indice2d]
149      if ny EQ 1 then begin
150         msku = reform(msku, nx, ny)
151         mskv = reform(mskv, nx, ny)
152;          glam = reform(glam, nx, ny)
153;          gphi = reform(gphi, nx, ny)
154      endif
155;-----------------------------------------------------------
156; We mask u and v et v the long of coasts (the place where we
157; can not calculate the average)
158;-----------------------------------------------------------
159; extention of the mask
160      u = u*msku*shift(msku,1,0)
161      v = v*mskv*shift(mskv,0,1)
162   ENDIF ELSE BEGIN
163      u = u*tmask[firstxt:lastxt,firstyt:lastyt,firstzt]
164      v = v*tmask[firstxt:lastxt,firstyt:lastyt,firstzt]
165      indice2d = lindgen(jpi, jpj)
166      indice2d = indice2d[firstxt:lastxt, firstyt:lastyt]
167      nx = nxt
168      ny = nyt
169   endelse
170   tabnorme=sqrt(u^2+v^2)
171   nan = where(finite(u, /nan) EQ 1)
172   if nan[0] NE -1 then u[nan] = 1e5
173   nan = where(finite(v, /nan) EQ 1)
174   if nan[0] NE -1 then v[nan] = 1e5
175   if keyword_set(vectmin) then BEGIN
176      toosmall=where(tabnorme lt vectmin)
177      if toosmall[0] NE -1 then begin
178         u[toosmall] = 1e5
179         v[toosmall] = 1e5
180      ENDIF
181   endif
182   if keyword_set(vectmax) then BEGIN
183      toobig=where(tabnorme gt vectmax)
184      if toobig[0] NE -1 then begin
185         u[toobig] = 1e5
186         v[toobig] = 1e5
187      ENDIF
188   ENDIF
189;-----------------------------------------------------------
190; Put back of a big value on all points for which we can do the calculation.
191;-----------------------------------------------------------
192   if interpolle then t2 = msku*shift(msku,1,0)*mskv*shift(mskv,0,1) $
193   ELSE t2 = tmask[firstxt:lastxt,firstyt:lastyt,firstzt]
194   if NOT keyword_set(key_periodic) OR nx NE jpi then t2[0, *]=0.
195   t2[*,0]=0.
196   terre=where(t2 eq 0)
197   if terre[0] ne -1 then begin
198      u[terre]=1e5
199      v[terre]=1e5
200   ENDIF
201;-----------------------------------------------------------
202; trace only one vector one two
203;-----------------------------------------------------------
204   if keyword_set(unvectsur) then BEGIN ;
205; indx is a vector containing number of columns to be selected.
206; indy is a vector containing number of lines to be selected.
207      if n_elements(unvectsur) EQ 1 then begin
208         indx = where((lindgen(nx) MOD unvectsur[0]) eq 0)
209         indy = where((lindgen(ny) MOD unvectsur[0]) eq 0)
210      ENDIF ELSE BEGIN
211         indx = where((lindgen(nx) MOD unvectsur[0]) eq 0)
212         indy = where((lindgen(ny) MOD unvectsur[1]) eq 0)
213     ENDELSE
214; From indx and indy, we will construct an array which will give indexes
215; of intersections points of columns specified by indx.
216      indicereduit = indx#replicate(1,n_elements(indy))+nx*replicate(1,n_elements(indx))#indy
217; We reduce arrays which will be passed to vecteur.
218      u = u[indicereduit]
219      v = v[indicereduit]
220      tabnorme = tabnorme[indicereduit]
221;
222   endif
223;-----------------------------------------------------------
224;
225;-----------------------------------------------------------
226   if keyword_set(inverse) then begin
227      rien = u
228      u = v
229      v = rien
230   endif
231;-----------------------------------------------------------
232; Drawing of vectors.
233;----------------------------------------------------------
234   vecteur, u, v, tabnorme, indice2d, indicereduit, missing=1e5, _extra = ex
235;-----------------------------------------------------------
236; We complete the caption.
237;-----------------------------------------------------------
238   if terre[0] ne -1 then mini = min(tabnorme[where(t2 eq 1)], max = maxi, /nan) $
239   ELSE mini = min(tabnorme, max = maxi, /nan)
240   
241   if litchamp(vecteur.(0), /u) NE '' then $
242    vectlegende = {minmax:[mini, maxi], unite:litchamp(vecteur.(0), /u)} $
243   ELSE vectlegende = {minmax:[mini, maxi], unite:varunit}
244
245
246sortie:
247   if keyword_set(key_performance) NE 0 THEN print, 'temps ajoutvect', systime(1)-tempsun
248   return
249end
250
251
Note: See TracBrowser for help on using the repository browser.