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

Last change on this file since 327 was 327, checked in by pinsard, 16 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

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