1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
4 | ; Allows to pass from a 2d depth array to a corresponding 2d level array. |
---|
5 | ; |
---|
6 | ; @categories |
---|
7 | ; Without loop |
---|
8 | ; |
---|
9 | ; @param TAB {type=2d array} |
---|
10 | ; 2d depth array (or a structure respecting litchamp criterions) |
---|
11 | ; |
---|
12 | ; @keyword UPPER |
---|
13 | ; (activated by default) We select the level just above the depth |
---|
14 | ; |
---|
15 | ; @keyword LOWER |
---|
16 | ; We select the level just below the depth |
---|
17 | ; |
---|
18 | ; @keyword CLOSER |
---|
19 | ; We select the depth's closer level |
---|
20 | ; |
---|
21 | ; @keyword NOMASK |
---|
22 | ; To do not mask land points |
---|
23 | ; |
---|
24 | ; @returns |
---|
25 | ; It is a 2d array containing level's values. |
---|
26 | ; |
---|
27 | ; @uses |
---|
28 | ; common.pro |
---|
29 | ; |
---|
30 | ; @restrictions |
---|
31 | ; For depths out of gdep's values, the value !values.f_nan is sent back. |
---|
32 | ; if the depth is superior to this one of the bottom, we send back jpk-1 in |
---|
33 | ; the upper case, and !values.f_nan in the lower case. |
---|
34 | ; |
---|
35 | ; @history |
---|
36 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
37 | ; 17/6/1999 |
---|
38 | ; 15/6/2000 accepte !values.f_nan |
---|
39 | ; |
---|
40 | ; @version |
---|
41 | ; $Id$ |
---|
42 | ;- |
---|
43 | ; |
---|
44 | FUNCTION depth2level, tab, LOWER = lower, UPPER = upper, CLOSER = closer $ |
---|
45 | , NOMASK = nomask, _EXTRA = ex |
---|
46 | ; |
---|
47 | compile_opt idl2, strictarrsubs |
---|
48 | ; |
---|
49 | tempsun = systime(1) ; for key_performance |
---|
50 | @common |
---|
51 | ;------------------------------------------------------------ |
---|
52 | upper = 1 |
---|
53 | if keyword_set(lower) THEN upper = 0 |
---|
54 | ;------------------------------------------------------------ |
---|
55 | ; Reading of the input field and recuperation of the used subdomain's size |
---|
56 | ;------------------------------------------------------------ |
---|
57 | in = litchamp(tab) |
---|
58 | grille,mask,-1,-1,gdep,nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz |
---|
59 | ;--------------------------------------------------------------- |
---|
60 | ; Verification of the coherence between array's size and the defined by domdef domain |
---|
61 | ;--------------------------------------------------------------- |
---|
62 | IF ny EQ 1 THEN in = reform(in, nx, ny, /over) |
---|
63 | taille = size(in) |
---|
64 | if taille[0] NE 2 then return, report('le champ en entree doit contenir un tableau 2d') |
---|
65 | case 1 of |
---|
66 | taille[1] eq jpi and taille[2] eq jpj:in=in[firstx:lastx, firsty:lasty] |
---|
67 | taille[1] eq nx and taille[2] eq ny: |
---|
68 | else:return, report('Probleme d''adequation entre les tailles du domaine et celle du champ.') |
---|
69 | endcase |
---|
70 | ;------------------------------------------------------------ |
---|
71 | ;------------------------------------------------------------ |
---|
72 | ;------------------------------------------------------------ |
---|
73 | ; delete points at !values.f_nan |
---|
74 | notanumber = where(finite(in, /nan) EQ 1) |
---|
75 | if notanumber[0] NE -1 then in[notanumber] = 0 |
---|
76 | ;------------------------------------------------------------ |
---|
77 | ; We transform the 2d depth value in a 2d array of levels corresponding to depths |
---|
78 | ;------------------------------------------------------------ |
---|
79 | ; We go on array who have the size of 3d arrays |
---|
80 | prof=replicate(1,nx*ny)#gdep[firstz:lastz] |
---|
81 | in = in[*]#replicate(1, nz) |
---|
82 | ; |
---|
83 | mask01 = (prof[*] LT in[*]) |
---|
84 | mask01 = reform(mask01, nx, ny, nz) |
---|
85 | levels = total(mask01, 3) |
---|
86 | notvalid = where(levels EQ nz) |
---|
87 | if keyword_set(upper) then begin |
---|
88 | levels = levels-1 |
---|
89 | notvalid = where(levels EQ -1) |
---|
90 | ENDIF ELSE notvalid = where(levels EQ nz) |
---|
91 | IF notvalid[0] NE -1 THEN levels[notvalid] = !values.f_nan |
---|
92 | |
---|
93 | ; If closer is activated |
---|
94 | if keyword_set(closer) then begin |
---|
95 | test = [ [[litchamp(tab)-level2depth(levels)]] $ |
---|
96 | , [[level2depth( (levels+1)<(jpk-1) )-litchamp(tab)]] ] |
---|
97 | test = test[*, *, 0]-test[*, *, 1] |
---|
98 | changer = where(test GE 0) |
---|
99 | if changer[0] NE -1 then levels[changer] = (levels[changer]+1) < (jpk-1) |
---|
100 | endif |
---|
101 | ;------------------------------------------------------------ |
---|
102 | ; We put back points at !values.f_nan |
---|
103 | if notanumber[0] NE -1 then levels[notanumber] = !values.f_nan |
---|
104 | ; We mask land points at valmask |
---|
105 | if NOT keyword_set(nomask) then begin |
---|
106 | if n_elements(valmask) EQ 0 then valmask = 1e20 |
---|
107 | terre = where(mask[*, *, 0] EQ 0) |
---|
108 | if terre[0] NE -1 then levels[terre] = valmask |
---|
109 | endif |
---|
110 | ;------------------------------------------------------------ |
---|
111 | ;------------------------------------------------------------ |
---|
112 | ;------------------------------------------------------------ |
---|
113 | if keyword_set(key_performance) THEN print, 'temps depth2level', systime(1)-tempsun |
---|
114 | return, levels |
---|
115 | end |
---|