source: trunk/SRC/ToBeReviewed/PLOTS/VECTEUR/vecteur.pro @ 297

Last change on this file since 297 was 297, checked in by pinsard, 17 years ago

typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.6 KB
Line 
1;+
2;
3; @file_comments
4;
5; @categories
6;
7; @param ANGLE
8;
9; @returns
10;
11; @restrictions
12;
13; @examples
14;
15; @history
16;
17; @version
18; $Id$
19;-
20;
21FUNCTION cv_cm2normal, angle
22;
23; Give the length in normal coordinates of a trait oriented of an angle
24; by rapport at the x axis and which must do 1 cm on the drawing.
25; Angle can be an array.
26;
27;
28;
29  compile_opt idl2, strictarrsubs
30;
31@common
32; What is the length in normal coordinates of a trait which will do 1 cm
33; on the paper an which is parallel to x?
34  mipgsz = min(page_size, max = mapgsz)
35   sizexfeuille = mipgsz*key_portrait+mapgsz*(1-key_portrait)
36   sizeyfeuille = mapgsz*key_portrait+mipgsz*(1-key_portrait)
37   cm_en_normal = 1./sizexfeuille
38;
39; If the aspect rapport of the window is not equal to 1, the length in
40; normalized coordinates of  a trait of 1 cm vary following the polar
41; angle of this trait.
42;
43   aspect = sizexfeuille/sizeyfeuille
44   cm_en_normal = cm_en_normal*sqrt( 1 +(aspect^2-1)*sin(angle)^2 )
45;
46   return, cm_en_normal
47END
48;
49;+
50;
51; @file_comments
52;
53; @categories
54;
55; @param U
56;
57; @param V
58;
59; @param W
60;
61; @restrictions
62;
63; @examples
64;
65; @history
66;
67; @version
68; $Id$
69;-
70;
71PRO normalise, u, v, w
72;
73; normalize the vector
74;
75;
76  compile_opt idl2, strictarrsubs
77;
78   IF n_elements(w) NE 0 THEN BEGIN
79      norme = sqrt(u^2.+v^2.+w^2.)
80      ind = where(norme NE 0)
81      u[ind] = u[ind]/norme[ind]
82      v[ind] = v[ind]/norme[ind]
83      w[ind] = w[ind]/norme[ind]
84   ENDIF ELSE BEGIN
85      norme = sqrt(u^2.+v^2.)
86      ind = where(norme NE 0)
87      u[ind] = u[ind]/norme[ind]
88      v[ind] = v[ind]/norme[ind]
89   ENDELSE
90END
91;
92;+
93;
94; @file_comments
95; Trace vectors (even if they are on a deformed grid) on any projection.
96; In this way, all vectors have a comparable norme on the drawing (to be
97; clear, a vector which measure 1 cm measure it, no matter the projection
98; and is position on the sphere).
99;
100; @categories
101; Graphics
102;
103; @param COMPOSANTEU {in}{required}
104; It is the u component of the vector to be traced. This 2d array has the
105; same dimension that reduitindice2d (see further)
106;
107; @param COMPOSANTEV {in}{required}
108; It is the v component of the vector to be traced. This 2d array has the
109; same dimension that reduitindice2d (see further)
110;
111; @param NORMEVECTEUR
112;
113;
114; @param INDICE2D  {in}{required}
115; It in an index allowing to to pass from an jpi or jpj array to the zoom
116; on which we do the drawing
117;
118; @param REDUITINDICE2D {in}{required}
119; It is an index allowing to pass from an array defined by indice2d to the
120; array for which we really have vectors to be traced (to be clear, it is
121; for example when we trace only one vector on two).
122;
123; @keyword CMREF {default=between .5 and 1.5 cm}
124; The length in cm that must measure the arrow normed normeref. By default,
125; it is adjusted to other drawing and included between .5 and 1.5 cm.
126;
127; @keyword MISSING
128; The value of a missing value. Do not use this keyword. Fixed at 1e5 by
129; ajoutvect.pro
130;
131; @keyword NORMEREF
132; The norme of the reference arrow.
133;
134; @keyword VECTCOLOR {default=0}
135; The color of the arrow. Black by default (color 0)
136;
137; @keyword VECTTHICK {default=1}
138; The thick of the arrow.
139;
140; @keyword VECTREFPOS
141; Vector composed of 2 elements specifying the position on DATA coordinates
142; from the beginning of the reference vector. By default at the right bottom
143; of the drawing.
144;
145; @keyword VECTREFFORMAT
146; The format to be used to specify the norme of the reference vector.
147;
148; @keyword NOVECTREF
149; To delete the display of the reference vector.
150;
151; @keyword _EXTRA
152; Used to pass keywords
153;
154; @uses
155; common.pro
156;
157; @history
158;  Creation : 13/02/98 G. Roullet (grlod\@lodyc.jussieu.fr)
159;  Modification : 14/01/99 realise la transformation
160;  spherique<->cartesien G. Roullet
161;                 12/03/99 verification de la routine G. Roullet
162;  8/11/1999:
163;  G. Roullet et Sebastien Masson (smasson\@lodyc.jussieu.fr)
164;  adaptation pour les zoom. reverification...traitement separe de la
165;  direction et de la norme des vecteurs. mots cles NORMEREF et CMREF.
166;
167; @version
168; $Id$
169;
170;-
171PRO vecteur, composanteu, composantev, normevecteur, indice2d, reduitindice2d $
172             , CMREF = cmref, MISSING = missing, NORMEREF = normeref $
173             , VECTCOLOR = vectcolor, VECTTHICK = vectthick, VECTREFPOS = vectrefpos $
174             , VECTREFFORMAT = vectrefformat, NOVECTREF = novectref, _EXTRA = extra
175;
176  compile_opt idl2, strictarrsubs
177;
178@common
179   tempsun = systime(1)         ; For key_performance
180;
181;
182   taille = size(composanteu)
183   nx = taille[1]
184   ny = taille[2]
185   if n_elements(reduitindice2d) EQ 0 then reduitindice2d = lindgen(nx, ny)
186   zu = composanteu
187   zv = composantev
188   norme = normevecteur
189   taille = size(indice2d)
190   nxgd = taille[1]
191   nygd = taille[2]
192;
193   msk = replicate(1, nx, ny)
194   if keyword_set(missing) then terre = where(abs(zu) GE missing/10) ELSE terre = -1
195   if terre[0] NE -1  then BEGIN
196      msk[terre] = 0
197      zu[terre] = 0
198      zv[terre] = 0
199      norme[terre] = 0
200   ENDIF
201;
202; Stage 1:
203;
204; Given that the directions and the sense that the vector has on the sphere,
205; we have to try to determinate this direction and the sense that the vector
206; will have on the screen once it will have been projected.
207;
208; In theory: on the sphere, a vector in a given point has for direction the
209; tangent at the circle passing by the center of the Earth and by the vector.
210; So, find the direction once the projection is done, it is find the tangent
211; to the curve representing the projection of the circle on the 2d plan at the
212; point representing the projection of the starting point of the sphere on the
213; 2d plan.
214;
215; In practice we do no know the definition of the curve given by the projection
216; of a circle so find its tangente in a point...
217;
218; What we do:
219; In a 3d cartesian reference,
220;       a) We find coordinates of the point T (starting of the arrow) situed
221;       on the sphere.
222;       b) To each point T, we determine local directions defined by the grid
223;       on this point and on which coordinates (u,v) of the vector refer to.
224;       These local directions are defined by gradients of glam and gphi. Once
225;       we have obtain these directions, we consider them like orthogonal and
226;       by norming them, we build an orthonormal reference (nu,nv) on which
227;       coordinates (u,v) of the vector refer to. In the starting 3d cartesian
228;       reference, the vector is defined by:
229;       V=u*nu+v*nv
230;       (where V, nu and nv are 3d vectors and u and v are scalars).
231;       c) To approximate the tangente to the circle by the chord defined by
232;       the beginning and the ending of the arrow, we will normalize V, and
233;       then divide it by 100.
234;       d) This allows us to determine coordinates of extremities of the chord
235;       in the 3d cartesian reference. We pass them in spherical coordinates in
236;       order to recuperate latitude and longitude position of these points on
237;       the sphere.
238;       e) We pass coordinates of these points in normalized coordinates, then
239;       in polar coordinates in order to find the angle and the direction they
240;       determine on the drawing.
241;
242;
243; Stage 1, a)
244;
245;
246; coordinates of the point T (beginning of the arrow) in spherical coordinates.
247   glam = glamt[indice2d[reduitindice2d]]
248   gphi = gphit[indice2d[reduitindice2d]]
249;
250; Coordinates of the point T (beginning of the arrow) in the cartesian reference.
251; For the sphere, we use a sphere with a radius of 1.
252;
253   radius = replicate(1,nx*ny)
254   coord_sphe = transpose([ [glam[*]], [gphi[*]], [radius[*]] ])
255   r = cv_coord(from_sphere=coord_sphe,/to_rect,/degrees)
256;
257   x0 = reform(r[0, *], nx, ny)
258   y0 = reform(r[1, *], nx, ny)
259   z0 = reform(r[2, *], nx, ny)
260;
261; Stage 1, b)
262;
263; Construction of a vector nu (resp. nv), vectr normed carried by the axis of
264; points u[i,j] and u[i-1,j] (resp v[i,j] and v[i,j-1]) which define, for each
265; point on the sphere, local directions associated with u and v. These vectors
266; define a local orthonormal reference.
267; These vectors are built in a cartesian reference (cv_coord). We have choose a
268; unity radius of the Earth (unit).
269;
270; definition of nu
271   radius = replicate(1,nxgd*nygd)
272   IF finite(glamu[0]*gphiu[0]) NE 0 THEN $
273     coord_sphe = transpose([ [(glamu[indice2d])[*]], [(gphiu[indice2d])[*]], [radius[*]] ]) $
274   ELSE coord_sphe = transpose([ [(glamf[indice2d])[*]], [(gphit[indice2d])[*]], [radius[*]] ])
275   r = cv_coord(from_sphere=coord_sphe,/to_rect,/degrees)
276; coordinates of points of the grid u in cartesian.
277   ux = reform(r[0, *], nxgd, nygd)
278   uy = reform(r[1, *], nxgd, nygd)
279   uz = reform(r[2, *], nxgd, nygd)
280; calculation of nu
281   nux = ux-shift(ux, 1, 0)
282   nuy = uy-shift(uy, 1, 0)
283   nuz = uz-shift(uz, 1, 0)
284; conditions at extremities.
285   if NOT keyword_set(key_periodic) OR nxgd NE jpi then begin
286      nux[0, *] = nux[1, *]
287      nuy[0, *] = nuy[1, *]
288      nuz[0, *] = nuz[1, *]
289   ENDIF
290; reduction of the grid
291   nux = nux[reduitindice2d]
292   nuy = nuy[reduitindice2d]
293   nuz = nuz[reduitindice2d]
294; definition of nv
295   IF finite(glamv[0]*gphiv[0]) NE 0 THEN $
296   coord_sphe = transpose([ [(glamv[indice2d])[*]], [(gphiv[indice2d])[*]], [radius[*]] ]) $
297   ELSE coord_sphe = transpose([ [(glamt[indice2d])[*]], [(gphif[indice2d])[*]], [radius[*]] ])
298   r = cv_coord(from_sphere=coord_sphe,/to_rect,/degrees)
299; coordinates of points of the grid in cartesian.
300   vx = reform(r[0, *], nxgd, nygd)
301   vy = reform(r[1, *], nxgd, nygd)
302   vz = reform(r[2, *], nxgd, nygd)
303; calcul of nv
304   nvx = vx-shift(vx, 0, 1)
305   nvy = vy-shift(vy, 0, 1)
306   nvz = vz-shift(vz, 0, 1)
307; conditions at extremities
308   nvx[*, 0] = nvx[*, 1]
309   nvy[*, 0] = nvy[*, 1]
310   nvz[*, 0] = nvz[*, 1]
311; reduction of the grid
312   nvx = nvx[reduitindice2d]
313   nvy = nvy[reduitindice2d]
314   nvz = nvz[reduitindice2d]
315;
316; normalization
317;
318   normalise, nux, nuy, nuz
319   normalise, nvx, nvy, nvz
320;
321; Stage 1, c)
322;
323; coordinates of the vector V in the cartesian reference
324;
325   direcx = zu*nux + zv*nvx
326   direcy = zu*nuy + zv*nvy
327   direcz = zu*nuz + zv*nvz
328; normalization of the vector V
329   normalise, direcx, direcy, direcz
330; on divide by 100
331   direcx = direcx/100.
332   direcy = direcy/100.
333   direcz = direcz/100.
334;
335; Stage 1, d)
336; coordinates of the point of the arrow in the cartesian reference.
337
338   x1 = x0 + direcx
339   y1 = y0 + direcy
340   z1 = z0 + direcz
341
342; coordinates of the point of the arrow in spherical coordinates.
343
344   coord_rect = transpose([ [x1[*]], [y1[*]], [z1[*]] ])
345   r = cv_coord(from_rect=coord_rect,/to_sphere,/degrees)
346   glam1 = reform(r[0, *], nx, ny)
347   gphi1 = reform(r[1, *], nx, ny)
348
349;
350; modification of glams. Everything take place at the level of the line
351; of changing of date... BEWARE, do not cut arrow which goes out of the
352; window!
353; test: If it goes out of the frame, but, thanks to +/- 360° it come in,
354; we modify it
355;
356   ind = where(glam1 LT !x.range[0] AND glam1+360. LE !x.range[1])
357   if ind[0] NE -1 then glam1[ind] = glam1[ind]+360.
358   ind = where(glam1 GT !x.range[1] AND glam1-360. GE !x.range[0])
359   if ind[0] NE -1 then glam1[ind] = glam1[ind]-360.
360
361   ind = where(glam LT !x.range[0] AND glam+360. LE !x.range[1])
362   if ind[0] NE -1 then glam[ind] = glam[ind]+360.
363   ind = where(glam  GT !x.range[1] AND glam-360. GE !x.range[0])
364   if ind[0] NE -1 then glam[ind] = glam[ind]-360.
365;
366;
367; Stage 1, e)
368;
369   r = convert_coord(glam,gphi,/data,/to_normal)
370   x0 = r[0, *]                 ; normal coordinates of the beginning of the array.
371   y0 = r[1, *]                 ;
372
373   r = convert_coord(glam1,gphi1,/data,/to_normal)
374   x1 = r[0, *]                 ; normal coordinates of the ending of the array (Before scaling).
375   y1 = r[1, *]                 ;
376;
377; tests to avoid that arrows be drawing out of the domain.
378;
379   out = where(x0 LT !p.position[0] OR x0 GT !p.position[2]  $
380               OR y0 LT !p.position[1] OR y0 GT !p.position[3])
381   if out[0] NE -1 THEN x0[out] = !values.f_nan
382;
383; Following projections, there may are points at NaN when we pass in normal coordinates.
384; We delete these points.
385;
386   nan = finite(x0*y0*x1*y1)
387   number = where(nan EQ 1)
388   x0 = x0[number] & x1 = x1[number]
389   y0 = y0[number] & y1 = y1[number]
390   msk = msk[number]
391   norme = norme[number]
392;
393; We define the vector direction in the normalize reference.
394;
395   dirx = x1-x0
396   diry = y1-y0
397;
398;We pass in polar coordinates to recuperate the angle which wasb the goal of all the first stage!!!
399;
400
401   dirpol = cv_coord(from_rect = transpose([ [dirx[*]], [diry[*]] ]), /to_polar)
402   dirpol = msk*dirpol[0, *]
403;
404; Stage 2
405;
406; Now we take care of the norme...
407;
408; Automatic putting at the scale
409;
410   if NOT keyword_set(cmref) then BEGIN
411      mipgsz = min(page_size, max = mapgsz)
412      sizexfeuille = mipgsz*key_portrait+mapgsz*(1-key_portrait)
413      sizexfeuille = 10.*sizexfeuille
414      cmref = 5 > floor(sizexfeuille/10.) < 15
415      cmref = cmref/10.
416   ENDIF
417   if NOT keyword_set(normeref) then BEGIN
418      value = max(norme)
419      puissance10 = 10.^floor(alog10(value))
420      normeref = puissance10*floor(value/puissance10)
421   endif
422   cm = 1.*normeref/cmref
423;
424; We modify the array norme to an element having the value cm be represented
425; by a trait of lenght 1 cm on the paper. Norme contain the norme of vectors
426; we want to draw.
427;
428   norme = 1/(1.*cm)*norme*cv_cm2normal(dirpol)
429;
430;
431; Stage 3
432; Now that we have the angle and the norme, we recuperate coordinates in
433; rectangular and we draw arrows.
434;
435   r = cv_coord(from_polar = transpose([ [dirpol[*]], [norme[*]] ]), /to_rect)
436   composantex = r[0, *]
437   composantey = r[1, *]
438;
439   x1 = x0+composantex
440   y1 = y0+composantey
441;
442; Drawing
443;
444   if NOT KEYWORD_SET(vectcolor) then vectcolor = 0
445
446   points = where(msk EQ 1)
447   IF points[0] NE -1 THEN arrow, x0[points], y0[points], x1[points], y1[points], /norm $
448    , hsize = -.2, COLOR = vectcolor, THICK = vectthick
449;
450;  Draw an arrow at the right bottom of the drawing as a caption.
451;
452   if NOT keyword_set(novectref) then BEGIN
453      dx = cmref*cv_cm2normal(0) ; Length of the vector of reference in normalized coordinates.
454      if keyword_set(vectrefformat) then $
455       normelegende = strtrim(string(normeref, format = vectrefformat), 1)+' ' $
456      ELSE normelegende = strtrim(normeref, 1)+' '
457;
458      if keyword_set(vectrefpos) then begin
459         r = convert_coord(vectrefpos,/data, /to_normal)
460         x0 = r[0]
461         y0 = r[1]
462      ENDIF ELSE BEGIN
463         x0 = !x.window[1]-dx
464         r = convert_coord(!d.x_ch_size, !d.y_ch_size, /device, /to_normal)
465         dy = 3*r[1]*!p.charsize
466         y0 = !y.window[0]-dy
467      ENDELSE
468
469      arrow, x0, y0, x0+dx, y0, /norm, hsize = -.2, color = 0
470      xyouts, x0, y0, normelegende, /norm, align = 1, charsize = !p.charsize, color = 0
471
472   endif
473;
474;
475
476   if keyword_set(key_performance) NE 0 THEN print, 'temps vecteur', systime(1)-tempsun
477;------------------------------------------------------------
478;------------------------------------------------------------
479   return
480END
481
482
483
484
Note: See TracBrowser for help on using the repository browser.