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