Changeset 432 for trunk/SRC/ToBeReviewed


Ignore:
Timestamp:
05/14/10 12:11:28 (14 years ago)
Author:
smasson
Message:

add VECTNORMCOLOR keyword

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/ToBeReviewed/PLOTS/VECTEUR/vecteur.pro

    r370 r432  
    134134; The color of the arrow. Black by default (color 0) 
    135135; 
     136; @keyword VECTNORMCOLOR 
     137; a 2 elements vector used to specify the color of the vector according to 
     138; its norm. Vector norm will be scaled to color numbers (1 to 254) by using 
     139; the following rule: VECTNORMCOLOR[0] corresponds to 1 and VECTNORMCOLOR[1] to 254 
     140; 
    136141; @keyword VECTTHICK {default=1} 
    137142; The thick of the arrow. 
     
    169174;- 
    170175PRO 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             , CMREF = cmref, MISSING = missing, NORMEREF = normeref $ 
     177             , VECTCOLOR = vectcolor, VECTTHICK = vectthick $ 
     178             , VECTREFPOS = vectrefpos, VECTNORMCOLOR = vectnormcolor $ 
     179             , VECTREFFORMAT = vectrefformat, NOVECTREF = novectref $ 
     180             , _EXTRA = extra 
    176181; 
    177182  compile_opt idl2, strictarrsubs 
    178183; 
    179184@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 
     185  tempsun = systime(1)          ; For key_performance 
     186; 
     187; 
     188  taille = size(composanteu) 
     189  nx = taille[1] 
     190  ny = taille[2] 
     191  if n_elements(reduitindice2d) EQ 0 then reduitindice2d = lindgen(nx, ny) 
     192  zu = composanteu 
     193  zv = composantev 
     194  norme = normevecteur 
     195  taille = size(indice2d) 
     196  nxgd = taille[1] 
     197  nygd = taille[2] 
     198; 
     199  msk = replicate(1, nx, ny) 
     200  if keyword_set(missing) then terre = where(abs(zu) GE missing/10) ELSE terre = -1 
     201  if terre[0] NE -1  then BEGIN 
     202    msk[terre] = 0 
     203    zu[terre] = 0 
     204    zv[terre] = 0 
     205    norme[terre] = 0 
     206  ENDIF 
    202207; 
    203208; Stage 1: 
     
    246251; 
    247252; coordinates of the point T (beginning of the arrow) in spherical coordinates. 
    248    glam = glamt[indice2d[reduitindice2d]] 
    249    gphi = gphit[indice2d[reduitindice2d]] 
     253  glam = glamt[indice2d[reduitindice2d]] 
     254  gphi = gphit[indice2d[reduitindice2d]] 
    250255; 
    251256; Coordinates of the point T (beginning of the arrow) in the cartesian reference. 
    252257; For the sphere, we use a sphere with a radius of 1. 
    253258; 
    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) 
     259  radius = replicate(1, nx*ny) 
     260  coord_sphe = transpose([ [glam[*]], [gphi[*]], [radius[*]] ]) 
     261  r = cv_coord(from_sphere = coord_sphe, /to_rect, /degrees) 
     262; 
     263  x0 = reform(r[0, *], nx, ny) 
     264  y0 = reform(r[1, *], nx, ny) 
     265  z0 = reform(r[2, *], nx, ny) 
    261266; 
    262267; Stage 1, b) 
     
    270275; 
    271276; definition of nu 
    272    radius = replicate(1,nxgd*nygd) 
    273    IF finite(glamu[0]*gphiu[0]) NE 0 THEN $ 
     277  radius = replicate(1, nxgd*nygd) 
     278  IF finite(glamu[0]*gphiu[0]) NE 0 THEN $ 
    274279     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) 
     280  ELSE coord_sphe = transpose([ [(glamf[indice2d])[*]], [(gphit[indice2d])[*]], [radius[*]] ]) 
     281  r = cv_coord(from_sphere = coord_sphe, /to_rect, /degrees) 
    277282; 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) 
     283  ux = reform(r[0, *], nxgd, nygd) 
     284  uy = reform(r[1, *], nxgd, nygd) 
     285  uz = reform(r[2, *], nxgd, nygd) 
    281286; calculation of nu 
    282    nux = ux-shift(ux, 1, 0) 
    283    nuy = uy-shift(uy, 1, 0) 
    284    nuz = uz-shift(uz, 1, 0) 
     287  nux = ux-shift(ux, 1, 0) 
     288  nuy = uy-shift(uy, 1, 0) 
     289  nuz = uz-shift(uz, 1, 0) 
    285290; 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  if NOT keyword_set(key_periodic) OR nxgd NE jpi then begin 
     292    nux[0, *] = nux[1, *] 
     293    nuy[0, *] = nuy[1, *] 
     294    nuz[0, *] = nuz[1, *] 
     295  ENDIF 
    291296; reduction of the grid 
    292    nux = nux[reduitindice2d] 
    293    nuy = nuy[reduitindice2d] 
    294    nuz = nuz[reduitindice2d] 
     297  nux = nux[reduitindice2d] 
     298  nuy = nuy[reduitindice2d] 
     299  nuz = nuz[reduitindice2d] 
    295300; 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) 
     301  IF finite(glamv[0]*gphiv[0]) NE 0 THEN $ 
     302     coord_sphe = transpose([ [(glamv[indice2d])[*]], [(gphiv[indice2d])[*]], [radius[*]] ]) $ 
     303  ELSE coord_sphe = transpose([ [(glamt[indice2d])[*]], [(gphif[indice2d])[*]], [radius[*]] ]) 
     304  r = cv_coord(from_sphere = coord_sphe, /to_rect, /degrees) 
    300305; 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) 
     306  vx = reform(r[0, *], nxgd, nygd) 
     307  vy = reform(r[1, *], nxgd, nygd) 
     308  vz = reform(r[2, *], nxgd, nygd) 
    304309; calcul of nv 
    305    nvx = vx-shift(vx, 0, 1) 
    306    nvy = vy-shift(vy, 0, 1) 
    307    nvz = vz-shift(vz, 0, 1) 
     310  nvx = vx-shift(vx, 0, 1) 
     311  nvy = vy-shift(vy, 0, 1) 
     312  nvz = vz-shift(vz, 0, 1) 
    308313; conditions at extremities 
    309    nvx[*, 0] = nvx[*, 1] 
    310    nvy[*, 0] = nvy[*, 1] 
    311    nvz[*, 0] = nvz[*, 1] 
     314  nvx[*, 0] = nvx[*, 1] 
     315  nvy[*, 0] = nvy[*, 1] 
     316  nvz[*, 0] = nvz[*, 1] 
    312317; reduction of the grid 
    313    nvx = nvx[reduitindice2d] 
    314    nvy = nvy[reduitindice2d] 
    315    nvz = nvz[reduitindice2d] 
     318  nvx = nvx[reduitindice2d] 
     319  nvy = nvy[reduitindice2d] 
     320  nvz = nvz[reduitindice2d] 
    316321; 
    317322; normalization 
    318323; 
    319    normalise, nux, nuy, nuz 
    320    normalise, nvx, nvy, nvz 
     324  normalise, nux, nuy, nuz 
     325  normalise, nvx, nvy, nvz 
    321326; 
    322327; Stage 1, c) 
     
    324329; coordinates of the vector V in the cartesian reference 
    325330; 
    326    direcx = zu*nux + zv*nvx 
    327    direcy = zu*nuy + zv*nvy 
    328    direcz = zu*nuz + zv*nvz 
     331  direcx = zu*nux + zv*nvx 
     332  direcy = zu*nuy + zv*nvy 
     333  direcz = zu*nuz + zv*nvz 
    329334; normalization of the vector V 
    330    normalise, direcx, direcy, direcz 
     335  normalise, direcx, direcy, direcz 
    331336; on divide by 100 
    332    direcx = direcx/100. 
    333    direcy = direcy/100. 
    334    direcz = direcz/100. 
     337  direcx = direcx/100. 
     338  direcy = direcy/100. 
     339  direcz = direcz/100. 
    335340; 
    336341; Stage 1, d) 
    337342; coordinates of the point of the arrow in the cartesian reference. 
    338343 
    339    x1 = x0 + direcx 
    340    y1 = y0 + direcy 
    341    z1 = z0 + direcz 
     344  x1 = x0 + direcx 
     345  y1 = y0 + direcy 
     346  z1 = z0 + direcz 
    342347 
    343348; coordinates of the point of the arrow in spherical coordinates. 
    344349 
    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) 
     350  coord_rect = transpose([ [x1[*]], [y1[*]], [z1[*]] ]) 
     351  r = cv_coord(from_rect = coord_rect, /to_sphere, /degrees) 
     352  glam1 = reform(r[0, *], nx, ny) 
     353  gphi1 = reform(r[1, *], nx, ny) 
    349354 
    350355; 
     
    355360; we modify it 
    356361; 
    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. 
     362  ind = where(glam1 LT !x.range[0] AND glam1+360. LE !x.range[1]) 
     363  if ind[0] NE -1 then glam1[ind] = glam1[ind]+360. 
     364  ind = where(glam1 GT !x.range[1] AND glam1-360. GE !x.range[0]) 
     365  if ind[0] NE -1 then glam1[ind] = glam1[ind]-360. 
     366 
     367  ind = where(glam LT !x.range[0] AND glam+360. LE !x.range[1]) 
     368  if ind[0] NE -1 then glam[ind] = glam[ind]+360. 
     369  ind = where(glam  GT !x.range[1] AND glam-360. GE !x.range[0]) 
     370  if ind[0] NE -1 then glam[ind] = glam[ind]-360. 
    366371; 
    367372; 
    368373; Stage 1, e) 
    369374; 
    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, *]                 ; 
     375  r = convert_coord(glam, gphi, /data, /to_normal) 
     376  x0 = r[0, *]                  ; normal coordinates of the beginning of the array. 
     377  y0 = r[1, *]                  ; 
     378 
     379  r = convert_coord(glam1, gphi1, /data, /to_normal) 
     380  x1 = r[0, *]                  ; normal coordinates of the ending of the array (Before scaling). 
     381  y1 = r[1, *]                  ; 
    377382; 
    378383; tests to avoid that arrows be drawing out of the domain. 
    379384; 
    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 
     385  out = where(x0 LT !p.position[0] OR x0 GT !p.position[2]  $ 
     386              OR y0 LT !p.position[1] OR y0 GT !p.position[3]) 
     387  if out[0] NE -1 THEN x0[out] = !values.f_nan 
    383388; 
    384389; Following projections, there may are points at NaN when we pass in normal coordinates. 
    385390; We delete these points. 
    386391; 
    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 ; 
     392  nan = finite(x0*y0*x1*y1) 
     393  number = where(nan EQ 1) 
     394  x0 = x0[number] & x1 = x1[number] 
     395  y0 = y0[number] & y1 = y1[number] 
     396  msk = msk[number] 
     397  norme = norme[number] 
     398; 
     399  points = where(msk EQ 1) 
     400  IF points[0] NE -1 THEN BEGIN  
     401 
     402  x0 = x0[points] & x1 = x1[points] 
     403  y0 = y0[points] & y1 = y1[points] 
     404  msk = msk[points] 
     405  norme = norme[points] 
     406 
    394407; We define the vector direction in the normalize reference. 
    395408; 
    396    dirx = x1-x0 
    397    diry = y1-y0 
     409    dirx = x1-x0 
     410    diry = y1-y0 
    398411; 
    399412;We pass in polar coordinates to recuperate the angle which wasb the goal of all the first stage!!! 
    400413; 
    401  
    402    dirpol = cv_coord(from_rect = transpose([ [dirx[*]], [diry[*]] ]), /to_polar) 
    403    dirpol = msk*dirpol[0, *] 
     414    dirpol = cv_coord(from_rect = transpose([ [dirx[*]], [diry[*]] ]), /to_polar) 
     415    dirpol = msk*dirpol[0, *] 
    404416; 
    405417; Stage 2 
     
    409421; Automatic putting at the scale 
    410422; 
    411    if NOT keyword_set(cmref) then BEGIN 
     423    if NOT keyword_set(cmref) then BEGIN 
    412424      mipgsz = min(page_size, max = mapgsz) 
    413425      sizexfeuille = mipgsz*key_portrait+mapgsz*(1-key_portrait) 
     
    415427      cmref = 5 > floor(sizexfeuille/10.) < 15 
    416428      cmref = cmref/10. 
    417    ENDIF 
    418    if NOT keyword_set(normeref) then BEGIN 
     429    ENDIF 
     430    if NOT keyword_set(normeref) then BEGIN 
    419431      value = max(norme) 
    420432      puissance10 = 10.^floor(alog10(value)) 
    421433      normeref = puissance10*floor(value/puissance10) 
    422    endif 
    423    cm = 1.*normeref/cmref 
     434    endif 
     435    cm = 1.*normeref/cmref 
    424436; 
    425437; 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 
     438; by a line of lenght 1 cm on the paper. Norme contains the norm of vectors 
    427439; we want to draw. 
    428440; 
    429    norme = 1/(1.*cm)*norme*cv_cm2normal(dirpol) 
    430 ; 
     441; define colors before norme is changed... 
     442    IF NOT KEYWORD_SET(vectcolor) THEN vectcolor = 0 
     443    IF keyword_set(vectnormcolor) THEN BEGIN  
     444      mp = projsegment([vectnormcolor], [1, 254], /mp) 
     445      colors = byte(round(mp[0] * norme +  mp[1] )) 
     446    ENDIF ELSE colors = byte(vectcolor) 
     447; 
     448    norme = 1/(1.*cm)*norme*cv_cm2normal(dirpol) 
    431449; 
    432450; Stage 3 
    433 ; Now that we have the angle and the norme, we recuperate coordinates in 
     451; Now that we have the angle and the norm, we recuperate coordinates in 
    434452; rectangular and we draw arrows. 
    435453; 
    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 
     454    r = cv_coord(from_polar = transpose([ [dirpol[*]], [norme[*]] ]), /to_rect) 
     455    composantex = r[0, *] 
     456    composantey = r[1, *] 
     457; 
     458    x1 = x0+composantex 
     459    y1 = y0+composantey 
    442460; 
    443461; Drawing 
    444462; 
    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 
     463    points = where(msk EQ 1) 
     464    IF n_elements(colors) GT 1 THEN BEGIN 
     465      FOR i = 0, n_elements(colors)-1 DO arrow, x0[i], y0[i], x1[i], y1[i], /norm, hsize = -.2, COLOR = colors[i], THICK = vectthick 
     466    ENDIF ELSE arrow, x0, y0, x1, y1, /norm, hsize = -.2, COLOR = colors, THICK = vectthick 
    450467; 
    451468;  Draw an arrow at the right bottom of the drawing as a caption. 
    452469; 
    453    if NOT keyword_set(novectref) then BEGIN 
     470    if NOT keyword_set(novectref) then BEGIN 
    454471      dx = cmref*cv_cm2normal(0) ; Length of the vector of reference in normalized coordinates. 
    455472      if keyword_set(vectrefformat) then $ 
    456        normelegende = strtrim(string(normeref, format = vectrefformat), 1)+' ' $ 
     473         normelegende = strtrim(string(normeref, format = vectrefformat), 1)+' ' $ 
    457474      ELSE normelegende = strtrim(normeref, 1)+' ' 
    458475; 
    459476      if keyword_set(vectrefpos) then begin 
    460          r = convert_coord(vectrefpos,/data, /to_normal) 
    461          x0 = r[0] 
    462          y0 = r[1] 
     477        r = convert_coord(vectrefpos, /data, /to_normal) 
     478        x0 = r[0] 
     479        y0 = r[1] 
    463480      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 
     481        x0 = !x.window[1]-dx 
     482        r = convert_coord(!d.x_ch_size, !d.y_ch_size, /device, /to_normal) 
     483        dy = 3*r[1]*!p.charsize 
     484        y0 = !y.window[0]-dy 
    468485      ENDELSE 
    469486 
     
    471488      xyouts, x0, y0, normelegende, /norm, align = 1, charsize = !p.charsize, color = 0 
    472489 
    473    endif 
    474 ; 
    475 ; 
    476  
    477    if keyword_set(key_performance) NE 0 THEN print, 'temps vecteur', systime(1)-tempsun 
     490    endif 
     491  endif 
     492; 
     493; 
     494 
     495  if keyword_set(key_performance) NE 0 THEN print, 'temps vecteur', systime(1)-tempsun 
    478496;------------------------------------------------------------ 
    479497;------------------------------------------------------------ 
    480    return 
     498  return 
    481499END 
    482500 
Note: See TracChangeset for help on using the changeset viewer.