source: trunk/procs/mask_z.pro @ 203

Last change on this file since 203 was 203, checked in by pinsard, 14 years ago

remove trailing blanks

  • Property svn:keywords set to Id
File size: 12.0 KB
Line 
1;+
2;
3; mask zonal mean
4;
5; mask pltz data according to bathy or box
6;
7; @param FLD
8;
9; @param CMD {in}{required}{type=structure}
10; command line of window
11;
12; @param DIMPLOT {in}{required}{type=integer}
13; dimension of plot (1,2)
14;
15; @param LEGZ {out}{type=string}
16; @param BOITE_PLTZ {out}{type=1d array of integer}
17;
18; @examples
19; IDL> cmd={plt:'xy',var:''}
20; IDL> dimplot=1
21; IDL> mesh_type='oce'
22; IDL> splot=1
23; IDL> sig_min=20.
24; IDL> sig_max=28.
25; IDL> data_domain='global'
26; IDL> box_h=[20L,380L,-30L,30L]
27; IDL> msf_mean = 0
28; IDL> mask_z, fld, cmd, boite_pltz, dimplot, legz
29; IDL> print, boite_pltz,legz
30;          20         380         -30          30
31;
32; @uses
33; <pro>common</pro>
34; <propost_it>com_eg</propost_it>
35;
36; <propost_it>grep</propost_it>
37;
38; @todo
39; explication sur common oce, splot, sig_min, sig_max, data_domain, box_h, msf_mean
40;
41; ne plante pas si fld n'est pas défini
42;
43; @history
44;
45; - fplod 20091210T100350Z aedon.locean-ipsl.upmc.fr (Darwin)
46;
47;   * check parameters
48;
49; @version
50; $Id$
51;
52;-
53PRO mask_z, fld, cmd, boite_pltz, dimplot, legz
54;
55  compile_opt idl2, strictarrsubs
56;
57@common
58@com_eg
59;
60; Return to caller if errors
61 ON_ERROR, 2
62;
63 usage='mask_z, fld, cmd, boite_pltz, dimplot, legz'
64
65 arg_type = size(cmd,/type)
66 IF (arg_type NE 8) THEN BEGIN
67   ras = report(['Incorrect arg type cmd' $
68          + '!C' $
69          + 'Usage : ' + usage])
70    stop
71 ENDIF
72 arg_struct_tags=TAG_NAMES(cmd)
73 tag=WHERE(STRMATCH(arg_struct_tags, 'PLT'))
74 IF (tag EQ -1) THEN BEGIN
75   ras = report(['Incorrect arg tag PLT cmd' $
76          + '!C' $
77          + 'Usage : ' + usage])
78    stop
79 ENDIF
80
81 arg_type = size(cmd.plt,/type)
82 IF (arg_type NE 7) THEN BEGIN
83   ras = report(['Incorrect arg type cmd.plt' $
84          + '!C' $
85          + 'Usage : ' + usage])
86    stop
87 ENDIF
88
89 tag=WHERE(STRMATCH(arg_struct_tags, 'VAR'))
90 IF (tag EQ -1) THEN BEGIN
91   ras = report(['Incorrect arg tag VAR cmd' $
92          + '!C' $
93          + 'Usage : ' + usage])
94   stop
95 ENDIF
96 arg_type = size(cmd.var,/type)
97 IF (arg_type NE 7) THEN BEGIN
98   ras = report(['Incorrect arg type cmd.grid' $
99          + '!C' $
100          + 'Usage : ' + usage])
101   stop
102 ENDIF
103
104 arg_type = size(dimplot,/type)
105 IF ((arg_type NE 2) AND (arg_type NE 3)) THEN BEGIN
106   ras = report(['Incorrect arg type dimplot' $
107          + '!C' $
108          + 'Usage : ' + usage])
109   stop
110 ENDIF
111
112 common_type=size(mesh_type,/type)
113 IF (common_type NE 7) THEN BEGIN
114   ras = report(['Incorrect common type mesh_type' $
115          + '!C' $
116          + 'Usage : ' + usage])
117   stop
118 ENDIF
119
120 common_type=size(splot,/type)
121 IF (common_type NE 3) THEN BEGIN
122   ras = report(['Incorrect common type splot' $
123          + '!C' $
124          + 'Usage : ' + usage])
125   stop
126 ENDIF
127
128 common_type=size(sig_min,/type)
129 IF (common_type NE 4) THEN BEGIN
130   ras = report(['Incorrect common type sig_min' $
131          + '!C' $
132          + 'Usage : ' + usage])
133   stop
134 ENDIF
135
136 common_type=size(sig_max,/type)
137 IF (common_type NE 4) THEN BEGIN
138   ras = report(['Incorrect common type sig_max' $
139          + '!C' $
140          + 'Usage : ' + usage])
141   stop
142 ENDIF
143
144 common_type=size(data_domain,/type)
145 IF (common_type NE 7) THEN BEGIN
146   ras = report(['Incorrect common type data_domain' $
147          + '!C' $
148          + 'Usage : ' + usage])
149   stop
150 ENDIF
151
152 common_type=size(box_h,/type)
153 IF ((common_type NE 2) AND (common_type NE 3)) THEN BEGIN
154   ras = report(['Incorrect common type box_h' $
155          + '!C' $
156          + 'Usage : ' + usage])
157   stop
158 ENDIF
159 common_nelem=size(box_h,/n_elements)
160 IF (common_nelem NE 4) THEN BEGIN
161   ras = report(['Incorrect common n_elements box_h' $
162          + '!C' $
163          + 'Usage : ' + usage])
164   stop
165 ENDIF
166
167 common_type=size(msf_mean,/type)
168 IF (common_type NE 3) THEN BEGIN
169   ras = report(['Incorrect common type msf_mean' $
170          + '!C' $
171          + 'Usage : ' + usage])
172   stop
173 ENDIF
174
175
176   legz = ''
177
178   CASE mesh_type OF
179      'oce': BEGIN
180
181         IF splot EQ 1 THEN vertical_domain = [sig_min, sig_max] ELSE vertical_domain = [0, depth_z]
182
183         CASE data_domain OF
184            'equator': BEGIN
185               tmask[*, *, *] = 1
186               IF dimplot EQ 1 THEN boite_pltz = box_h
187               IF dimplot EQ 2 THEN boite_pltz = [box_h, vertical_domain]
188            END
189            'zonal': BEGIN
190                tmask[*, *, *] = 1
191                zbox = def_box(cmd.plt, dimplot, legz, time_stride)
192                boite_pltz = zbox
193                IF dimplot EQ 2 THEN BEGIN
194                   IF n_elements(boite_pltz) EQ 4 THEN boite_pltz = [zbox, vertical_domain]
195                ENDIF
196;               IF dimplot EQ 1 THEN boite_pltz = box_h
197;               IF dimplot EQ 2 THEN boite_pltz = [box_h,
198;               vertical_domain]
199                idxmsk=where(fld eq valmask)
200                IF idxmsk[0] ne -1 THEN BEGIN
201                    print, '     mask_z: building mask from fld valmask'
202                    IF (size(fld))[0] EQ 3 THEN BEGIN
203                        zmsk = fld[*,*,1] LT valmask/10.
204                    ENDIF ELSE BEGIN
205                        zmsk = fld LT valmask/10.
206                    ENDELSE
207                    tmask=reform(replicate(jpi,1)#zmsk[*],jpi,jpj,jpk,/overwrite)
208                ENDIF
209            END
210            ELSE: BEGIN
211               ; ORCA geographical domain
212               ; mask with medit
213               IF strlen(cmd.plt) EQ 2 THEN BEGIN
214                  IF cmd.var NE 'vozonbsf' THEN BEGIN
215                     IF (dimplot EQ 1 AND (size(fld))[0] EQ 2) $
216                      OR (dimplot EQ 2 AND (size(fld))[0] EQ 3) THEN BEGIN
217                        maskzm = 1-maskread('mediteranean', 'orca', /D3)
218                        print, '     [masking out mediteranean]'
219                        print, ' '
220                        tmask = tmask*maskzm
221                     ENDIF
222                     IF dimplot EQ 1 THEN boite_pltz = box_h
223                     IF dimplot EQ 2 THEN BEGIN
224                        CASE strmid(cmd.plt, 1, 1) OF
225                           't': boite_pltz = box_h
226                           ELSE : boite_pltz = [box_h, vertical_domain]
227                        ENDCASE
228                     ENDIF
229                  ENDIF ELSE BEGIN
230                     ; mask MSF as field=valmask
231                     idx=where (fld eq valmask)
232                     fld[idx] = !values.f_nan
233                     boite_pltz = [box_h, vertical_domain]
234                  ENDELSE
235               ENDIF ELSE BEGIN
236                  CASE strmid(cmd.plt, 0, 2) OF
237                  'xy': BEGIN & char = strmid(cmd.plt,3, 1) & ideb = 4 & END
238                  ELSE: BEGIN & char = strmid(cmd.plt,dimplot+1, 1) & ideb = dimplot+2 & END
239                  ENDCASE
240
241                  CASE char OF
242                     '#': BEGIN
243                                ; bathymetry mask for data
244                        stop
245                        bat_name = strmid(cmd.plt, ideb, strlen(cmd.plt)-ideb)
246                        full_name = grep('ls -al '+hom_idl+'grids | grep orca.'+bat_name+' | awk ''NR == 1 {print $0}''', ' ', 8)
247                        full_name = strmid(full_name, 5, 50)
248                        legz = full_name
249                        legbox = full_name
250                        IF cmd.var NE 'vozonbsf' THEN BEGIN
251                           maskzm = maskread(full_name, 'orca', /D3)
252                           tmask = tmask*maskzm
253                           IF dimplot EQ 1 THEN boite_pltz = box_h
254                           IF dimplot EQ 2 THEN BEGIN
255                              CASE strmid(cmd.plt, 1, 1) OF
256                                 't': boite_pltz = box_h
257                                 ELSE : boite_pltz = [box_h, vertical_domain]
258                              ENDCASE
259                           ENDIF
260                        ENDIF ELSE BEGIN
261                                ; mask MSF as field=valmask
262                           idx=where (fld eq valmask)
263                           fld[idx] = !values.f_nan
264                           boite_pltz = [box_h, vertical_domain]
265                        ENDELSE
266                     END
267;                        '@': BEGIN
268;                           ; density level
269;                        END
270                     ELSE: BEGIN
271                                ; mask in box
272                        zbox = def_box(cmd.plt, dimplot, legz, time_stride)
273                        boite_pltz = zbox
274                        IF dimplot EQ 2 THEN BEGIN
275                           CASE strmid(cmd.plt, 1, 1) OF
276                              't': boite_pltz = zbox
277                              ELSE : IF n_elements(boite_pltz) EQ 4 THEN boite_pltz = [zbox, vertical_domain]
278                           ENDCASE
279                        ENDIF
280                        IF dimplot EQ 1 THEN BEGIN
281                           CASE strmid(cmd.plt, 1, 1) OF
282                              't': boite_pltz = zbox
283                              ELSE : BEGIN
284                                 CASE strmid(cmd.plt, 0, 1) OF
285                                    'x': boite_pltz = zbox
286                                    'y': boite_pltz = zbox
287                                    ELSE: IF n_elements(boite_pltz) EQ 4 THEN boite_pltz = [zbox, vertical_domain]
288                                 ENDCASE
289                              END
290                           ENDCASE
291                        ENDIF
292                     END
293                  ENDCASE
294
295              ENDELSE
296               IF cmd.var EQ 'vozonbsf' AND msf_mean EQ 0 THEN BEGIN
297                   print, '     Mask_z special case for vozonbsf'
298                   idx = where(gphit EQ max(gphit))
299                   idx = idx MOD jpi
300                   print, idx[0]
301                   boite_pltz = [idx[0], idx[0], boite_pltz[2:5]]
302                   domdef, boite_pltz, /xindex ; indice pour x
303                   IF (size(fld))[0] EQ 3 THEN BEGIN
304                       tmask[idx[0], firstyt:lastyt, *] = fld[*,*,1] LT valmask/10.
305                   ENDIF ELSE BEGIN
306                       tmask[idx[0], firstyt:lastyt, *] = fld LT valmask/10.
307                   ENDELSE
308               ENDIF
309            END
310         ENDCASE
311      END
312      ELSE: BEGIN ; atmosphere or data
313
314;         IF masked_data EQ 0 THEN tmask[*] = 1
315         CASE strmid(cmd.plt, 0, 2) OF
316            'xy': BEGIN & char = strmid(cmd.plt,3, 1) & ideb = 4 & END
317            ELSE: BEGIN & char = strmid(cmd.plt,dimplot+1, 1) & ideb = dimplot+2 & END
318         ENDCASE
319
320
321         IF char EQ '#' THEN BEGIN
322                                ; mask from file
323            bat_name = strmid(cmd.plt, ideb, strlen(cmd.plt)-ideb)
324            full_name = grep('ls -al '+hom_idl+'grids | grep '+cmd.grid+'.'+bat_name+' | awk ''NR == 1 {print $0}''', ' ', 8)
325            full_name = strmid(full_name, strlen(cmd.grid)+1, 50)
326            legz = full_name
327            legbox = full_name
328            maskzm = maskread(full_name, cmd.grid)
329            maskzm = reverse(maskzm, 2)
330            maskzm = reform(maskzm, jpi*jpj)
331            tmask = reform(maskzm#replicate(1, jpk), jpi, jpj, jpk)
332            boite_pltz = box_h
333            IF dimplot EQ 2 THEN BEGIN
334               CASE strmid(cmd.plt, 1, 1) OF
335                  't': boite_pltz = box_h
336                  ELSE :  boite_pltz = [box_h, pres_min, pres_max ]
337               ENDCASE
338            ENDIF
339         ENDIF ELSE BEGIN
340           ; mask in box
341            IF masked_data EQ 0 THEN BEGIN
342               CASE atmos_msk OF
343               0: BEGIN & mskt = 'ALL points' & tmask[*] = 1 & END
344               1: BEGIN & mskt = 'ocean points only' & END
345               2: BEGIN & mskt = 'land points only' & tmask = 1-tmask & END
346               ENDCASE
347               print, '    Using ',mskt, ' (atmos_msk =', atmos_msk, ')'
348               print, ' '
349            ENDIF
350
351            zbox = def_box(cmd.plt, dimplot, legz, time_stride)
352            boite_pltz = zbox
353            prof1 = gdept[0]
354            prof2 = gdept[0]
355            IF dimplot EQ 2 THEN BEGIN
356               CASE strmid(cmd.plt, 1, 1) OF
357                  't': boite_pltz = zbox
358                  ELSE : IF n_elements(boite_pltz) EQ 4 THEN boite_pltz = [zbox, pres_min, pres_max]
359               ENDCASE
360            ENDIF
361         ENDELSE
362      END
363      ELSE:
364   ENDCASE
365END
Note: See TracBrowser for help on using the repository browser.