source: trunk/procs/def_grid.pro

Last change on this file was 213, checked in by ericg, 14 years ago

Initial debug of new headers by Eric

  • Property svn:keywords set to Id
File size: 14.6 KB
Line 
1;+
2;
3; define which grid to use and set corresponding arrays
4;
5; @param CMD {in}{required}{type=structure}
6; only cmd.exp, cmd.out, cmd.grid and cmd.var are used
7;
8; @examples
9;
10; IDL> cmd={exp:'HH',out:'-',grid:'umath',var:'temp_1'}
11; IDL> glamboundary_box=0L
12; IDL> box_h=[20L,380L,-30L,30L]
13; IDL> sw_diffg=1L
14; IDL> data_domain='global'
15; IDL> def_grid, cmd
16; IDL> help,cmd,/struct
17
18; @uses
19; <pro>common</pro>
20; <propost_it>com_eg</propost_it>
21;
22; @todo
23; get rid of spawn
24;
25; explication common glamboundary_box, box_h, sw_diffg, data_domain
26;
27; realistic example
28;
29; @history
30;
31; - fplod 20091209T094824Z aedon.locean-ipsl.upmc.fr (Darwin)
32;
33;   * check parameters
34;
35; @version
36; $Id$
37;
38;-
39PRO def_grid, cmd
40;
41  compile_opt idl2, strictarrsubs
42;
43@common
44@com_eg
45;
46; Return to caller if errors
47 ON_ERROR, 2
48;
49   IF debug_w THEN BEGIN
50    info = report('enter ...')
51    print, 'cmd =', cmd
52   ENDIF
53
54 usage='def_grid, cmd'
55;
56 nparam = N_PARAMS()
57 IF (nparam LT 1) THEN BEGIN
58    ras = report(['Incorrect number of arguments.' $
59          + '!C' $
60          + 'Usage : ' + usage])
61    stop
62 ENDIF
63 arg_type = size(cmd,/type)
64 IF (arg_type NE 8) THEN BEGIN
65   ras = report(['Incorrect arg type cmd' $
66          + '!C' $
67          + 'Usage : ' + usage])
68    stop
69 ENDIF
70 arg_struct_tags=TAG_NAMES(cmd)
71 tag=WHERE(STRMATCH(arg_struct_tags, 'EXP'))
72 IF (tag EQ -1) THEN BEGIN
73   ras = report(['Incorrect arg tag EXP cmd' $
74          + '!C' $
75          + 'Usage : ' + usage])
76    stop
77 ENDIF
78
79 arg_type = size(cmd.exp,/type)
80 IF (arg_type NE 7) THEN BEGIN
81   ras = report(['Incorrect arg type cmd.exp' $
82          + '!C' $
83          + 'Usage : ' + usage])
84   stop
85 ENDIF
86 tag=WHERE(STRMATCH(arg_struct_tags, 'OUT'))
87 IF (tag EQ -1) THEN BEGIN
88   ras = report(['Incorrect arg tag OUT cmd' $
89          + '!C' $
90          + 'Usage : ' + usage])
91   stop
92 ENDIF
93
94 arg_type = size(cmd.out,/type)
95 IF (arg_type NE 7) THEN BEGIN
96   ras = report(['Incorrect arg type cmd.out' $
97          + '!C' $
98          + 'Usage : ' + usage])
99   stop
100 ENDIF
101 tag=WHERE(STRMATCH(arg_struct_tags, 'GRID'))
102 IF (tag EQ -1) THEN BEGIN
103   ras = report(['Incorrect arg tag GRID cmd' $
104          + '!C' $
105          + 'Usage : ' + usage])
106   stop
107 ENDIF
108
109 arg_type = size(cmd.grid,/type)
110 IF (arg_type NE 7) THEN BEGIN
111   ras = report(['Incorrect arg type cmd.grid' $
112          + '!C' $
113          + 'Usage : ' + usage])
114   stop
115 ENDIF
116 tag=WHERE(STRMATCH(arg_struct_tags, 'VAR'))
117 IF (tag EQ -1) THEN BEGIN
118   ras = report(['Incorrect arg tag VAR cmd' $
119          + '!C' $
120          + 'Usage : ' + usage])
121   stop
122 ENDIF
123
124 arg_type = size(cmd.var,/type)
125 IF (arg_type NE 7) THEN BEGIN
126   ras = report(['Incorrect arg type cmd.grid' $
127          + '!C' $
128          + 'Usage : ' + usage])
129   stop
130 ENDIF
131 common_type=size(glamboundary_box,/type)
132 IF ((common_type NE 2) AND (common_type NE 3))THEN BEGIN
133   ras = report(['Incorrect common type glamboundary_box' $
134          + '!C' $
135          + 'Usage : ' + usage])
136   stop
137 ENDIF
138 common_type=size(box_h,/type)
139 IF ((common_type NE 2) AND (common_type NE 3)) THEN BEGIN
140   ras = report(['Incorrect common type box_h' $
141          + '!C' $
142          + 'Usage : ' + usage])
143   stop
144 ENDIF
145 common_nelem=size(box_h,/n_elements)
146 IF (common_nelem NE 4) THEN BEGIN
147   ras = report(['Incorrect common n_elements box_h' $
148          + '!C' $
149          + 'Usage : ' + usage])
150   stop
151 ENDIF
152 common_type=size(sw_diffg,/type)
153 IF (common_type NE 3) THEN BEGIN
154   ras = report(['Incorrect common type sw_diffg' $
155          + '!C' $
156          + 'Usage : ' + usage])
157   stop
158 ENDIF
159 common_type=size(data_domain,/type)
160 IF (common_type NE 7) THEN BEGIN
161   ras = report(['Incorrect common type data_domain' $
162          + '!C' $
163          + 'Usage : ' + usage])
164   stop
165 ENDIF
166
167;   varexp = cmd.exp
168
169   IF cmd.out EQ 'cdf' THEN BEGIN
170      no_shift = 1
171      whole_arrays = 1
172      ;meshlec_type = '-' ; force grid read
173      test_read = 1 ; force grid read : better test ? at least for atm grid
174      key_onearth = 1
175      glambound = 0
176  ENDIF ELSE BEGIN
177      no_shift = 0
178      whole_arrays = 0
179      tag = ''
180      key_onearth = 1
181      glambound = glamboundary_box
182   ENDELSE
183
184; If tv no key_shift
185   IF cmd.out EQ 'tv' THEN BEGIN
186      no_shift = 1
187   ENDIF
188
189; append name of variable to file ?
190   file_suff_var = ''
191   IF strpos(cmd.grid, '#') NE -1 THEN BEGIN
192      cmd.grid = strmid(cmd.grid, 0, strlen(cmd.grid)-1)
193      @def_file_suff_var
194   ENDIF
195
196   IF debug_w THEN BEGIN
197    print, '    file_suff_var = ', file_suff_var
198   ENDIF
199
200; read_grid_from_file ?
201
202   read_grid_from_file = 0
203
204   IF strpos(cmd.grid, '@') EQ 0 THEN BEGIN
205      cmd.grid = strmid(cmd.grid, 1, strlen(cmd.grid)-1)
206      read_grid_from_file = 1
207      print, '    Will read grid info '+cmd.grid+' from data file'
208      key_shift_map = 0
209      IF strpos(cmd.var, '@@') NE -1 THEN BEGIN
210         @def_macro_base_fld
211         var_read_grd_file = macro_base_fld_1
212      ENDIF ELSE BEGIN
213         var_read_grd_file = cmd.var
214      ENDELSE
215   ENDIF ELSE BEGIN
216      var_read_grd_file = cmd.var
217   ENDELSE
218
219   IF debug_w THEN BEGIN
220    print, '    cmd.grid after test read_grid_from_file: ', cmd.grid
221   ENDIF
222
223; choose grid (if not already loaded)
224
225; tests to read
226   test_box = 0
227   IF box_h[0] NE box_h_prev[0] OR box_h[1] NE box_h_prev[1] THEN BEGIN
228    test_box = 1
229   ENDIF
230   test_read = 0
231   IF cmd.grid NE cmd_prev.grid OR test_box EQ 1 THEN BEGIN
232      test_read = 1
233      suff_domain = ''
234   ENDIF ELSE BEGIN
235      suff_domain = suff_domain
236   ENDELSE
237   IF sw_diffg EQ 1 THEN BEGIN
238    test_read = 1
239   ENDIF
240
241   IF test_read EQ 1 THEN BEGIN
242 ; read attributes from Defaults/Grids/grid_config.def
243      file_grid_config = hom_def+'grid_config.def'
244      IF debug_w THEN BEGIN
245       print, '      doing: grep -i "\ '+cmd.grid+' " '+file_grid_config
246      ENDIF
247      spawn, 'grep -i "\ '+cmd.grid+' " '+file_grid_config, line
248      line = strcompress(strtrim(line[0], 2))
249      length = strlen(line)
250
251      IF debug_w THEN BEGIN
252       print, '      line from grid_config.def  ',line
253      ENDIF
254
255      IF length EQ 0 THEN BEGIN
256         print, ' *** def_grid : define grid ', cmd.grid, ' in file ', file_grid_config
257         stop
258      ENDIF ELSE BEGIN
259         argvar = strsplit(line, ' ', /EXTRACT)
260         mesh_type = argvar[1]
261         masked_data = argvar[2]
262         mesh_type2 = argvar[3]
263         vargrid = argvar[4]
264         name_level = argvar[5]
265      ENDELSE
266      meshlec_type = mesh_type
267   ENDIF
268
269   IF masked_data EQ 0 THEN BEGIN
270    atmos_msk = 0
271   ENDIF
272
273; init zoom for data read
274
275   IF data_domain EQ 'global' THEN BEGIN
276      ixmindta = 0
277      iymindta = 0
278      izmindta = 0
279   ENDIF
280   IF debug_w THEN BEGIN
281    print, '     varexp in def_grid before case cmd.grid:', varexp
282   ENDIF
283
284   IF read_grid_from_file EQ 1 THEN BEGIN
285    GOTO, final
286   ENDIF
287   CASE cmd.grid OF
288      't30': BEGIN
289         IF test_read EQ 1 THEN BEGIN
290            mesh_gaussian, 30, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, glamboundary = glambound
291            domdef & triangles=triangule()
292        ENDIF
293      END
294      't42': BEGIN
295         IF test_read EQ 1 THEN BEGIN
296            mesh_gaussian, 42, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, glamboundary = glambound
297            domdef & triangles=triangule()
298         ENDIF
299      END
300      't62': BEGIN
301         IF test_read EQ 1 THEN BEGIN
302            mesh_gaussian, 62, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, glamboundary = glambound
303            domdef & triangles=triangule()
304         ENDIF
305      END
306      't106': BEGIN
307         IF test_read EQ 1 THEN BEGIN
308            mesh_gaussian, 106, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, glamboundary = glambound
309            domdef & triangles=triangule()
310         ENDIF
311      END
312      'umat': BEGIN
313         IF test_read EQ 1 THEN BEGIN
314            mesh_um, 96, 73, 'T', NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, /reverse_y
315            domdef & triangles=triangule()
316         ENDIF
317      END
318      'umau': BEGIN
319         IF test_read EQ 1 THEN BEGIN
320            mesh_um, 96, 72, 'U', NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, /reverse_y
321            domdef & triangles=triangule()
322         ENDIF
323      END
324      'umath': BEGIN
325         IF test_read EQ 1 THEN BEGIN
326            mesh_um, long(288), long(217), 'T', NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays
327            domdef & triangles=triangule()
328         ENDIF
329      END
330      'umauh': BEGIN
331         IF test_read EQ 1 THEN BEGIN
332            mesh_um, long(288), long(216), 'U', NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays
333            domdef & triangles=triangule()
334        ENDIF
335      END
336      'reg1.125': BEGIN
337         IF test_read EQ 1 THEN BEGIN
338          read_grid_from_file = 1
339         ENDIF
340      END
341;      'reg2.5': BEGIN
342;         IF test_read EQ 1 THEN BEGIN
343;           read_grid_from_file = 1
344;         ENDIF
345;      END
346      'reg1m': BEGIN
347         IF test_read EQ 1 THEN BEGIN
348          read_grid_from_file = 1
349         ENDIF
350      END
351      'reg1': BEGIN
352         IF test_read EQ 1 THEN BEGIN
353          read_grid_from_file = 1
354         ENDIF
355      END
356      'reg1mtrop': BEGIN
357         IF test_read EQ 1 THEN BEGIN
358                                ; j in [69,110] (20.5S,20.5N)
359            mesh_regular, 1., 1., inilon = -179.5, mask_file = 'hadisst1', j_index =69, delta_j = 42, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, glamboundary = glambound
360            domdef & triangles=triangule()
361         ENDIF
362      END
363      'tao': BEGIN
364         IF test_read EQ 1 THEN BEGIN
365            mesh_tao, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays
366            domdef & triangles=triangule()
367         ENDIF
368      END
369;       'new_grid': BEGIN
370;          IF test_read EQ 1 THEN BEGIN
371;             mesh_new_grid ...
372;             domdef & triangles=triangule()
373;          ENDIF
374;       END
375      ELSE: BEGIN
376         ; nc_grids_list defined in plt_def.pro
377         indx = where(nc_grids_list EQ cmd.grid)
378         IF indx NE -1 THEN BEGIN
379            IF test_read EQ 1 THEN BEGIN
380               mesh_pcmdi, cmd.grid, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays
381               domdef & triangles=triangule()
382            ENDIF
383         ENDIF ELSE BEGIN
384
385            h_config_oce = 'ORCA_R2'
386            IF strpos (cmd.grid, '05') NE -1 THEN BEGIN
387             h_config_oce = 'ORCA05'
388            ENDIF
389
390            IF meshlec_type NE 'oce' OR data_dom_type NE data_domain OR h_config_oce_type NE h_config_oce OR v_config_oce_type NE v_config_oce OR orca_mask_version_type NE orca_mask_version OR test_box EQ 1 OR test_read EQ 1 THEN BEGIN
391               CASE data_domain OF
392                  'equator': BEGIN
393                     mesh_orca, j_index=73, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
394                     suff_domain = '_eq'
395                     domdef
396                  END
397                  'equator_band': BEGIN
398                                ; j in [64,82] (5S,5N)
399                     mesh_orca, j_index=64, delta_j = 19, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
400                     suff_domain = '_eqb'
401                     domdef
402                  END
403                  'pacific': BEGIN
404                                ; j in [49,97] (30S,30N), i in
405                                ; [16,106] (110E,290), k in [1-19] for ORCA2L30
406                                ; (0.,364 m)
407                     CASE h_config_oce of
408                        'ORCA_R2': mesh_orca, j_index=49, delta_j = 49, i_index = 16, delta_i =91, k_index = 1, delta_k = 19, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
409                        'ORCA05': mesh_orca, j_index=183, delta_j = 130, i_index = 54, delta_i =381, k_index = 1, delta_k = 19, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
410                     ENDCASE
411                     suff_domain = '_pac'
412                     domdef
413                     triangles=triangule()
414                  END
415                  'pacific_eq': BEGIN
416                                ; j in [64,82] (5S,5N), i in [16,106] (110E,290)
417                     mesh_orca, j_index=64, delta_j = 19, i_index = 16, delta_i =91, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays , H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
418                     suff_domain = '_paceq'
419                     domdef
420                  END
421                  'zonal': BEGIN
422                     mesh_orca, /zonal, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
423                     suff_domain = '_diaznl'
424                     domdef
425                  END
426                  'glosea': BEGIN
427                     mesh_glosea, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays
428                     suff_domain = '_glosea'
429                     domdef
430                     triangles=triangule()
431                  END
432                  ELSE: BEGIN
433                     IF cmd.grid EQ 'BMT' OR cmd.grid EQ 'BMU' OR cmd.grid EQ 'BMV' THEN BEGIN
434                        mesh_micom, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
435                        ;; We Need to redefine vargrid because it
436                        ;; has changed when call to initncdf
437                        vargrid = argvar[4]
438                        suff_domain = ''
439                     ENDIF ELSE BEGIN
440                        mesh_orca, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays, H_CONFIG = h_config_oce, V_CONFIG = v_config_oce
441                        suff_domain = ''
442                        domdef
443                        triangles=triangule()
444                     ENDELSE
445                  END
446               ENDCASE
447               masked_data = 1
448               meshlec_type = 'oce'
449               mesh_type = 'oce'
450               data_dom_type = data_domain
451               h_config_oce_type = h_config_oce
452               v_config_oce_type = v_config_oce
453               orca_mask_version_type = orca_mask_version
454            ENDIF
455         ENDELSE
456      END
457   ENDCASE
458
459   key_shift_map = key_shift
460
461   IF read_grid_from_file EQ 1 THEN BEGIN
462      ; def base field if macro
463 ; needed ?     cmd.grid = strmid(cmd.grid, 0, strlen(cmd.grid)-1)
464      @def_file_suff_var
465      var_read_grd_file = macro_base_fld
466      file_suff_var = ''
467   ENDIF
468
469final:
470
471   box_h_prev = box_h
472
473   IF debug_w THEN BEGIN
474    print, '     cmd.grid:          ', cmd.grid
475    print, '     file_suff_var:     ', file_suff_var
476    print, '     var_read_grd_file: ', var_read_grd_file
477    print, '     meshlec_type:      ', meshlec_type
478    print, '     varexp:            ', varexp
479    info = report('leaving...')
480   ENDIF
481
482END
Note: See TracBrowser for help on using the repository browser.