source: trunk/SRC/ToBeReviewed/GRILLE/tracegrille.pro @ 279

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

typo and links in header in some pro files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1;+
2;
3; @file_comments
4; Draw the grid
5;
6; @categories
7; Grid
8;
9; @param GLAMIN {in}{optional}{type=1d or 2d array}{default=glam specified by vargrid, on the domain defined by <pro>domdef</pro>}
10; Longitude of points of the grid.
11;
12; @param GPHIIN {in}{optional}{type=1d or 2d array}{default=gphi specified by vargrid, on the domain defined by <pro>domdef</pro>}
13; Latitude of points of the grid.
14;
15; @keyword XSTRIDE {type=integer}{default=1}
16; It specify that we want to trace only one line of
17; constant i every xstride points
18;
19; @keyword YSTRIDE {type=integer}{default=1}
20; It specify that we want to trace only one line of
21; constant j every xstride points
22;
23; @keyword OCEAN
24; To trace the grid only on ocean points.
25;
26; @keyword EARTH
27; To trace the grid only on land points.
28;
29; @keyword RMOUT
30; Select to remove all cell having one corner out of the
31; plot boundaries (!x.range, !y.range)
32;
33; @keyword _EXTRA
34; Used to pass keywords
35;
36; @uses
37; common.pro
38;
39; @examples
40;
41;     IDL> plt,indgen(jpi,jpj),/nocontour,/nofill
42;     IDL> vargrid='T'
43;     IDL> tracegrille,/ocean,color=20
44;     IDL> tracegrille,/earth,color=80
45;
46;
47; @history
48; Sebastien Masson (smasson\@lodyc.jussieu.fr)
49;
50; @version
51; $Id$
52;
53;-
54;
55PRO tracegrille, glamin, gphiin, OCEAN = ocean, EARTH = earth $
56                 , XSTRIDE = xstride, YSTRIDE = ystride, RMOUT = rmout $
57                 , _EXTRA = extra
58;
59  compile_opt idl2, strictarrsubs
60;
61@cm_4mesh
62@cm_4data
63  IF NOT keyword_set(key_forgetold) THEN BEGIN
64@updatenew
65  ENDIF
66;---------------------------------------------------------
67  tempsun = systime(1)          ; For key_performance
68; to avoid warning message
69  oldexcept = !except
70  !except = 0
71  if n_elements(key_gridtype) EQ 0 then key_gridtype = 'c'
72;
73  if n_elements(glamin) * n_elements(gphiin) EQ 0 then BEGIN
74    grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz
75    IF keyword_set(ocean) AND strmid(key_gridtype, 0, 1) EQ 'c' THEN BEGIN
76; we reduce the mask to take into account the point located ON the coastline.
77      CASE vargrid OF
78        'U':BEGIN
79          mask = tmask[firstx:lastx, firsty:lasty]
80          IF NOT keyword_set(key_periodic) OR nx NE jpi $
81            THEN tmpx = mask[nx-1, *]
82          mask = (mask+shift(mask, -1, 0)) < 1
83          IF NOT keyword_set(key_periodic) OR nx NE jpi $
84            THEN mask[nx-1, *] = temporary(tmpx)
85        END
86        'V':BEGIN
87          mask = tmask[firstx:lastx, firsty:lasty]
88          tmpy = mask[*, ny-1]
89          mask = (mask+shift(mask, 0, -1)) < 1
90          mask[*, ny-1] = temporary(tmpy)
91        END
92        'F':BEGIN
93          mask = tmask[firstx:lastx, firsty:lasty]
94          IF NOT keyword_set(key_periodic) OR nx NE jpi $
95            THEN tmpx = mask[nx-1, *]
96          tmpy = mask[*, ny-1]
97          mask = (mask+shift(mask, -1, 0)+shift(mask, 0, -1)+shift(mask, -1, -1)) < 1
98          mask[*, ny-1] = temporary(tmpy)
99          IF NOT keyword_set(key_periodic) OR nx NE jpi $
100            THEN mask[nx-1, *] = temporary(tmpx)
101        END
102        ELSE:
103      ENDCASE
104    ENDIF
105  ENDIF ELSE BEGIN
106    glam = glamin
107    gphi = gphiin
108    IF (size(glam))[0] EQ 1 AND (size(gphi))[0] EQ 1 THEN BEGIN
109      nx = n_elements(glam)
110      ny = n_elements(gphi)
111      glam = glam#replicate(1, ny)
112      gphi = replicate(1, nx)#gphi
113    ENDIF ELSE BEGIN
114      nx = (size(glam))[1]
115      ny = (size(glam))[2]
116    ENDELSE
117  ENDELSE
118  if n_elements(mask) EQ 0 then mask = replicate(1b, nx, ny)
119  if (size(mask))[0] EQ 3 then mask = mask[*, *, 0]
120;
121  IF keyword_set(RMOUT) THEN BEGIN
122    out = where(glam GT max(!x.range) OR glam LT min(!x.range) $
123                OR gphi GT max(!y.range) OR gphi LT min(!y.range))
124    IF out[0] NE -1 THEN BEGIN
125      glam[out] = !values.f_nan
126      gphi[out] = !values.f_nan
127    ENDIF
128  ENDIF
129;
130  IF keyword_set(ocean) then BEGIN
131    earth = where(mask EQ 0)
132    if earth[0] NE -1 then begin
133      glam[earth] = !values.f_nan
134      gphi[earth] = !values.f_nan
135    ENDIF
136    earth = 0
137  ENDIF
138;
139  IF keyword_set(earth) THEN BEGIN
140    ocean = where(mask EQ 1)
141    if ocean[0] NE -1 then begin
142      glam[ocean] = !values.f_nan
143      gphi[ocean] = !values.f_nan
144    ENDIF
145    ocean = 0
146  ENDIF
147;
148  if NOT keyword_set(xstride) then xstride = 1
149  if NOT keyword_set(ystride) then ystride = 1
150  case strmid(key_gridtype, 0, 1) of
151    'c':BEGIN
152      for i = 0, ny-1, ystride do begin
153        plots,  glam[*, i], gphi[*, i], _extra = extra
154      endfor
155      for i = 0, nx-1, xstride do begin
156        plots,  glam[i, *], gphi[i, *], _extra = extra
157      endfor
158    END
159    'e':BEGIN
160      shifted = glam[0, 0] LT glam[0, 1]
161      glam2 = glam+(glam[1]-glam[0])/2.
162      if shifted then begin
163        for i = 0, ny-2 do BEGIN
164          xx = (transpose([[glam[*, i]], [glam2[*, i]]]))[*]
165          yy = (transpose([[gphi[*, i]], [gphi[*, i+1]]]))[*]
166          plots, xx[0:2*nx-2], yy[0:2*nx-2], _extra = extra
167        ENDFOR
168      ENDIF ELSE BEGIN
169        for i = 1, ny-1 do BEGIN
170          xx = (transpose([[glam[*, i]], [glam2[*, i]]]))[*]
171          yy = (transpose([[gphi[*, i]], [gphi[*, i-1]]]))[*]
172          plots, xx[0:2*nx-2], yy[0:2*nx-2], _extra = extra
173        ENDFOR
174      ENDELSE
175      for i = 1, (ny-1)/2 do $
176        plots, [glam[0, 2*i-1], glam[0, 2*i]] $
177        , [gphi[0, 2*i-1], gphi[0, 2*i]], _extra = extra
178      for i = 0, (ny-2)/2 do $
179        plots, [glam[nx-1, 2*i], glam[nx-1, 2*i+1]] $
180        , [gphi[nx-1, 2*i], gphi[nx-1, 2*i+1]], _extra = extra
181    END
182  endcase
183
184  if keyword_set(key_performance) THEN print, 'temps trace grille', systime(1)-tempsun
185  !except = oldexcept
186
187  return
188end
Note: See TracBrowser for help on using the repository browser.