1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; NAME: depth2level |
---|
6 | ; |
---|
7 | ; PURPOSE: permet de passer d''un tableau 2d de profondeur au tableau |
---|
8 | ; 2d correspondant de niveaux. |
---|
9 | ; |
---|
10 | ; CATEGORY: SANS BOUCLE |
---|
11 | ; |
---|
12 | ; CALLING SEQUENCE: res=depth2level(depth2d) |
---|
13 | ; |
---|
14 | ; INPUTS: depth2d tableau 2d de profondeur (ou une structure repondant |
---|
15 | ; aux criteres de litchamp) |
---|
16 | ; |
---|
17 | ; KEYWORD PARAMETERS: |
---|
18 | ; |
---|
19 | ; /UPPER: (active par defaut) on selectionne le niveau |
---|
20 | ; directement au dessus de la profondeur |
---|
21 | ; |
---|
22 | ; /LOWER: on selectionne le niveau directement au dessous de la |
---|
23 | ; profondeur |
---|
24 | ; |
---|
25 | ; /CLOSER: on selectionne le niveau le plus proche de la |
---|
26 | ; profondeur |
---|
27 | ; |
---|
28 | ; /NOMASK: pour ne pas masquer les points terres |
---|
29 | ; |
---|
30 | ; OUTPUTS: un tableau 2d contenant les valeurs des niveaux. |
---|
31 | ; |
---|
32 | ; COMMON BLOCKS:common.pro |
---|
33 | ; |
---|
34 | ; SIDE EFFECTS:pour les profondeurs hors des valeurs de gdep, la |
---|
35 | ; valeur !values.f_nan est retournee. |
---|
36 | ; Si la profondeur est superieur a celle du fond, on retourne |
---|
37 | ; jpk-1dans le cas upper, et !values.f_nan ds le cas lower. |
---|
38 | ; |
---|
39 | ; RESTRICTIONS: |
---|
40 | ; |
---|
41 | ; EXAMPLE: |
---|
42 | ; |
---|
43 | ; MODIFICATION HISTORY: Sebastien Masson (smasson@lodyc.jussieu.fr) |
---|
44 | ; 17/6/1999 |
---|
45 | ; 15/6/2000 accepte !values.f_nan |
---|
46 | ;- |
---|
47 | ;------------------------------------------------------------ |
---|
48 | ;------------------------------------------------------------ |
---|
49 | ;------------------------------------------------------------ |
---|
50 | FUNCTION depth2level, tab, LOWER = lower, UPPER = upper, CLOSER = closer $ |
---|
51 | , NOMASK = nomask, _extra = ex |
---|
52 | tempsun = systime(1) ; pour key_performance |
---|
53 | @common |
---|
54 | ;------------------------------------------------------------ |
---|
55 | upper = 1 |
---|
56 | if keyword_set(lower) THEN upper = 0 |
---|
57 | ;------------------------------------------------------------ |
---|
58 | ; lecture du champ d''entree et recuperation de la taille du sous |
---|
59 | ; domaine utilise |
---|
60 | ;------------------------------------------------------------ |
---|
61 | in = litchamp(tab) |
---|
62 | grille,mask,glam,gphi,gdep,nx,ny,nz,premierx,premiery,premierz,dernierx,derniery,dernierz |
---|
63 | glam = 1 |
---|
64 | gphi = 1 |
---|
65 | ;--------------------------------------------------------------- |
---|
66 | ; verification de la coherence entre la taille du tableau et le domaine definit par domdef |
---|
67 | ;--------------------------------------------------------------- |
---|
68 | IF ny EQ 1 THEN in = reform(in, nx, ny, /over) |
---|
69 | taille = size(in) |
---|
70 | if taille[0] NE 2 then return, report('le champ en entree doit contenir un tableau 2d') |
---|
71 | case 1 of |
---|
72 | taille[1] eq jpi and taille[2] eq jpj:in=in[premierx:dernierx, premiery:derniery] |
---|
73 | taille[1] eq nx and taille[2] eq ny: |
---|
74 | else:return, report('Probleme d''adequation entre les tailles du domaine et celle du champ.') |
---|
75 | endcase |
---|
76 | ;------------------------------------------------------------ |
---|
77 | ;------------------------------------------------------------ |
---|
78 | ;------------------------------------------------------------ |
---|
79 | ; vire les points a !values.f_nan |
---|
80 | notanumber = where(finite(in, /nan) EQ 1) |
---|
81 | if notanumber[0] NE -1 then in[notanumber] = 0 |
---|
82 | ;------------------------------------------------------------ |
---|
83 | ; on transforme le tableau 2d de profondeur en tableau 2d de niveaux |
---|
84 | ; correspondant aux profondeurs |
---|
85 | ;------------------------------------------------------------ |
---|
86 | ; on passe en tableaux qui ont la taille des tableaux 3d |
---|
87 | prof=replicate(1,nx*ny)#gdep[premierz:dernierz] |
---|
88 | in = in[*]#replicate(1, nz) |
---|
89 | ; |
---|
90 | mask01 = (prof[*] LT in[*]) |
---|
91 | mask01 = reform(mask01, nx, ny, nz) |
---|
92 | levels = total(mask01, 3) |
---|
93 | notvalid = where(levels EQ nz) |
---|
94 | if keyword_set(upper) then begin |
---|
95 | levels = levels-1 |
---|
96 | notvalid = where(levels EQ 0) |
---|
97 | ENDIF ELSE notvalid = where(levels EQ nz) |
---|
98 | IF notvalid[0] NE -1 THEN levels[notvalid] = !values.f_nan |
---|
99 | |
---|
100 | ; si closer est active |
---|
101 | if keyword_set(closer) then begin |
---|
102 | test = [ [[litchamp(tab)-level2depth(levels)]] $ |
---|
103 | , [[level2depth( (levels+1)<(jpk-1) )-litchamp(tab)]] ] |
---|
104 | test = test[*, *, 0]-test[*, *, 1] |
---|
105 | changer = where(test GE 0) |
---|
106 | if changer[0] NE -1 then levels[changer] = (levels[changer]+1) < (jpk-1) |
---|
107 | endif |
---|
108 | ;------------------------------------------------------------ |
---|
109 | ; on replace les points a !values.f_nan |
---|
110 | if notanumber[0] NE -1 then levels[notanumber] = !values.f_nan |
---|
111 | ; on masque les points terres a valmask |
---|
112 | if NOT keyword_set(nomask) then begin |
---|
113 | if n_elements(valmask) EQ 0 then valmask = 1e20 |
---|
114 | terre = where(mask[*, *, 0] EQ 0) |
---|
115 | if terre[0] NE -1 then levels[terre] = valmask |
---|
116 | endif |
---|
117 | ;------------------------------------------------------------ |
---|
118 | ;------------------------------------------------------------ |
---|
119 | ;------------------------------------------------------------ |
---|
120 | if keyword_set(key_performance) THEN print, 'temps depth2level', systime(1)-tempsun |
---|
121 | return, levels |
---|
122 | end |
---|